Skip to content

Instantly share code, notes, and snippets.

@DouglasSherk
Created April 16, 2017 18:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DouglasSherk/64944b340105c2b3ac5e78a0e66cc691 to your computer and use it in GitHub Desktop.
Save DouglasSherk/64944b340105c2b3ac5e78a0e66cc691 to your computer and use it in GitHub Desktop.
ARP NPCs API simplified.
// 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