Home   Help Search Login Register  

Author Topic: kill script for friendly/enemy... help!  (Read 3786 times)

0 Members and 1 Guest are viewing this topic.

kill script for friendly/enemy... help!
« on: 29 Jun 2014, 20:29:44 »
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!

Offline savedbygrace

  • Intel Depot
  • Administrator
  • *****
  • Be swift to hear...slow to speak...slow to wrath.
Re: kill script for friendly/enemy... help!
« Reply #1 on: 29 Jun 2014, 22:16:18 »
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.

Re: kill script for friendly/enemy... help!
« Reply #2 on: 30 Jun 2014, 00:10:26 »
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?

Offline Rellikki

  • Members
  • *
  • Die-hard OFP player
Re: kill script for friendly/enemy... help!
« Reply #3 on: 30 Jun 2014, 08:58:23 »
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: [Select]
oges = 0
accident = 0
teamkill = 0
murder = 0
[] exec "events.sqs"

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: [Select]
?! 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"

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: [Select]
_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

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: [Select]
#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"

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: [Select]
_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

I hope it works and didn't miss anything important.
« Last Edit: 03 Jul 2014, 21:19:20 by Rellikki »

Re: kill script for friendly/enemy... help!
« Reply #4 on: 02 Jul 2014, 02:22:37 »
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!

Re: kill script for friendly/enemy... help!
« Reply #5 on: 03 Jul 2014, 16:24:01 »
I implemented the script and it works well! Thank you!

I had a couple questions about tweaking it... I noticed that if the killer dies a few times (kills himself) the computer will start to treat him as a west player... and vise versa... if a cop tk's a few times it will begin to display east messages to that officer lol. I assume this is due to the player's score going negative and making them enemy to their team - so would resetting the offender's score to zero after they lose a point fix the problem? And if so is there a set score command? I messed around with Score player and and add or minus a point, but don't know how to reset a score to zero ie.   score player == 0 etc.

The other question regarding vehicles - which are also still going to jail with the offending party... is there an eject/remove from vehicle command that will remove vehicle from player/player from vehicle? And I imagine if the gunner of a heli or jeep tk's but the pilot/driver didn't - it would be unfair to punish the entire crew... so I guess removing the player from whatever vehicle they're in would be best?

Again, thanks in advance for any help - so far the mission is coming along pretty darn well :D

« Last Edit: 03 Jul 2014, 16:26:09 by ÐurbanPoison™ »

Offline Rellikki

  • Members
  • *
  • Die-hard OFP player
Re: kill script for friendly/enemy... help!
« Reply #6 on: 03 Jul 2014, 21:19:03 »
Yes, it's true that the game engine will change the player's side if they get too many negative points. I wrote a script that fixes that issue:

Code: [Select]
?! local player : exit

#loop
@ rating player < 0
player addrating -(rating player)
goto "loop"

That'll negate any negative points that the player gets, reset them back to zero and change their side back to their default one. Execute it to all players.

You can fix the problem with the jailed guy's vehicle coming along with them by adding the following line into the killed.sqs script after the first two lines:

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

Basicly it assumes that if the killer's vehicle didn't have a gunner, then it must be the driver (In case of manual fire.) Also works if no vehicle was present and they were on foot. I updated my previous post with this change.
« Last Edit: 03 Jul 2014, 21:25:42 by Rellikki »

Re: kill script for friendly/enemy... help!
« Reply #7 on: 04 Jul 2014, 05:53:30 »
Man that works perfectly! Thank you again very much, your coding will have saved me many hours of  ???:P

Cheers~