Frankloco

Negative player respect causing problems with purchases

4 posts in this topic

Hello everyone,

For quite a while I have been working on implementing my own version of Humanity. I have managed to setup pretty much everything up correctly except for one thing. Bandit (negative respect/humanity) purchases won't work for me.
I thought I figured out all the scripts that I needed to change in the ExileClient and ExileServer, but I still keep getting the "Code 14" error. I am currently clueless on what I am doing wrong or what I am missing.
Firstly I encountered the problem that the available items would be greyed out even though the character had enough humanity and only heroes could still buy it (sounds weird, don't worry, it is).
I managed to resolve that problem and the purchase button is available at the correct moments, but when pressing the "Buy" button I receive my code 14 error.

These are the scripts that I modified with their original bits commented out for easy comparison.

ExileClient_gui_traderDialog_event_onStoreListBoxSelectionChanged.sqf

Spoiler

private["_listBox", "_index", "_dialog", "_purchaseButton", "_quantityDropdown", "_inventoryLoadLabel", "_inventoryLoadValue", "_itemClassName", "_inventoryDropdown", "_selectedInventoryDropdownIndex", "_currentContainerType", "_canBuyItem", "_tradingResult", "_salesPrice", "_quality", "_requiredRespect", "_itemInformation", "_itemType", "_containerNetID", "_containerVehicle", "_inventoryListBox"];
disableSerialization;
if !(uiNameSpace getVariable ["RscExileTraderDialogIsInitialized", false]) exitWith {};
_listBox = _this select 0;
_index = _this select 1;
_dialog = uiNameSpace getVariable ["RscExileTraderDialog", displayNull];
_purchaseButton = _dialog displayCtrl 4010;
_quantityDropdown = _dialog displayCtrl 4011;
_inventoryLoadLabel = _dialog displayCtrl 4013;
_inventoryLoadValue = _dialog displayCtrl 4014;
_inventoryLoadLabel ctrlSetTextColor [1, 1, 1, 1];
_inventoryLoadValue ctrlSetTextColor [1, 1, 1, 1];
if (_index > -1) then
{
    _itemClassName = _listBox lbData _index;
    _itemClassName call ExileClient_gui_traderDialog_updateItemStats;
    _inventoryDropdown = _dialog displayCtrl 4004;
    _selectedInventoryDropdownIndex = lbCurSel _inventoryDropdown;
    _currentContainerType = _inventoryDropdown lbValue _selectedInventoryDropdownIndex;
    _canBuyItem = true;
    _tradingResult = 0;
    try 
    {
        _salesPrice = getNumber(missionConfigFile >> "CfgExileArsenal" >> _itemClassName >> "price");
        if (_salesPrice > (player getVariable ["ExileMoney", 0])) then 
        {
            throw 5;
        };
        _quality = getNumber(missionConfigFile >> "CfgExileArsenal" >> _itemClassName >> "quality");
        _requiredRespect = getNumber(missionConfigFile >> "CfgTrading" >> "requiredRespect" >> format["Level%1",_quality]);
        /* OLD CODE
        if (_requiredRespect > ExileClientPlayerScore) then
        {
            throw 14;
        };
        */

        // NEW CODE
        if (_requiredRespect == 0) then
        {
            //DO NOTHING
        }
        else
        {
            if (_requiredRespect > 0) then
            {
                if (_requiredRespect > ExileClientPlayerScore) then
                {
                    throw 14;
                };
            }
            else
            {
                if (_requiredRespect < 0) then
                {
                    if (_requiredRespect < ExileClientPlayerScore) then
                    {
                        throw 14;
                    };
                };
            };
        };
        //NEW CODE END

        switch (_currentContainerType) do
        {
            case 1:
            {
                _itemInformation = [_itemClassName] call BIS_fnc_itemType;
                _itemType = _itemInformation select 1;
                if !([player, _itemClassName] call ExileClient_util_playerCargo_canAdd) then
                {
                    throw 9;
                };
            };
            case 2:
            {    
                if !(player canAddItemToUniform _itemClassName) then 
                {
                    throw 9;
                };
            };
            case 3:
            {
                if !(player canAddItemToVest _itemClassName) then 
                {
                    throw 9;
                };
            };
            case 4:
            {
                if !(player canAddItemToBackpack _itemClassName) then 
                {
                    throw 9;
                };
            };
            default 
            {
                _containerNetID = _inventoryDropdown lbData _selectedInventoryDropdownIndex;
                _containerVehicle = objectFromNetId _containerNetID;
                if (_containerVehicle isEqualTo objNull) then 
                {
                    throw 8;
                };
                if !([_containerVehicle, _itemClassName] call ExileClient_util_containerCargo_canAdd) then 
                {
                    throw 9;
                };
            };
        };
    }
    catch
    {
        _tradingResult = _exception;
        _canBuyItem = false;
    };
    if (ExileClientIsWaitingForServerTradeResponse) then
    {
        _canBuyItem = false;
    };
    if (_canBuyItem) then 
    {
        _purchaseButton ctrlEnable true;
        _quantityDropdown ctrlEnable true;    
    }
    else 
    {
        if (_tradingResult isEqualTo 9) then
        {
            _inventoryLoadLabel ctrlSetTextColor [0.91, 0, 0, 0.6];
            _inventoryLoadValue ctrlSetTextColor [0.91, 0, 0, 0.6];
        };
        _purchaseButton ctrlEnable false;
        _quantityDropdown ctrlEnable false;
    };
    _inventoryListBox = _dialog displayCtrl 4005;
    _inventoryListBox lbSetCurSel -1;
}
else 
{
    _purchaseButton ctrlEnable false;
    _quantityDropdown ctrlEnable false;
};
true


ExileServer_system_trading_network_purchaseItemRequest.sqf

Spoiler

private["_sessionID","_parameters","_itemClassName","_quantity","_containerType","_containerNetID","_playerObject","_vehicleObject","_salesPrice","_playerMoney","_playerRespect","_quality","_requiredRespect","_logging","_traderLog","_responseCode"];
_sessionID = _this select 0;
_parameters = _this select 1;
_itemClassName = _parameters select 0;
_quantity = _parameters select 1;
_containerType = _parameters select 2;
_containerNetID = _parameters select 3;
try 
{
    _playerObject = _sessionID call ExileServer_system_session_getPlayerObject;
    if (_playerObject getVariable ["ExileMutex",false]) then
    {
        throw 12;
    };
    _playerObject setVariable ["ExileMutex",true];
    _vehicleObject = objNull;
    if (isNull _playerObject) then
    {
        throw 1;
    };
    if !(alive _playerObject) then
    {
        throw 2;
    };
    if !(isClass (missionConfigFile >> "CfgExileArsenal" >> _itemClassName) ) then
    {
        throw 3;
    };
    _salesPrice = getNumber (missionConfigFile >> "CfgExileArsenal" >> _itemClassName >> "price");
    if (_salesPrice <= 0) then
    {
        throw 4;
    };
    _playerMoney = _playerObject getVariable ["ExileMoney", 0];
    if (_playerMoney < _salesPrice) then
    {
        throw 5;
    };
    _playerRespect = _playerObject getVariable ["ExileScore", 0];
    _quality = getNumber(missionConfigFile >> "CfgExileArsenal" >> _itemClassName >> "quality");
    _requiredRespect = getNumber(missionConfigFile >> "CfgTrading" >> "requiredRespect" >> format["Level%1",_quality]);

    /* OLD CODE
    if (_playerRespect < _requiredRespect) then
    {
        throw 14;
    };
    */

    // NEW CODE
    if (_requiredRespect == 0) then
    {
        ["InfoTitleAndText", ["DEBUG", "No respect required"]] call ExileClient_gui_toaster_addTemplateToast;
    }
    else
    {
        if (_requiredRespect > 0) then
        {
            if (_requiredRespect > _playerRespect) then
            {
                ["InfoTitleAndText", ["DEBUG", "Hero buy attempt"]] call ExileClient_gui_toaster_addTemplateToast;
                throw 14;
            };
        }
        else
        {
            if (_requiredRespect < 0) then
            {
                if (_requiredRespect < _playerRespect) then
                {
                    ["InfoTitleAndText", ["DEBUG", "Bandit buy attempt"]] call ExileClient_gui_toaster_addTemplateToast;
                    throw 14;
                };
            };
        };
    };
    // END OF NEW CODE
    
    _playerMoney = _playerMoney - _salesPrice;
    _playerObject setVariable ["ExileMoney", _playerMoney, true];
    format["setPlayerMoney:%1:%2", _playerMoney, _playerObject getVariable ["ExileDatabaseID", 0]] call ExileServer_system_database_query_fireAndForget;
    [_sessionID, "purchaseItemResponse", [0, _salesPrice, _itemClassName, 1, _containerType, _containerNetID]] call ExileServer_system_network_send_to;
    _logging = getNumber(configFile >> "CfgSettings" >> "Logging" >> "traderLogging");
    if (_logging isEqualTo 1) then
    {
        _traderLog = format ["PLAYER: ( %1 ) %2 PURCHASED ITEM %3 FOR %4 POPTABS | PLAYER TOTAL MONEY: %5",getPlayerUID _playerObject,_playerObject,_itemClassName,_salesPrice,_playerMoney];
        "extDB2" callExtension format["1:TRADING:%1",_traderLog];
    };
    if !(_vehicleObject isEqualTo objNull) then
    {
        _vehicleObject call ExileServer_object_vehicle_database_update;
    }
    else 
    {
        _playerObject call ExileServer_object_player_database_update;
    };
}
catch 
{
    _responseCode = _exception;
    [_sessionID, "purchaseItemResponse", [_responseCode, 0, "", 0, 0, ""]] call ExileServer_system_network_send_to;
};    
_playerObject setVariable ["ExileMutex",false];
true


I am quite positive that the ExileClient_gui_traderDialog_event_onStoreListBoxSelectionChanged has nothing to do with it anymore, but I am totally clueless so I included it anyway.
I did not modify the ExileClient_gui_traderDialog_even_onPurchaseButtonClick at all.
Currently the buying of items with 0 required respect only works if you have more than 0 respect (didn't test it when playerRespect = 0), and if you are a bandit you aren't able to buy any bandit items or default items either.

Hopefully someone has an answer to my problem. You will be forever remembered!
Thanks in advance!

Greetings,
Frankloco

Edited by Frankloco

Share this post


Link to post
Share on other sites

Hello FrankLoco,

Quick and dirty solution.

When the 'purchase script' kicks in, set a temporary variable (client) for the original respect value.  Then change the original value to some positive number.  At the end of the 'buy sub', restore/reset the original respect value to match the temporary value.  You could also go as far as to ignore this if the original value is a positive number.

 

Example:

...Purchase....

_TempRespect = ExileRespect;

OR

if (ExileRespect < 0) then {_TempRespect = ExileRespect};

...

...Buy...

ExileRespect = _TempRespect;

OR

if (_TempRespect < 0) then {ExileRespect = _TempRespect};

_TempRespect = 0;

...end of Buy Script...

 

It's lame and simple, but it should address the issue of you having a negative respect value upon entering the 'purchase script'.

 

Will this work EXACTLY as listed above?  I do not know, BUT, this will point you in a direction that may work for ya!

 

:)

  • Like 2

Share this post


Link to post
Share on other sites
Advertisement

Ehm... I just want to mention that this is on purpose. People that have a negative respect with the Mafia will end up with the Mafia not wanting to deal with you. 

  • Like 3

Share this post


Link to post
Share on other sites

Sorry for the late response, but I had been struggling with the problem for quite a while after I received the suggestions, but I have managed to find a workaround which works for me!
I eventually removed one of the final checks for Humanity (Respect) which seemed double to me and that fixed it!

Thank you for taking your time to respond to those who did!

EDIT: This topic can be marked as solved!

Edited by Frankloco
  • Like 1

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.