Jump to content
Sign in to follow this  
terox

Addeventhandler "hit"  query

Recommended Posts

The addeventhandler "Hit" creates an array automatically when the event occurs

This array is made up of two elements

_victim = _this select 0

_shooter = _this select 1

any script that is run from an addevent is run locally on the "_victims" client

Using a script on the clients machine, you can setdammage to the _shooter

You can probably setpos _shooter as well and maybe some other set commands

My problem is, i need the _shooter client to know he is the _shooter, so i can run a punishment system for him

I have tried setting viewdistance 500 for the _shooter on the _victims machine, then checking on the _shooters client to see if he had viewdistance 500, it didnt work

I dont want to setpos the _shooter

My theory to get it working was

On the _victims machine, eg.

_shooter = shooter; publicvariable "shooter"

On the server

@! shooter objnull

shooter = killer; publicvariable "Killer"

shooter = objnull

On all clients machines

in a looping system

?(Player = killer):goto "Labelname"

(Basically i have respawndelay set to 0.1 for everybody)

Under normal respawn conditions, a script run locally on all clients, loops the clients player in a cutscene until his respawntime is up.

During this loop, i want the _shooter to check to see if he is the _shooter, then the script can jump to another label

I tried my theory but could not get the _shooter client to recognise himself as "Killer"

Share this post


Link to post
Share on other sites

I'll just point out syntax errors:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">@! shooter objnull what is shooter objnull? It's not a valid statement I don't think.

Quote[/b] ]?(Player = killer):goto "Labelname"
Thats an assignment operator, try ?(Player == killer):

Share this post


Link to post
Share on other sites

forget the typo errors thats just me typing in forums instead of cut n paste

The problem still exists  i need to let the _shooters client know he is the _shooter

only the _victims client knows who he is

**********************************************

*********************************************

The system in full

The addevent "hit" occurs anywhere on the map

When the event does occur, the spawnkill.sqs (Locally run on the _victims machine)  queries where the _shooter and the _victim are. If either are in a safezone, (This is an illegal kill) then it kills the _shooter, and either repairs the _victim or immediately respawns him to the same location he died, with the weapons loadout he died with.

If its a legal kill the dead victim simply goes into the normal respawn routine and the shooter remains unpunished

Now if anyone dies, they go into a cutscene loop which acts as a respawn delay (The actual respawndelay = 0.1)

During this cutscene loop, i want the respawn.sqs to check and see if the _shooter is the local player and if he is, break out of the normal respawn loop into an even longer loop.

Everything works apart from the fact, that the _shooter client doesnt know he is the shooter and therefore doesnt break out of the normal respawn loop

so now to the scripts

Description.ext

respawn = 3

respawndelay = 0.1

*********************************************

Init.sqs

respawntime = 10

prisontime = 70

shooter = objnull

?!(local server): [] exec "respawn.sqs"

?(local server): [] exec "serverspawnkill.sqs"

**********************************************

spawnkill.sqs

;; The hitdetectactice lines stop more instances of script runningm in event of spash damage, autmoatic fire etc

;; Testing showed that with an m16 on auto, 3 rounds would be fired before shooter was killed

?(hitdetectactive):exit

hitdetectactive = true

Hint "debug: spawnkill.sqs activated"

_victim = _this select 0

_shooter = _this select 1

?(_shooter in list safezone_west OR _shooter in list safezone_east OR _victim in list safezone_west OR _victim in list safezone_east): goto "next"

goto "End"

#next

hint format ["Debug: %1 is victim\n%2 is shooter",name (_victim), name (_shooter)]

Hint "debug: Illegal kill detected"

fastrespawn = true

murder = true; publicvariable "murder"

;;;;; &&&& Tried following line to PV _shooter

;;;;; &&&& It Didnt work

shooter = _shooter; publicvariable "shooter"

_shooter setDammage 1

titletext[format["%1\n is PV shooter",name shooter],"PLAIN DOWN"]

~0.1

?!alive _victim:goto "end"

_victim setDammage 0

fastrespawn = false

#end

hitdetectactive = false

exit

**********************************************

serverspawnkill.sqs

;;serverspawnkill.sqs

;; In the event of a player receiving  illegal spawnkill damage from the enemy, the victim client creates a PV called Shooter

;; This script waits for that PV (Publicvariable) to be declared

;; It then makes Shooter into Killer

;; Meanwhile the Shooter client has been killed and is waiting to become active in a loop

;; Part of this loop is checking if he is "Killer"

?!(local server):exit

#start

@ murder

murderer = shooter; publicvariable "murderer"

;; get rid of shooter ready for next instance

shooter = objnull

;;shooter = []

murder = false

goto "start"

**********************************************

respawn.sqs

;; locally run script on all clients

?(local server):exit

@time > 1

player addEventHandler ["hit", {_this exec "spawnkill.sqs"}]

player addrating 10000

;;Remove following weaponsarray when Pimm has Armoury selection done and add "removeallweapons player"

;;removeAllWeapons player

_weapArray = weapons player

_magArray = magazines player

_primary = primaryweapon player

?(_primary == "M16GrenadeLauncher"): _primary = "M16Muzzle"

?(_primary == "Ak74GrenadeLauncher"): _primary = "AK74Muzzle"

?(_primary == "Ak47GrenadeLauncher"): _primary = "AK47Muzzle"

#START

@!alive player

player removeAllEventHandlers "hit"

_kilpos = getpos player

_kildir = getdir player

_kilposweapArray = weapons player

_kilposmagArray = magazines player

_kilprimary = primaryweapon player

?(_kilprimary == "M16GrenadeLauncher"): _kilprimary = "M16Muzzle"

?(_kilprimary == "Ak74GrenadeLauncher"): _kilprimary = "AK74Muzzle"

?(_kilprimary == "Ak47GrenadeLauncher"): _kilprimary = "AK47Muzzle"

@alive player

hint "adding eventhandler"

player addEventHandler ["hit", {_this exec "spawnkill.sqs"}]

removeAllWeapons player

?(fastrespawn):goto "Fastrespawn"

#SLOWRESPAWN

_pos = getpos player

;; Remove all weapon statements when Pimm  has armoury select working

{player addMagazine _x} forEach _magArray

{player addWeapon _x} forEach _weapArray

player selectWeapon _primary

showcinemaborder true

_camera = "camera" camCreate _pos

_camera cameraEffect ["external", "back"]

_camera camSetTarget player

_camera camSetRelPos [0,1,2]

_camera camCommit 0

@camCommitted _camera

_count = 0

#LOOP

~1

_count = _count + 1

;;;;; &&&&&  CHECK IF I AM murderer (_shooter)

?(player == murderer):goto "PUNISH"

?(_count >= respawntime): goto "KILLCAM"

goto "LOOP"

#PUNISH

Hint "debug: I am murderer"

;; Delays the _shooter (Killer) in the cutscene for a longer period

titletext[format["%1\nYou are being punished for an illegal Kill", name murderer],"PLAIN"]

~1

_count = _count + 1

?(_count == (prisontime - 60)): titletext[format["%1\nYou will be freed in 1 minute", name murderer],"PLAIN DOWN"]

?(_count >= prisontime):hint "Play On War Criminal"; goto "KILLCAM"

goto "PUNISH"

#kILLCAM

;; Kills the cam freezing the player, allows him back into game

player cameraeffect ["terminate","back"]

camDestroy _camera

showcinemaborder false

goto "START"

#FASTRESPAWN

;; instant respawn if player is _victim of illegal kill

;; also rearms him with weapons he was killed with

{player addMagazine _x} forEach _kilposmagArray

{player addWeapon _x} forEach _kilposweapArray

player selectWeapon _kilprimary

player setPos _kilpos

player setdir _kildir

fastrespawn = false

goto "START"

Share this post


Link to post
Share on other sites

you can do something like this:

in the Hit EH:

murderer = _shooter

publicvariable "murderer"

that should work okay, not great, but okay.

Share this post


Link to post
Share on other sites

aha always good for someone to see it from a different point of view, thanks a lot will try this

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  

×