Jump to content
Sign in to follow this  
D.murphy man

Who ever killed man1 gets a reward!

Recommended Posts

Hey guys i tried searching but suprisingly only came up with one or 2 vauge answers and nothing solid.

My proplem is this.

I want to detect what player killed another player and then hand out a reward.

Somthing along the lines of:

?(man1 killed man2) : man1_reward_money=man1_reward_money+100;man2_money=man2_money-100

Of course this would not work, inless theres a killed command im not aware of? rock.gif so im asking you kind lot to once again help me find a solution! biggrin_o.gif

Any one got an idea?

Share this post


Link to post
Share on other sites

Hmm never thought of that, but 'the guy' will be respawning as this is a MP mission so it might cause some proplems in detecting the distance of the killer to the victem when he is killed., as well as what if the killer sniped the vistem of from a long distance?

Edit: Ok i have manage to script a work around for my little proplem, so thanks for the help anyway. This is what ive done, just incase itll help any one else in my posistion:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">; Select the Unit

_deadguy = _this select 0

_timetilldelete=0

#check?

_timetilldelete=_timetilldelete+1

_bandit= nearestobject [_deadguy, "SoldierGB"]

? _deadguy distance _bandit <=3 : goto "check2"

? _timetilldelete => 120 : deletevehicle _deadguy;exit

~1

goto "check?"

;---------------------------------

#check2

?(_bandit == man1) : goto "man1reward"

?(_bandit == man2) : goto "man2reward"

exit

;----------------------------------

#man1reward

man1 groupchat format ["you have searched the body and found %1 scrap and %2 food", _deadguyscrap, _deadguyfood]

man1food=man1food+_deadguyfood

man1scrap=man1scrap+_deadguyscrap

~10

deletevehicle _deadguy

;-------------------------

#man2reward

man2 groupchat format ["you have searched the body and found %1 scrap and %2 food", _deadguyscrap, _deadguyfood]

man2food=man2food+_deadguyfood

man2scrap=man2scrap+_deadguyscrap

~10

deletevehicle _deadguy

;---------------------------

exit

This is for 2 players one called 'man1' and the other called 'man2', when one of the pair is killed the body will be deleted after 2 minutes, inless the killer, or the victem returns to within 3 meters of the corpse where they will be rewarded with the mans 'scrap' and 'food'; for example man1 kills man2, walks up to man2s body and collects all of man2's food and scrap. this should be activated with a Killed eventhandeler. and require varibles set for 'man1scrap' and 'man1food' and the same again with 'man2scrap' and 'man2food'.

Edit2:

Darn that dosent work, strang but on further testing it fails to work, the dead guy keeps detecting himself as 'bandit' so he keeps rewarding him self scrap...

Share this post


Link to post
Share on other sites

You should use the killed-eventhandler.

A description of how it must be used should be found by searching.

Share this post


Link to post
Share on other sites
Quote[/b] ]

man1 addEventHandler [{killed},{man1 exec {killdetect.sqs}}]

Put that into the init of the unit, or exec it from init.sqs or something so all players have the eventhandler added properly to whichever unit is supposed to have it.  Then have this script:

Quote[/b] ]

;;begin killdetect.sqs

_shooter = _this select 1

_shot = _this select 0

;;For MP publicvar it if you want everyone to know who shot what

;;You can also add points this way

Shooter = _shooter; publicVariable {Shooter}

?(_shooter == _shot): exit

;;you can do other stuff here

exit

;;end killdetect.sqs

The Killed eventhandler is local to the shooter and the shootee, i.e. they're the only two who automatically get the info when it happens.

Share this post


Link to post
Share on other sites

Ah i never knew you could do that with the kill event handeler, i just thought it could only be used to detect 'who got shot' and not 'who he was shot by' thanks for the info its cleared a lot of things up for me. wink_o.gif

Share this post


Link to post
Share on other sites

I get 'unknown operator' when I run the following code from the unit's init, and also from the init.sqs

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">man1 addEventHandler [{killed},{man1 exec {killdetect.sqs}}]

What am I doing wrong? Is it because im running on 1.46?

Share this post


Link to post
Share on other sites
I get 'unknown operator' when I run the following code from the unit's init, and also from the init.sqs

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">man1 addEventHandler [{killed},{man1 exec {killdetect.sqs}}]

What am I doing wrong? Is it because im running on 1.46?

Yes, event handlers was introduced in 1.90 if im not mistaken?

Share this post


Link to post
Share on other sites

Ok working in 1.96 and using KaRRiLLioN's example...

What would be the correct way to write the following code?

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">hint format ["%1 was killed by %2", name _shot, name _shooter]

I've already set _shot and _shooter as public variables, but how do I get the names displayed in the hint box?

Share this post


Link to post
Share on other sites

In Karillion's example Shooter = _shooter, the public variable is Shooter not _shooter. So:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">hint format ["%1 was killed by %2", name shot, name shooter]

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  

×