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

creating vehicles/units mid air?!

(1/2) > >>

ÐurbanPoison™:
Hi there,

I'm trying to add some challenge to a mission im working on - but can't seem to get it to work  :dunno:

Ideally I'd like to spawn a chinook flying at position1, then tell it to follow an enemy. Once it's within 150 feet of enemy I' like it to be able to have the chinook spawn 12 ai units (west) that para down to enemy and then pursue them on foot .... BUT those west units need to use the Civilian11 skin! (police.)

Once units have spawned script should stop and wait for at least 6 of the spawned units to die before dropping another 6 via para from chinook.

I've also had problems with telling a police ai unit who to follow... there are 2 east players - killer1 and killer2... is there a way to tell a ai police unit to follow either killer1 or killer2? (sometimes people will only use killer2 slot... other times they may select killer1 slot... or both!)  struggle to know how to tell ai to persue either or both!  :confused:

Any help would be greatly appreciated and thanks in advance! By myself and those who will play and face this onslaught!  :D

savedbygrace:
Out of curiosity only, do you have a clan or group of friends you play MP with? If not, why not just create some scenarios for SP?

Have you checked out our COMREF yet?

ÐurbanPoison™:
Hey there sbg,

Thanks for the reply! Firstly, you have a unique name - are you a practicing christian or is that a metal song? lol (you don't have to answer this obviously :whistle: )
 
In regards to your reply - I host †veterans of destruction† server for cwa 1.99 which still (amazingly!) has players! Last weekend had 12 in a game which is pretty darn good for ofp  :D That and my brother overseas still plays this game with me once in a while... so mp is kind of essential! THis mission does have sp elements... such as the script im trying to get working. IF there are only 1 or 2 killers playing - it activates other ai to attack and defend the civilians :)

I know the comref well but am more of an artist and musician than computer programmer lol. I can post what have scripted (or failed at scripting lol) but usually it's as useless to the person replying as it is to me lol... i understand some principles but every time I try read tutorials i get confused and my head hurts lol.  :-[
Imo the comrel is like a dictionary - it has great snippets... and hints...  but won't teach you how to speak the language! ...for me anyway!


--- Code: ---#drop

?!(alive hELI4): EXIT  ; heli4 is the name of the chinook
?(botcops > 6) : goto "search" ; checks to see how many ai are still alive and whether it should spawn more
?((POLHELI4pilot Distance KILLER1) or (POLHELI4pilot Distance KILLER2) < 150) : goto "PARA" ; tells chinook to spawn ai if close to either Killer1 or Killer2

goto "search"

#PARA
pOLHELI4PILOT setSpeedMode "LIMITED" ;slows down chopper?
pOLHELI4 setSpeedMode "LIMITED" ; slows down chopper?
?(botcops > 6) : goto "search"; checks to see how many ai are still alive
botcops = botcops + 1 ;adds a unit to the police counter
PublicVariable "botcops" ; as above
_unit1 ="civilian11" createUnit [position AI1, group Polheli4pilot] ;spawns civilian police ai at pad AI1 and groups with pilot
_unit1 setskill 1; makes this ai unit meaner
_unit1 action ["eject", Polheli4] ;tells ai unit to eject from heli4
_unit1 AddEventHandler ["killed",{_unit1 exec "botkilled.sqs"}] ; adds EH to removed dead body once killed
?(botcops < 6) : goto "para" ; checks to see how many ai are still alive and whether it should spawn more


CutText [format["\nPolice officer dispatched! There are %1  active officers hunting killers!", botcops], "Plain"] ; relays officer spawned and amount active (more just to see if it's working lol)


#search
pOLHELI4PILOT setSpeedMode "FULL"; speeds chopper back up
pOLHELI4 setSpeedMode "FULL" ; same as above? Not sure if I need to command the ai I put in the empty chinook or the chinook itself... so did both lol
pOLHELI4PILOT domove (position killer1); tells heli to hunt killer 1 - I'm not sure how to have the heli pick the closest killer to hunt :(
pOLHELI4GUNNER dotarget  killer1; tells heli to target killer 1 -Again I'm not sure how to have the heli pick the closest killer to hunt!
_unit1 domove (position killer1); as above
_unit1 dotarget  killer
_unit2 domove (position killer1); as above
_unit2 dotarget  killer
_unit3 domove (position killer1); as above
_unit3 dotarget  killer
_unit4 domove (position killer1); as above
_unit4 dotarget  killer
_unit5 domove (position killer1); as above
_unit5 dotarget  killer
_unit6 domove (position killer1); as above
_unit6 dotarget  killer

~1
?(botcops < 7) and ((POLHELI4 Distance KILLER1) or (POLHELI4 Distance KILLER2) < 150) : goto "PARA" ; Checks to see how many cops are alive and if to spawn more or go back to loop
goto "drop"
--- End code ---

The above simply does not work... Chinook doesn't start flying, only 3 ai spawn and they are on gound next to heli lol. That is all it does so clearly im missing the mark here lol .

botkilled.sqs:

--- Code: ---_body = _this select 0


botcops = botcops - 1
PublicVariable "botcops"
~60
deleteVehicle _body

exit 

--- End code ---

Mission init has

--- Code: ---botcops = 0
PublicVariable "botcops";
--- End code ---

As there are 2 killers (killer1 and killer2)  - I'm not sure how to tell the ai to choose who's closest... or who's killed more civilians... I think I need an array but hell if I know how to implement that!

Oh and please don't laugh at the code i just posted!! :no:  I imagine it's pretty hilarious to an expert :P 
I'm just kidding... laugh away!

Rellikki:
I'm not particularly fond of these scripts of mine as I find them really messy and I believe there are better ways of doing this, but they should do it.

First you must place two groups of police officers and change their side to West as you wanted by editing the mission.sqm file. I believe you already know how to do this so I won't go into detail on it. Splitting them into two different groups makes this whole thing a lot simpler. Type the following into both of the group leaders' init fields, but make sure to change the variable searchparty1 into searchparty2 for the second group:

searchparty1 = group this; {_x moveInCargo heli4} forEach units this

You also need to have a game logic named server in your mission as these are supposed to be run by the server only.

Add para = 0 into your init.sqs script; it initializes a variable that's used to check when a group has been parachuted, so the helicopter won't parachute them all at once.

Here come the scripts themselves. First off is the script for the helicopter. I set it up so it'll wait at a position named heliWait until there are any units in its cargo, so you'll need a game logic named like that. It then goes to the position of the killer(s) and parachutes the search parties to hunt them. If either one of the killers doesn't exist, it also parachutes the other search party too at the position of the other killer. To activate it, you need to type [] exec "heli.sqs" whenever you want the hunt to begin.

heli.sqs

--- Code: ---?! local server : exit

#loop
?! alive heli4 : exit
heli4 flyInHeight 150
heli4 move getPos heliWait
@ count crew heli4 > 2

;paradrop1
? format ["%1", killer1] == "scalar bool array string 0xfcffffef" || count crew heli4 <= 2 : goto "paradrop2"
_parapos = "Logic" camCreate [getPos killer1 select 0, getPos killer1 select 1, 150]
heli4 move getPos _parapos
@ heli4 distance _parapos < 150
deleteVehicle _parapos
[units searchparty1] exec "paradrop.sqs"
@ para == 1
para = 0
? format ["%1", killer2] != "scalar bool array string 0xfcffffef" : goto "paradrop2"
[units searchparty2] exec "paradrop.sqs"
@ para == 1
para = 0

#paradrop2
? format ["%1", killer2] == "scalar bool array string 0xfcffffef" || count crew heli4 <= 2 : goto "loop"
_parapos = "Logic" camCreate [getPos killer2 select 0, getPos killer2 select 1, 150]
heli4 move getPos _parapos
@ heli4 distance _parapos < 150
deleteVehicle _parapos
[units searchparty2] exec "paradrop.sqs"
@ para == 1
para = 0
? format ["%1", killer1] != "scalar bool array string 0xfcffffef" : goto "loop"
[units searchparty1] exec "paradrop.sqs"
@ para == 1
para = 0
goto "loop"
--- End code ---

This is the parachuting script. It's run by the heli script above:

paradrop.sqs

--- Code: ---?! local server : exit

_paras = _this select 0

_count = 0
#loop
_para = (_paras select _count)
_para action ["Eject", vehicle _para]
unassignVehicle _para
_count = _count + 1
? _count >= count _paras : goto "end"
~0.5
goto "loop"

#end
para=1
exit
--- End code ---

And finally the script for the search parties. It takes care of the search for the killer(s) and respawns them whenever they've been killed. To activate it, you need to type the following for the first group:

[searchparty1, killer1, killer2] exec "search.sqs";

And for the second group:

[searchparty2, killer2, killer1] exec "search.sqs";

The first parameter in the array is the group name obviously. The second parameter is their primary target. If the primary target doesn't exist, then they revert to their secondary target, which is the third parameter. These are reversed for both of the search parties, so in case either one of the killers doesn't exist, both of the groups will go after the same target, and if both killers do exist, then they go after both of them respectively.

search.sqs

--- Code: ---?! local server : exit

_group = _this select 0
_killer1 = _this select 1
_killer2 = _this select 2
_killer = objNull
_count = 0

if (format ["%1", _killer1] == "scalar bool array string 0xfcffffef") then {_killer = _killer2} else {_killer = _killer1}

#loop
?! alive heli4 : exit
? {alive _x} count units _group == 0 : goto "respawn"
(leader _group) move getPos _killer
~10
goto "loop"

#respawn
"Civilian11" createUnit [getPos heli4, _group, "loon = this"]
loon moveInCargo heli4
loon = nil
_count = _count + 1
? _count >= 6 : goto "loop"
goto "respawn"
--- End code ---

I might have overlooked something important, so let me know if there are any problems.

ÐurbanPoison™:
Thank you very much Rellikki, this is very helpful but i think im missing something...

Couple questions just to be sure I don't mess it up -

You said create 2 different groups so...

So I did as you said and put 2 west units as leaders, each having 5 ai to command. So in other words 2 teams of 6 units. I then added
--- Code: ---searchparty1 = group this; {_x moveInCargo heli4} forEach units this
--- End code ---

In the first team leaders init field and then
--- Code: ---searchparty2 = group this; {_x moveInCargo heli4} forEach units this
--- End code ---

in the second leaders init field. I then changed them all in the mission.sqs from west soldier to the civilian11.
So teams set up.

I got a little confused with this part...


--- Quote ---To activate it, you need to type the following for the first group:

[searchparty1, killer1, killer2] exec "search.sqs";

And for the second group:

[searchparty2, killer2, killer1] exec "search.sqs";

--- End quote ---

How would I go about calling/activating the above? Meaning where should I type the above code? In each team leader's init field? In a trigger? I think this may be where I'm missing it.

And in regards to the heli...
Do the pilots Heli4pilot1 and Heli4gunner1 need anything in their init fields? (They moveindriver  & moveingunner of empty chinook named Heli4 at start of mission).

If I change the values of

--- Code: ---heli4 flyInHeight 150
--- End code ---
and/or

--- Code: ---@ heli4 distance _parapos < 150
--- End code ---
...will this cause the scripts to malfunction or not work? (I realize if they jump too low they will die or if the distance is too little from killer they will not spawn.)

Oh and I also forgot to ask - I modified the mission so that the killer can have a few extra lives... so this the original units named killer1 and killer2 may respawn a few times during the mission... will this mess up the script? Will the created units know to hunt the respawned killer? I hope this isn't a dumb question lol. And thank you again for all the info and help - It's really made this entire process a lot less stressful and the mission a lot more fun! :D
 

*EDIT: I tried and it seems that if the killer stays on the little island he starts on and I call heli.sqs via radio - the script works as it should... however strangely if I teleport to island the heli will come find me but not spawn units. (at least that's how it appears to be happening)

I'll play with it some more this weekend and hopefully get it working  :)

Navigation

[0] Message Index

[#] Next page

Go to full version