Kenya

Help Needed With Script - Hire Vehicles

46 posts in this topic

Hi guys thanks for reading the post, I am a first time poster here and new arma3 server owner. After bumbling around setting up the basics and learning the battleye filters I have decided to "try" give some scripts a go which I plan to use via xm8-apps addon to generate my code.

My goal: I plan to use this script to allow the hiring of non persistant vehicles, charged at 50% deposit (same they get back when selling) plus a 10% hire fee.

My problems: 2 issues so far. When using the "if" condition to check a players available cash code withing the if statement is not executed even when funds are available, the second issue I noticed when using without "if" condition the player is not charged at all for the vehicle spawn, essentially a free car at the moment.

My HireVan.sqf

Spoiler

// Hire Van Script 50% Deposit + 10% Hire Fee = 7200
// To Spawn Non-Persistant Hire Vehicle And Charge User

_availableMoney = _playerObject getVariable ["ExileMoney", 0];
if (_availableMoney > 7200) then
{
_availableMoney = _availableMoney - 7200;
_playerObject setVariable ["ExileMoney", _availableMoney];
format["setAccountMoney:%1:%2", _availableMoney, (getPlayerUID _playerObject)] call ExileServer_system_database_query_fireAndForget;
_veh = createVehicle ["Exile_Car_Van_White",getpos player,[], 0, ""];
_veh setpos (player modelToWorld [0,6,0]);
_veh setDir ([_veh, player] call BIS_fnc_dirTo);
};

My code calling the sqf in xm8-apps

Spoiler

//App 8
_app8Text = "Hire Van $7200";
_app8Logo = "xm8Apps\images\logo.paa";
app8_action = {
execVM "xm8Apps\Apps\ZombieLife Hire Vehicles\HireVan.sqf";

};

Any help/advice appreciated, getting the check if a player can afford before spawning and deducting the hire value from the exile cash balance seem to be my hurdles, ive tried reading through scripts online but still at a loss - Thanks

  • Like 1

Share this post


Link to post
Share on other sites
Spoiler

_money = ExileClientPlayerMoney;

if(_money < 7500) then {
    _smbeh = ExileClientPlayerMoney - 7500;
    ENIGMA_UpdateStats = [player,_smbeh];
    publicVariableServer "ENIGMA_UpdateStats";
    _veh = createVehicle ["Exile_Car_Van_White",getpos player,[], 0, ""];
    _veh setpos (player modelToWorld [0,6,0]);
    _veh setDir ([_veh, player] call BIS_fnc_dirTo);
} else {
	hint "You do not have enough funds!";
};

 

^ w/ engima

Spoiler

_money = ExileClientPlayerMoney;

if(_money < 7500) then {
    _target = player;
	_money = _target getVariable ['ExileMoney', 0];
	_moneyremove = _money - 7500;
	_target setVariable ['ExileMoney', _moneyremove];
	_target setVariable['PLAYER_STATS_VAR',[_target getVariable ['ExileMoney', 0],_moneyremove],true];
	ExileClientPlayerMoney = _moneyremove;
	(owner _target) publicVariableClient 'ExileClientPlayerMoney';
	format['setAccountMoney:%1:%2', _moneyremove, (getPlayerUID _target)] call ExileServer_system_database_query_fireAndForget;
    _veh = createVehicle ["Exile_Car_Van_White",getpos player,[], 0, ""];
    _veh setpos (player modelToWorld [0,6,0]);
    _veh setDir ([_veh, player] call BIS_fnc_dirTo);
} else {
	hint "You do not have enough funds!";
};

 

^ standered exile

Also, this would be easier if you use "Engima poptabs / respect updater" but ^ will solve your issue ;P

Spoiler

This topic should help you :)

 

 

  • Like 1

Share this post


Link to post
Share on other sites
Advertisement

Ok so I tried both scripts and got the hint I didn't have cash on both occasions, I had a test float of 50k cash.

I noticed in your script it had

if(_money < 7500) then

So tried a greater than value as the balance wasnt being read correctly

if(_money > 7500) then

This allowed the vehicle to be spawned ok, however it set my balance from the +50,00 to -7500 actual balance, instead of the money -7500, is there a way around that so only the vehicle hire cost is deducted instead of exile cash total + the hire cost ?

My HireVanUpdated.sqf
 

Spoiler

 

// Hire Van Script 50% Deposit + 10% Hire Fee = 7200
// To Spawn Non-Persistant Hire Vehicle And Charge User
_money = ExileClientPlayerMoney;

if(_money > 7500) then {
    _target = player;
    _money = _target getVariable ['ExileMoney', 0];
    _moneyremove = _money - 7500;
    _target setVariable ['ExileMoney', _moneyremove];
    _target setVariable['PLAYER_STATS_VAR',[_target getVariable ['ExileMoney', 0],_moneyremove],true];
    ExileClientPlayerMoney = _moneyremove;
    (owner _target) publicVariableClient 'ExileClientPlayerMoney';
    format['setAccountMoney:%1:%2', _moneyremove, (getPlayerUID _target)] call ExileServer_system_database_query_fireAndForget;
    _veh = createVehicle ["Exile_Car_Van_White",getpos player,[], 0, ""];
    _veh setpos (player modelToWorld [0,6,0]);
    _veh setDir ([_veh, player] call BIS_fnc_dirTo);
} else {
    hint "You do not have enough funds!";
};

 

Call for the sqf in xm8-apps updated to new name HireVanUpdated.sqf

Thanks

Share this post


Link to post
Share on other sites

Would encasing in brackets work, ?

_moneyremove = (_money - 7500); 

I seem to have gone from free cars to hugely expensive ones xD

Thanks in advance :D

Share this post


Link to post
Share on other sites

Sorry, i didn't really read what you had put but you can change the number 7500, to 7200 i had also just woke up :P

i guess i don't understand your problem. may you explain? 

Share this post


Link to post
Share on other sites

Hi again and thanks, heres the problem, I have 50,000 poptabs, I hire a vehicle for 7500, it should leave me 42,500 poptabs left, but it doesnt it takes all the poptabs and leaves me at -7500 total poptabs, meaning cost was 57,500 poptabs for the vehicle hire

Share this post


Link to post
Share on other sites

essentially the _moneyremove value is not storing correct, instead of 42500 after purchase as it should be it is setting itself to the hire instead cost of -7500 and upon execution is wiping out the whole exile accounts money by setting the new player balance to -7500 total cash

Share this post


Link to post
Share on other sites

_money = ExileClientPlayerMoney;

if(_money > 7500) then {
    _target = player;

  _moneyremove = _money - 7500;
    _target setVariable ['ExileMoney', _moneyremove];
    _target setVariable['PLAYER_STATS_VAR',[_target getVariable ['ExileMoney', 0],_moneyremove],true];
    ExileClientPlayerMoney = _moneyremove;
    (owner _target) publicVariableClient 'ExileClientPlayerMoney';
    format['setAccountMoney:%1:%2', _moneyremove, (getPlayerUID _target)] call ExileServer_system_database_query_fireAndForget;
    _veh = createVehicle ["Exile_Car_Van_White",getpos player,[], 0, ""];
    _veh setpos (player modelToWorld [0,6,0]);
    _veh setDir ([_veh, player] call BIS_fnc_dirTo);
} else {
    hint "You do not have enough funds!";
};

 

try that.

  • 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.