OFPEC Forum

Editors Depot - Mission Editing and Scripting => OFP - Editing/Scripting Multiplayer => Topic started by: Dinger on 15 Oct 2002, 04:55:09

Title: Event Handlers and MP: Killshooter script
Post by: Dinger on 15 Oct 2002, 04:55:09
just an example of what you can do with an event handler.
Here's a script to kill a TK'er:

init.sqs line:
Code: [Select]
teamkill = player addeventhandler [{Killed}, {_this exec {Killshooter.sqs}]

then this little script

Code: [Select]
_killer = _this select 1
?side _killer == side player:_killer setdammage 1
exit
cool, huh?


(edit: removed little bug: brackets around _this)
Title: Re:Event Handlers and MP: Killshooter script
Post by: TheCaptain on 15 Oct 2002, 21:54:41
Thanks dinger, exactly what i needed!
Title: Re:Event Handlers and MP: Killshooter script
Post by: walker on 15 Oct 2002, 23:13:24
Hi dinger

Within 4 hours of me posting the thought you come up with the script. Man you are a God.

The OFP multi-player community should sing your praises to the heavens.

Die Die Die you Cheater Strike Wusses (walker wonders off ranting and raving)

Regards Walker
Title: Re:Event Handlers and MP: Killshooter script
Post by: Hamdinger on 16 Oct 2002, 00:25:30
As another alternative to killing the offending player, you could take away their weapons and cripple them.

Code: [Select]
_killer = _this select 1
?side _killer == side player: removeAllWeapons _killer; _killer setdammage .8
exit

I have no idea if .8 is the right value to force a person to crawl.  Also, I don't know if removeAllWeapons gets rid of grenades, satchel charges, etc.  But you get the idea.

BTW, Dinger, sorry about the similarity in names.  This is a name I've used for a while and I registered it before I saw yours.  If it's any consolation, I'm also excited about being able to use braces instead of quotes.  :)
Title: Re:Event Handlers and MP: Killshooter script
Post by: _54th_Yoshi on 16 Oct 2002, 00:42:53
*To Hamdinger* I think it's .9 to cripple someone.

*To Dinger* Great job Dinger! You solved to holy grail of dealing with the 7 year-old punks that can't kill the other team, so they have to kill their own. Cheers!  :cheers:
Title: Re:Event Handlers and MP: Killshooter script
Post by: SafetyCatch on 16 Oct 2002, 00:50:58
the thing is there are a lot of players out there setting out to piss people off intentionally
they normally disconnect as soon as they'e killed some1 and that is the most frustrating thing because u cant punish them, or ban them because they change their name and recirculate into the sad world of TKers
thanks
i just thought i might make that comment to make more people aware of the fact that TKers suck
Title: Re:Event Handlers and MP: Killshooter script
Post by: Dinger on 16 Oct 2002, 02:17:15
I didn't do anything other than point out what BIS did.
Heh, Ham, I don't have a lock on the name.
One other thing, youshould probably first check:
?_killer == player:exit

another killshooter variation is to give the shooter the damage the player received, so if I hit a buddy with a stray bullet, he's okay, and I take the bullet (and nobody dies).  That's done this way:
teamkill = player addeventhandler [{Hit}, {_this exec {killshooter.sqs}}]

;Killshooter.sqs
;dinger@raf303.org
_killer = _this select 1
_damage = _this select 2
?_killer == player:exit
?side _killer != side player: exit
player setdammage ((getdammage player) - _damage)
_killer  setdammage ((getdammage player) + _damage)
exit
Title: Re:Event Handlers and MP: Killshooter script
Post by: HK on 20 Dec 2002, 19:46:56
@ Dinger thanks for your help man. OK i tried this and there seems to be a problem occuring after respawn, it works ok initially BUT after respawn the problems begin, it seems that your soldier respawns and his name comes up red instead of green thus indicating enemy status. Is there any way to reset this after or during the respawn process to be Friendly again?
Title: Re:Event Handlers and MP: Killshooter script
Post by: CapMorgan on 28 Dec 2002, 18:59:05
@ Dinger thanks for your help man. OK i tried this and there seems to be a problem occuring after respawn, it works ok initially BUT after respawn the problems begin, it seems that your soldier respawns and his name comes up red instead of green thus indicating enemy status. Is there any way to reset this after or during the respawn process to be Friendly again?

Im making a script to kill the respawn killers, and had the same problem.
I belive it's because when unit is dead, it's rating is 0 untill it respawn, so when the eventhandler "checks" the side, the result is "CIV".
I solved it putting a name to the group and not using side command.
I still have the problem of inserting again the eventhandler to the dead guy. I can do that by making a trigger with the condition !alive unit, but there must be a better way. i dont want to make a trigger for each unit in the map.
Also, i don't know if this will work in MP because the "killed" eventhandler is local ... :-\  
Any hook will be apreciated


My script so far goes like this

_muerto = _this select 0
_matador = _this select 1

? _muerto in units grpOeste  && _matador in units grpOeste: goto "fin"
? _muerto in units grpEste && _matador in units grpEste: goto "fin"

_linea = "Don't kill in the respwn zone"
? _muerto in units grpOeste  && _muerto in list listaRespOeste: _matador setdammage 1; hint _linea; goto "fin"
? _muerto in units grpEste && _muerto in list listaRespEste: _matador setdammage 1; hint _linea; goto "fin"

#fin
exit
Title: Re:Event Handlers and MP: Killshooter script
Post by: Dinger on 28 Dec 2002, 22:39:30
Ahh, true.
What you need to do is set a variable like PlayerSide = Side player when you load the EH, and use that as your check.
Second, when the player respawns, you need to respawn the EH too.
Third, all EHs are local events. You need to load an EH on each client (for the player).  If you want messages ("you are a bad boy"), you need to have a publicvariable broadcast/monitor system.
I'll see what I can do when I get home in a cupola weeks.
Title: Re:Event Handlers and MP: Killshooter script
Post by: CapMorgan on 30 Dec 2002, 06:18:38
well, here's a new one. I can't add handlers to a respawned unit. Not by script or trigger.
Here's what i have. Works fine first time, but when unit respwns no handler is added. Any hook?

init.sqs
ArrayGlobal = units grpEste + units grpOeste
eventos = true

trigger:
condition: Eventos
on activation:"""_X removeAllEventHandlers {killed}"" foreach ArrayGlobal; ""_x addeventhandler [{killed}, {_this exec {Camper.sqs}}]"" forEach ArrayGlobal; eventos = false;publicVariable ""eventos"""

;script Camper.sqs
_muerto = _this select 0
_matador = _this select 1

? _muerto in units grpOeste  && _matador in units grpOeste: goto "fin"
? _muerto in units grpEste && _matador in units grpEste: goto "fin"

_linea = "Dont kill in respawn"
? _muerto in units grpOeste  && _muerto in list listaRespOeste: _matador setdammage 1; hint _linea; goto "fin"
? _muerto in units grpEste && _muerto in list listaRespEste: _matador setdammage 1; hint _linea; goto "fin"
#fin
Eventos =  true
Publicvariable "eventos"
exit

Title: Re:Event Handlers and MP: Killshooter script
Post by: Nedal on 10 Jan 2003, 11:59:06
I am not sure, but perhaps the problem is in the Init.Sqs
init.sqs:          ArrayGlobal = units grpEste + units grpOeste
                      eventos = true


the init.sqs runns just one time, when the mission is startet. so everything you set in the init.sqs counts just for all units who are existing when the game starts.
As soon a unit gets respawned, all setings from init.sqs will be lost for this unit.

i think
 ArrayGlobal = units grpEste + units grpOeste
                      eventos = true  
should be in a seperate script (globarrays.sqs) , with a never ending loop, and you start this script in the init.sqs


could this be a solution?


best wishes Oberst Nedal
Title: Re:Event Handlers and MP: Killshooter script
Post by: CapMorgan on 10 Jan 2003, 19:53:21
I am not sure, but perhaps the problem is in the Init.Sqs
init.sqs:          ArrayGlobal = units grpEste + units grpOeste
                      eventos = true


the init.sqs runns just one time, when the mission is startet. so everything you set in the init.sqs counts just for all units who are existing when the game starts.
As soon a unit gets respawned, all setings from init.sqs will be lost for this unit.

i think
 ArrayGlobal = units grpEste + units grpOeste
                      eventos = true  
should be in a seperate script (globarrays.sqs) , with a never ending loop, and you start this script in the init.sqs


could this be a solution?


best wishes Oberst Nedal


Thanx for the reply Nedal !!. That's correct, the problem was the array. I get the answer @ the official forum the past week. I solved the problem, but i still don't get why the respawned unit is not in the array if it's still in the gruop.
Title: Re:Event Handlers and MP: Killshooter script
Post by: Nedal on 14 Jan 2003, 18:32:05
I am working on another way to get this working
but i have to problem, that it is just working for the guy who starts the game (server) not for all the others
If he kills someone in savezone, his weapons will be removed. But if someone else is doing it nothing happens. I dont know why. there is no trigger gamelogic server.

if you want to see or try, you can download the pbo file at
http://www.bikeadventure.ch/ofp/respawnbeta1.Noe.pbo
Title: Re:Event Handlers and MP: Killshooter script
Post by: CapMorgan on 14 Jan 2003, 19:02:10
well, this is what i've done (tested on MP and woprking)

;init.sqs
eventos = true

2 triggers covering each respawn area (west example, you shoul change the act and name for EAST)
rad: your respawn zone
act:west/present
name: ListaRespOeste

1 big trigger covering the entire battlefield
rad: big
act:anyone/present/repet
countdown: 1 second higer than the respanwdelay you setted in de description.ext
condition:eventos
onactivation::"_X removeAllEventHandlers {killed}" foreach thislist; "_x addeventhandler [{killed}, {_this exec {Camper.sqs}}]" forEach thislist; eventos = false; publicVariable "eventos"

Now the script
;;camper.sqs
_muerto = _this select 0
_matador = _this select 1
? _muerto in units grpOeste && _matador in units grpOeste: goto "fin"
? _muerto in units grpEste && _matador in units grpEste: goto "fin"
_linea = "No mates en el Respawn"
? _muerto in units grpOeste && _muerto in list listaRespOeste: _matador setdammage 1; hint _linea; goto "fin"
? _muerto in units grpEste && _muerto in list listaRespEste: _matador setdammage 1; hint _linea; goto "fin"
#fin
Eventos = true
Publicvariable "eventos"
exit

Note: define the name of the groups (grpOeste for west and grpEste for east)
Title: Re:Event Handlers and MP: Killshooter script
Post by: hurlothrumbo on 18 Apr 2003, 17:12:50
error in top line for Init with dingers orig. post- missing }
Title: Re:Event Handlers and MP: Killshooter script
Post by: hurlothrumbo on 19 Apr 2003, 15:06:31
This works!

OK after lots of tweaking
in init field
Quote
this addEventHandler ["hit",{_this exec "teamwound.sqs"}]

in teamwound.sqs

Quote
killer = _this select 1
hurt = _this select 0

killera = driver killer

Publicvariable "killera"

? side killera != side hurt :goto "enemy"

? IsNull killer:goto "enemy"

killera setdammage 0.99; removeallweapons killera; Killera globalchat "I nearly killed a teammate!  I'm such an

idiot I should throw my weapon away!"


exit

#enemy
~5

exit

Works perfectly in msn editor.  I'm not sure if it will in MP, I'm going to test later.
If someone on your side shoots you, they get their weapon taked off them and their damage set to .99 (crawling)
It even works if they are inside a vehicle.
Title: Re:Event Handlers and MP: Killshooter script
Post by: hurlothrumbo on 19 Apr 2003, 16:53:35
But now what I want is the action to drop weapons (introduced in resistance) so I can make the player drop his weapon, because it could be that they are the only LAW or AT soldier and the team needs it.  Anyone know what it is?  It's not in the unofficial command reference with the other actions, unless there has bee na new version out.








************EDIT
Actually there is a problem with the above script, if you are driving a car or vehicle, the weapon is removed from whooever you drive over and their damage is set to 9.9...... which is REALLY weird, although it could stop people getting killed by vehicles so much with some changes!  (because even though they are hurt with this, they don't die!)
Title: Re:Event Handlers and MP: Killshooter script
Post by: Terox on 23 May 2003, 17:59:24
punishing them with "disableuserinput" after respawning them would be a good twist
Title: Re:Event Handlers and MP: Killshooter script
Post by: toadlife on 23 May 2003, 22:08:05
But now what I want is the action to drop weapons (introduced in resistance) so I can make the player drop his weapon, because it could be that they are the only LAW or AT soldier and the team needs it.  Anyone know what it is?  It's not in the unofficial command reference with the other actions, unless there has bee na new version out.

See this thread for all fo your "action" needs. :)

http://www.ofpec.com/yabbse/index.php?board=6;action=display;threadid=9376

Title: Re:Event Handlers and MP: Killshooter script
Post by: Terox on 23 May 2003, 22:40:59
I have been thinking about this a bit and was wondering if the following was possible and if so how to do it


Objective
1)  To check if a player in his safezone had been killed by an enemy
2)  To check if player in safezone had killed an enemy player

My idea is to have 1 main trigger which encompasses the whole playing area
Which uses the addeventhandler "hit " or "killed"

and two smaller triggers which are the same size and in the same location as the east and west ("_x setdammage 1" forEach thislist; ) respawn protection triggers

These two smaller triggers would switch a variable "Insafezone" to true for any player that is within the triggers perimeter


Then the addeventhandler script exec by the init.sqs
that is continuously looping would check to see if

a) The "hit" target was ?(insafezone)
or
b) The shooter was ?(insafezone)

If either the shooter or target was ?(insafezone), then the shooter would be punished by being
{player setPos (getMarkerPos "respawn_east")} or if west the respawn_west
and then
player=shooter disableuserinput = true
~ punishment
player=shooter disableuserinput = false

I aint that familiar with eventhandlers, but i think i got a failry good understanding of them

However, what i do need to know, is how to make the smaller triggers switch "insafezone" to true for any player in its list


If i can get it working, i think it will be far more efficient that any of the Anti spawn shooting systems used so far


Any help will be appreciated Thx
Title: Re: Event Handlers and MP: Killshooter script
Post by: SpectrumWarrior on 24 May 2009, 01:08:58
Hi Dinger: How would I take one of these scripts you mentioned above and make it to ( say ) take points away from someone killing an unarmed enemy officer or soldier? As a rules of engagment script?
Title: Re: Event Handlers and MP: Killshooter script
Post by: Planck on 24 May 2009, 01:40:09
After 6 years I doubt you will get a response from Dinger, but you never know I suppose.    :cool2:


Planck
Title: Re: Event Handlers and MP: Killshooter script
Post by: SpectrumWarrior on 24 May 2009, 02:49:50
Well really if anyone can help me on this I would be greatful