theavonlady 2 Posted October 18, 2004 I've never used event handlers before. I want to do somethimg in an SP mission which should be very simple. If the player kills a particular AI unit, add 3000 points to the mission score. Now I'm totally unfamiliar with event handlers, down to their syntax and usage. Would the following code in the AI unit's INIT field do the trick? <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">this addeventhandler ["killed",{_this select 1 addRating 3000}] Is that the correct syntax? TIA. Share this post Link to post Share on other sites
xenom 0 Posted October 18, 2004 don't use event handler "killed" in this case; add a trigger, place in the condition field: !(alive A), where A is the particular AI unit. in the init flied write the execute command to a script or write a command. simple example: trigger: activation: none condition: !(Alive unit) init: player addRating 3000 anyway the sintax is wrong; you must call a script in the event handler. sorry for bad english  Share this post Link to post Share on other sites
theavonlady 2 Posted October 18, 2004 don't use event handler "killed" in this case; Why not? Isn't this exactly what it's for? Quote[/b] ]add a trigger, place in the condition field: !(alive A), where A is the particular AI unit.in the init flied write the execute command to a script or write a command. I don't understand this. INIT field of a trigger? What's that? Init field of the AU unit? What will this script contain? If in the addEventHandler command, what else will tell me who killed the AI unit? And if the script does contain the addEventHandler command, why can't I code it right in the AI unit's INIT field, as I originally asked? Quote[/b] ]anyway the sintax is wrong; you must call a script in the event handler. I've seen addEventHandler examples that don't call scripts. For example, they contain "hint" commands, etc. Share this post Link to post Share on other sites
theavonlady 2 Posted October 18, 2004 trigger:activation: none condition: !(Alive unit) init: player addRating 3000 No. What if another AI unit on the player's side killed the enemy AI unit? I only want the player's score changed if the player did the kill. Share this post Link to post Share on other sites
xenom 0 Posted October 18, 2004 trigger:activation: none condition: !(Alive unit) init: player addRating 3000 No. What if another AI unit on the player's side killed the enemy AI unit? I only want the player's score changed if the player did the kill. it's true, sorry well, you must use the event handler. this is sintax: object addEventHandler ["killed",{_this exec "unitKilled.sqs"}] and then create the "unitKilled" script (i'm not sure, try also use object addEventHandler ["killed",{(_this select 1) addRating 3000}]): _array = _this select 0 _killed = _array select 0 _killer = _array select 1 _killer addrating 3000 exit Share this post Link to post Share on other sites
Sui 0 Posted October 18, 2004 Err... it's really not. Try sticking some brackets around the _this select 1 in your original code, Ma'am ;) this addeventhandler ["killed",{(_this select 1) addRating 3000}] Share this post Link to post Share on other sites
xenom 0 Posted October 18, 2004 Err... it's really not.Try sticking some brackets around the _this select 1 in your original code, Ma'am ;) this addeventhandler ["killed",{(_this select 1) addRating 3000}] yes, try Share this post Link to post Share on other sites
theavonlady 2 Posted October 18, 2004 Err... it's really not.Try sticking some brackets around the _this select 1 in your original code, Ma'am ;) this addeventhandler ["killed",{(_this select 1) addRating 3000}] yes, try Even multiple commands worked! <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_unit addEventHandler ["killed",{(_this select 1) addRating 3000; hint "eventhandler on"}] Thanks everyone for your help! Share this post Link to post Share on other sites