Jump to content
Sign in to follow this  
wiggum2

How to spawn unit at specific time ?

Recommended Posts

Hi,

i searched this forum and the Editing Guide but found no answer.

How can i make a unit spawn or start another script at a specific time like 07:00 or something ?

My mission starts at 05:00 and the unit should spawn at 06:00, is there some other way then "sleep 3600" ?

Share this post


Link to post
Share on other sites
Hi,

i searched this forum and the Editing Guide but found no answer.

How can i make a unit spawn or start another script at a specific time like 07:00 or something ?

My mission starts at 05:00 and the unit should spawn at 06:00, is there some other way then "sleep 3600" ?

Oh damn this is a great question, I could use this in my current WIP. I was just doing a search for it but no real luck. I eagerly wait to see a solution.

Share this post


Link to post
Share on other sites
Hi,

i searched this forum and the Editing Guide but found no answer.

How can i make a unit spawn or start another script at a specific time like 07:00 or something ?

My mission starts at 05:00 and the unit should spawn at 06:00, is there some other way then "sleep 3600" ?

the way i would do it is to write a script to run on mission start and just let it wait until the time spent has reached your limit so to say:

waituntil {((time) >= 3600)}

More Info

another way to do it is maybe use a trigger from within the editor to just wait for 3600 seconds (countdown/timeout) or use the condition field of that trigger with:

((time) >= 3600)

sorry if i can't come up with anything better :)

Share this post


Link to post
Share on other sites

thanks soccerboy !

i have another problem with my spawn, i want to spawn a unit and give it a name, nut how can i give a spawned unit a name ?

my script:

if (isServer) then {

_pos = getMarkerPos "ziel";

_skill = [0.8, 0.8];

_side = RESISTANCE;

_units = ["Functionary2"];

_newGroup = [_pos, _side, _units, [], [], _skill] call BIS_fnc_spawnGroup;

_waypoint0 = _newGroup addwaypoint[getmarkerpos"WP1",0];

_waypoint0 setwaypointtype"Move";

_waypoint0 setWaypointBehaviour "Safe";

_waypoint0 setWaypointSpeed "LIMITED";

_waypoint1 = _newGroup addwaypoint[getmarkerpos"WP2",0];

_waypoint1 setwaypointtype "GETIN NEAREST";

_waypoint1 setWaypointBehaviour "Safe";

_waypoint1 setWaypointSpeed "LIMITED";

_waypoint2 = _newGroup addwaypoint[getmarkerpos"WP3",0];

_waypoint2 setwaypointtype"Move";

_waypoint2 setWaypointBehaviour "Safe";

_waypoint2 setWaypointSpeed "NORMAL";

_waypoint3 = _newGroup addwaypoint[getmarkerpos"WP4",0];

_waypoint3 setwaypointtype"Move";

_waypoint3 setWaypointBehaviour "Safe";

_waypoint3 setWaypointSpeed "NORMAL";

};

Share this post


Link to post
Share on other sites
thanks soccerboy !

i have another problem with my spawn, i want to spawn a unit and give it a name, nut how can i give a spawned unit a name ?

my script:

what exactly are you trying to do with the unit names?

you could just save the names in a global array like for instance "group_array = (units _newgroup)" then you could easily access the names with "select (index number)" without () :)

lets imagine your script creates two units then it'll be "group_array = [unit1, unit2]" then if you want to check if they're still alive or set damage or what ever you just select the index of the unit you want to access and do what ever you want to him like "_unit = group_array select 0".

you also can put that command anywhere after the group has been created before the script exits.

if you need more info about arrays here is a nice page to read up on them

Edited by soccerboy

Share this post


Link to post
Share on other sites
Hi,

i searched this forum and the Editing Guide but found no answer.

How can i make a unit spawn or start another script at a specific time like 07:00 or something ?

My mission starts at 05:00 and the unit should spawn at 06:00, is there some other way then "sleep 3600" ?

Use the dayTime command.

if (daytime == 6.00) then 
{
...................
};

For spawning units with name, take a look at Tajins script here.

Edited by Imutep

Share this post


Link to post
Share on other sites

Thanks soccerboy and Imutep !

I simple want to give every spawned unit a name so i can ckeck if they are alive. At the moment i dont understand how to setup it correctly, what comes in the triggers ?

I want the spawned unit name = target1 and in a trigger as condition (!alive target1).

Share this post


Link to post
Share on other sites
what exactly are you trying to do with the unit names?

you could just save the names in a global array like for instance "group_array = (units _newgroup)" then you could easily access the names with "select (index number)" without () :)

lets imagine your script creates two units then it'll be "group_array = [unit1, unit2]" then if you want to check if they're still alive or set damage or what ever you just select the index of the unit you want to access and do what ever you want to him like "_unit = group_array select 0".

you also can put that command anywhere after the group has been created before the script exits.

if you need more info about arrays here is a nice page to read up on them

soccerboy,

Good f*&$in' post. I've never been able to figure what this is all about. That really helped. Question though, could you show how we could use this to set damage and check if they are still alive. Sometimes the BIKI makes my head explode, but it sure is a helpful thing nonetheless.

Thanks in advance.

Share this post


Link to post
Share on other sites
Use the dayTime command.

if (daytime == 6.00) then 
{
...................
};

For spawning units with name, take a look at Tajins script here.

ah i totally forgot about that command :)

soccerboy,

Good f*&$in' post. I've never been able to figure what this is all about. That really helped. Question though, could you show how we could use this to set damage and check if they are still alive. Sometimes the BIKI makes my head explode, but it sure is a helpful thing nonetheless.

Thanks in advance.

glad i could help somewhere. over the past few weeks/months i've become very proficient with arrays and i love using them to pass information around :)

when it comes to that kind of things i like to use a "For loop" because i just find it to be easier readable as to what you're really doing and its better if you want to include ascending or descending number variables to your commands.

like if you're passing an array of units to check if those units are still alive you would go:

here and here is some info on for loops.

for both examples we'll call the unit array "array = [unit1, unit2]". now we can check those units.

for [{_u = 0},{_u < (count (array))},{_u = _u + 1}] do
{
     _unit = array select _u;
     if (alive _unit) then
     {
            _unit setdamage 1;
     };
};

you could also probably do it with a foreach command that i don't have much experience with but i'm guessing it would look like this (foreach is good if you're not trying to add other information like ascending or descending numbers. i can be wrong however since i don't use much of foreach commands):

here is some info on the foreach command.


{
    if (alive _x) then
    {
            _x setdamage 1;
    };
} foreach array;

the way i understand how foreach works is "{code} foreach array" so i can only assume that my foreach demo is correct however i can't try that out at this moment but i will at a later time.

if you need more help or have more questions feel free to PM me or post in this topic. i'll be keeping my eye on this one for a while to help out where i can :)

Edited by soccerboy
updated link for the for loop

Share this post


Link to post
Share on other sites

Thanks again soccerboy !

But i dont know where i should put "array = [unit1, unit2]"...

Share this post


Link to post
Share on other sites
Thanks again soccerboy !

But i dont know where i should put "array = [unit1, unit2]"...

oh that's just an example as to what the array would look like to the computer, if you're trying to get the units from a group you would use

array_name = units groupname

or if you only know one units name then

array_name = units group unitname

the breakdown of it is

"units" means get the units of a known group name into an array
"group" means get the known unit's group name

i'm going to take your script for example the way you have it setup is you're unit's group name will be "_newgroup" so to get the units name in a global array it would be

array_name = units _newgroup

Group

Units

i hope that clarifies things a bit better :)

Edited by soccerboy

Share this post


Link to post
Share on other sites

Sorry, me again...

But i dont get it...i read some stuff about "arrays" but i dont know how this works.

Can someone please make a little example mission that has just a empty car that i can spawn with a trigger RADIO ALPHA.

Now if the spawned car is destroyed a hint message should tell me something, i mean in "Conditions" field of another trigger !(alive .... <- name of car)

Please, i think this is so important for any mission maker !

Share this post


Link to post
Share on other sites
Sorry, me again...

But i dont get it...i read some stuff about "arrays" but i dont know how this works.

Can someone please make a little example mission that has just a empty car that i can spawn with a trigger RADIO ALPHA.

Now if the spawned car is destroyed a hint message should tell me something, i mean in "Conditions" field of another trigger !(alive .... <- name of car)

Please, i think this is so important for any mission maker !

Here you go, as simple as it gets :)

http://www.filefactory.com/file/b070ac0/n/TriggerSpawn.utes.zip

Share this post


Link to post
Share on other sites

Thanks JW Custom for your help.

If you want to know how to give a spawned Unit a name look here:

if (true) then
{
 _this = createVehicle ["ACE_UH60M", markerPos "AMS_heloStart", [], 0, "FORM"];
 [color="Red"]_this setVehicleVarName "unitname";
 unitname = _this;[/color]
};

http://community.bistudio.com/wiki/setVehicleVarName

In your spawn script it could look like this:

_helo2 = createVehicle ["ACE_UH60M", markerPos "AMS_heloStart2", [], 0, "FLY"];
_helo2 setDir -118.24;
[color="Red"]_helo2 setVehicleVarName "heli1";
heli1 = _helo2;[/color]

Thanks to Imutep and JW Custom !

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  

×