Home   Help Search Login Register  

Author Topic: eventhandlers  (Read 2506 times)

0 Members and 1 Guest are viewing this topic.

Offline Zombie

  • Members
  • *
  • Beware the night, the zombie walks among you
    • USI
eventhandlers
« on: 13 Oct 2003, 21:13:30 »
I'm trying to make a script where if a person kills someone on thier own side, their score is reduced.  I have to set everyones rating to negative in the beginning, but I still want a "penalty" for killing someone on your own side.  I am doing a TDM.  This is what I have tried and it doesn't work:
#Init
_hit = _this Select 0
_shooter = _this Select 1
?(_hit == _shooter): goto end
?(side _hit == side _shooter): goto adjust
exit
#adjust
_shooter Addscore -2
#end
Exit

I have a "anyone" trigger on activation player addeventhandler ["killed", player exec "killed.sqs"]

Any Ideas?
« Last Edit: 13 Oct 2003, 21:14:37 by Zombie »

Offline rhysduk

  • Former Staff
  • ****
Re:eventhandlers
« Reply #1 on: 13 Oct 2003, 23:38:22 »
I might be wrong but is it nessecary for the :

player exec bit to be in the addaventhandler line ?

Shoudlnt it just be

player addeventhandler ["killed", "killed.sqs"]

Maybe i am wrong ? ;D

Rhys
Reviewed Missions Board: Please Read the User's Guide before posting!

Pride and Joy 1 (HW100-T)

Offline Zombie

  • Members
  • *
  • Beware the night, the zombie walks among you
    • USI
Re:eventhandlers
« Reply #2 on: 14 Oct 2003, 01:01:11 »
seemed like a good idea, but alas, still not the solution.  Thanks tho

Offline Chris Death

  • Former Staff
  • ****
  • Finally Death's gonna get ya
    • OFPEC
Re:eventhandlers
« Reply #3 on: 14 Oct 2003, 03:26:45 »
Quote
?(side _hit == side _shooter): goto adjust

OK, i haven't taken a deep look into that yet, but the
first thing i noticed was the line above.

goto adjust will not work, as it should be:

goto "adjust"

:edit - ah yeah and the same goes for: goto end / goto "end"

~S~ CD
« Last Edit: 14 Oct 2003, 03:27:31 by Chris Death »
Dont argue with idiots....they will bring you down to their level and beat you there with experience.

How to use Waypoint type Scripted

Offline Killswitch

  • Members
  • *
  • Peace, cheese and ArmA
Re:eventhandlers
« Reply #4 on: 14 Oct 2003, 17:35:26 »
seemed like a good idea, but alas, still not the solution.  Thanks tho
What rhysduk posted is part of the solution, since that is the correct syntax for addEventHandler

With that and Chris's notes on the goto syntax, you should get closer to a solution.

*EDIT: Error, that is not the correct syntax. See my post below...
« Last Edit: 15 Oct 2003, 13:12:03 by Killswitch »

Offline Zombie

  • Members
  • *
  • Beware the night, the zombie walks among you
    • USI
Re:eventhandlers
« Reply #5 on: 14 Oct 2003, 18:04:55 »
thanks to everyone, some dumb mistakes on my part.  Prob is, it still doesn't work, still trying tho

Offline Zombie

  • Members
  • *
  • Beware the night, the zombie walks among you
    • USI
Re:eventhandlers
« Reply #6 on: 14 Oct 2003, 19:08:18 »
OK, trying a new tactic, instead of giving everyone a negative rating so they will kill the civilians, and get a score for it, I tried the following:
side [s13,s14,s15,s16] == _enemy
_enemy==enemy

where s13,s14,s15 ans s16 are the names of the civilian units, problem is, those units get no score for shooting someone, and if another side shoots them, they get a negative score.  Giving everyone a negative rating makes the scoring work, but you get a positive score for shooting a teammate.  Maybe I am thinking in the wrong direction here?

Offline Terox

  • Former Staff
  • ****
  • Follow the Sappers!
    • zeus-community.net
Re:eventhandlers
« Reply #7 on: 14 Oct 2003, 21:26:53 »
just had a quick look at this.

things to note

the event handler killed runs locally only to the victim, therefore any scripts that are run from it are also local to the victim. I dont know how this will affect the "addscore" due to it being a reserved variable

if it is affecting things then you will simply have to create another variable and pass it globally to the server then have the server addscore to the shooter or whatever is required
Zeus ARMA2 server IP = 77.74.193.124 :2302
Teamspeak IP = 77.74.193.123

Offline Zombie

  • Members
  • *
  • Beware the night, the zombie walks among you
    • USI
Re:eventhandlers
« Reply #8 on: 15 Oct 2003, 01:21:59 »
OK, I understand it runs only to the victim, so how can I detect who his killer was?  Is there an eventhandler that will detect killed by?

Offline Killswitch

  • Members
  • *
  • Peace, cheese and ArmA
Re:eventhandlers
« Reply #9 on: 15 Oct 2003, 13:11:13 »
First, a correction on what I said above. The syntax for addEventHandler is not like in rhysduk's example. I was struck by temporary (?) ;D stupidity and made a mistake. We'll get to addEventhandler below...

OK, I understand it runs only to the victim, so how can I detect who his killer was?  Is there an eventhandler that will detect killed by?
The "killed" event gives you just that, so you're on the right track. Ok, how about this...

1 - Modify that "anybody trigger" and use this (can also be put this in the init.sqs if you remove the trigger)
Code: [Select]
player addEventHandler ["killed", {_this exec "killed.sqs"}]
That's the correct addEventHandler syntax. This will add a killed EH to all players.

2 - Make a "killed.sqs" like so:
Code: [Select]
; killed.sqs
?!(count _this == 2):exit
_victim = _this select 0
_shooter = _this select 1

?(_victim == _shooter): exit
?(side _victim == side _shooter): _shooter addScore -2
exit

...and see if that does what you want. There is one thing though... the addScore command. It's quite possible that you have to run that where the unit to be affected is local. In other words, one would have to do addScore on the shooter's machine and not on the vicim's. With the script as above, the addScore will be run on the victim's machine, since the killed EH only runs where the killed unit (i.e the victim) is local. Test it and tell me if it works. Otherwise, we have to think of a way to do the addScore on the perpetrator's machine...

(Add my vote for making the killed event be distributed to all machines, no matter how many old scripts it will break. )
« Last Edit: 15 Oct 2003, 13:20:44 by Killswitch »

Offline Zombie

  • Members
  • *
  • Beware the night, the zombie walks among you
    • USI
Re:eventhandlers
« Reply #10 on: 15 Oct 2003, 13:54:31 »
I tried it the way you said, maybe there is a concept I am missing here.  I tried it as a multiplayer game , by myself, on my machine, and it doesn't work.  Is it because the ai aren't "players" to execute the script?
  I am certain there is a forest around here somewhere, somebody move all these trees

Offline Killswitch

  • Members
  • *
  • Peace, cheese and ArmA
Re:eventhandlers
« Reply #11 on: 15 Oct 2003, 14:26:24 »
Is it because the ai aren't "players" to execute the script?
Yes. Only the player unit (i.e you on your machine) on each computer will get the event handler the way we have been doing it so far. AI:s wont have the killed EH.

To add the killed EH to all soldiers, players or not, you'd have to do something like
Code: [Select]
{if ("Man" countType [_x] == 1) then {_x addEventHandler ["killed",{_this exec "killed.sqs"}]} } forEach thislist
in the "Anybody present" trigger.


Offline Zombie

  • Members
  • *
  • Beware the night, the zombie walks among you
    • USI
Re:eventhandlers
« Reply #12 on: 15 Oct 2003, 15:00:59 »
OK, we're getting closer now, for some reason I take a minus for killing resistance soldiers, and get a plus for everyone else while playing the civilian side

Offline Terox

  • Former Staff
  • ****
  • Follow the Sappers!
    • zeus-community.net
Re:eventhandlers
« Reply #13 on: 15 Oct 2003, 17:35:49 »
to allow the shooter to recognise himself as the shooter then you need the victims client to create a publicvariable out of his local shooter

eg

Shooter = _Shooter; publicvariable "Shooter"

then have the killers client wait for the public variable

eg
@ player == shooter


or something like that


« Last Edit: 15 Oct 2003, 17:38:35 by Terox »
Zeus ARMA2 server IP = 77.74.193.124 :2302
Teamspeak IP = 77.74.193.123