Jump to content
Sign in to follow this  
Victor_S.

All units executing a script

Recommended Posts

ok I searched but I couldnt find what I am looking for.

Im making a mission and everytime a soldier is killed on the west side after 10 seconds his body is deleted and a grave cross is created in a little cemetary behind the base.

I cant figure out how to make the script execute everytime some one on the west side is killed. I am going to have units respawning as they die also. I know how to create the cross where I want it and everything but I can seem to figure out how to get it going for everyone.

is there a way I could put like:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">"_x exec (grave.sqs)" forEach units sideWest

any help would be great unclesam.gif

Share this post


Link to post
Share on other sites

Assuming you have resistance, you can just use an eventhandler.

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">{_x addeventhandler ["Killed",_this exec "yourscript.sqs"]} forEach units sideWest

And in your script, _this select 0 will be the body of the man to be deleted so you can have something like this:<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_man = _this select 0

~10

deletevehicle _man

_grave = "Grave" createvehicle getpos cemetary

exit

Share this post


Link to post
Share on other sites

I got it to work using a triger with a group named west 1:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">{[_x] exec "grave.sqs"} foreach units west 1

I was going to try to figure out how to combine all groups into one variable like: _allwest = (west1,west2,west3)

but i dont think this is possible.

Ill try how you suggested but I have another problem. I want it to move over a meter every time it creates a new grave so there will be a line. Any Ideas on how to do this?

Share this post


Link to post
Share on other sites

Korax's way is the easiest way to handle the dead.

Regarding the grave placement, if you can put up with a line that goes N-S or E-W it's not too tricky:

Get the coordinates of your starting point (e.g. _gravepos) by whatever means you prefer.

Create GLOBAL variables, say:

gravex = _gravepos Select 0

gravey = _gravepos Select 0

Your cemetery script becomes:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

_man = _this select 0

; shift next grave 1m East

gravex = gravex + 1

; or shift next grave 1m West

; gravex = gravex - 1

; or shift next grave 1m North

; gravey = gravey + 1

; or shift next grave 1m South

; gravey = gravey - 1

~10

_grave = "Grave" CamCreate [gravex,gravey,0]

_grave Setdir whateveranglelooksright

deletevehicle _man

exit

Because gravex and gravey are global, each execution of the script should produce a unique position.  The lines can be run at other angles with a bit of trig.

Share this post


Link to post
Share on other sites

Yea I got that one to work but for some reason i cant get the spawned units to have the eventhandler. I am doing it like this:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_new = "sebnamarmywo" createunit (bla bla bla...)

_new addeventhandler [{killed},{[_new] exec "grave.sqs"}]

they spawn but it does not appear that they have the event handler?

Share this post


Link to post
Share on other sites

Try:

_new addeventhandler ["killed",{_this exec "grave.sqs"}]

Rationale:

"" can work for a code string but maybe {} doesn't work on a string.

[_new] is using a local variable tht won't exist outside the respawn script - use the _this as before.

Share this post


Link to post
Share on other sites
Quote[/b] ]_new = "sebnamarmywo" createunit (bla bla bla...)

_new addeventhandler [{killed},{[_new] exec "grave.sqs"}]

Your doing everything with the eventhandler right, however you cant do _new = "unit" createunit, as the createunit command does not return anything. what you can do is place the code or something similar in the init line part of the createunit command. For example...

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

_Type CreateUnit [[_posX,_posY],_group,"addeventhandler [{killed},{[_new] exec {grave.sqs}}] ",_skill,_rank]

Share this post


Link to post
Share on other sites

alright im still not getting this to work. the way I have it set up is: (this is in the trigger that executes the script.  The group is us1 and they are on the west side.)

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">{_x addEventHandler [{killed},{[_this,west,us1] exec "respawn.sqs"}]} forEach units us1

so it has three parameters. The west and group are working fine. An AI is created after a unit in the group dies and the AI returns to the correct group, but the original body does not disapear and the new AI does not have this event handler. This is the respawn.sqs:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_man = _this select 0

_side = _this select 1

_group = _this select 2

?not(Alive player):exit

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

?(_side==east): goto"east"

#west

?(_group==us1): goto "us1"

?(_group==us2): goto "us2"

?(_group==us3): goto "us3"

?(_group==sfwest): goto "sf"

#us1

~10

deletevehicle (_man select 0)

"gravecross1" camCreate [(getpos site1 select 0)+movePoint,getpos site1 select

1,+0.3]

movePoint = movePoint + 1

goto "usSpawn"

#us2

~10

deleteVehicle (_man select 0)

"gravecross1" camCreate [(getpos site2 select 0)+movePoint,getpos site2 select

1,+0.3]

movePoint = movePoint + 1

goto "usSpawn"

#us3

~10

deleteVehicle (_man select 0)

"gravecross1" camCreate [(getpos site3 select 0)+movePoint,getpos site3 select

1,+0.3]

movePoint = movePoint + 1

goto "usSpawn"

#usSpawn

~3

_u = "sebnamarmywo" createUnit [getpos USbase, _group, "w1 = this", 1,

"PRIVATE"]

~1

_u addEventHandler [{killed},{[_u,west,_group] exec "respawn.sqs"}]

#east

exit

when it gets to deletevehicle earlier in script it gives me error that and object is expected but its an array. So the body is not deleted. So im guessing that its not understanding which guy has executed the script. I know it might be hard to undertand what im tying to explain so thank you in advance for any help.

EDIT: ok I got the original unit to delete when he dies by adding the changes in bold but the newly created unit still will not execute the respawn script.

Share this post


Link to post
Share on other sites

BUMP*

ok I have every thing working but my units will only respawn once. ex. a unit is killed,he is deleted, then a new unit spawns if he is killed he is deleted but no unit is spawned? I dont know what the problem is. Can anyone help me pls sad_o.gif

Share this post


Link to post
Share on other sites

make a sqs with the name alive.sqs and ride in this:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">? !(local player) : exit

#a

_n = player

@ not alive player

_GW = weapons Player

_MA = magazines Player

_GW1 = count weapons Player

_MA1 = count magazines Player

@ alive player

_t = "Body" CreateVehicle [0,0]; _t setpos getpos _n; _t setdir getdir _n;

Player setdir getdir _n

deletevehicle _n

~0.1

Removeallweapons Player

_Z = 0

#ab

Player addmagazine (_MA select _Z)

_Z = _Z + 1

?_Z > _MA1 : goto "aa"

goto "ab"

#aa

_Z = 0

#aaa

Player addweapon (_GW select _Z)

_Z = _Z + 1

?_Z > _GW1 : goto "ac"

goto "aaa"

#ac

goto "a"

in the init.sqs

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

this exec "alive.sqs"

and in the description.ext

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

respawn=2;

respawndelay = 5;

try and fun!

Share this post


Link to post
Share on other sites

I got it to work but dont remember how. I did alot of fooling around but in the end i think i just added the event handle to everyone in the group instead of just the new guy.

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×