Jump to content
Sign in to follow this  
wld427

Script application

Recommended Posts

This is the script from the domination mission. I am running a simple add action script on the ammo truck. The problem i have is after the truck respawns the script no longer applies itself. anybody have any ideas. I higlited the line i added to try and run the script.

_empty = true;

_disabled = false;

_waiting = true;

_startpos = getpos _vehicle;

_startdir = getdir _vehicle;

_type = typeof _vehicle;

_st = format ["TW%1=this;this addeventhandler [""killed"", {nil=[_this select 0, _this select 1] execVM ""x_scripts\x_checkkillveh.sqf""}];",_number_v];

_vehicle setVehicleInit _st;

processInitCommands;

while {_waiting} do {

sleep (_delay + random 15);

_empty = true;

_crew = crew _vehicle;

if (count _crew > 0) then {

_i = 0;

_run = true;

while {_i < count _crew && _run} do {

if (alive (_crew select _i)) then {

_empty = false;

_run = false;

};

_i = _i + 1;

};

};

_disabled = false;

if (damage _vehicle > 0.86) then {

_disabled = true;

};

if ((_disabled && _empty) || !(alive _vehicle)) then {

sleep 0.1;

_waiting = false;

_vehicle removeAllEventHandlers "killed";

deletevehicle _vehicle;

sleep 0.5;

_vehicle = objNull;

_newveh = _type createvehicle _startpos;

_newveh setpos _startpos;

_newveh setdir _startdir;

build = [_newveh] exec "action.sqs";

nil = [_newveh, _delay,_number_v] execVM "x_scripts\x_truckrespawn.sqf";

};

};

[b][u][u]

Share this post


Link to post
Share on other sites
_empty = true;

_disabled = false;

_waiting = true;

_startpos = getpos _vehicle;

_startdir = getdir _vehicle;

_type = typeof _vehicle;

_vname = VehicleVarName _vehicle;

_st = format ["TW%1=this;this addeventhandler [""killed"", {nil=[_this select 0, _this select 1] execVM ""x_scripts\x_checkkillveh.sqf""}];",_number_v];

_vehicle setVehicleInit _st;

processInitCommands;

while {_waiting} do {

sleep (_delay + random 15);

_empty = true;

_crew = crew _vehicle;

if (count _crew > 0) then {

_i = 0;

_run = true;

while {_i < count _crew && _run} do {

if (alive (_crew select _i)) then {

_empty = false;

_run = false;

};

_i = _i + 1;

};

};

_disabled = false;

if (damage _vehicle > 0.86) then {

_disabled = true;

};

if ((_disabled && _empty) || !(alive _vehicle)) then {

sleep 0.1;

_waiting = false;

_vehicle removeAllEventHandlers "killed";

deletevehicle _vehicle;

sleep 0.5;

_vehicle = objNull;

_newveh = _type createvehicle _startpos;

call compile format ["_vehicle = %1;", _vname];

_newveh setdir _startdir;

_newveh setpos _startpos;

_newveh setvelocity [0,0,0];

build = [_newveh] exec "action.sqs";

nil = [_newveh, _delay,_number_v] execVM "x_scripts\x_truckrespawn.sqf";

};

};

make sure you do setDir before setPos and, do a setVelocity afterwards...

Share this post


Link to post
Share on other sites

You don't need vehicleVarname stuff as I do not use vehicle varnames in Domination.

Solution for your problem, simply put "build = [_newveh] exec "action.sqs";" in the vehicle init... (I have updated the complete code)...

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

if (!isServer) exitWith {};

_startpos = position _vehicle;

_startdir = direction _vehicle;

_type = typeof _vehicle;

_st = format ["TW%1=this;build = [this] exec ""action.sqs"";this addeventhandler [""killed"", {nil=[_this select 0, _this select 1] execVM ""x_scripts\x_checkkillveh.sqf""}];",_number_v];

_vehicle setVehicleInit _st;

processInitCommands;

while {true} do {

sleep (_delay + random 15);

_empty = (if (({alive _x} count (crew _vehicle)) > 0) then {false} else {true});

_disabled = (if (damage _vehicle > 0.86) then {true} else {false});

if ((_disabled && _empty) || !(alive _vehicle)) exitWith {

sleep 0.1;

_vehicle removeAllEventHandlers "killed";

deletevehicle _vehicle;

sleep 0.5;

_vehicle = objNull;

_newveh = _type createvehicle _startpos;

_newveh setpos _startpos;

_newveh setdir _startdir;

nil = [_newveh, _delay,_number_v] execVM "x_scripts\x_truckrespawn.sqf";

};

};

The script runs on the server, so if you add an action to the vehicle on the server, no client will see that action.

Solution, put it in the vehicle init which will be broadcasted over the network to all clients (even those clients that connect later, JIP).

Xeno

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  

×