Created
April 16, 2017 18:12
-
-
Save DouglasSherk/64944b340105c2b3ac5e78a0e66cc691 to your computer and use it in GitHub Desktop.
ARP NPCs API simplified.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ARP_Core.sma | |
// Handler for NPC registration API call | |
public _ARP_RegisterNpc(plugin, params) { | |
new ent = create_entity("info_target") | |
entity_set_string(ent, EV_SZ_classname, NPC_CLASSNAME) // "arp_npc" | |
entity_set_string(ent, EV_SZ_model, NPC_MODEL) // "711clerk" | |
// Store the registering plugin on the NPC so we can notify it of events later | |
entity_set_int(ent, EV_INT_iuser3, plugin) | |
// ... set other parameters passed from plugin | |
} | |
// Called on every server frame for every client | |
public client_PreThink(id) { | |
new ent = looking_at_npc(id) | |
// Check if the user is looking at an entity and holding down the "Use" button | |
if (ent && entity_get_int(id,EV_INT_button) & IN_USE) { | |
// Get the plugin from the entity which we registered earlier | |
new plugin = entity_get_int(ent, EV_INT_iuser3) | |
// Send a callback to the plugin notifying it that the NPC was "used" (chatted with) | |
notify_plugin_of_use(plugin, ent) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment