Jump to content
Sign in to follow this  
theavonlady

Question about AddEventHandler ["Killed",]

Recommended Posts

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? rock.gif

TIA. smile_o.gif

Share this post


Link to post
Share on other sites

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

smile_o.gif

anyway the sintax is wrong; you must call a script in the event handler.

sorry for bad english  biggrin_o.gif

Share this post


Link to post
Share on other sites
don't use event handler "killed" in this case;

Why not? Isn't this exactly what it's for? rock.gif

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? rock.gif

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
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
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 biggrin_o.gif

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

smile_o.gif

Share this post


Link to post
Share on other sites

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
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 biggrin_o.gif

Share this post


Link to post
Share on other sites
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 biggrin_o.gif

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! wink_o.gif

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×