geekm0nkey

[solved] Respect issue

19 posts in this topic

I have a script that lets you sell crates from vehicle.. Seem to be resetting everyone's score? Here is the code if someone want to point out the flaw.

Spoiler

/**
 * ExileServer_system_trading_network_wasteDumpRequest
 *
 * Exile Mod
 * exile.majormittens.co.uk
 * © 2015 Exile Mod Team
 *
 * This work is licensed under the Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License.
 * To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-nd/4.0/.
 */
 
private["_sessionID","_parameters","_vehicleNetID","_mode","_vehicleObject","_vehicleDBID","_playerObject","_cargo","_revenue","_playerMoney","_respectGain","_playerRespect","_logging","_traderLog","_responseCode"];
_sessionID = _this select 0;
_parameters = _this select 1;
_vehicleNetID = _parameters select 0;
_mode = _parameters select 1;

try
{
    _vehicleObject = objectFromNetId _vehicleNetID;
    _vehicleDBID = _vehicleObject getVariable "ExileDatabaseID";
    if (isNull _vehicleObject) then
    {
        throw 6;
    };
    if (_vehicleObject getVariable ["ExileMutex", false]) then
    {
        throw 12;
    };
    _vehicleObject setVariable ["ExileMutex", true];
    _playerObject = _sessionID call ExileServer_system_session_getPlayerObject;
    if (isNull _playerObject) then
    {
        throw 1;
    };
    if !(alive _playerObject) then
    {
        throw 2;
    };
    if !((owner _vehicleObject) isEqualTo (owner _playerObject)) then
    {
        throw 6;
    };
    /* deafult
    _cargo = _vehicleObject call ExileClient_util_containerCargo_list;
    _revenue = _cargo call ExileClient_util_gear_calculateTotalSellPrice;
    clearBackpackCargoGlobal _vehicleObject;
    clearItemCargoGlobal _vehicleObject;
    clearMagazineCargoGlobal _vehicleObject;
    clearWeaponCargoGlobal _vehicleObject;
    */
    _cargo = [];
    _revenue = 0;
    
    if(_mode isEqualTo 1) then
    {
        //standard cargo
        _cargo = _vehicleObject call ExileClient_util_containerCargo_list;
        _revenue = _cargo call ExileClient_util_gear_calculateTotalSellPrice;
        clearBackpackCargoGlobal _vehicleObject;
        clearItemCargoGlobal _vehicleObject;
        clearMagazineCargoGlobal _vehicleObject;
        clearWeaponCargoGlobal _vehicleObject;
        _vehicleObject call ExileServer_object_vehicle_database_update;
    };
    if(_mode isEqualTo 2) then
    {
        if (count (_vehicleObject getVariable ["R3F_LOG_objets_charges", []]) >0) then
        {
            {
                _cargo = _x call ExileClient_util_containerCargo_list;
                _revenue = _revenue + (_cargo call ExileClient_util_gear_calculateTotalSellPrice);
                _revenue = _revenue + ([(typeOf _x)] call ExileClient_util_gear_calculateTotalSellPrice);
                clearBackpackCargoGlobal _x;
                clearItemCargoGlobal _x;
                clearMagazineCargoGlobal _x;
                clearWeaponCargoGlobal _x;
                _x call ExileServer_object_vehicle_remove;
                deleteVehicle _x;
            }forEach (_vehicleObject getVariable ["R3F_LOG_objets_charges", []]);
        };
        _vehicleObject setVariable ["R3F_LOG_objets_charges", [], true];
        _vehicleObject call ExileServer_object_vehicle_database_update;
    };
    if (_mode isEqualTo 3) then
    {
            {
                _cargo = _x call ExileClient_util_containerCargo_list;
                _revenue = _revenue + (_cargo call ExileClient_util_gear_calculateTotalSellPrice);
                _revenue = _revenue + ([(typeOf _x)] call ExileClient_util_gear_calculateTotalSellPrice);
                clearBackpackCargoGlobal _x;
                clearItemCargoGlobal _x;
                clearMagazineCargoGlobal _x;
                clearWeaponCargoGlobal _x;
                _x call ExileServer_object_vehicle_remove;
                deleteVehicle _x;
            }forEach (_vehicleObject getVariable ["R3F_LOG_objets_charges", []]);

        //standard cargo
        _cargo = _vehicleObject call ExileClient_util_containerCargo_list;
        _revenue = _revenue + (_cargo call ExileClient_util_gear_calculateTotalSellPrice);
        clearBackpackCargoGlobal _vehicleObject;
        clearItemCargoGlobal _vehicleObject;
        clearMagazineCargoGlobal _vehicleObject;
        clearWeaponCargoGlobal _vehicleObject;
        
        _revenue = _revenue + ([(typeOf _vehicleObject)] call ExileClient_util_gear_calculateTotalSellPrice);
        _vehicleObject call ExileServer_object_vehicle_remove;
        deleteVehicle _vehicleObject;
    };
    /*
    else
    {
        _vehicleObject call ExileServer_object_vehicle_database_update;
    };
    */
    _playerMoney = _playerObject getVariable ["ExileMoney", 0];
    _playerMoney = _playerMoney + _revenue;
    _playerObject setVariable ["ExileMoney", _playerMoney, true];
    format["setPlayerMoney:%1:%2", _playerMoney, _playerObject getVariable ["ExileDatabaseID", 0]] call ExileServer_system_database_query_fireAndForget;
    
    _respectGain = floor (_revenue * getNumber (configFile >> "CfgSettings" >> "Respect" >> "tradingRespectFactor"));
    
    _playerRespect = _playerObject getVariable ["ExileScore", 0];
    _playerRespect = _playerRespect + _respectGain;
    if (_playerRespect > _playerObject getVariable ["ExileScore", 0]) then
    {
        _playerObject setVariable ["ExileScore", _playerRespect, true];
        format["setAccountScore:%1:%2", _playerRespect, (getPlayerUID _playerObject)] call ExileServer_system_database_query_fireAndForget;
    };
    [_sessionID, "wasteDumpResponse", [0, _revenue, str _playerRespect]] call ExileServer_system_network_send_to;
    _logging = getNumber(configFile >> "CfgSettings" >> "Logging" >> "traderLogging");
    if (_logging isEqualTo 1) then
    {
        _traderLog = format ["PLAYER: ( %1 ) %2 SOLD ITEM: %3 (ID# %4) with Cargo %5 FOR %6 POPTABS AND %7 RESPECT | PLAYER TOTAL MONEY: %8",getPlayerUID _playerObject,_playerObject,typeOf _vehicleObject,_vehicleDBID,_cargo,_revenue,_respectGain,_playerMoney];
        "extDB2" callExtension format["1:TRADING:%1",_traderLog];
    };
}
catch
{
    _responseCode = _exception;
    [_sessionID, "wasteDumpResponse", [_responseCode, 0, ""]] call ExileServer_system_network_send_to;
};
if (!isNull _vehicleObject) then
{
    _vehicleObject setVariable ["ExileMutex", false];
};
true

So lets say you sign in, sell a vehicle.. it will reset your score to 0 and give you the respect for the sell, and will work correct from this point on till you sin off and back on, seems to loose your score on the first calculation?

Edited by geekm0nkey
updated code with what is current.

Share this post


Link to post
Share on other sites

Change this line

format["setAccountScore:%1:%2", _playerRespect, _playerObject getVariable ["ExileDatabaseID", 0]] call ExileServer_system_database_query_fireAndForget; 

To this

format["setAccountScore:%1:%2", _playerRespect, (getPlayerUID _playerObject)] call ExileServer_system_database_query_fireAndForget;

 

That is what handles respect saving and it differs from exile default though i don't think it should.

Share this post


Link to post
Share on other sites
Advertisement

What if i do this?

	if (_playerRespect > _playerObject getVariable ["ExileScore", 0]) then 
	{
		_playerObject setVariable ["ExileScore", _playerRespect, true];
		format["setAccountScore:%1:%2", _playerRespect, (getPlayerUID _playerObject)] call ExileServer_system_database_query_fireAndForget;
	};

I'm trying to prevent a players score from dropping to 0 or say 1000 when it originally was like 68000. Its almost as if the initial read of what their score is, is incorrect or coming out as zero?

Share this post


Link to post
Share on other sites
Advertisement

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.