Jump to content
Sign in to follow this  
halex1316

Advanced Help Needed (Tire and Fuel Randomization)

Recommended Posts

So I'm making a zombie apocalypse mission using the Undead Mod, and I've filled the road with vehicles (as if a mass evacuation was occurring) however, I don't want the vehicles to have tires (at least most of them) so that it's not particularly easy to get transportation. Or even make the gas on all of the vehicles extremely low (hopefully without having to manually edit the fuel slider). Is there some kind of startup script or parameter I can set to destroy the tires on most of the vehicles and randomize the fuel levels on the vehicles that are spawned into the map?

Share this post


Link to post
Share on other sites

Wrote some quick code for you:

_vehicles = nearestObjects [getArray(configFile >> "CfgWorlds" >> worldName >> "centerPosition"), ["Car"], 10000];
_hitpoints = ["HitLFWheel", "HitRFWheel", "HitLF2Wheel", "HitRF2Wheel", "HitLMWheel", "HitRMWheel", "HitLBWheel", "HitRBWheel", "HitFWheel", "HitBWheel"];
{
_veh = _x;
_veh setFuel (random 0.2);
{
	_damage = random 1;
	if(random 10 < 5) then {
		_damage = 1;
	};
	_veh setHit [getText(configFile >> "cfgVehicles" >> (typeOf _veh) >> "HitPoints" >> (_x) >> "name"), _damage];
} forEach _hitpoints;
} forEach _vehicles;

This will go through all cars on entire map, set them random amount of fuel (Code: _veh setFuel (random 0.2); which is random between 0% and 20% fuel), then go through all possible wheels and set wheel damage to either 1 (completely broken) or random 1 (random damage of wheel) with 50% chance (Code: if(random 10 < 5))

Place this code in init.sqf of your mission, make sure to wrap it in

if(isServer) then {
//Code here
};

To make sure it runs only once per game on mission init.

Edited by SaMatra

Share this post


Link to post
Share on other sites
Place this code in init.sqf of your mission, make sure to wrap it in

PHP Code:

if(isServer) then {

//Code here

};

To make sure it runs only once per game on mission init.

this just means the server will run the script - not that it will only run once. If someone else joins they will call the same script and the server will run the script again.

Share this post


Link to post
Share on other sites
this just means the server will run the script - not that it will only run once. If someone else joins they will call the same script and the server will run the script again.

Joining clients are not server and therefore will not run the code. init.sqf doesn't executes on all machines when one client joins, only on client that joins.

Edited by SaMatra

Share this post


Link to post
Share on other sites

Holy crap, thank you so much! I really appreciate this! Now, I have a few other questions (if you don't mind helping me out a bit more!).

1. When I placed all of the vehicles on the road, there were some random Jerry Cans floating about. . . I'm not sure that you would know anything of it, but if you did, how would I remove them? Here's a screenshot of what I mean.

VmlVMl.jpg

This is what it looks like in the map.

oYCv7l.png

2. Realistically, these cars would have supplies in them right? How can I find a variety of supplies (ammo, equipment, etc.) and then have these dynamically spawn within the vehicle? I've heard o the config viewer, but I'm not quite sure as to how I can access it, or what uses it has.

P.S. I'm really not trying to mooch or use anyone, I really am trying to learn, and what you wrote (after looking at it mindlessly for about 10 minutes) does make sense, and hopefully as I learn this stuff, I won't have to resort to asking for so much help!

Perhaps giving me a hint, or guiding me in the right direction would be best (so as to help me learn more!)

Edited by halex1316

Share this post


Link to post
Share on other sites

Did you place fuel cans in your mission? Or maybe some other script\mod spawning them?

As for random stuff inside cars, expanding my original script:

_vehicles = nearestObjects [getArray(configFile >> "CfgWorlds" >> worldName >> "centerPosition"), ["Car"], 10000];
_hitpoints = ["HitLFWheel", "HitRFWheel", "HitLF2Wheel", "HitRF2Wheel", "HitLMWheel", "HitRMWheel", "HitLBWheel", "HitRBWheel", "HitFWheel", "HitBWheel"];

_weapons = [
["M16A2",	"30Rnd_556x45_Stanag",	4],
["AKS_74_U",	"30Rnd_545x39_AK",	5],
["Colt1911",	"7Rnd_45ACP_1911",	7],
["Makarov",	"8Rnd_9x18_Makarov",	7]
];

{
_veh = _x;
_veh setFuel (random 0.2);

clearWeaponCargoGlobal _veh;
clearMagazineCargoGlobal _veh;
if(random 10 < 3) then {
	_weapon = _weapons select floor(random(count _weapons));
	_veh addWeaponCargoGlobal [_weapon select 0, 1];
	_veh addMagazineCargoGlobal [_weapon select 1, round(random(_weapon select 2))];
};

{
	_damage = random 1;
	if(random 10 < 5) then {
		_damage = 1;
	};
	_veh setHit [getText(configFile >> "cfgVehicles" >> (typeOf _veh) >> "HitPoints" >> (_x) >> "name"), _damage];
} forEach _hitpoints;
} forEach _vehicles;

(With proper tabs: http://pastie.org/pastes/4648527/text)

The addition is _weapons array which consists of arrays of possible weapons. First value for sub-array is weapon name, second value is magazine name, third value is max amount of ammo for this weapon. Now along with setting fuel and tyres, script clears default inventory of vehicles and with change of 30% (Code: if(random 10 < 3)) adds random weapon and random amount of magazines for the weapon (random from 0 to 3rd array value, so it might be no ammo at all).

As for config browser, you probably wanted this: http://browser.six-projects.net/cfg_weapons/tree?version=58 When adding new weapons into _weapons, double check commas after sub-arrays, last sub-array shouldn't have comma after it.

Edited by SaMatra

Share this post


Link to post
Share on other sites
Did you place fuel cans in your mission? Or maybe some other script\mod spawning them?

Not as far as I know. The only thing I've done so far in the mission was place the vehicles, and there's really no pattern to the jerry cans, so I can't quite tell which vehicles may be spawning them in. I can show you a list of the mods that I have running when I'm creating the mission, so maybe that will help.

Other than that, I really appreciate your help! I'll link you to the mission once it's completed so you can see what you've had a hand in creating :)

Share this post


Link to post
Share on other sites

I'm not much of a mod user to tell if something spawns jerry cans, but either way you can delete all fuel cans with

{deleteVehicle _x;} forEach nearestObjects [getArray(configFile >> "CfgWorlds" >> worldName >> "centerPosition"), ["Fuel_can"], 10000];

Share this post


Link to post
Share on other sites
Would this go in where the other scripts were?

Yes, either before or after fuel\tyres code.

Share this post


Link to post
Share on other sites

The jerrycans are most likely ACE-related.

There was a bug that spawned jerrycans even if the vehicle had no cargo. Have you updated your ACE addon?

Share this post


Link to post
Share on other sites

In SixUpdater, my ACE is completely up-to-date, so as far as I can tell, it should be. Any ideas on how to fix this?

Share this post


Link to post
Share on other sites

Also, does anyone know how to add in a flashlight to the various surviving characters that I've created? I put in the init field -

"removeAllWeapons this; this addWeapons "binocular";"

but I don't know the item ID for a flashlight (if they even exist?)

Share this post


Link to post
Share on other sites

I do not believe flashlights, by themselves are available in Arma 2, or ACE. They are available in DayZ.

Some weapons in Arma 2 have flashlights on them, but I do not believe anyone has created a separate flashlight as seen here in DayZ:

Share this post


Link to post
Share on other sites
I do not believe flashlights, by themselves are available in Arma 2, or ACE. They are available in DayZ.

Some weapons in Arma 2 have flashlights on them, but I do not believe anyone has created a separate flashlight as seen here in DayZ:

Flashlight (or MUG lite) has been in ACE for a long time.

Share this post


Link to post
Share on other sites
Flashlight (or MUG lite) has been in ACE for a long time.

Do you happen to know the item ID?

Share this post


Link to post
Share on other sites
Flashlight (or MUG lite) has been in ACE for a long time.

Interesting...I couldn't find anything but this in the ACE documentation and class lists:

ACE Flashlights

I will have to do some more research.

Found these:

ACE_Flashlight

ACE_Muglite

Edited by panther42

Share this post


Link to post
Share on other sites

hey i was wondering if u knew a script that would enable me to pick up jerry cans and fill them up with fuel to fill up a car/vehicle. i am fairly new to scripting so i thought i might ask someone about it...please let me know if u can do anything about this???

Share this post


Link to post
Share on other sites
hey i was wondering if u knew a script that would enable me to pick up jerry cans and fill them up with fuel to fill up a car/vehicle. i am fairly new to scripting so i thought i might ask someone about it...please let me know if u can do anything about this???

If you search google with "arma jerry can" this is the first link

http://forums.bistudio.com/showthread.php?136552-Refueling-with-Jerry-can-problems-Trigger-not-attaching-to-vehicle

There are atleast 5 other links that deal with it as well.

I don't know why people have such a hard time finding stuff.

Share this post


Link to post
Share on other sites
I don't know why people have such a hard time finding stuff.

Because jerry cans are now bananas? :)

Refueling with jerry cans should be built into ACE though I thought, no need for a script. Needs the cargo system enabled though.

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  

×