Home   Help Search Login Register  

Author Topic: Fuel status not broadcasted on MP?  (Read 1477 times)

0 Members and 1 Guest are viewing this topic.

Offline myke13021

  • Contributing Member
  • **
  • Myke
Fuel status not broadcasted on MP?
« on: 26 Aug 2007, 22:47:42 »
What i've tried to do:

I want some sort of more realistic refueling of Aircrafts, disabling the automated refueling capacities of Gas stations and Fuel trucks. For this, i wrote a script which simulates a refuelling with a fixed fueal rate (50kg/s) and with defined fuel capacities of the Aircrafts (i.e. a Su34 carries a max of 12100kg fuel). So refuelling a SU34 would take a lot of time (i offer the possibility to refuel only to a certain amount, say 50% i.e), much more than a Mi17. I also simulate a Gas depot with finite amount of fuel (strategic issue: should i fill up a SU or insted refuel 3 choppers?). This all works really fine in Editor preview and also when i host myself to test it. But when i open a dedicated server and a friend tries it, the choppers fuel stays empty.

I bet is a problem of locality in MP but i don't know how to solve it. Maybe someone could give me a helping hand.

Code: (refuel2.sqf) [Select]
private ["_using", "_fuel_diff", "_fuel_flow", "_limit_kg", "_limit", "_object", "_plane", "_added", "_fuel_value"];
if (mission_refueling) exitwith {};
_object = _this select 0;
_limit = _this select 3;
_plane = nearestobject [_object, "AIR"];
_fuel_flow = fuel_flow;

switch (typeof _plane) do
{
case "Su34":
{
_fuel_value = fuel_capacity_su34;
};
case "Su34B":
{
_fuel_value = fuel_capacity_su34;
};
case "KA50" :
{
_fuel_value = fuel_capacity_ka50;
};
case "Mi17_MG" :
{
_fuel_value = fuel_capacity_mi17;
};
};

_limit_kg = (_fuel_value / (1 / _limit));

if (mission_fuel <= 0) exitwith {hint "We have no gas for you"};
if (isnull _plane) exitwith {hint "No Aircraft in range"};
if ((_plane distance _object) >= 25) exitwith {hint "No Aircraft in range"};
if (fuel _plane == 1) exitwith {hint format ["%1 is fuel", typeof _plane]};

mission_refueling = true;
publicvariable "mission_refueling";

{
_x action ["Getout", _plane];
}
foreach units vehicle _plane;

while {fuel _plane < _limit} do
{
if ((_plane distance _object) >= 25) exitwith {hint "Refueling aborted!"};
_fuel_diff = ((_fuel_value / (1 / _limit)) - (_fuel_value * fuel _plane));
if (mission_fuel >= _fuel_flow) then
{
if (_fuel_diff < _fuel_flow) then
{
_added = (1 / (_fuel_value / _fuel_diff)) + fuel _plane;
_using = _fuel_diff;
}
else
{
_added = (1 / (_fuel_value / fuel_flow)) + fuel _plane;
_using = _fuel_flow;
};
}
else
{
_added = (1 / (_fuel_value / mission_fuel)) + fuel _plane;
_using = mission_fuel;
};
_plane setfuel _added;
mission_fuel = mission_fuel - _using;
publicvariable "mission_fuel";
hint format ["Refueling %1 with %2kg/s\n\nRequested fuel: %3kg\nCurrent fuel: %4kg\n\nRemaining in Depot: %5kg", typeof _plane, _fuel_flow, (_fuel_value * _limit), (_fuel_value * fuel _plane), mission_fuel];
sleep 2;
if (fuel _plane >= _limit) exitwith {hint "Limit reached.\nRefueling terminated"};
if (mission_fuel <= 0) exitwith {hint "Gas tanks are empty"};
};
sleep 2;
mission_refueling = false;
publicvariable "mission_refueling";
if (fuel _plane == 1) then
{
hint format ["%1 refueled.", typeof _plane];
};

Related to this are parts from the init.sqf:
Code: (init.sqf) [Select]
mission_fuel = 500;
mission_refueling = false;

fuel_capacity_su34 = 12100;
fuel_capacity_mi17 = 1140;
fuel_capacity_ka50 = 1600;

fuel_flow = 50;
This only defines some parameters as max capacity of fuelload and how fast refueling goes (fuel_flow). The mission_fuel sets the init fuel available to 500kg (not very much but it is part of the mission to get more fuel at another place).

My guess is, the issue lies as the Aircraft isn't local to player and the fuel status is not broadcasted. But i have no idea how i must solve this issue...probably something stupidly easy  :D


Myke out

Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
Re: Fuel status not broadcasted on MP?
« Reply #1 on: 26 Aug 2007, 23:18:33 »
Check locality first. Empty vehicles would be local to the server, anything else would be local to the machine where the leader of the group of the driver of the vehicle is local.

Offline myke13021

  • Contributing Member
  • **
  • Myke
Re: Fuel status not broadcasted on MP?
« Reply #2 on: 26 Aug 2007, 23:43:41 »
Yep, know that. So i tried to exec the script on the server but then the player (the one who did the action) will not get the hints.

I had the idea to create a gamelogic, group it with the unit that used the action (which is always a player, never AI) and put it into the aircraft. The first idea i had as i tried this...AI grouped with a player is local to the player and NOT to the server. But then i read somewhere that a gamelogic is always local to the server. Also the script wouldnt delete the logic at the end, blocking the drivers seat (cargo isn't an option since a Su34 has no cargo seats).

So, what i know for now: as the script is called from an action, it runs local to the player that called the action. But for taking effect on the fuel status it should be run from the server. But then i run into problems as the player wont see the status hints.

What now comes into my mind, the mando_tractor should handle the same issue, i think i'll take a look there how you solved that, Mandoble.

One thing though...i would be happy if i haven't to tear it apart into client/server scripts as to keep up the hints synced would be a hell.


Myke out.

:EDIT:
Ok, i'm a step further. It seems to be an ArmA bug, at least what Bugtracker says:
Quote
If you use the setfuel command from an client only running script,
no changes to the fuel of the given vehicle happens !
Source: http://bugs.armed-assault.net/view.php?id=2750

:EDIT again:
Based on that, would a script called from the above with a isServer check run only on the server even the parent script is called at local player? Then just outsourcing the setfuel would do the job? And therefor my next question: can ANY .sqf script return values or is this reserved for functions? So could i call a "child-script", changing the fuel serverside and meanwhile the parent script waits untill setfuel is done? I'm not familiar with this topic at all.

:and still EDIT:
Tried now to outsource the setfuel command into a function which checks isServer. But didn't worked either. I think i definately have to strip it apart into a script that runs serverside for the refuel and another one which runs player local for the hints.
« Last Edit: 27 Aug 2007, 02:05:43 by myke13021 »

Offline Mr.Peanut

  • Former Staff
  • ****
  • urp!
Re: Fuel status not broadcasted on MP?
« Reply #3 on: 27 Aug 2007, 16:05:11 »
The fuel status is supposed to be broadcast as is lock status. Yet another ArmA bug.  :blink:
urp!

Offline myke13021

  • Contributing Member
  • **
  • Myke
Re: Fuel status not broadcasted on MP?
« Reply #4 on: 27 Aug 2007, 21:12:27 »
Ok, no i've tried to workaround to this problem. I was thinking when i use setfuel on every machine (server and all clients) the aircraft would be filled. so i've splitted up the scripts and fooled around with some publicvariables. But now even in Editor preview the aircraft will not be filled with gas. Here what i've done sofar:

The init script. This is called from the init.sqf therefor should it be runnin on all machines:
Code: (refuel_system.sqf) [Select]
_object = _this select 0;

_object setfuelcargo 0;

refuel_params_ready = false;
refuel_params_plane = objnull;
refuel_params_added = 0;

mission_refueling = false;
mission_fuel = 500;

fuel_capacity_su34 = 12100;
fuel_capacity_mi17 = 1140;
fuel_capacity_ka50 = 1600;

fuel_flow_plane = 50;
fuel_flow_land = 0.8;
_nul = [] execVM "refuel_system\do_refuel.sqf";
if (! isServer) exitwith {};
refuel100 = _object addaction ["Refuel Aircraft 100%", "refuel_system\refuel2.sqf", 1, 6];
refuel75 = _object addaction ["Refuel Aircraft 75%", "refuel_system\refuel2.sqf", 0.75, 5];
refuel50 = _object addaction ["Refuel Aircraft 50%", "refuel_system\refuel2.sqf", 0.5, 4];
refuel25 = _object addaction ["Refuel Aircraft 25%", "refuel_system\refuel2.sqf", 0.25, 3];
_object addaction ["Check fuel status", "refuel_system\checkfueldepot.sqf", 0, 2];

As this is runnin on all machines, also the do_refuel.sqf is called on each:
Code: (do_refuel.sqf) [Select]
private ["_plane", "_added", "_i"];
for [{_i=0}, {_i<10000}, {_i=_i+1}] do
{
waituntil {(refuel_params_ready)};
_plane = refuel_params_plane;
_added = refuel_params_added;
_plane setfuel _added;
refuel_params_ready = false;
publicvariable "refuel_params_ready";
};

And at last the script which is called by the action and therefor only runnin on the respective client:
Code: (refuel2.sqf) [Select]
private ["_using", "_fuel_diff", "_fuel_flow", "_limit_kg", "_limit", "_object", "_added", "_fuel_value"];
if (mission_refueling) exitwith {};
_object = _this select 0;
_limit = _this select 3;
refuel_params_plane = nearestobject [_object, "AIR"];
_fuel_flow = fuel_flow_plane;

switch (typeof refuel_params_plane) do
{
case "Su34":
{
_fuel_value = fuel_capacity_su34;
};
case "Su34B":
{
_fuel_value = fuel_capacity_su34;
};
case "KA50" :
{
_fuel_value = fuel_capacity_ka50;
};
case "Mi17_MG" :
{
_fuel_value = fuel_capacity_mi17;
};
};

_limit_kg = (_fuel_value / (1 / _limit));

if (mission_fuel <= 0) exitwith {hint "We have no gas for you"};
if (isnull refuel_params_plane) exitwith {hint "No Aircraft in range"};
if ((refuel_params_plane distance _object) >= 25) exitwith {hint "No Aircraft in range"};
if (fuel refuel_params_plane == 1) exitwith {hint format ["%1 is fuel", typeof refuel_params_plane]};

mission_refueling = true;
publicvariable "mission_refueling";

_object removeaction refuel100;
_object removeaction refuel75;
_object removeaction refuel50;
_object removeaction refuel25;

{
_x action ["Getout", refuel_params_plane];
}
foreach units vehicle refuel_params_plane;

while {fuel refuel_params_plane < _limit} do
{
if ((refuel_params_plane distance _object) >= 25) exitwith {hint "Refueling aborted!"};
_fuel_diff = ((_fuel_value / (1 / _limit)) - (_fuel_value * fuel refuel_params_plane));
if (mission_fuel >= _fuel_flow) then
{
if (_fuel_diff < _fuel_flow) then
{
_added = (1 / (_fuel_value / _fuel_diff)) + fuel refuel_params_plane;
_using = _fuel_diff;
}
else
{
_added = (1 / (_fuel_value / fuel_flow)) + fuel refuel_params_plane;
_using = _fuel_flow;
};
}
else
{
_added = (1 / (_fuel_value / mission_fuel)) + fuel refuel_params_plane;
_using = mission_fuel;
};
// refuel_params_plane setfuel _added;

refuel_params_added = _added;
mission_fuel = mission_fuel - _using;
publicvariable "mission_fuel";
publicvariable "refuel_params_plane";
publicvariable "refuel_params_added";
sleep 0.5;
refuel_params_ready = true;
publicvariable "refuel_params_ready";

hint format ["Refueling %1 with %2kg/s\n\nRequested fuel: %3kg\nCurrent fuel: %4kg\n\nRemaining in Depot: %5kg", typeof refuel_params_plane, _fuel_flow, (_fuel_value * _limit), (_fuel_value * fuel refuel_params_plane), mission_fuel];
sleep 1;
if (fuel refuel_params_plane >= _limit) exitwith {hint "Limit reached.\nRefueling terminated"};
if (mission_fuel <= 0) exitwith {hint "Gas tanks are empty"};
};
sleep 2;
mission_refueling = false;
publicvariable "mission_refueling";

refuel100 = _object addaction ["Refuel Aircraft 100%", "refuel_system\refueling.sqf", 1, 6];
refuel75 = _object addaction ["Refuel Aircraft 75%", "refuel_system\refueling.sqf", 0.75, 5];
refuel50 = _object addaction ["Refuel Aircraft 50%", "refuel_system\refueling.sqf", 0.5, 4];
refuel25 = _object addaction ["Refuel Aircraft 25%", "refuel_system\refueling.sqf", 0.25, 3];

if (fuel refuel_params_plane == 1) then
{
hint format ["%1 refueled.", typeof refuel_params_plane];
};

The "refueling..." hint shows me that the gas in the depot is subtracted but the aircrafts fuel stays at 0. If anyone has a solution to this, please share it with me because i'm goin slightly mad.


Myke out

:EDIT:

- solved -

..and again the problem was self made...missing underline.
« Last Edit: 28 Aug 2007, 00:39:45 by myke13021 »