Jump to content
Sign in to follow this  
[evo] dan

Spawning and keeping a global count of the number of spawns

Recommended Posts

I am trying to write a script that allows someone to spawn a vehicle from a box. I have got this part to work using the addAction command. However, I want to set a limit on the number of spawns that are available for the whole team. I have been unable to get it working in multiplayer. I had a look at the public variable page on the BIKI but it wasn't really very helpful to me as it did not tell me how to set the value of the public variable, nor get the value so I could compare it in an if statement. Here is the code that I have produced so far using the public variables but this does not spawn at all now:

publicVariable "scoring";
if(scoring >= 2)then
{
0 = "LAV25" createVehicle (getMarkerPos "hspawn");
scoring = scoring + 1;
sleep 1;
publicVariable "scoring";
};

and this is the code I used before and did spawn but did not keep the count with JIP:

_aVariable = truck_0 getVariable "myVariable";
_meh = truck_0 getVariable "meh";
if(_aVariable <= 2)then
{
0 = "LAV25" createVehicle (getMarkerPos "hspawn");
_meh = _meh + 1;
truck_0 setVariable ["myVariable", _meh, true];
sleep 1;
truck_0 setVariable ["meh",_meh];
};

Thank you in advance for any help you provide.

Share this post


Link to post
Share on other sites

You have scoring >= 2 which means if it starts from 0 it'll never be true since it'll never add to it. :) Did you mean scoring <= 2 as in the second bit of code?

Share this post


Link to post
Share on other sites

Yeah I meant that, but it still doesn't work with it that way around either. What am I doing wrong then?

Just got it working properly.

I put the public variable name in the init.sqf so it would sync on JIP.

Then I put this in the script I was running with this addAction and it worked with JIP!

meh = truck_0 getVariable ["scoring", 0];
if(meh <= 2)then
{
0 = "LAV25" createVehicle (getMarkerPos "hspawn");
meh = meh + 1;
sleep 1;
truck_0 setVariable["scoring", meh, TRUE];
};

Edited by [EVO] Dan

Share this post


Link to post
Share on other sites

I have another question, how would I get this script to spawn an object on a marker with a certain height (i.e. to go on a lhd deck?) because it says on the biki use setPos, but I have no clue how I would insert this into my script. Can anyone help me out here?

EDIT:

Found this on the comref:

createVehicle [type, position, markers, placement, special]

Operand types:

[type, position, markers, placement, special]: Array

Compatibility:

Version 2.32 required.

Type of returned value:

Object

Description:

Creates a vehicle of the given type (type is the name of the subclass in CfgVehicles). If the markers array contains several marker names, the position of a random one is used. Otherwise, the given position is used. The vehicle is placed inside a circle with this position as center and placement as its radius. Special properties can be: "NONE", "FLY" and "FORM".

Example:

veh = createVehicle ["Cobra", position player, [], 0, "FLY"]

Is there a way to then use this to set the height of the marker and then set it to spawn on that marker or can I set it to spawn relative to the object which I am using the addaction from?

Edited by [EVO] Dan

Share this post


Link to post
Share on other sites

Something like this should work for you.

_mkrpos = getMarkerPos "hspawn";
_veh = createVehicle ["LAV25" , [b][_mkrpos select 0,_mkrpos select 1,15.4][/b], [], 0, "NONE"];

Where... 15.4 is the height to spawn the object at. From memory.... on the LHD I think the value you need is 15.4 or close to that. I may be totally wrong there. LOL!....but you can work it out. I'm sure.

Edited by twirly
Change

Share this post


Link to post
Share on other sites

Thank you Twirly, it worked for me, couldn't quite figure it out on my own. Thank you again!

(height was slightly off, but thats easily fixed)

also noticed it doesn't like spawning aircraft onto the deck of the Khe Shan, do I need to set height or should I just let it spawn where it does by default? (may be the wrong height, I spawned a ACE HMMWV armored at the same height as the LAV's, but it was WAY higher then the LAV's)

This is the code I am using:

meh = truck_0 getVariable ["scoring", 0];
if(meh <= 2)then
{
//0 = "UH1Y" createVehicle (getMarkerPos "hspawn");
_mkrpos = getMarkerPos "hspawn1";
_veh = createVehicle ["UH1Y" , [_mkrpos select 0,_mkrpos select 1,26.3], [], 0, "NONE"];
meh = meh + 1;
sleep 1;
truck_0 setVariable["scoring", meh, TRUE];
};

It works fine when I execute this on the airfield, but out on the Khe Shan, it doesn't want to spawn it at all, maybe it is an issue with room or something? Can anybody help me out with this please?

Edited by [EVO] Dan

Share this post


Link to post
Share on other sites

I found the issue it was that it was seemingly spawning it on the seabed. Ihad to set the aircraft to spawn over 100m above the marker.

Has anyone got any ideas on how to improve this so it spawns the objects relative to the sea level (using the code in my last post?)?

Share this post


Link to post
Share on other sites

Could I insert the code like this:

_veh = createVehicle ["UH1Y" , [_mkrpos select 0,_mkrpos select 1,_veh setPosASL +16.3], [], 0, "NONE"];

or this way?

              _height = 16;
              _veh = createVehicle ["UH1Y" , _veh setPosASL [_mkrpos select 0,_mkrpos select 1,_height],[], 0, "NONE"];

or would I have to do it in a different way?

Edited by [EVO] Dan

Share this post


Link to post
Share on other sites

I don't think the top one will work....as the vehicle hasn't been created yet in order to use it in the actual statement. The bottom one should.. Oooops...Just read it again...and neither one will work for the same reason.

You can also create the vehicle somewhere else and then move it to it's final position.

_mkrpos = getMarkerPos "hspawn1";
_veh = createVehicle ["UH1Y" , [0,0,30], [], 0, "NONE"];   //bottom left corner of map... 30 up meters in the air
_veh setpos [_mkrpos select 0,_mkrpos select 1,26.3];    //move it to it's new location

I don't think you actually need the setPosASL and setPosATL commands just to spawn something at a height. I never use them. In certain cases though I might be wrong. Someone else might be a little clearer on that.... but all it takes is some testing.

Edited by twirly
Clarity

Share this post


Link to post
Share on other sites

Ignore me... guess it's just for people and HMMWVs :) Those are spawning fine, but aircraft spawn on the ocean floor, even if you specifically set it to 16m up or whatever. LAVs are spawning on the water surface. So odd.

Edited by kylania

Share this post


Link to post
Share on other sites
Just a side note, but you don't need to use the 15.4 setPos trick with the USS Khe Sanh on the Utes map anymore. Simply spawn at the coords and it'll be on the deck. Same with placing units in the editor, just put them where you want them and they'll be on the deck.

Kylania is right.... I do remember having seen that somewhere.

Edited by twirly

Share this post


Link to post
Share on other sites
Ignore me... guess it's just for people and HMMWVs :) Those are spawning fine, but aircraft spawn on the ocean floor, even if you specifically set it to 16m up or whatever. LAVs are spawning on the water surface. So odd.

This is exactly what happens. However I have figured out the height needed for all my vehicles now - they range from a mere 0.1m to roughly 110m depending on what vehicle it is (humvee at 0.1 and huey at 110). Anyway thanks for the help guys!

Share this post


Link to post
Share on other sites

You should post the results you have figured out so others can use them since obviously the old way isn't working anymore. :)

Share this post


Link to post
Share on other sites

I think they broke it when they allowed the game to put stuff on the deck of the ship if you place it in the editor, guess they forgot to update the spawning code to do the same. Will post the results later when I have gotten everything I want nailed down.

Share this post


Link to post
Share on other sites

Just to update, I used the code from the other page on this and it works fine when you move it. Here is the code I used:

ar1 = truck_0 getVariable ["air1", 0];
if(ar1 <= 2)then
{
//0 = "UH1Y" createVehicle (getMarkerPos "hspawn");
_mkrpos = getMarkerPos "hspawn1";
_veh = createVehicle ["UH1Y" , [0,0,30], [], 0, "NONE"];   //bottom left corner of map... 30 up meters in the air
_veh setpos [_mkrpos select 0,_mkrpos select 1,15.6];    //move it to it's new location
ar1 = ar1 + 1;
sleep 1;
truck_0 setVariable["air1", ar1, TRUE];
};

Thank you guys for helping me out! :yay:

Share this post


Link to post
Share on other sites

Ahh good to know. So placing on the map works perfect. Spawning doesn't work at all, but spawning then moving works how it used to. Great info.

Share this post


Link to post
Share on other sites

I think I had to use that same method to place people/objects in buildings. Spawn the unit/object somewhere else and then move it into the building pos. Otherwise they fall through the floor. Not sure if this behaviour still exists or not.

It's amazing how long the simplest thing can take to figure out... even if you have done it already a million times! Lol!

Anyway glad you got things working.

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  

×