Skip to content

Commit

Permalink
add altv::ScriptEventController
Browse files Browse the repository at this point in the history
  • Loading branch information
xxshady committed Jun 18, 2023
1 parent 3eb148d commit d2221da
Show file tree
Hide file tree
Showing 7 changed files with 261 additions and 28 deletions.
12 changes: 12 additions & 0 deletions altv/src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@
//! });
//!
//! altv::events::emit("example", &[&true, &123])?;
//!
//! // Event handler can also be removed later
//! let mut controller = altv::events::on("example", |event| {});
//! controller.destroy()?; // ok
//! controller.destroy()?; // err "Already destroyed"
//!
//! # Ok(()) }
//! ```
//!
Expand All @@ -42,13 +48,19 @@
//! altv::log!("args: {args:?}"); // args: (true, 123)
//! Ok(())
//! });
//!
//! // Event handler can also be removed later
//! let mut controller = altv::events::on_player("example", |event| {});
//! controller.destroy()?; // ok
//! controller.destroy()?; // err "Already destroyed"
//! # Ok(()) }
//! ```

use core_resource::exports::{events, IntoVoidResult};
pub use events::{
emit, emit_all_players, emit_all_players_unreliable, emit_some_players,
emit_some_players_unreliable, on, on_player, ClientEventContext, FireInfo, LocalEventContext,
ScriptEventController, LocalEventController, ClientEventController,
};

pub use events::custom_contexts::*;
Expand Down
5 changes: 4 additions & 1 deletion core_resource/src/exports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,10 @@ pub mod events {
add_custom_handler, add_sdk_handler, custom_contexts, sdk_contexts, structs::FireInfo,
CustomHandler, SDKHandler,
},
script_events::{emit, on, on_player, ClientEventContext, LocalEventContext},
script_events::{
emit, on, on_player, ClientEventContext, LocalEventContext, ScriptEventController,
LocalEventController, ClientEventController,
},
};
}

Expand Down
2 changes: 1 addition & 1 deletion core_resource/src/ped.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::{
base_objects::{ped},
base_objects::ped,
helpers::{self, Hash, IntoHash},
meta::entity_stream_synced_meta::StreamSyncedEntityMeta,
sdk,
Expand Down
10 changes: 10 additions & 0 deletions core_resource/src/resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ pub struct Resource {
pub timer_schedule: RefCell<timers::ScheduleState>,
pub events: RefCell<events::EventManager>,
pub local_script_events: RefCell<script_events::LocalEventManager>,
pub local_script_events_schedule: RefCell<script_events::LocalEventSchedule>,
pub client_script_events: RefCell<script_events::ClientEventManager>,
pub client_script_events_schedule: RefCell<script_events::ClientEventSchedule>,
pub base_objects: RefCell<base_objects::Store>,
pub pending_base_object_destroy_or_creation: RefCell<base_objects::PendingDestroyOrCreation>,
pub alt_resources: RefCell<alt_resource::AltResourceManager>,
Expand Down Expand Up @@ -135,7 +137,15 @@ impl Resource {
impl_borrow_mut_fn!(timer_schedule, timers::ScheduleState);
impl_borrow_mut_fn!(events, events::EventManager);
impl_borrow_mut_fn!(local_script_events, script_events::LocalEventManager);
impl_borrow_mut_fn!(
local_script_events_schedule,
script_events::LocalEventSchedule
);
impl_borrow_mut_fn!(client_script_events, script_events::ClientEventManager);
impl_borrow_mut_fn!(
client_script_events_schedule,
script_events::ClientEventSchedule
);
impl_borrow_mut_fn!(base_objects, base_objects::Store);
impl_borrow_fn!(base_objects, base_objects::Store);
impl_borrow_mut_fn!(
Expand Down
Loading

0 comments on commit d2221da

Please sign in to comment.