Home   Help Search Login Register  

Author Topic: DELETEVEHICLE USING ARRAY  (Read 927 times)

0 Members and 1 Guest are viewing this topic.

Offline ZNorQ

  • Members
  • *
  • ehr... uhm... duh...
DELETEVEHICLE USING ARRAY
« on: 30 May 2004, 14:44:30 »
Hey,

I'm trying to make an easy way to remove a whole group after their deaths. I've had a look around in the forus, but I can't really find something that gives me a solution to my problem.

I make a enemy group containing 12 soldiers - and in the leader's init I wrote

     gGroup = group this; [gGroup] exec "AllDead.sqs"

The AllDead.sqs waits for this line to be activated using this statement;
@(count units gGroup) == 0

But since units are taken out of the gGroup (since they are dead) - how on
earth can I deleteVehice each unit?

I've tried making an own array listing the units, but I misrably failed...;
yGroup = []
{yGroup = yGroup + _x} forEach units gGroup
(btw; I added those two lines BEFORE the "@" statement.

Anyone?

ZNorQ

Offline alimag

  • Contributing Member
  • **
  • I'm a llama!
Re:DELETEVEHICLE USING ARRAY
« Reply #1 on: 30 May 2004, 17:03:45 »
Hi,

There are many ways you can handle this problem.

If you dont mind deleting the soldier as soon as he is dead you can just put this in his init field:

this addEventHandler ["killed", {deleteVehicle (_this select 0)}]

The only problem is that the dead soldier disapears right away in your face.

To wait until the group is destroyed you have to save a reference of the soldier when he dies and then delete the entire group when it is destroyed:

As an example...

Put this in init.sqs:

vBodies = []

Put this in the leader of the group init field:

{_x addEventHandler ["killed", {_this exec "delBodies.sqs"}]} forEach units group this

Then in delBodies.sqs:

_unit = _this select 0
_group = group _unit
vBodies = vBodies + [_unit]
if (count units _group == 0) then {{deleteVehicle _x} forEach vBodies}


Good luck
Cheers

Offline ZNorQ

  • Members
  • *
  • ehr... uhm... duh...
Re:DELETEVEHICLE USING ARRAY
« Reply #2 on: 30 May 2004, 19:44:27 »
Thx bud, I'll try it out.

One question though... The reason I wanted only one trigger pr. group
checking if all soldiers in that group is dead, is because I'm not sure if
too many of these eventhandlers/triggers may slow down performace
if I use many soldiers..

I was thinking just one trigger pr. group; so if I have 6 groups - that is
only 6 triggers instead of 72 (12 soldiers *6 groups) triggers/eventhandlers running in the background.. (Just an example)

Would that cause serious lag problems?

PS! I'm making a LAN games for 20 players..

ZNorQ

Offline ZNorQ

  • Members
  • *
  • ehr... uhm... duh...
Re:DELETEVEHICLE USING ARRAY
« Reply #3 on: 30 May 2004, 19:56:25 »
Ehr... Let me show an example;

I'm thinking of making a group of 12 - where it says "myGroup = group this" in the leader's init field.

Then a trigger for that group saying;
condition; count units myGroup == 0
execution field; [myGroup] exec "removeBodies.sqs"

Then the removeBodies.sqs could have this code;
{deleteVehicle _x} forEach units myGroup

Now I know the above code doesn't work, because the above group array
wouldn't contanin any soldiers - since they are removed from the group
list when they die. And that is exactly what I'm after - a list that lists all the units no matter what if they are dead or not.

I've made custom unit arrays before - like yPlayers = [aP1, aP2, aP3] (an example) and used forEach to perform different tasks on that array... Example;

{removeAllWeapons _x; _x addMagazine "m16"; _x addWeapon "m16"} forEach yPLayers

Note that the "units" function isn't applicable here for standard arrays.

But I don't want to define those in a advance - I want the trigger waiting for everybody to die to do that based on what is initially in the myGroup.

Yeah, I know - I suck at explaining things... :p Sorry..

ZNorQ

Unnamed

  • Guest
Re:DELETEVEHICLE USING ARRAY
« Reply #4 on: 31 May 2004, 01:28:38 »
Alimags version works just as well, but if you want to wait until the entire group is dead. Add this to each group commanders init field:

Code: [Select]
[Group This] Exec "delBodies.sqs"
delBodies.sqs:

Code: [Select]
_Group=_This Select 0

_Units=Units _Group

#Loop

~1

If (IsNull _Group) Then {{DeleteVehicle _x} ForEach _Units} Else {goto "Loop"}
« Last Edit: 31 May 2004, 01:31:00 by Unnamed »

Offline ZNorQ

  • Members
  • *
  • ehr... uhm... duh...
Re:DELETEVEHICLE USING ARRAY
« Reply #5 on: 31 May 2004, 13:26:33 »
Hey Unnmaed,

Yeah, I tried out several things after my posts, and came up with something similar of what you proposed - and it worked..! Though I see you have some better refinements to it than mine, so if you don't mind, I'll use it! :D

Though may I recommend something for you; use "@" istead of a goto loop - alot cleaner...

For example;
Code: [Select]
_Group =  _This Select 0
_Units   =  Units _Group

@(IsNull _group)

{DeleteVehicle _x} ForEach _Units

The code wont continue till the condition is true, i.e. no soldiers in group.

Thx bud!

ZNorQ

ponq

  • Guest
Re:DELETEVEHICLE USING ARRAY
« Reply #6 on: 07 Jun 2004, 16:56:37 »
It may look cleaner, but afaik the loop with ~1 is a lot easier on your cpu.

the @ checks every 0.01 sec, while the loop only once each sec (~1).

Correct me if I'm wrong here ;)

Offline ZNorQ

  • Members
  • *
  • ehr... uhm... duh...
Re:DELETEVEHICLE USING ARRAY
« Reply #7 on: 10 Jun 2004, 14:14:30 »
@ponq; Hell, no! Won't argue at all - You are probably right :D.. I'll reconsider my way of thinking  ;D ;D

Thx!

ZNorQ
« Last Edit: 10 Jun 2004, 14:15:12 by ZNorQ »