Jump to content
Sign in to follow this  
Ub3rObama

Dynamic Placement CreateVehicle

Recommended Posts

So after seeing an admin complain about how hard it is to make a vehicle spawning script I thought hell I'd give it ago because I'm bloody bored atm.

Anyway this is what I have come up with so far:

_vehiclesArray = [
"ATV_US_EP1",
"HMMWV_M1035_DES_EP1",
"Ikarus_TK_CIV_EP1",
"LandRover_CZ_EP1",
"2S6M_Tunguska",
"MAZ_543_SCUD_TK_EP1",
"Offroad_SPG9_TK_GUE_EP1",
"SUV_UN_EP1",
"Ural_UN_EP1",
"VolhaLimo_TK_CIV_EP1"
];

_weaponsArray = [
"m107_TWS_EP1",
"M24_des_EP1",
"AKS_74_GOSHAWK",
"M4A3_RCO_GL_EP1",
"SCAR_L_STD_EGLM_TWS",
"M60A4_EP1",
"MG36_camo"
];

_magsArray = [
"10Rnd_127x99_m107",
"5Rnd_762x51_M24",
"30Rnd_762x39_AK47",
"30Rnd_556x45_Stanag",
"30Rnd_556x45_Stanag",
"100Rnd_762x51_M240",
"100Rnd_556x45_BetaCMag"
];

a = 0; for "a" from 0 to 20 do{
_veh = createVehicle [
	_vehiclesArray select random count _vehiclesArray,getMarkerPos "1",["1","2","3"], 50, "FLY"];
	_veh setDir random 360;
	_veh setFuel (100 - random 80) * 0.01;
	_veh setVehicleArmor (100 - random 50) * 0.01;
	_weapon = random count _weaponsArray;
	_veh addWeaponCargo [_weaponsArray select _weapon, 1];
	_veh addMagazineCargo [_magsArray select _weapon, (random 6) + 1];
	sleep 0.1;
};


My only problem is the placement radius. Its static, I want it to vary with the size of the marker, but I don't think that will work. I need a completely different way of doing it I think. Any ideas are appreciated or if you notice bad problems, I only started scripting for Arma today.

Also, DAM its difficult to post on these forums, got enough anti bot stuff? Sheesh.

Share this post


Link to post
Share on other sites

Why don't we just simplify it and get a random position around an object instead? (ie; invis Hpad)

_target = someObject;
_dist = random 100; // random distance from object. It could also be _dist = 50 + random 150. 50 being the minimum distance from the object it could spawn 
_dir = random 360;
_pos = getpos _target;
_position = [(_pos select 0) + (sin _dir) * _dist, (_pos select 1) + (cos _dir) * _dist, 0]; 

Or, make sure a functions module is on the map, (I've never used this) maybe:

waituntil {!isnil "bis_fnc_init"};
_position = [getPos someObject, random 150, random 360] call BIS_fnc_relPos; 

Then spawn the vehicle at _position

---------- Post added at 20:21 ---------- Previous post was at 20:14 ----------

Make sure a functions module is on the map.You could grab a random object/weapon/mag simply by using:

[color="#FF0000"]waituntil {!isnil "bis_fnc_init"};[/color]

_vehiclesArray = [

   "ATV_US_EP1",
   "HMMWV_M1035_DES_EP1",
   "Ikarus_TK_CIV_EP1",
   "LandRover_CZ_EP1",
   "2S6M_Tunguska",
   "MAZ_543_SCUD_TK_EP1",
   "Offroad_SPG9_TK_GUE_EP1",
   "SUV_UN_EP1",
   "Ural_UN_EP1",
   "VolhaLimo_TK_CIV_EP1"

] [color="#FF0000"]Call BIS_fnc_selectRandom;[/color]

just a matter of preference, though I wouldn't use bis_fnc_selectRandom with very large arrays, it seems not to reliable.

---------- Post added at 20:25 ---------- Previous post was at 20:21 ----------

Also you could use

_vehiclesArray select random count _vehiclesArray,getMarkerPos "1",["1","2","3"], [color="#FF0000"]random 360[/color], "FLY"];

Instead of setting the vehicle direction with an additional statement

---------- Post added at 20:46 ---------- Previous post was at 20:25 ----------

Also, you're creating a vehicle in "fly" mode. If you spawn an empty helo, it will be flying and crash.

Edited by Iceman77

Share this post


Link to post
Share on other sites

Using your method it still leaves me with the problem of not being able to have different sized areas populated with vehicles. E.G All the towns are different sizes, thats why I wanted to use something like a marker when I can select an area for the vehicles to spawn in, but it didn't really work they way I intended.

I cannot find anything on the wiki on what BIS_fnc_relPos is.

These BIS functions are very confusing.

What I am thinking of now is, having an array of something (locations), I'm not sure yet, but like markers cover an area and will allow me to loop through each one and use the information provided from it (size) as the distance in your formula.

The only other way I can see of doing it, is having a separate vehicle spawn script for every single town, which performance wise, I don't think would be very good.

Yeah the fly mode thing I was just gonna wait till I spawned a helo and have a little laugh before I changed it.

Share this post


Link to post
Share on other sites

Also, you may want to take a look around, there are some functions/scripts that actually return a random position inside of a markers area. shk_pos is one. There may be some others. Anyhow, my math certainly isn't up to the task, but maybe yours is.

Yeah, those BIS_fncs turn up out of nowhere. Certainly alot more than what's in the wiki. If you really wanted to learn the bis functions, you could call the bis_fnc_help or w/e. It supposedly lists all of the functions and shows how the function is written. Which can be copy and pasted into your own file so you can edit it etc.

---------- Post added at 21:17 ---------- Previous post was at 21:15 ----------

Please share what you come up with.

Edited by Iceman77

Share this post


Link to post
Share on other sites

shk_pos is perfect! Unfortunately though putting the random 360 in the vehicle spawn part no longer works with it and I have to go back to the setDir way.

What syntax highlighter/editor do you use? ATM I'm just using Notepad++ with no plugin because I couldn't find one that worked.

Also is there a general rule on how many vehicles should be on the map?

Here is my final code for now, I want to add in wreck clearing then spawning later on.

Init.sqf

call compile preprocessfile "SHK_pos\shk_pos_init.sqf";
call compile preprocessfile "script.sqf"

Script.sqf

_vehiclesArray = [
"ATV_US_EP1",
"HMMWV_M1035_DES_EP1",
"Ikarus_TK_CIV_EP1",
"LandRover_CZ_EP1",
"2S6M_Tunguska",
"MAZ_543_SCUD_TK_EP1",
"Offroad_SPG9_TK_GUE_EP1",
"SUV_UN_EP1",
"Ural_UN_EP1",
"VolhaLimo_TK_CIV_EP1"
];

_weaponsArray = [
"m107_TWS_EP1",
"M24_des_EP1",
"AKS_74_GOSHAWK",
"M4A3_RCO_GL_EP1",
"SCAR_L_STD_EGLM_TWS",
"M60A4_EP1",
"MG36_camo"
];

_magsArray = [
"10Rnd_127x99_m107",
"5Rnd_762x51_M24",
"30Rnd_762x39_AK47",
"30Rnd_556x45_Stanag",
"30Rnd_556x45_Stanag",
"100Rnd_762x51_M240",
"100Rnd_556x45_BetaCMag"
];

_townsArray = [
"Kamenyy",
"Strelka",
"Airfield"
];

x = 0; for "x" from 0 to count _townsArray do{
a = 0; for "a" from 0 to 20 do{
	_pos = [_townsArray select x] call SHK_pos;
	_veh = createVehicle [
		_vehiclesArray select random count _vehiclesArray,_pos,[], 1, "NONE"];
		_veh setDir random 360;
		_veh setFuel (100 - random 80) * 0.01;
		_veh setVehicleArmor (100 - random 50) * 0.01;
		_weapon = random count _weaponsArray;
		_veh addWeaponCargo [_weaponsArray select _weapon, 1];
		_veh addMagazineCargo [_magsArray select _weapon, (random 6) + 1];
		sleep 0.1;
};
};

Edited by Ub3rObama

Share this post


Link to post
Share on other sites

I only use normal note pad. Squint is good for syntax highlighting aswell as Arma Edit. Arma edit can do even more things pertaining to arma2, though I haven't used AE since Arma1.

You can have as many vehicles as you & the other clients can withstand (lag wise). Also, createvehicle has global effects. Make sure you only create objects (vehicles etc) on the server. Else it will create one for the server and every client. ie;There's 3 players, you spawn a helo, 4 helos will spawn.

At the start of your script use:

if (!isServer) exitWith {};

Assuming you didn't already call the script on the server...

Edited by Iceman77

Share this post


Link to post
Share on other sites

So, what should be on the client side? I haven't worked with client-server side before. Would only things be clientside like stuff that is only meant to be viewed by one person e.g. menus?

Using Squint, it told me I need to insert:

private ["_pos","_veh","_weapon","_vehiclesArray","_weaponsArray","_magsArray","_townsArray"];

At the start, I don't see why? Something to do with the scope I assume.

Share this post


Link to post
Share on other sites

Yeah it's to limit the _localVariable(s) to a scope. Obviously unessecary if you don't need to do that. Someone else could better explain it to you. If you look @ all of the A2 commands it will tell you if the command effects & arguments are local or global. I'm not really going to go any further than that about locality. It's a whole new can of worms, and I'm fairly new at scripting in general, muchless MP locality. I know the basics, like hey only create objects on the server... sqf is the only syntax/language I've ever "scripted" LOL.

But yeah you have to dictate where the scripts run. ie; you only want a given role/unit to see a message

Edited by Iceman77

Share this post


Link to post
Share on other sites

As far as Notepad++ plugins go, I'm using this one currently:

http://forums.bistudio.com/showthread.php?91939-Notepad-SQF-syntax-highlight/page3

And I can only recommend it. Includes about everything currently available and even has autocorrect.

I personally have no idea about the vehicle spawn stuff, my only idea would be to use a rectangle marker to cover the whole town up and then use that.

Share this post


Link to post
Share on other sites

What syntax highlighter/editor do you use? ATM I'm just using Notepad++ with no plugin because I couldn't find one that worked.

I use this one, seems to work good for me:

notepad ++ SQF syntax highlight

See the note in post #24 of that thread for auto completion

ninja'd by tryteyker...

Share this post


Link to post
Share on other sites

The only issue I'm running into (fairly often that is) is that Notepad++ automatically seems to change my line of code into a comment when I edit it. That IS annoying, especially because I always try to spam other line of codes with sdsdsdsd and these get commented out aswell. Just something I feel I could add about that.

Share this post


Link to post
Share on other sites

Thanks guys I got that notepad++ one it seems to work quite nicely, squint was giving a few problems anyway.

I'm having a bit of a problem. In the editor weapons spawn in the vehicles, most of the time, with a few exceptions, but if I host the game online with a friend, barely any weapons spawn in the car, like maybe 1 in 5, which is really odd. Im going to have to look into it more, maybe I gotta create them clientside? Any ideas in the mean time?

Edited by Ub3rObama

Share this post


Link to post
Share on other sites

Make sure you're using addMagazineCargoGlobal so the weapons and ammo is mp synchronized

Share this post


Link to post
Share on other sites

Think that will do it. My other problem is, I turned on showscripterrors, and I'm getting this error which I can't work out what the problem is:

_veh = createVehicle ["SUV_UN_EP1",_pos,[], 0, >
 Error position: <createVehicle ["SUV_UN_EP1",_pos,[], 0, >
 Error 0 elements provided, 3 expected

I tried declaring _pos as a array, but really I have no idea what it means, because the vehicles are spawning fine in the correct positions.

Share this post


Link to post
Share on other sites

Any chance of a complete working code (with some "for dummies" comments preferably) without the shkpos requirement?

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  

×