Home   Help Search Login Register  

Author Topic: CreateUnit / CreateVehicle Q's  (Read 1721 times)

0 Members and 3 Guests are viewing this topic.

Offline General Barron

  • Former Staff
  • ****
  • Semper Fi!
CreateUnit / CreateVehicle Q's
« on: 14 Mar 2005, 04:48:22 »
Hello all! I'm wondering: how do I create / spawn a CREWED vehicle? I tried to create one via the "createUnit" command, and it didn't seem to do anything. If I use the "createVehicle" command, it just creates an empty vehicle. Is there any way to create a pre-crewed vehicle (kinda like when you plop a vehicle down in the editor under the west/east side)?

Thanks!

EDIT

I also am wondering how waypoints work with respawned groups. Basically, I would like an AI group to spawn from point A, then move along a few waypoints towards point B. After a certain amount of time, the group will be dead, and it is respawned at point A again. I would then like them to REPEAT those waypoints from the very first waypoint. I'm not sure if that was clear, but hopefully you understand what I'm getting at...
« Last Edit: 14 Mar 2005, 04:57:57 by General Barron »
HANDSIGNALS COMMAND SYSTEM-- A realistic squad-control modification for OFP
kexp.org-- The best radio station in the world, right here at home! Listen to John Richards!

Silencer

  • Guest
Re:CreateUnit / CreateVehicle Q's
« Reply #1 on: 14 Mar 2005, 07:14:23 »
Hi,

- Maybe you should camcreate an empty vehicle and a group, and then getpos them in
  the vehicle?

- You can also look in the mission.sqm what the name of the "vehicle" is. And then
  camcreate / vehiclecreate it. (I dunno if this works).

Good luck!

Offline trinec

  • Members
  • *
  • I'm a llama!
Re:CreateUnit / CreateVehicle Q's
« Reply #2 on: 14 Mar 2005, 07:32:50 »
you can try this if you want im not sure that you can actually create a vehicle with a unit actually in it at the time of createing the vehicle but I know that you can do this.  For a group put one unit out in the ocean of the type you want to use and assign it a group name. Then make a trigger for when you want the vehicle to be made and on activation put whatever you want to name your script file.  Add a Game logic whatever name you want it anywhere on the map.  For the example below i used a gamelogic name of gl1 im not some script guru so here is what i did.  rb1 is the same name of the group that you put in the ocean at the start.

_units4 = units rb1
rb1 allowfleeing 0
"deletevehicle _x" foreach _units4
~1
_type1 = "Truck5tOpen"
_wtruck1 = _type1 createvehicle getpos gl1
~1
"SoldierWB" createunit [getpos gl1, rb1, "e1 = this", 1, "LIEUTENANT"]
~1
"SoldierWB" createunit [getpos gl1, rb1, "e2 = this", 1, "SERGEANT"]
~1
"SoldierWB" createunit [getpos gl1, rb1, "e3 = this", 1, "PRIVATE"]
~1

e1 moveindriver _wtruck1
e2 moveincargo _wtruck1
e3 moveincargo _wtruck1

which creates a vehicle at gamelogic named gl1 then creates 3 units at gl1 then moves them into the vehicle.  Don't know if this helps good luck.  
« Last Edit: 14 Mar 2005, 07:45:03 by trinec »

Offline trinec

  • Members
  • *
  • I'm a llama!
Re:CreateUnit / CreateVehicle Q's
« Reply #3 on: 14 Mar 2005, 07:39:36 »
you can actually for the units going to the vehicle getpos _wtruck1 instead of to the game logic guess it dont matter

Offline General Barron

  • Former Staff
  • ****
  • Semper Fi!
Re:CreateUnit / CreateVehicle Q's
« Reply #4 on: 14 Mar 2005, 23:45:24 »
Thanks guys, I had considered creating the vehicle separately w/createvehicle, then creating units and moving them into the vehicle. The problem, however, is that I want this to be dynamic, so I won't know what slots the vehicle has (does it have a commander? a gunner?). That's why I was hoping there was some way to just create the vehicle with the crew already there...

Oh well, I guess I'll have to work it the way you are suggesting, unless someone knows of a way to create it with the crew inside...? Still need an answer to the second Q though...
HANDSIGNALS COMMAND SYSTEM-- A realistic squad-control modification for OFP
kexp.org-- The best radio station in the world, right here at home! Listen to John Richards!

Offline trinec

  • Members
  • *
  • I'm a llama!
Re:CreateUnit / CreateVehicle Q's
« Reply #5 on: 15 Mar 2005, 06:23:05 »
Hey gen I found this in the bis forum not tried it yet

It requires a gamelogic, a unit with waypoints what executes the script like this;

Code Sample  
teamW1=group this; ["west",teamW1,g2,2] exec "spawnw.sqs";deletevehicle this



Code Sample  

; *****************************************************
; ** Operation Flashpoint Script File
; *****************************************************


~(random 1) + 1
_side = _this select 0
_team = _this select 1
_spawnpoint = _this select 2
_min = _this select 3



? (_side == "west"):goto "loop2"

~(random 1) + 1

#loop1
~12
? (count units _team > _min):goto "loop1"
"WH_SQDLDR2" createUnit [_spawnpoint,_team,"man1=this",0.5,"CORPORAL"]
~0.5
"WH_Panzerschreck1" createUnit [_spawnpoint,_team,"man2=this",0.3,"PRIVATE"]
~0.5
"WH_Schutze6" createUnit [_spawnpoint,_team,"man3=this",0.3,"PRIVATE"]
~0.5
"WH_Schutze1" createUnit [_spawnpoint,_team,"man4=this",0.3,"PRIVATE"]
~0.5
"WH_Schutze2" createUnit [_spawnpoint,_team,"man5=this",0.3,"PRIVATE"]
~0.5
"WH_Schutze1" createUnit [_spawnpoint,_team,"man6=this",0.3,"PRIVATE"]
~0.5
"WH_Schutze3" createUnit [_spawnpoint,_team,"man7=this",0.3,"PRIVATE"]
~0.5
"WH_Schutze4" createUnit [_spawnpoint,_team,"man8=this",0.3,"PRIVATE"]
~0.5
"WH_Schutze5" createUnit [_spawnpoint,_team,"man9=this",0.3,"PRIVATE"]
~0.5
"WH_LMGunner" createUnit [_spawnpoint,_team,"man10=this",0.3,"PRIVATE"]
~0.5
"WH_LMAmmo" createUnit [_spawnpoint,_team,"man11=this",0.3,"PRIVATE"]
~0.5
"WH_Medic" createUnit [_spawnpoint,_team,"man12=this",0.3,"PRIVATE"]
~0.5


("_x addeventhandler [ {killed} , {_this exec {killbody.sqs}} ] " foreach units _team)
~0.5

;allow for easier enemies
;("_x setdammage -1" foreach units _team)

("_x allowfleeing 0.5" foreach units _team)

hint "GERMAN created"
goto "loop1"

;======================west===================================


#loop2
~10
? (count units _team > _min):goto "loop2"
"82_ABNCO2" createUnit [_spawnpoint,_team,"wman1=this",0.5,"CORPORAL"]
~0.5
"82_ABMGAMMO" createUnit [_spawnpoint,_team,"wman2=this",0.3,"PRIVATE"]
~0.5
"82_ABMGUN" createUnit [_spawnpoint,_team,"wman3=this",0.3,"PRIVATE"]
~0.5
"82_ABBLAUNCHER" createUnit [_spawnpoint,_team,"wman4=this",0.3,"PRIVATE"]
~0.5
"82_ABRIFLEMAN1" createUnit [_spawnpoint,_team,"wman5=this",0.3,"PRIVATE"]
~0.5
"82_ABRIFLEMAN1" createUnit [_spawnpoint,_team,"wman6=this",0.3,"PRIVATE"]
~0.5
"82_ABRIFLEMAN2" createUnit [_spawnpoint,_team,"wan7=this",0.3,"PRIVATE"]
~0.5
"82_ABRIFLEMAN2" createUnit [_spawnpoint,_team,"wan8=this",0.3,"PRIVATE"]
~0.5
"82_ABRIFLEMAN3" createUnit [_spawnpoint,_team,"wan9=this",0.3,"PRIVATE"]
~0.5
"82_ABRIFLEMAN3" createUnit [_spawnpoint,_team,"wan10=this",0.3,"PRIVATE"]
~0.5
"82_ABBAR" createUnit [_spawnpoint,_team,"wan11=this",0.3,"PRIVATE"]
~0.5
"82_ABMEDIC" createUnit [_spawnpoint,_team,"wan12=this",0.3,"PRIVATE"]
~0.5
("_x addeventhandler [ {killed} , {_this exec {killbody.sqs}} ] " foreach units _team)
~0.5

("_x allowfleeing 0.5" foreach units _team)
;("_x setdammage -1" foreach units _team)

hint "USA created"
goto "loop2"

 


and killbody.sqs

Code Sample  

_unit = _this select 0
_unit removealleventhandlers "killed"
~60
deletevehicle _unit
exit
 


Simple, and they keep comming over and over again..

Offline h-

  • OFPEC Site
  • Administrator
  • *****
  • Formerly HateR_Kint
    • OFPEC
Re:CreateUnit / CreateVehicle Q's
« Reply #6 on: 15 Mar 2005, 17:12:36 »
I also am wondering how waypoints work with respawned groups. Basically, I would like an AI group to spawn from point A, then move along a few waypoints towards point B. After a certain amount of time, the group will be dead, and it is respawned at point A again. I would then like them to REPEAT those waypoints from the very first waypoint. I'm not sure if that was clear, but hopefully you understand what I'm getting at...
Take a look at Chain of Command AI on Demand...
You can find it here...

It simply deletes the wanted units and then re-creates them when desired...
The re-created AI will continue their original WPs...
Afaik the WPs are stored (among the myriad of other stuff stored) for later use in some array or something.....

Altough I must say that code is not the most readable ones I've seen... ::)

I have not used this latest version of the AI OD yet, but I think the earlier version only emptied vehicles so that only the crew was re-created, or it did it so that the vehicle and the crew were re-created separately and the crew was then moveInXed...

Just a thought:
Quote
The problem, however, is that I want this to be dynamic, so I won't know what slots the vehicle has
You could try something like moveInXing a gamelogic in the created vehicle and check with that which positions the vehicle has available...
You know, something like
Code: [Select]
_logic="logic" createVehicle [somepos]
_logic moveInCommander _vehicle
? commander _vehicle == _logic: _commanderSlot=true

etc......
Project MCAR   ---   Northern Fronts   ---   Emitter 3Ditor
INFORMATIVE THREAD TITLES PLEASE. "PLEASE HELP" IS NOT ONE..
Chuck Norris can divide by zero.

Offline General Barron

  • Former Staff
  • ****
  • Semper Fi!
Re:CreateUnit / CreateVehicle Q's
« Reply #7 on: 15 Mar 2005, 22:53:37 »
@ trinec
Thanks for posting the script. It is pretty similar to what I already have working for infantry spawns. Unfortunately it still doesn't help with vehicle spawns....

@ HateR_Kint
Thanks, I'll check out the AIOD scripts, although my initial poking around makes me think that those scripts don't respawn the groups after they are killed, so it isn't exactly what I'm looking for in terms of waypoints... I might end up having to script some "virtual" waypoints I suppose.

As for the function to check available positions: good idea, I guess I'll have to resort to that. I needed to make such a function for something else anyway, so I guess I'll put it to double use. Thanks :)
HANDSIGNALS COMMAND SYSTEM-- A realistic squad-control modification for OFP
kexp.org-- The best radio station in the world, right here at home! Listen to John Richards!

Kyle Sarnik

  • Guest
Re:CreateUnit / CreateVehicle Q's
« Reply #8 on: 16 Mar 2005, 00:28:04 »
Not tested:

Code: [Select]
_type = _this select 0
_crewtype = _this select 1
_pos = _this select 2
_include = []

_veh = _type createvehicle [0,0,0]
_veh setpos _pos

_gl1 = "Logic" createvehicle [0,0,0]
_gl1 moveindriver _veh
? count crew _veh > 0 : _include = _include + ["driver"]
_gl1 action ["GETOUT",_veh]
_gl1 moveingunner _veh
? count crew _veh > 0 : _include = _include + ["gunner"]
_gl1 action ["GETOUT",_veh]
_gl1 moveincommander _veh
? count crew _veh > 0 : _include = _include + ["commander"]
_gl1 action ["GETOUT",_veh]
_gl1 moveincargo _veh
? count crew _veh > 0 : _include = _include + ["cargo"]

? "cargo" in _include : goto "loopstart"
goto "next"

#loopstart
_n = 0
_cargos = 1
_deletes = [_gl1]
#loop
? _n >= count crew _veh : goto "next"
_count = count crew _veh
_new = "Logic" createvehicle [0,0,0]
_deletes = _deletes + [_new]
_new moveincargo _veh
? count crew _veh > _count : _cargos = _cargos + 1
_n = _n + 1
goto "loop"

#next
{_X action ["EJECT",_veh} foreach _deletes
{deletevehicle _X} foreach _deletes

? "driver" in _include : goto "driver"
goto "guncheck"
#driver
_crewtype createunit [getpos _veh, temp_group, "New Solder = this", 1, "LIEUTENANT"]
_newsoldier = units temp_group select 1
_newsoldier moveindriver _veh
[_newsoldier] join _newsoldier
_leader = _newsoldier
#guncheck
? "gunner" in _include : goto "gunner"
goto "comcheck"
#gunner
_crewtype createunit [getpos _veh, temp_group, "New Solder = this", 1, "LIEUTENANT"]
_newsoldier = units temp_group select 1
_newsoldier moveingunner _veh
?! Isnull _leader : [_newsoldier] join _leader; goto "comcheck"
[_newsoldier] join _newsoldier
_leader = _newsoldier
#comcheck
? "commander" in _include : goto "commander"
goto "cargcheck"
#commander
_crewtype createunit [getpos _veh, temp_group, "New Solder = this", 1, "LIEUTENANT"]
_newsoldier = units temp_group select 1
_newsoldier moveincommander _veh
?! Isnull _leader : [_newsoldier] join _leader; goto "cargcheck"
[_newsoldier] join _newsoldier
_leader = _newsoldier
#cargcheck
? "cargo" in _include : goto "cargo"
goto "end"
#cargo
_c = 0
#cargoloop
? _c >= _cargos : goto "end"
_c = _c + 1
_crewtype createunit [getpos _veh, temp_group, "New Solder = this", 1, "LIEUTENANT"]
_newsoldier = units temp_group select 1
_newsoldier moveincargo _veh
?! Isnull _leader : [_newsoldier] join _leader; goto "cargoloop"
[_newsoldier] join _newsoldier
_leader = _newsoldier
goto "cargoloop"

#end
NewVehicle = _veh
NewGroup = group _leader
hint "Hope this works ;) "
exit

Requires a single soldier with   group this = temp_group    in his init box.
« Last Edit: 16 Mar 2005, 00:30:40 by Kyle Sarnik »

Offline h-

  • OFPEC Site
  • Administrator
  • *****
  • Formerly HateR_Kint
    • OFPEC
Re:CreateUnit / CreateVehicle Q's
« Reply #9 on: 16 Mar 2005, 16:13:38 »
@ HateR_Kint
Thanks, I'll check out the AIOD scripts, although my initial poking around makes me think that those scripts don't respawn the groups after they are killed, so it isn't exactly what I'm looking for in terms of waypoints... I might end up having to script some "virtual" waypoints I suppose.
Yeah, when they die they don't get 're-animated', but the idea is there...

How it works is that you put for example a group on the map and do the stuff required in the init field and the group gets deleted and then re-created after the certain conditions are met, and the re-created AI follows it's original waypoints... So in a sense they respawn and continue following their waypoints...

So it should give you at least the right direction on how to approach this WP thing/problem...
Project MCAR   ---   Northern Fronts   ---   Emitter 3Ditor
INFORMATIVE THREAD TITLES PLEASE. "PLEASE HELP" IS NOT ONE..
Chuck Norris can divide by zero.

johan_d2

  • Guest
Re:CreateUnit / CreateVehicle Q's
« Reply #10 on: 17 Mar 2005, 00:29:08 »
Unbelieveable that I, humble me can be of any help.
The script you posted, (trinec) is my expiriment, and you just make one single unit, give it waypoints, they will be remembered. Deletevehicle the unit, and spawn the group, it comes over and over again over the same waypoints, unless you place them somewhere else.

Now on the vehicle, I found it here, cant remember where:

Code: [Select]
requiredVersion "1.91"
? not local Server : exit
_obj = _this select 0

_pos = getPos _obj
_dir = getDir _obj
_type = typeOf _obj
_group = group _obj
_crew = []
"_crew = _crew + [typeOf _x]" forEach crew _obj
"_x addEventHandler [""Killed"", {(_this select 0) removeAllEventHandlers ""Killed""; deleteVehicle (_this select 0)}]" forEach crew _obj

#clear
_t = 0

#alive
~3
? not alive _obj : _delay = 15; goto "notalive"

? fuel _obj == 1 : goto "clear"
? count crew _obj != 0 : goto "clear"

? _t == 0 : _t = _time + 11
? _t > _time : goto "alive"

"_obj removeMagazine _x" forEach magazines _obj
_obj setFuel 0
_obj setDamage 1
_delay = 10

#notalive
~_delay


~1
_obj = _type createVehicle _pos
_obj setDir _dir

? count _crew < 1 : goto "clear"
Soldier = []
_crew select 0 createUnit [_pos, _group, "Soldier = this"]
Soldier moveInDriver _obj
Soldier setdammage -1
Soldier doMove getWPPos [_group, 1]
Soldier addEventHandler ["Killed", {(_this select 0) removeAllEventHandlers "Killed"; deleteVehicle (_this select 0)}]

? count _crew < 2 : goto "clear"
Soldier = []
_crew select 1 createUnit [_pos, _group, "Soldier = this"]
Soldier moveInGunner _obj
Soldier setdammage -1
Soldier doMove getWPPos [_group, 1]
Soldier addEventHandler ["Killed", {(_this select 0) removeAllEventHandlers "Killed"; deleteVehicle (_this select 0)}]

? count _crew < 3 : goto "clear"
Soldier = []
_crew select 2 createUnit [_pos, _group, "Soldier = this"]
Soldier moveInCommander _obj
Soldier setdammage -1
Soldier doMove getWPPos [_group, 1]
Soldier addEventHandler ["Killed", {(_this select 0) removeAllEventHandlers "Killed"; deleteVehicle (_this select 0)}]

goto "clear"


Works for ANY kind of vehicle, and respawns the correct crew. Even INV44 units!

The vehicle stays on the battlefield when destroyed, the crew not, and comes back with a new vehicle, unless you deletevehicle the dammages one too.


Just start with [this] exec "vehicle.sqs"
Johan
« Last Edit: 17 Mar 2005, 00:30:24 by johan_d2 »

Offline General Barron

  • Former Staff
  • ****
  • Semper Fi!
Re:CreateUnit / CreateVehicle Q's
« Reply #11 on: 17 Mar 2005, 00:40:52 »
Wow, thanks for the scripts guys. I'll look into them. :D
HANDSIGNALS COMMAND SYSTEM-- A realistic squad-control modification for OFP
kexp.org-- The best radio station in the world, right here at home! Listen to John Richards!