Тема: Сервер Wasteland
Показать сообщение отдельно
Старый 01.10.2012, 12:43   #221
Prodavec
Подполковник
 
Аватар для Prodavec
 
Регистрация: 23.07.2009
Сообщений: 2,358
Сказал cпасибо: 268
Поблагодарили 915 раз в 549 сообщениях
Удаленный вызов процедуры? М?
Код:
if (local _vehicle) then
{
    _vehicle setFuel 1;
}
else
{
    ["HPP_fnc_SetFuel", [_vehicle, 1]] call HPP_fnc_SendToServer;

    // or
    ["HPP_fnc_SetFuel", [_vehicle, 1]] call HPP_fnc_Broadcast;

    // or more traffic optimized
    ["HPP_fnc_RequestFuel", [_vehicle, 1]] call HPP_fnc_SendToServer;

    // or with changing the owner to the server (more optimized! the best way)
    ["HPP_fnc_SetFuelAndOwnerA", [_vehicle, 1]] call HPP_fnc_SendToServer;

    // or with changing the owner to the client (less optimized)
    ["HPP_fnc_SetFuelAndOwnerB", [player, _vehicle, 1]] call HPP_fnc_SendToServer;

    // refuel at server and change owner to refueller
    ["HPP_fnc_SetFuelAndOwnerC", [player, _vehicle, 1]] call HPP_fnc_SendToServer;
};

//...

// Common function
HPP_fnc_SetFuel =
{
    (_this select 0) setFuel (_this select 1);
};

// Server-side function
HPP_fnc_RequestFuel =
{
    private
    [
        "_vehicle",
        "_fuel"
    ];
    _vehicle = _this select 0;
    _fuel = _this select 1;

    _owner = owner _vehicle;
    if (_owner == 0) then
    {
        _vehicle setFuel _fuel;
    }
    else
    {
        [_owner, "HPP_fnc_SetFuel", [_vehicle, _fuel]] call HPP_fnc_SendToClient;
    };
};

// Server-side function
HPP_fnc_SetFuelAndOwnerA =
{
    private
    [
        "_vehicle",
        "_fuel"
    ];
    _vehicle = _this select 0;
    _fuel = _this select 1;

    _vehicle setOwner 0; // Server is owner now
    _vehicle setFuel _fuel;
};

// Server-side function
HPP_fnc_SetFuelAndOwnerB =
{
    private
    [
        "_vehicle",
        "_fuel",
        "_newOwner",
    ];
    _newOwner = _this select 0
    _vehicle = _this select 1;
    _fuel = _this select 2;

    _owner = owner _newOwner;
    _vehicle setOwner _owner; // Player which refuels the vehicle becames the owner
    [_owner, "HPP_fnc_SetFuel", [_vehicle, _fuel]] call HPP_fnc_SendToClient;
};

// Server-side function
HPP_fnc_SetFuelAndOwnerC =
{
    private
    [
        "_vehicle",
        "_fuel",
        "_newOwner",
    ];
    _newOwner = _this select 0
    _vehicle = _this select 1;
    _fuel = _this select 2;

    _owner = owner _newOwner;
    _vehicle setOwner 0;
    _vehicle setFuel _fuel;
    _vehicle setOwner _owner; // Player which refuels the vehicle becames the owner
};
UPDATE
Еще кое-какие варианты пришли в голову)

Последний раз редактировалось Prodavec; 01.10.2012 в 14:21.
Prodavec вне форума   Ответить с цитированием