OFPEC Forum
Editors Depot - Mission Editing and Scripting => OFP - Editing/Scripting Multiplayer => Topic started by: Seven on 29 Jun 2006, 23:49:41
-
Hi there :)
Got a little question about eventhandlers in a CTF where I want to have anti spawnkill zone
I have in each units inits field an eventhandler: this addEventHandler ["killed",{_this exec "playerkilled.sqs"}] which checks if the killed player is in the safezone.
When this script starts, do I have to remove eventhandler & add it again when he respawns?
I'm using Toadslife's respawnscript (which I called respawn.sqs) so I could put a line in there if needed?
And one to remove the eventhandler (in the playerkilled.sqs)
Your help is much appreciated :)
Greetings,
Seven
playerkilled.sqs
_victim = _this select 0
_killer = _this select 1
? (_victim in list ESafezone && side _killer == resistance):goto "guerwarning"
? (_victim in list GSafezone && side _killer == EAST):goto "eastwarning"
exit
#guerwarning
hint format ["Warning!\n%1 (EAST) killed in Russian safezone by %2 (RESISTANCE)\n%2 will be punished",name _victim,name _killer]
RemoveAllWeapons _killer
_killer setpos [(getpos prisonlog select 0), (getpos prisonlog select 1), 2600]
_killer switchmove "FXangel"
#loop
? ((getdammage _killer) > 0.9) : goto "boom"
~0.1
goto "loop"
#boom
BOOOM="LaserGuidedBomb" camcreate getpos _killer
_killer switchmove "StandDeadVer2"
titletext["","PLAIN DOWN"]
Exit
#eastwarning
hint format ["Warning!\n%1 (RESISTANCE) killed in Resistance safezone by %2 (EAST)\n%2 will be punished",name _victim,name _killer]
RemoveAllWeapons _killer
_killer setpos [(getpos prisonlog select 0), (getpos prisonlog select 1), 2600]
_killer switchmove "FXangel"
#loop
? ((getdammage _killer) > 0.9) : goto "boom"
~0.1
goto "loop"
#boom
BOOOM="LaserGuidedBomb" camcreate getpos _killer
_killer switchmove "StandDeadVer2"
titletext["","PLAIN DOWN"]
Exit
-
YES when the player dies, remove the eventhandler,
Player removealleventhandlers "killed"
@ alive player
player addEventHandler ["killed", {_this exec "playerkilled.sqs"}]
however your system has a flaw.
A killed event is a local based event, meaning that the playerkilled.sqs only runs on the machine of the player that got killed, so the camcreate bomb, will only appear on that machine.
Therefore, the only commands that will work on _killer are global commands such as setpos or setdammage etc
if you want to run local commands on the _killer, then you have to do it on the _killer's machine and to do this, the _killer must be told it's him
to do this, we change a variable that is objnull to the _killer object and then publicvariable it
eg
DESCRIPTION.EXT
respawndelay = 0.1
INIT.SQS
;; set the following variable to the respawn delay you want
;; eg in this case 30 seconds
tx_respawntime = 30
;; set the following variable to the respawn delay you want for the spawnkiller
;; eg in this example 120 seconds 92 minutes)
tx_prisontime = 120
tx_PunishMe = false
tx_Killer = objnull
player addEventHandler ["killed", {_this exec "playerkilled.sqs"}]
?(local player): "" exec spawnkill.sqs
Playerkilled.sqs
#START
?!(local player):exit
_unit = _this select 0
_killer = _this select 1
_kilpos = getpos _unit
_kildir = getdir _unit
_wepArray = weapons _unit
_magArray = magazines _unit
_primary = primaryweapon _unit
_count = 0
cutText ["","Black out",0.001]
player removeAllEventHandlers "killed"
? (Tx_PunishMe) : goto "PUNISH"
;; << NB Protection for victim if in safezone and killed by enemy
? ((_unit in list ESafezone && side _killer == resistance) OR (_unit in list GSafezone && side _killer == EAST)):goto "FASTRESPAWN"
;; << NB Protection for victim if _killer safezone >>
? ((_killer in list ESafezone && side _unit == resistance) OR (_killer in list GSafezone && side _unit == EAST)):goto "FASTRESPAWN"
@ alive player
player addEventHandler ["killed", {_this exec "playerkilled.sqs"}]
_respawntime = tx_respawntime
titletext[format["%1\nYou have been killed", name player],"PLAIN"]
goto "NORMALRESPAWN"
#FASTRESPAWN
tx_Killer == vehicle _Killer; Publicvariable "tx_Killer"
titletext[format["%1\nYou were illegally killed by \n%2", name player,name _killer],"PLAIN"]
;; << NB find out what weapons the victim had and where he was killed etc >>
removeAllWeapons _unit
@ alive player
removeAllWeapons _unit
player addEventHandler ["killed", {_this exec "playerkilled.sqs"}]
;; << NB Following code places the illegally killed victim back to the place where he was killed and rearms him with the weapons he had when killed (additional code will be required if the unit was in a vehicle)
{player addMagazine _x} forEach _magArray
{player addWeapon _x} forEach _wepArray
?(_primary == "M16GrenadeLauncher"): _primary = "M16Muzzle"
?(_primary == "Ak74GrenadeLauncher"): _primary = "AK74Muzzle"
?(_primary == "Ak47GrenadeLauncher"): _primary = "AK47Muzzle"
player selectWeapon _primary
player setPos _kilpos
player setdir _kildir
cutText ["","Black in",0.001]
exit
#PUNISH
@ alive player
Tx_PunishMe = false
player addEventHandler ["killed", {_this exec "playerkilled.sqs"}]
titletext[format["%1\nYou are being punished for an illegal kill", name player],"PLAIN"]
_respawntime = tx_prisontime
tx_killer = objnull
goto "NORMALRESPAWN"
#NORMALRESPAWN
_pos = getpos player
cutText ["","Black in",2]
showcinemaborder true
_cam = "camera" camCreate _pos
_cam cameraEffect ["internal", "back"]
_cam camSetTarget player
_cam camSetRelPos [1,1,1.25]
_cam camCommit 0
@camCommitted _cam
~2
#CAMLOOP
_now = _time
#SUBLOOP
?(_time > _respawntime):goto "END"
?(_time > (_now + 5)): titletext[format["Respawning in\n\n%1 secs", (_respawntime - _time)],"PLAIN"] ; goto "CAMLOOP"
goto "SUBLOOP"
#END
cutText ["","Black out",2]
player switchCamera "INTERNAL"
cutText ["","Black in",2]
player cameraeffect ["terminate","back"]
camDestroy _cam
showcinemaborder false
exit
spawnkill.sqs
#START
~0.5
? (player in crew tx_killer): goto "PUNISH"
goto "START"
#PUNISH
tx_killer = objnull
Tx_PunishMe = true
player SetDammage 1
@ alive player
~1
goto "START"
Ok brief rundown
Set your description.ext up, with a 0.1 respawndelay, this will allow the illegally killed victim, to respawn at the place he died at in 0.1 seconds and re-arm him with the weapons he was killed with
(In other words, he will hardly notice he was killed
, whereas the Murderer, will be placed in a cutscene (which acts as the respawn delay, for tx_prisontime
Legally killed units will pass into a cutscene for tx_respawntime
Respawning units will respawn at their respawnmarker as normal, , the victim will then be setpossed to his "killed" location
afaik, this system is the best type of anti spawnkill system i have seen to date
Utilisation of CoC Networks would create a better system
Additional code may have to be added, if the Victim could be a flag carrier or in a vehicle
code is untested, i wrote it on the fly, editing it from some previous code i have, so expect some minor errors
The ECL C&H, CTF, FLAGBALL templates all have a similar system
-
Thx alot Terox for the effort!
I will try this tonight :)
I did take a look at the templates you made for ECL, but didn't really know what to keep and what not in there & things looked somehow complicated cause you have the weapondialog stuff that I absolutely don't understand (well maybe a very small part of it ;D )
One more question:
player addEventHandler ["killed", {_this exec "playerkilled.sqs"}] Will this set the EventHandler on each machine?
Respect ;)
-
One more question:
player addEventHandler ["killed", {_this exec "playerkilled.sqs"}] Will this set the EventHandler on each machine?
The one in the INIT.sqs will, as the INIT.sqs is run on all machines at the start of the mission.
mmm maybe the one in the INIT.sqs might be better prefixed with ?(local player):
The one in the playerkilled.sqs will only do it to the player who's machine it is being run on, eg the killed player, which is what you want
-
Hi Terox,
Late reply but it's been too hot here lately to stay long at the pc so I didn't have the time to test it untill now;
Here's what happens:
If you get illegaly shot, you get that message ( the killer doesn't) and have instant respawn, but you don't get your weapons you started with & the killer doesn't get punished.
Any further help would be very much appreciated because I would really like to have this script working 8)
Kind regards,
Seven
-
have updated the playerkilled.sqs and the spawnkill.sqs in my above post,
replace your existing code with the updated stuff
there were errors in it, my fault.
A tip
to debug a script, you need to ascertain 2 things
1) which lines are being read in the script, eg which label is the script jumping too
2) what are the actual values for a certaion variable
so lets say we have a problem, as in, the killer isnt getting killed after an illegal kill
As the victim, the playerkilled.sqs should jump to the #FASTRESPAWN label
so
we place the following piece of code just after the @ alive player under the #FASTRESPAWN label
player sidechat "DEBUG: at FASTRESPAWN (playerkilled.sqs)"
and then you get a player to kill you, you should then see the sidechat message, if you dont, then the sscript hasnt got to that point, so then you have to start placing other debug lines further up the script
So let us now say, that the victim's version of the playerkilled.sqs is running through the fast respawn label, but the killer still isnt getting punished, we then can start looking at variable values.
lets say we wanted to see what value tx_killer is seen as, it should be the same as vehicle _killer
so we use a player sidechat format line
in the following line we are checking 3 variable values
_killer
vehicle _killer
tx_killer
eg
player sidechat format ["killer = %1 ..veh _killer = %2 ... tx killer = %3",_killer, vehicle _killer, tx_killer]
using these 2 basic debugging principals, lets you track down where the fault lies
-
Hi Terox,
It still doesn't work;
Not respawning with initial weapons and no punishment :-\
playerkilled.sqs looks like this (with debuggers in)
No msg when I am killer
#START
?!(local player):exit
_unit = _this select 0
_killer = _this select 1
_kilpos = getpos _unit
_kildir = getdir _unit
_wepArray = weapons _unit
_magArray = magazines _unit
_primary = primaryweapon _unit
_count = 0
cutText ["","Black out",0.001]
player removeAllEventHandlers "killed"
? (Tx_PunishMe) : goto "PUNISH"
;; << NB Protection for victim if in safezone and killed by enemy
? ((_unit in list ESafezone && side _killer == resistance) OR (_unit in list GSafezone && side _killer == EAST)):goto "FASTRESPAWN"
;; << NB Protection for victim if _killer safezone >>
? ((_killer in list ESafezone && side _unit == resistance) OR (_killer in list GSafezone && side _unit == EAST)):goto "FASTRESPAWN"
@ alive player
player addEventHandler ["killed", {_this exec "playerkilled.sqs"}]
_respawntime = tx_respawntime
titletext[format["%1\nYou have been killed", name player],"PLAIN"]
goto "NORMALRESPAWN"
#FASTRESPAWN
player sidechat "DEBUG: at FASTRESPAWN (playerkilled.sqs)"
tx_Killer == vehicle _Killer; Publicvariable "tx_Killer"
titletext[format["%1\nYou were illegally killed by \n%2", name player,name _killer],"PLAIN"]
player sidechat format ["killer = %1 ..veh _killer = %2 ... tx killer = %3",_killer, vehicle _killer, tx_killer]
;; << NB find out what weapons the victim had and where he was killed etc >>
removeAllWeapons _unit
@ alive player
removeAllWeapons _unit
player addEventHandler ["killed", {_this exec "playerkilled.sqs"}]
;; << NB Following code places the illegally killed victim back to the place where he was killed and rearms him with the weapons he had when killed (additional code will be required if the unit was in a vehicle)
{player addMagazine _x} forEach _magArray
{player addWeapon _x} forEach _wepArray
?(_primary == "M16GrenadeLauncher"): _primary = "M16Muzzle"
?(_primary == "Ak74GrenadeLauncher"): _primary = "AK74Muzzle"
?(_primary == "Ak47GrenadeLauncher"): _primary = "AK47Muzzle"
player selectWeapon _primary
player setPos _kilpos
player setdir _kildir
cutText ["","Black in",0.001]
exit
#PUNISH
player sidechat "DEBUG: at PUNISH (playerkilled.sqs)"
@ alive player
Tx_PunishMe = false
player addEventHandler ["killed", {_this exec "playerkilled.sqs"}]
titletext[format["%1\nYou are being punished for an illegal kill", name player],"PLAIN"]
_respawntime = tx_prisontime
tx_killer = objnull
goto "NORMALRESPAWN"
#NORMALRESPAWN
_pos = getpos player
cutText ["","Black in",2]
showcinemaborder true
_cam = "camera" camCreate _pos
_cam cameraEffect ["internal", "back"]
_cam camSetTarget player
_cam camSetRelPos [1,1,1.25]
_cam camCommit 0
@camCommitted _cam
~2
#CAMLOOP
_now = _time
#SUBLOOP
?(_time > _respawntime):goto "END"
?(_time > (_now + 5)): titletext[format["Respawning in\n\n%1 secs", (_respawntime - _time)],"PLAIN"] ; goto "CAMLOOP"
goto "SUBLOOP"
#END
cutText ["","Black out",2]
player switchCamera "INTERNAL"
cutText ["","Black in",2]
player cameraeffect ["terminate","back"]
camDestroy _cam
showcinemaborder false
exit
forgot to mention I changed last line of the init.sqs to ?(local player): "" exec "spawnkill.sqs" because without the "round" the sqs it would give me an error (unknown operator orso can't remember ATM)
Here a screenshot of Debug
(http://seven.belgianeliteforce.be/spawnkill.jpg)
Cheers :)
***EDIT***
I looked it over again and saw that while in the playerkilled.sqs there is a blackout of 0.0001
cutText ["","Black out",0.001]
player removeAllEventHandlers "killed"
? (Tx_PunishMe) : goto "PUNISH"
and in the spawnkill.sqs there is a pauze of 0.5 seconds where the variable is declared:
Tx_PunishMe = true
Am I thinking in the correct way that both scripts would run at the same time?
And maybe therefor the variable Tx_PunishMe is declared later then the check on it in the playerkilled.sqs ?