Jump to content
Sign in to follow this  
Katatafisch

setFuel and setArmor Questions

Recommended Posts

Hey guys.

Im currently starting to take my first steps at mission editing.

Today i was trying to add a vehicle "healing" and "rearm" at a certain area.

I tried to use Code, what i did was the following:

I created a Trigger:

"repeatedly"

set to: BLUFOR - present

condition: this;

and On Act.: ve setFuel 1; ve = (vehicle player); publicVariable "ve";

and another one

all the same but:

On Act.: va setVehicleArmor 1; va = (vehicle player); publicVariable "va";

Now i was playing the mission in Multiplayer but it didnt work. Was my approach wrong? is there a better method without extra *.sqf files and codes?

Share this post


Link to post
Share on other sites

Well, you are defining 've' AFTER you are trying to do something with the variable. That won't work, since the engine won't know what 've' when you want it to do something.

It's also pretty bad practice to define variables like that in triggers.

However you can easily get away with using the function to find the vehicle without saving it as a variable, i.e:

On Activation: (vehicle player) setFuel 1;

Triggers fire on all machines, clients and servers alike, unless they are set to react on variables only existing on some specific (set of) machine(s) in which case you can control where a trigger will do something, therefore you don't need to use publicVariable for this (and even if you would need to the implementation and context of it is wrong here, and would need to be a bit more complex to force other machines to execute a transmitted or event-fired piece of code).

Also, note that the use of the magic variable 'player' is dangerous to use in multiplayer and need to be used with care. You would for example need to change the condition to this && player in thisList to make sure that only when the local player is in the trigger area the trigger will do its magic on the player's vehicle. Otherwise when ANY blufor enters the area, every single player-controlled vehicle will get repaired/refueled.

Edited by Inkompetent

Share this post


Link to post
Share on other sites

I use the REARM.SQF which REPAIRS, REARMS and RE-FUEL's vehicles and Aircraft.

You create reigger area and stop for 3 seconds..

All good.

Share this post


Link to post
Share on other sites

Hey guys, thanks alot for the replies.

@Wastelander: i tried to add that rearm.sqf but i cannot seem to get it work, since i cannot test the multiplayer due to the arma2 bug i posted here:

http://forums.bistudio.com/showthread.php?t=98812

I added a trigger with {[_x] execVM "rearm.sqf"} foreach thislist; but it wont work.

@Inkompetent: thanks alot man! yeah i know what you mean but in a youtube tutorial someone explained that the script is read backwards...it was due to briefing creation. So i thought maybe it has to be like this in the editor too.

i tried your (vehicle player) setFuel 1; but i got an error: Missing ";" or something similar, and i didnt find a way how to add vehicle player instead of putting it into a variable.

and thanks alot for the multiplayer hint.

Share this post


Link to post
Share on other sites

okay, now i took this script i found in the forums and everything works fine

// Written by Weasel [PXS] - andy@andymoore.ca

// This script rearms, refuels, and repairs vehicles.

// Vehicles must be less than height 2 (typically landed, if air vehicles) and must remain in the

// trigger area for 3 seconds. It then drains all fuel, repairs, rearms, and refuels.

//

// Setup a trigger area to activate this (F3 in map editor) with the following settings:

//

// Trigger REPEATEDLY, BLUFOR, PRESENT

// Name: Rearmlist

// Condition: this;

// Activation: {[_x] execVM "rearm.sqf"} foreach thislist;

//

// Warning: If this trigger area overlaps another trigger area (such as ammo-transport Scripts), sometimes

// things don't work as planned. Keep this seperate if you can.

_unit = _this select 0;

// Don't start the script until the unit is below a height of 2, and make sure they hold that

// height for at least 3 seconds.

WaitUntil{(getPos _unit select 2)<2};

sleep 3;

if((getPos _unit select 2)>2 || not (_unit in list Rearmlist)) exitWith{};

_unit VehicleChat "Repairing...";

sleep 3;

_unit setDammage 0;

_unit VehicleChat "Rearming...";

sleep 2;

_unit setVehicleAmmo 1;

_unit VehicleChat "Refueling...";

sleep 1;

_unit setFuel 1;

_unit VehicleChat "Finished.";

if(true) exitWith{};

Though now i have a problem with another script, but i already figured what could be the mistake

the one i use is the

Simple Vehicle Respawn Script v1.5

/*

=========================================================

Simple Vehicle Respawn Script v1.5

by Tophe of Östgöta Ops [OOPS]

Put this in the vehicles init line:

veh = [this] execVM "vehicle.sqf"

Options:

There are some optional settings. The format for these are:

veh = [this, Delay, Deserted timer, Respawns, Effect, Static] execVM "vehicle.sqf"

Default respawn delay is 30 seconds, to set a custom

respawn delay time, put that in the init as well.

Like this:

veh = [this, 15] execVM "vehicle.sqf"

Default respawn time when vehicle is deserted, but not

destroyed is 120 seconds. To set a custom timer for this

first put the respawn delay, then the deserted vehicle timer-

Like this:

veh = [this, 15, 10] execVM "vehicle.sqf"

By default the number of respawns is infinite. To set a limit

First set the other values then the number of respawns you want (0 = infinite).

Like this:

veh = [this, 15, 10, 5] execVM "vehicle.sqf"

Set this value to TRUE to add a special explosion effect to the wreck when respawning.

Default value is FALSE, which will simply have the wreck disappear.

Like this:

veh = [this, 15, 10, 5, TRUE] execVM "vehicle.sqf"

By default the vehicle will respawn to the point where it first

was when the mission started (static). This can be changed to

dynamic. Then the vehicle will respawn to the position where it was destroyed.

First set all the other values then set TRUE for dynamic or FALSE for static.

Like this:

veh = [this, 15, 10, 5, TRUE, TRUE] execVM "vehicle.sqf"

If you you want to set the INIT field of the respawned vehicle, first set all other

values, then set init commands. Those must be inside quotations.

Like this:

veh = [this, 15, 10, 5, TRUE, FALSE, "this setDammage 0.5"] execVM "vehicle.sqf"

Default values of all settings are:

veh = [this, 30, 120, 0, FALSE, FALSE] execVM "vehicle.sqf"

Contact & Bugreport: harlechin@hotmail.com

=========================================================

*/

// Define variables

_unit = _this select 0;

_delay = if (count _this > 1) then {_this select 1} else {30};

_deserted = if (count _this > 2) then {_this select 2} else {120};

_respawns = if (count _this > 3) then {_this select 3} else {0};

_explode = if (count _this > 4) then {_this select 4} else {false};

_dynamic = if (count _this > 5) then {_this select 5} else {false};

_unitinit = if (count _this > 6) then {_this select 6} else {};

_haveinit = if (count _this > 6) then {true} else {false};

_unitname = vehicleVarName _unit;

_noend = true;

_run = true;

_rounds = 0;

if (_delay < 0) then {_delay = 0};

if (_deserted < 0) then {_deserted = 0};

if (_respawns <= 0) then {_respawns= 0; _noend = true;};

if (_respawns > 0) then {_noend = false};

_dir = getDir _unit;

_position = getPosASL _unit;

_type = typeOf _unit;

_dead = false;

_nodelay = false;

// Start monitoring the vehicle

while {_run} do

{

sleep (2 + random 10);

if ((getDammage _unit > 0.8) and ({alive _x} count crew _unit == 0)) then {_dead = true};

// Check if the vehicle is deserted.

if ((getPosASL _unit distance _position > 10) and ({alive _x} count crew _unit == 0)) then

{

_timeout = time + _deserted;

sleep 0.3;

if (alive _unit) then {waitUntil {_timeout < time or {alive _x} count crew _unit > 0};};

if ({alive _x} count crew _unit > 0) then {_dead = false;};

if ({alive _x} count crew _unit == 0) then {_dead = true; _nodelay =true;};

};

// Respawn vehicle

if (_dead) then

{

if (_nodelay) then {sleep 0.1; _nodelay = false;} else {sleep _delay};

if (_dynamic) then {_position = getPosASL _unit; _dir = getDir _unit;};

if (_explode) then {_effect = "M_TOW_AT" createVehicle getPosASL _unit; _effect setPosASL getPosASL _unit;};

sleep 0.1;

deleteVehicle _unit;

sleep 2;

_unit = _type createVehicle _position;

_unit setPosASL _position;

_unit setDir _dir;

if (_haveinit) then

{_unit setVehicleInit format ["%1 = this; this setVehicleVarName ""%1"";%2;",_unitname, _unitinit];

processInitCommands;};

if !(_haveinit) then

{_unit setVehicleInit format ["%1 = this; this setVehicleVarName ""%1"";",_unitname];

processInitCommands;};

_dead = false;

// Check respawn amount

if !(_noend) then {_rounds = _rounds + 1};

if ((_rounds == _respawns) and !(_noend)) then {_run = false;};

};

};

it works fine so far, but the problem is, it has to be written into each vehicle init line, if the vehicle now should respawn, so if the _dead condition is true, a new one will be created on the old one's position, but this happens at every user's machine, so if i test the mission in multiplayer alone, it works as it should, but when there are 2 or more players, the number of vehicles respawning are equal to the players on the server (i think, i only tested it with a friend yet) which results in 2 vehicles respawning at the same spot causing explosions and make the vehicles unusable.

now all i wanted to ask is how could i implement the condition in the code that it only runs on the host's machine and not on every user's machine?

would be nice if someone could help ^^

EDIT: just browsed a bit through the forums and stumbeled upon the boolean isServer, may this one help to ensure the code is only runned at the host's machine?

if( !isServer ) then exitWith{};

i would put it just before the

while { _run } do {...

loop, that do you guys think?

Edited by Katatafisch
updated title and put the files i used into the spoiler thing, and had another idea

Share this post


Link to post
Share on other sites

A friendly warning/advice: First steps of mission making should not touch multiplayer. Not in a long time.

Share this post


Link to post
Share on other sites

There are also Warfare buildings that you can place that will service vehicles. The service stations and some of the Ammo crates have vehicle ammo for rearming. You can just place them on top of each other or side by side.

The only problem I had with placing those buildings though was the server client issue. The only way I could figure out how to fix it so the building existed AND serviced all players was the

Servicestation = createvehiclelocal "USMCservicestation"

command. It works for placing the warfare buildings. The only problem here is that I believe it will not show for the host comp.. That is assuming your not using a dedicated server though. Which I highly recommend to test your maps on for MP maps. You need to know how your scripts will react for Join in progress players and so on.

Hope it helps. Keep in mind I am still half retarded when it comes to editing myself. and Carl is right MP is very difficult to map edit because things do not work like they should. The biggest challenge is trying to understand the Server Client relationship and how it is effected by different commands.

Share this post


Link to post
Share on other sites

Here's my question: it seems like "setVehicleAmmo" only fills the current magazine. When a HMMV, for instance, starts, it has about 4 100-round magazines. Is there a way to get those other 3 magazines again?

I've tried "setAmmoCargo" (which let's you store ammo in the vehicle, but not USE that ammo for the vehicle). Even if a soldier/gunner/driver carry the ammo into the vehicle, I still can't seem to make use of it in the vehicle's weapon - a HMMV with an M240, in this case.

I bet there's a way to do this; anyone know what it is?

Share this post


Link to post
Share on other sites

SetAmmoCargo also doesn't work at all if the last bullet is fired. You have to use addMagazine. Either keep track of magazines yourself, per vehicle you use, or check out Dominations x_scripts\x_reload.sqf for how to handle automatic config lookup.

Silly solution to a major problem in my mission. Grad21s will use their rocket artillery to fire on nearby enemies. Has a tendency to get themselves killed if vehicle is attempted "hidden". This one removed the magazines if the weapon is pointed at less than 45° angle, and adds it (only one mag, lifetime supply, not an issue :)) back when weapon is pointing up again:

[] spawn {
while {true} do {
	sleep 4; //Probably good enough
	{
		if ((_x weaponDirection "GRAD") select 2 < 0.5) then {
			_x setVehicleAmmo 0;
		} else {
			if (count magazines _x == 0) then {
				_x addMagazine "40Rnd_Grad";
			};
		};
	} forEach [dG1,dG2,dG3,dG4,dG5];
};
};

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  

×