Editors Depot - Mission Editing and Scripting > OFP - Editing/Scripting Multiplayer

kill script for friendly/enemy... help!

(1/2) > >>

ÐurbanPoison™:
Hi there,

Firstly, let me say that I was STOKED!!! to see OFPEC return! I'm overjoyed at the thought that this site is back and it seems back for good!  All hail the flashpoint gods!(and props to Armaholic!)

Okay to my question... I'm trying to work on a script but keep running into errors... the script by now is pretty much garbage due to all the tweaks I tried to implement :(

In the mission there are 13 west players (police) who hunt 1 east player (killer). The east player hunts civilians and will kill police if they get in the way. I have it scripted so far that the above works well.

I now need a script (ideally a "killed EH) to prevent police from team killing and deal punishment/display messges if this happens. If a tk does happen, I would like to Play a global cuttext message that reports the violator (to all players including east) that says he's been sent to jail for 3 minutes -  then send the tk'ing player to a designated area (object Prison1) for 3 minutes. I would also like to add hint messages every 30seconds that inform the jailed player (only/locally), how much time is remaining, ending with a "You've been released!" hint and setpos'ing him out side the jail.

PROBLEMS so far...
I've tried to use an array that checks to see if the tk'ing player is on west side... only problem is if the player kills himself by accident... he gets sent to jail for tk'in himself lol. Also if he's in a vehicle, it doesn't recognize the player is a police officer (in west array). The few times I managed to get the tk'er in jail, their vehicle also goes to jail with them! I've also not being able to get the messages to play the appropriate local/global messages! The script is now a total mess and pretty useless!

I'm now losing my mind, so I took my therapists advice and came to you guys for help! :blink:

I'll try layout the concept of what I mean in my limited scripting knowledge

Event:  West player killed
? was this death caused by east player?
If so play "officer has been shot" hint messages to west players only. I use public variable "oges" to add a point earned by killer for killing a police officer)

? was this death caused by accident/fall/roadkill?
If so play "officer has died!" hint messages to west players only. (no "oges" point awarded as killer didn't kill the officer- running down doesn't count as police kill)

? was this death a tk caused by another west player? (no "oges" point awarded as killer didn't kill the officer-)

If so play "officer %1 teamkilled a fellow police officer and has been sent to jail for 3 min" cuttext message to west players only... (no "oges" point awarded as killer didn't kill the officer)
Then sent tk'ing officer to object jail and play hint messages every 30 seconds listing remaining jail time until this offending player is released.

I'm not sure if the above makes sense, like I said my mind has gone at this point. But if anyone could kickdown some code that may easy my weary mind... well I'd be forever grateful. Please fee free to ask for more information or explanation as to what I am trying to achieve! :P

Thanks guys!

savedbygrace:
I'm no MP editor but I can point you to a couple of resources that may be helpful until someone who has experience with MP comes along.
Eventhandler tutorial
MP editing Tutorial

Hope it helps some.

ÐurbanPoison™:
Thanks SBG, I actually did review those lol! But when I applied what I could understand... it didn't produce the desired result.

This may sound really dumb... but one of the biggest hurdles to mp scripting for me, is how things behave when I edit on my pc (fire up game, got to multiplayer, click NEW and create server and then edit) as opposed to what they do when hosted on a dedicated machine. Is it possible to edit missions on the dedicated server? ...so that when you test/play/preview the mission it's not acting locally as it would if edit on local machine that created the server?  :blink:


Does that even make sense?

Rellikki:
The idea sounds a lot like the good old Serial killer multiplayer mission that I used to play all the time.

I gave this a go. It hasn't been tested in multiplayer, so I'm not 100% confident that it works, so let me know how it turns out.

First you'll need to add a game logic named server into your mission. After that, you'll need the following script. It initializes some important variables that are used throughout the mission. It gets executed automatically by the game engine since it's called init.sqs.

init.sqs

--- Code: ---oges = 0
accident = 0
teamkill = 0
murder = 0
[] exec "events.sqs"
--- End code ---

Next you'll need the following script. This should add the killed event handler to an officer at the beginning of the mission and remove it from the dead body whenever they die and add it back when they respawn. Execute this to all the officers at the beginning of the mission. You could, for example, write this exec "addEventHandler.sqs" to each of the officers' init fields.

addEventHandler.sqs

--- Code: ---?! local player : exit

#loop
@ alive player
player addeventhandler ["killed", {[(_this select 0), (_this select 1)] exec "killed.sqs"}]

@! alive player
player removeAllEventHandlers "killed"
goto "loop"
--- End code ---

Next you'll need this. It's the script run by the killed event handler. It checks for the type of death and sends information about it to the clients.

killed.sqs

--- Code: ---_killed = _this select 0
_killer = _this select 1
if (format ["%1", gunner _killer] == "<NULL-OBJECT>") then {_killer = driver (_this select 1)} else {_killer = gunner (_this select 1)}

? _killer == _killed : goto "accident"
? side _killer == WEST : goto "teamkill"
? side _killer == EAST : goto "murder"
exit

#accident
accident = 1
publicVariable "accident"
killed = _killed
publicVariable "killed"
exit

#teamkill
teamkill = 1
publicVariable "teamkill"
killer = _killer
publicVariable "killer"
exit

#murder
murder = 1
publicVariable "murder"
killed = _killed
publicVariable "killed"
exit
--- End code ---

Then you'll need the following script. It's run by each client and constantly checks for when and how an officer has died and then displays the appropriate message about it. In the event of a team kill, it should also send the team killer to jail.

events.sqs

--- Code: ---#loop
? accident == 1 : goto "accident"
? teamkill == 1 : goto "teamkill"
? murder == 1 : goto "murder"
~1
goto "loop"

#accident
? side player == WEST : cutText [format ["Officer %1 was killed in an accident", name killed], "PLAIN DOWN"]
accident = 0
killed = nil
goto "loop"

#teamkill
? side player == WEST : cutText [format ["Officer %1 murdered a fellow police officer and has been sent to jail for 3 minutes", name killer], "PLAIN DOWN"]
? local killer : killer exec "jailed.sqs"
teamkill = 0
killer = nil
goto "loop"

#murder
? side player == WEST : cutText [format ["Officer %1 was murdered", name killed], "PLAIN DOWN"]
if (local server) then {oges = oges + 1; publicVariable "oges"}
murder = 0
killed = nil
goto "loop"
--- End code ---

And finally the jail script. For this you'll need an object or game logic named prison1 as you wanted. You didn't specify what would happen when an officer would be released from the jail, so I set it to position them to another location named releasePoint which you'll also need.

jailed.sqs

--- Code: ---_jailed = _this
?! local _jailed : exit
_jailtime = 180

_jailed setPos getPos prison1

#loop
? _time >= 180 : goto "release"
~30
hint format ["%1 seconds jailtime left", _jailtime - _time]
goto "loop"

#release
_jailed setPos getPos releasePoint
hint "You've been released"
exit
--- End code ---

I hope it works and didn't miss anything important.

ÐurbanPoison™:
This is great! Thank you for such a detailed and descriptive (no pun intended) explanation... I'm implementing your code and will let you know how it goes... but just by seeing what you've done and how you've passed information to other scripts is really useful to me and helped me understand a lot, so thanks thanks!

And you are correct... it is the serial killer mission but a mini version on the training island :) I'll let ya know how it turns out!

Navigation

[0] Message Index

[#] Next page

Go to full version