Home   Help Search Login Register  

Author Topic: Deleting CamCreated Units  (Read 1012 times)

0 Members and 1 Guest are viewing this topic.

Mr.BoDean

  • Guest
Deleting CamCreated Units
« on: 15 Jun 2004, 11:38:27 »
So I'm using this great script by a fine member of your staff here ...let's call him "Arctic Tactician" for long.  ;)

  Anyhow, I'm wondering since the units are created into the group of a single group leader in the editor, can those units be deleted?  i.e., I can't name units that don't yet exist.  I tried scripting something and using a group delete but didn't have any luck. Anyone know?   ???

Offline macguba

  • Former Staff
  • ****
    • macguba's operation flashpoint page
Re:Deleting CamCreated Units
« Reply #1 on: 15 Jun 2004, 12:14:48 »
I don't know the script to which you refer, but in general camCreated objects, or createUnit loons which is what I suspect you are talking about, can be deleted.

In both cases the object is named when it is created:-

flare1 = "flare" camCreate getpos gameLogic_1

"SoldierWB" createUnit [getMarkerPos "marker_1", groupAlpha, "loon1 = this; this addweapon {binocular}", 0.6, "corporal"]

Just apply deleteVehicle flare1 or loon1.

Plenty of reviewed ArmA missions for you to play

Mr.BoDean

  • Guest
Re:Deleting CamCreated Units
« Reply #2 on: 15 Jun 2004, 20:52:21 »
Hmm...I see .  Well, this script was designed to create multiple groups, so the units only get group affiliations, not names. I suppose that could be modified, too, if it's necessary. As mentioned, I'd tried using something like

"deletevehicle _x" foreach units Paragroup0

but that only deletes units that are still alive!  :o  The dead ones remain on the ground.  ::)

here is some of the code, note the unit gets no name.


Code: [Select]
_counter = 0
_groupnames = [paragroup0,paragroup1,paragroup2,paragroup3]
_groupname = paragroup0

_groupname = _groupnames select _counter
(leader _groupname) moveInCargo Mi17
_skill = random 0.8

?(local server): "SoldierEB" createunit [getmarkerpos "temp", _groupname, "this moveincargo mi17",_skill]

?(local server): "SoldierEB" createunit [getmarkerpos "temp", _groupname, "this moveincargo mi17",_skill]

?(local server): "SoldierEB" createunit [getmarkerpos "temp", _groupname, "this moveincargo mi17",_skill]

?(local server): "SoldierEG" createunit [getmarkerpos "temp", _groupname, "this moveincargo mi17",_skill]

Mr.BoDean

  • Guest
Re:Deleting CamCreated Units
« Reply #3 on: 16 Jun 2004, 08:50:17 »
OK, Mac ... I decided to add your little naming bit into the equation and came up with a way to count names in some arrays so that eacch created unit could be named. It seemed to work ...well at least I got no errors.  ;D

But again when it came down to deleting them, only the group leader which was created and named in the editor got deleted.   :-X   ???  Does OFP just not recognize unit names if they are not created in the editor?

Code: [Select]
_counter = 0
_groupnames = [paragroup0,paragroup1,paragroup2,paragroup3,paragroup4,paragroup5,paragroup6]
_groupname = paragroup0

_gnL = [_unitnames0,_unitnames1,_unitnames2,_unitnames3]
_gn = _unitnames0

_unitnames0 = [B0,C0,D0,E0,F0,G0,H0,I0,J0,K0,L0]
_unitnames1 = [B1,C1,D1,E1,F1,G1,H1,I1,J1,K1,L1]
_unitnames2 = [B2,C2,D2,E2,F2,G2,H2,I2,J2,K2,L2]
_unitnames3 = [B3,C3,D3,E3,F3,G3,H3,I3,J3,K3,L3]

_unitname = B0

#para
_U = 0
_groupname = _groupnames select _counter
(leader _groupname) moveInCargo Mi17
_skill = random 0.8

_gn = _gnL select _counter
_unitname = _gn select _U


   ?(local server): "SoldierEB" createunit [getmarkerpos "temp", _groupname, "_unitname = this; this moveincargo mi17",_skill]

_U = _U+1
_unitname = _gn select _U
   ?(local server): "SoldierEB" createunit [getmarkerpos "temp", _groupname, "_unitname = this; this moveincargo mi17",_skill]
_U = _U+1
_unitname = _gn select _U
   ?(local server): "SoldierEB" createunit [getmarkerpos "temp", _groupname, "_unitname = this; this moveincargo mi17",_skill]
_U = _U+1
_unitname = _gn select _U
   ?(local server): "SoldierEG" createunit [getmarkerpos "temp", _groupname, "_unitname = this; this moveincargo mi17",_skill]


I tried both of these forms of deleting:

Code: [Select]
"deletevehicle _x" foreach [A0,B0,C0,D0,E0]
and

Code: [Select]
deletevehicle A0; deleteVehicle B0; deleteVehicle C0; deleteVehicle D0; deleteVehicle E0
 ???    ???

ponq

  • Guest
Re:Deleting CamCreated Units
« Reply #4 on: 16 Jun 2004, 09:26:09 »
Here's how I do this:

-I create my units via a script units.sqs which does nothing special.
It just adds units to a leader.
Right after calling that script I create an array in which I store the new units (or add to an already existing array)
Code: [Select]
;part1 reinforcements
?!(local server): exit
[resgroup2, 6, ""] exec "units.sqs"
[resgroup3, 6, ""] exec "units.sqs"
[resgroup1, 6,  ""] exec "units.sqs"
part1resunits = [r1,r2,r3,r4,r5,r6,r7,r8,r9]
part1resunits = part1resunits + (units resgroup2) + (units resgroup3) + units (resgroup1)
Now I have an array "part1resunits" which, in my case, contains all the resistance units of part1 of my mission. (The r1 to r9 units are already placed at the start of the mission).

Now if you wan to delete these units (in my case, once part1 of the mission has been completed and we move on to part 2)

In my script which sets things up for Part2 I have this section, which deletes the troops from part1 (which are no longer needed):
Code: [Select]
; ***************************************
;delete dead bodies of part 1
"[_x] exec {delbody.sqs}" foreach part1resunits
"[_x] exec {delbody.sqs}" foreach units eastgrp1
"[_x] exec {delbody.sqs}" foreach units eastgrp2
"deletevehicle _x" foreach [fueltruck1, truck2, ural2, uaz1, uaz2, ural1, bmp1, bmp2]
; ***************************************
the delbody script if from somehwere at this forum ;)
Code: [Select]
;delbody.sqs by myke13021 (from ofpec forum)
;bodyhider is an blackop which can do "Hide Body" so the dead units sink slowly into the ground. You can comment that part if you want the to be removed instantly.

?!(local server): exit
_dude = _this select 0
removeallweapons _dude
;~60
bodyhider action ["hidebody", _dude]
~10
deletevehicle _dude
exit
__________
In short. Once you add units to a group, at that group to an array which stores all the available units at the moment they are created.
It doesn't matter if they are alive or dead at the end of part1, you stored them when they were alive so they will be deleted.

Mr.BoDean

  • Guest
Re:Deleting CamCreated Units
« Reply #5 on: 16 Jun 2004, 21:39:09 »
Hi ponq ..thanks for the reply  and    :o  ...trying to get my head around this.

Ok, first off, when you say
Quote
Now I have an array "part1resunits" which, in my case, contains all the resistance units of part1 of my mission. (The r1 to r9 units are already placed at the start of the mission).
 That looks to me like you have placed these units in the mission via the editor from the start, correct?

I only have a group leader for each group in the editor at the start.

Also, it looks like you don't create additional units into those bodies until the previous owners are dead and buried, right?

If that's true , it's a bit different than my scenario, as I will have several groups alive at the same time and not know which will die first.

I am also unclear on a few other things... maybe I need to see the whole script. :-\

U have resgroup2, resgroup3 and resgroup1 running the units script... is there a condition that makes the script wait or are all of these created at the same time?
   Then you create the array for part1resunits as unit names ...ok.  But then you change part1resunits value to add other groups ...totally lost me there.  :o   ???

Code: [Select]
;part1 reinforcements
?!(local server): exit
[resgroup2, 6, ""] exec "units.sqs"
[resgroup3, 6, ""] exec "units.sqs"
[resgroup1, 6,  ""] exec "units.sqs"
part1resunits = [r1,r2,r3,r4,r5,r6,r7,r8,r9]
part1resunits = part1resunits + (units resgroup2) + (units resgroup3) + units (resgroup1)


The delete part looks fine and i like the hidebody version of that script.

I just tested again my method using a simple radio trigger telling unit

C0 move getpos PoleZ

and nothing happened, so I think it's not recognizing the "unitname" portion of the unit creation line.

Maybe you can break it down a little more for me.  ;) Thanks a lot. ;D

Offline Zombie

  • Members
  • *
  • Beware the night, the zombie walks among you
    • USI
Re:Deleting CamCreated Units
« Reply #6 on: 26 Jun 2004, 13:28:00 »
My less than elegant solution to this problem is to create all the needed units ahead of time in the editor.  The ones that are not needed right away I place on one of the small outlaying islands.  Put them in "safe" mode, give the leader a move trigger a few feet from where he starts, then another where you need his group to be, and synchronize with a trigger to keep them in place.  Then when they are needed, setpos them in place, and change their combat mode as appropriate  I found that:
1. all units can be named this way, and deleted when dead
2. I don't get the slight "pause" that can occur when many units are camcreated at the same time.
  This works fine for me and has cut down on the lag created by all the bodies.  The map takes a little longer to start because all the units are being placed but it's not too bad

Mr.BoDean

  • Guest
Re:Deleting CamCreated Units
« Reply #7 on: 28 Jun 2004, 01:56:12 »
Hi Zombie. Thanks for your input. Yeah, it was a lag issue to begin with that got me using this otherwise excellent "createunit" script in the first place. I already have the standby units holding on an island as you suggested, but only the group leaders the created units are spawned in to, not whole squads.

    Seems strange they can't be deleted unless they were "born" in the editor.    :-\

As far as lag reduction goes, it seems a tossup. i.e., it's about the number of groups active ....and not necessarily the number of units in each group.  Which would suggest that my method is no less laggy than yours with full groups.  What method do you use to delete? Arrays with names of each soldier or a group delete line?   :-X

CrashnBurn

  • Guest
Re:Deleting CamCreated Units
« Reply #8 on: 28 Jun 2004, 07:00:29 »
Paste this into a new text file and save as rid.sqs. The rest is self explanatory.

;--------------------------------------------------------------------------
;-to call this script simply put this line into the units initialization:
;this addeventhandler [{killed},{_this exec {rid.sqs}}]
;-works with createunit command.(units initialization must be in quotes!)
;--------------------------------------------------------------------------
_unit = _this select 0
~60 + (random 60)
_unit removealleventhandlers "killed"
deletevehicle _unit
« Last Edit: 28 Jun 2004, 07:05:24 by CrashnBurn »

ponq

  • Guest
Re:Deleting CamCreated Units
« Reply #9 on: 28 Jun 2004, 12:42:08 »
Sorry for replying so late ;(

CnB, I think that doesn't solve the lag issue the TS is trying to deal with.

Here's how I do it, step by step:

step 1

I create a ResUnit in the editor:
Resistance Officer
Rank: Sergeant
init: resgroup1 = group this
-> Now I have a group consisting of 1 unit.

This unit will be in the mission right from the start. Advantage is I can easily give him waypoints in the editor. The units created during the mission are just added to him, so they will also get his waypoints.

step 2
I have a trigger (could be script ofcourse to) which will determine when I need to create units (I'm only creating them once they are really needed, once the player is about to fight them, to reduce lag).

In my mission I have a East Present trigger at ~500 meter from the above editor-created unit (player plays as east):

Trigger: East Present, Once
OnAct: [resgroup1, 6,  ""] exec "units.sqs"

Where units.sqs looks like this:
Code: [Select]
;only add units once they are needed to reduce lag/cpu strain
;written by ponq for Desert Ambush Revisited

;[leader, number of unites to add] exec "units.sqs", where leader is an existing leader *with group name*
; and number of units the number of units you want added.
;[loon1, 5] exec "unit.sqs" would create 3 solds, 1 mg and 1 rpg
;a group can only consist of 12 units, so 11 can be added max.
;the newly created units will have the same behaviour as the leader of the group.

;run only on server
?!(local server): exit

_leader = leader (_this select 0)
_amount = _this select 1
_beh = behaviour _leader
_group =  group _leader
_skill = difficulty
;difficulty is a Global Variable, set at the start of this MP mission. Use 0.5 here if you don't have the option to set difficulty
_delay = 0.2
_keer = 1
_init = ""

;adjust number of units and/or skill to fit with amount of players
;skip this part  :) it's too spefic for my mission
;_amount = _amount - 3
;_amount = _amount + NumberOfPlayers
;?(_amount >= 12): _skill = _skill + 0.1
;?(_amount >= 12): _amount = 11
;?(_amount <= 0): _amount = 1

~3
#loop
;normal sold
"JAM_GBSoldier" createUnit [getPos _leader, _group, _init, _skill, "private"]
_keer =_keer + 1
?_keer > _amount: goto "exitscript"
_delay
"JAM_GBSoldier" createUnit [getPos _leader, _group, _init, _skill, "private"]
_keer =_keer + 1
?_keer > _amount: goto "exitscript"
_delay
;machine gunner
"JAM_GBMG" createUnit [getPos _leader, _group, _init, _skill, "private"]
_keer =_keer + 1
?_keer > _amount: goto "exitscript"
_delay
;rpg soldier
"JAM_GBSoldierRPG" createUnit [getPos _leader, _group, _init, _skill, "private"]
_keer =_keer + 1
?_keer > _amount: goto "exitscript"
_delay
;sniper
"JAM_Gsniper" createUnit [getPos _leader, _group, _init, _skill, "private"]
_keer =_keer + 1
?_keer > _amount: goto "exitscript"
_delay
goto "loop"

#exitscript
~1
;set new units to same behaviour as leader
_leader setbehaviour _beh

As you see, this script will create units into a group (the group of the unit we created in the editor).

Right after creating the new units we have to "record" their existance somewhere.

step 3
So in the script where you call units.sqs add the new units to an array.
Code: [Select]
part1resunits = [r1,r2,r3,r4,r5,r6,r7,r8,r9]
part1resunits = part1resunits + (units resgroup2) + (units resgroup3) + units (resgroup1)

The r1, r2 etc are also units I created in the editor. The resgroups2 and 3 are created just like the example I used in this post.

Now part1resunits will hold all the names of the units, editor created and script-created ones.
(I couldn't give the units I create with CreateUnit a name btw)

step 4
Now I use a trigger to check when to remove the dead bodies (since I don't want them to sink into the ground when the player can still see that).
In my case it simply means all Resistance units have been killed ina specific area. Trigger, not present resistance, once, onact: [] exec "part2.sqs".

Now in part2.sqs I have a small cutscene, and once the camera leaves the battlefield of part1 I can safely remove the dead bodies without any1 seeing it.

Code: [Select]
"[_x] exec {delbody.sqs}" foreach part1resunits where delbody.sqs is:
Code: [Select]
;delbody.sqs by myke13021 (from ofpec forum)
;bodyhider is an blackop which can do "Hide Body" so the dead units sink slowly into the ground. You can comment that part if you want the to be removed instantly.

?!(local server): exit
_dude = _this select 0
removeallweapons _dude
bodyhider action ["hidebody", _dude]
~10
deletevehicle _dude
exit

That's it step by step.
___________
Now to answer your question:
Quote
That looks to me like you have placed these units in the mission via the editor from the start, correct?
I only create the 1st unit of the group in the editor. I hope I did explain this more cleary in this post

Quote
I only have a group leader for each group in the editor at the start.
Here you go, that's what I do too ;)

Quote
Also, it looks like you don't create additional units into those bodies until the previous owners are dead and buried, right?

If that's true , it's a bit different than my scenario, as I will have several groups alive at the same time and not know which will die first.

I don't fully understand your question, but you could check each group seperatly to see if it has been killed completely ?(count units resgroup1)==0: "[_x] exec {delbody.sqs}" foreach resgroup1array . (not sure about the code though). This would ofcourse require you to also have an array which holds all the units created just like I described above.

Quote
Then you create the array for part1resunits as unit names ...ok.  But then you change part1resunits value to add other groups ...totally lost me there.
I store the editor-created units in the array first, then I add the scriptcreated units to that array too. The whole point is that I know all these resunits have to be dead before i move on to part2 of my mission. So all these units will be removed once part2 starts.

Quote
I just tested again my method using a simple radio trigger telling unit

C0 move getpos PoleZ

and nothing happened, so I think it's not recognizing the "unitname" portion of the unit creation line.

I can't set the unitname while using createunit, and I guess the "option" is still in the script, which should be removed I guess. Sorry.
However, while I couldn't name the created units myself, ofp did seem to be able to identify them. The whole point of storing the created units into an array is to extract the "ofp-name" from the units.

If you want, you can email me the mission so I can see if I can get this script up and running for you (da.haarsma@student.unimaas.nl)

I hope this helps, and plz ask for clarification if I'm being unclear. I will respond faster next time, promised ;)

Mr.BoDean

  • Guest
Re:Deleting CamCreated Units
« Reply #10 on: 29 Jun 2004, 08:15:48 »
CrashNBurn: Thanks for the reply. I was able to get your method using eventhandlers to work for all of the "createunit" units. However, the in-editor INIT line of the group leader (I had already placed in the editor) did not like that syntax for eventhandler, and 2 others I tried simply gave errors in game.  SO.. I ended up using the eventhandler on the createunits and set up a separate delete script for the group leaders. Do you use this method with MP maps? Would I run into issues using eventhandlers in MP?

PONQ: Thanks for the very thorough explanation of your method.  ;) It seems I was already trying something similar to your approach , but had some details off. I will email you soon after further testing ..thanks!  8)

CrashnBurn

  • Guest
Re:Deleting CamCreated Units
« Reply #11 on: 29 Jun 2004, 11:04:33 »
I only make sp maps, so I have no idea how it would or wouldn't work with mp. Someone else will have to 'chime in' here or you'll have to experiment with it. As far as the syntax problem you had, it should work fine but you can try changing it to this for the editor placed units-

this addeventhandler ["killed",{_this exec "rid.sqs"}]

original-

this addeventhandler [{killed},{_this exec {rid.sqs}}]

The line with the quotes seems to work better on the editor placed units ini., but I got errors on the createunit line of my script with it (since the ini. line is already in quotes in script form), so I changed to brackets and it works fine there. I have lotsa good createunit scripts if you need any. They're already setup to work with the eventhandler delete script, including one that leaves the weapons after deleting the dead (sort of).
« Last Edit: 29 Jun 2004, 11:06:45 by CrashnBurn »