Thread: Lua Callbacks
View Single Post
Old 09-27-2007, 04:38 AM   #1
Mulchman MM
Retired FF Staff
 
Mulchman MM's Avatar
 
Join Date: Dec 2004
Location: Lacey, WA
Posts Rated Helpful 0 Times
Send a message via ICQ to Mulchman MM Send a message via AIM to Mulchman MM Send a message via MSN to Mulchman MM Send a message via Yahoo to Mulchman MM Send a message via Skype™ to Mulchman MM
Lua Callbacks

Okay, I started documenting the callbacks but got tired of it very quickly. This is sort of a high level programmer type overview as that's the quickest way I could do this. This documents a lot but not all of the callbacks the game makes into Lua. I started writing it as a .doc for a PM so that's why the format is like I'm talking to someone specifically or something.

Quote:
Okay, Lua callbacks.

In quotations is the callback name (and case). Next is whether the function is global or is invoked on an existing object. If invoked on an object then the word “entity” is available to the Lua script as the actual object the script is being called on – so you could do stuff like “IsPlayer(entity)” even if there’s no mention of entity in the function already. If it’s a global function then “entity” is nil. Next are any arguments – the forward slash should be treated as an “or”, and commas will be used to designate multiple arguments. Next is the return value – “none” indicates no return value is needed. Finally, there’s a short description of when it’s used or something.

“startup” – global – () – none – called during ff_restartround. I think it should be called during map startup as well but I didn’t check

“validspawn” – info_ff_teamspawn – (CFFPlayer *) – true / false – called on a spawn point and returns true/false for whether the player can spawn at the spawn point

“validtarget” – ff_miniturret – (CBaseEntity *) – true / false – called on a turret to see if the player / sg / dispenser it is targeting is a valid target or not [cast appropriately]

“deploydelay” – ff_miniturret – (CBaseEntity *) – float – called on a turret to get the delay until it should deploy [the parameter could be a player / sg / dispenser but is sent as a CBaseEntity * and would need to be cast appropriately before anything was done to it)

“onownercloak” – CBaseEntity * [ie. info_ff_script] - (CFFPlayer *) – none – called on each info_ff_script the player ‘owns’ (is carrying) so that the entity can be notified the player is cloaking and do something about it (get dropped perhaps)

“spawn” – trigger_ff_clip – () – none – called when a trigger_ff_clip gets spawned

“player_killed” – global – (CFFPlayer *, CTakeDamageInfo *) – none – called when a player is killed. On /kill no CTakeDamageInfo is passed along . On changing class this is also called with no CTakeDamageInfo. On changing team this is also called with no CTakeDamageInfo.

Okay, I’m already tired of doing this. I’m just going to jump to player specific stuff…

“player_onkill” – global – (CFFPlayer *) – true / false – called to see whether the player can /kill themselves or not

“player_spawn” – global – (CFFPlayer *) – none – called when a player is spawning

“player_switchteam” – global – (CFFPlayer *, current team number [int], proposed team number [int]) – true / false – called when a player tries to switch team

“flaginfo” – global – (CFFPlayer *) – none – called when a player hits their flaginfo key

“dropitemcmd” – CBaseEntity * [ie. info_ff_script] – (CFFPlayer *) – none – called on each item the player ‘owns’ when the player hits their drop items button

“player_onthrowgren1 / 2” – global – (CFFPlayer *, prime time [float]) – true / false – called when trying to release a grenade

“player_ondamage” – global – (CFFPlayer *, CTakeDamageInfo *) – none – called when a player takes damage. The CTakeDamageInfo can be modified by Lua.

And I’m kind of done for the moment. There’s a ton of the Lua effect ones that need to be documented. Most of these allow you to change or deny the effect, change the duration of the effect [with -1 being infinite], and change the icon duration [like the status icon (again with -1 being infinite)]. Most of these take player being effected and then a CBaseEntity * of the entity/player doing the effecting.

These events start with “onplayer%s” and fill %s with:

“fire”, “conc”, “gas”, “infect”, “radiotag”, “headshot”, “legshot”, “tranq”, “caltrop”, “acspinup”, “sniperrifle”, speedlua1”, “speedlua2”, up to “speedlua10” (so you could have up 10 speed effects Lua controlled).

Duration is initially set to 0, icon duration is initially set to 0, and speed is initially set to 0. If any of the events don’t use these they’ll always stay 0 otherwise they’ll be filled in with the default values for you to modify and return back to the game.

These variables are “%s_duration”, “%s_iconduration”, “%s_speed” where %s are the events listed above (like “fire”, “conc”, etc).

So, in Lua you’d have something like:

Code:
-- player_entity is guy getting conc’d
-- effector_entity is the one doing the conc’ing
function player_onconc(player_entity, effector_entity)
	-- make conc effect last 20 seconds
conc_duration = 20
-- make conc status icon last 1 second
	conc_iconduration = 1

	return EVENT_ALLOWED
	-- or you can just return “true” to let the conc happen. If you return false no conc
-- effect happens
end
Hopefully some of this helps.
__________________
Head of the Orca Revolution (TM)

Last edited by Mulchman MM; 09-27-2007 at 04:44 AM.
Mulchman MM is offline   Reply With Quote