Function cfx::events::subscribe [−][src]
pub fn subscribe<'a, In>(
event_name: &'a str,
scope: EventScope
) -> impl Stream<Item = Event<'a, In>> where
In: for<'de> Deserialize<'de> + 'a,
Expand description
Subscribes on an event with the given name.
Every time that an event is triggered this function decodes a raw message using messagepack.
Example
ⓘ
struct GiveMoney { to: String, // player name amount: u32 // amount of money } let events = fivem::events::subscribe::<GiveMoney>("myCustomEvent"); while let Some(event) = events.next().await { let source = event.source.clone(); let name_from_src = ...; let data = event.into_inner(); // consume an event and take GiveMoney let msg = format!("{} wants to give {} ${}", name_from_src, data.to, data.amount); }