Zombeast250 3 Posted March 3, 2018 ARMA 3 my issue is i have a custom script for store items my store works great so far but i have a issue where when i buy a item it will take my money even without giving me the object i am trying to buy because of no space in inventory i have a working store script & a working (check inventory script) i was wondering if i am able to merge the two scripts ??? any help would be great TY ALSO: the items i am calling are for Ravage Mod (if that matters) *MY: init.sqf: money = 0; * Player addaction/unit/custom store TRIGGER: this addAction ["(Tent Folded) $500","scripts\store_systems\gear\gear(TentFolded).sqf"]; *Item/store/ script NAME: gear(TentFolded).sqf *Item/store/ SCRIPT(please help merge the 2 scripts below this line)####### _cost=500; if(money >= _cost) then { money=money-_cost; hint "-$500", player additem "rvg_foldedTent"; }else{ hint "You Need More $$$"; }; *Script i have for checking carry weight (works alone off same trigger when added to My gear(TentFolded).sqf) if (player canAdd "rvg_foldedTent") then { player addItem "rvg_foldedTent"; } else { hint "Not enough space"; }; 1 Share this post Link to post Share on other sites
HazJ 1289 Posted March 3, 2018 Your post hurts my eyes. I recommend you use the code tag option. I will see if I can help then. Also... Why: gear(TentFolded).sqf A new naming convention? Share this post Link to post Share on other sites
Zombeast250 3 Posted March 3, 2018 LOL because when i look through my folder the names pop more (no reason) i think it is because the folder names kept changing lol please help Share this post Link to post Share on other sites
HazJ 1289 Posted March 3, 2018 ??? _cost = 500; if (money >= _cost) then { if !(player canAdd "rvg_foldedTent") exitWith { hint "Not enough space"; }; money = money - _cost; hint "-$500", player additem "rvg_foldedTent"; } else { hint "You Need More $$$"; }; Share this post Link to post Share on other sites
Zombeast250 3 Posted March 3, 2018 so i have tested that code and it seems to do a check (IF) the player has no items in inventory and display message "hint "Not enough space";" works once player has items in inventory (they spawn with a pistol & ammo) it does not do a check for space and goes to taking players money & still nothing in inventory Share this post Link to post Share on other sites
Zombeast250 3 Posted March 3, 2018 so i just took the weapons and ammo away from the player and it only does the........ hint "Not enough space"; so i killed npc and took his vest (to make space) and same problem ??? Share this post Link to post Share on other sites
Zombeast250 3 Posted March 3, 2018 also going from a check to exit is definitely not a good way to start??? if !(player canAdd "rvg_foldedTent") exitWith { hint "Not enough space"; Share this post Link to post Share on other sites
Grumpy Old Man 3545 Posted March 3, 2018 Just a few tips to make an easier, foolproof and expandable money system without cluttering your entire scripts/mission with if then else checks: //init.sqf or wherever //basic function to change a units money amount, works with positive and negative numbers TAG_fnc_changeMoney = { params ["_unit","_amount"]; _currentMoney = _unit getVariable ["TAG_fnc_money",0];//returns 0 money if the unit has non, current amount otherwise _newMoney = _amount + _currentMoney; if (_newMoney < 0) exitWith {systemchat "The transaction would set your balance below 0!";false}; _unit setVariable ["TAG_fnc_money",_newMoney,true]; systemchat "Money balance changed:"; systemchat format ["You now have %1$",_newMoney]; true }; //now anywhere in the game you simply use this to change a units money amount, as long as it stays above 0 [player,50000] call TAG_fnc_changeMoney; I assumed the money value has to stay above 0 or else the transaction won't happen. The TAG_fnc_changeMoney returns a bool if the transaction was successful so you'll only have to check for that. Money will also be stored on the player object, so you could have multiple players with their own assets without getting into global variable in MP hell. Now to your items store or what it's supposed to be, have to be more specific: TAG_fnc_buyItem = { params ["_unit","_item","_cost"]; if !(_unit canAdd _item) exitWith {systemchat "Not enough space!";false}; _purchase = [_unit,- _cost] call TAG_fnc_changeMoney;//notice the negative sign of the cost, will be handled in here instead of having to keep track of it everywhere else if !(_exchange) exitWith {systemchat "Not enough money!";false}; systemchat ["Congratulations on your new %1",_item]; true } //now when you want a purchase to happen simply use this: _purchase = [player,"rvg_foldedTent",500] call TAG_fnc_buyItem; if (_purchase) then {systemchat "Purchase successful!"} else {systemchat "Purchase failed!"}; This way you have it all happen in one line, readable and easily adaptable to enable player to player money transfer or other unvoluntary means of monetary exchange. Best thing about this is that you can even add a bank account or other places for the player to store money (car, hollow tree stump) or prevent transactions from happening because the player was naughty and the store clerk doesn't like him by modifying a single centralized function which only has to be defined once in init.sqf or better in the description.ext. Cheers Share this post Link to post Share on other sites
Zombeast250 3 Posted March 3, 2018 thank you for your time :) i can see you have put some work into this i was just wondering how do i implement these lines of code / where do i add this as this is a complete change to my system ? Share this post Link to post Share on other sites
Grumpy Old Man 3545 Posted March 3, 2018 Depends on if you want to go the full distance, then set up your own functions library with the link mentioning description.ext in my previous post as a guide. Alternatively you can put all functions in a single file, called TAG_fnc_moneySystem.sqf and run that from init.sqf so all functions will be available inside the mission. You can change the TAG to something more fitting, in your case probably ZOM_fnc_something would be a good identifier for functions made by you. These functions (like TAG_fnc_buyItem) need to be only defined once so you can use it anywhere during mission runtime, be it other scripts/functions, triggers that wait for a task to be succeeded so the player is rewarded some money etc. Using a simple approach make your init.sqf look like this: _initMoneySystem = [] execVM "TAG_fnc_moneySystem.sqf"; Then in the missions root folder put a file named TAG_fnc_moneySystem.sqf and paste all the functions into it: TAG_fnc_buyItem = { params ["_unit","_item","_cost"]; if !(_unit canAdd _item) exitWith {systemchat "Not enough space!";false}; _purchase = [_unit,- _cost] call TAG_fnc_changeMoney;//notice the negative sign of the cost, will be handled in here instead of having to keep track of it everywhere else if !(_exchange) exitWith {systemchat "Not enough money!";false}; systemchat ["Congratulations on your new %1",_item]; true }; TAG_fnc_changeMoney = { params ["_unit","_amount"]; _currentMoney = _unit getVariable ["TAG_fnc_money",0];//returns 0 money if the unit has non, current amount otherwise _newMoney = _amount + _currentMoney; if (_newMoney < 0) exitWith {systemchat "The transaction would set your balance below 0!";false}; _unit setVariable ["TAG_fnc_money",_newMoney,true]; systemchat "Money balance changed:"; systemchat format ["You now have %1$",_newMoney]; true }; That's basically it, init.sqf will be executed automatically, running the TAG_fnc_moneySystem.sqf in your mission root folder, which in turn defines all functions to be available in game. Now if you want to change or add functionality to the money system you can do it all in one file. Cheers Share this post Link to post Share on other sites
Zombeast250 3 Posted March 3, 2018 Thank you sooo much for your help/re-write of the scripts (if i ever get to publish a mod :) i will credit you for your scripts so with my last script i was using money as the( money NAME) so in the init.sqf i was calling ::: money = 0; to keep track of WALLET on the player/unit init i was using ::: this addAction ["Wallet", {hint format ["$%1",money];},[],6] and on custom money piles/case (to pick up money) model/init: this addaction ["Take Case Of Money","scripts\money\add_moneycase.sqf"]; & finally in the add_moneycase.sqf :::: _object = _this select 0; deletevehicle _object; playsound "scoreAdded"; money = money + 5000; hint "+$5000"; (((i would love to keep a similar system to be able to have money added???)))(((but whatever works))) Share this post Link to post Share on other sites
Zombeast250 3 Posted March 3, 2018 moneycase.sqf so this works for my add money pile: TY _object = _this select 0; deletevehicle _object; playsound "scoreAdded"; [player,5000] call TAG_fnc_changeMoney; hint "+$5000"; just need to figure out the wallet: i just got this::: ERROR:::: when i try to buy the Tent Folded in gear(TentFolded).sqf INSIDE :::::: gear(TentFolded).sqf _purchase = [player,"rvg_foldedTent",500] call TAG_fnc_buyItem; if (_purchase) then {systemchat "Purchase successful!"} else {systemchat "Purchase failed!"}; and that calls::::::::: TAG_fnc_moneySystem.sqf code inside that .sqf saays " TAG_fnc_buyItem = { params ["_unit","_item","_cost"]; if !(_unit canAdd _item) exitWith {systemchat "Not enough space!";false}; _purchase = [_unit,- _cost] call TAG_fnc_changeMoney;//notice the negative sign of the cost, will be handled in here instead of having to keep track of it everywhere else if !(_exchange) exitWith {systemchat "Not enough money!";false}; systemchat ["Congratulations on your new %1",_item]; true }; TAG_fnc_changeMoney = { params ["_unit","_amount"]; _currentMoney = _unit getVariable ["TAG_fnc_money",0];//returns 0 money if the unit has non, current amount otherwise _newMoney = _amount + _currentMoney; if (_newMoney < 0) exitWith {systemchat "The transaction would set your balance below 0!";false}; _unit setVariable ["TAG_fnc_money",_newMoney,true]; systemchat "Money balance changed:"; systemchat format ["You now have %1$",_newMoney]; true }; as you can see (from the pic) the money case is adding $5000 then when i got to hit the trigger at the trader/unit/trigger/store it gives the error & still charged me $500 for the Tent Folded trigger init:::::: this addAction ["(Tent Folded) $500","scripts\store_systems\gear\gear(TentFolded).sqf"]; Share this post Link to post Share on other sites
Grumpy Old Man 3545 Posted March 3, 2018 My bad, just change _exchange or _purchase in the TAG_fnc_buyItem to either one: _purchase = [_unit,- _cost] call TAG_fnc_changeMoney;//notice the negative sign of the cost, will be handled in here instead of having to keep track of it everywhere else if !(_purchase) exitWith {systemchat "Not enough money!";false}; Was just quickly sketching it up and used two different variable names for whatever reason. Cheers Share this post Link to post Share on other sites
Zombeast250 3 Posted March 3, 2018 i keep thanking you grumpy for the help i do much appreciate the help sry friend to keep you waiting while you are helping me i was up till 6am with this problem till i finally crashed :) so i changed the TAG_fnc_moneySystem.sqf THIS CODE: : : (and made sure it is using _purchase) TAG_fnc_buyItem = { params ["_unit","_item","_cost"]; if !(_unit canAdd _item) exitWith {systemchat "Not enough space!";false}; _purchase = [_unit,- _cost] call TAG_fnc_changeMoney;//notice the negative sign of the cost, will be handled in here instead of having to keep track of it everywhere else if !(_purchase) exitWith {systemchat "Not enough money!";false}; systemchat ["Congratulations on your new %1",_item]; true }; TAG_fnc_changeMoney = { params ["_unit","_amount"]; _currentMoney = _unit getVariable ["TAG_fnc_money",0];//returns 0 money if the unit has non, current amount otherwise _newMoney = _amount + _currentMoney; if (_newMoney < 0) exitWith {systemchat "The transaction would set your balance below 0!";false}; _unit setVariable ["TAG_fnc_money",_newMoney,true]; systemchat "Money balance changed:"; systemchat format ["You now have %1$",_newMoney]; true }; moneycase.sqf (works great as i said and seen in pic +5000) but when i try to purchase the Tent Folded it takes my money & I get this ERROR: Share this post Link to post Share on other sites
Grumpy Old Man 3545 Posted March 4, 2018 Again I forgot to add the format command so apologies again, as I said this was hastily sketched up, at least now I got around to test it, these two are working: TAG_fnc_changeMoney = { params ["_unit","_amount"]; _currentMoney = _unit getVariable ["TAG_fnc_money",0];//returns 0 money if the unit has non, current amount otherwise _newMoney = _amount + _currentMoney; if (_newMoney < 0) exitWith {systemchat "The transaction would set your balance below 0!";false}; _unit setVariable ["TAG_fnc_money",_newMoney,true]; systemchat "Money balance changed:"; systemchat format ["You now have %1$",_newMoney]; true }; //simple function to buy stuff and handle cases where a purchase might not happen TAG_fnc_buyItem = { params ["_unit","_item","_cost"]; if !(_unit canAdd _item) exitWith {systemchat "Not enough space!";false}; _purchase = [_unit,- _cost] call TAG_fnc_changeMoney;//notice the negative sign of the cost, will be handled in here instead of having to keep track of it everywhere else if !(_exchange) exitWith {systemchat "Not enough money!";false}; systemchat format ["Congratulations on your new %1",_item]; true }; Quote _object = _this select 0; deletevehicle _object; playsound "scoreAdded"; [player,5000] call TAG_fnc_changeMoney; hint "+$5000"; No need for the playsound or hint, you can put those into the TAG_fnc_changeMoney if you want the hint and sound on every time the player gets/loses some money. You can also add flavor text or display different messages if the player gets or loses money. Cheers 1 Share this post Link to post Share on other sites
Zombeast250 3 Posted March 4, 2018 im using that last script/ TAG_fnc_moneySystem.sqf that you posted with ::: gear(TentFolded).sqf and in that i have:: _purchase = [player,"rvg_foldedTent",500] call TAG_fnc_buyItem; if (_purchase) then {systemchat "Purchase successful!"} else {systemchat "Purchase failed!"}; and when i try to buy the tent i get this ERROR (i am using Ravage Mod & CBA_A3) Share this post Link to post Share on other sites
Grumpy Old Man 3545 Posted March 4, 2018 Seems you still are using _exchange instead of _purchase somewhere. The error message is basically telling you this. Cheers Share this post Link to post Share on other sites
Zombeast250 3 Posted March 4, 2018 i now see it was calling _exchange i have fixed it to _purchase now i get no errors but THIS:::(takes my money and says hint but no item) Share this post Link to post Share on other sites
Grumpy Old Man 3545 Posted March 4, 2018 The functions only handle the money part, and return true or false if the transaction was positive or not. You'd need to handle it in your own way to add the item, like this: _purchase = [player,"rvg_foldedTent",500] call TAG_fnc_buyItem;//purchase only returns true if the player had enough money AND enough space to buy the item if (_purchase) then { player addItem "YourItemHere"; systemchat "Purchase successful!" } else { systemchat "Purchase failed!" }; The examples I provided are not set in stone and you're free to edit/adjust them as you seem fit. Cheers Share this post Link to post Share on other sites
Zombeast250 3 Posted March 4, 2018 thank you soo much that was the FIX i only need to know now (with the new money system) how do i call a wallet to check money balance? i was using in my player/unit init : player addAction ["Open Wallet", {hint format ["Money: %1",money];},[],6]; Share this post Link to post Share on other sites
Grumpy Old Man 3545 Posted March 4, 2018 You could use this, since every player has the money stored on the player object: player addAction ["Open Wallet", { params ["_object","_caller","_ID"]; _cash = _object getVariable ["TAG_fnc_money",0]; hint format ["Money: %1",_cash]; },[],6]; Cheers Share this post Link to post Share on other sites
Zombeast250 3 Posted March 4, 2018 i placed that into the init on my unit/player and no errors BUT it does nothing in game no hint Share this post Link to post Share on other sites
Zombeast250 3 Posted March 4, 2018 @Grumpy Old Man friend i just wanted to say "You Are A LEGEND" thank you for all the help and writing a new store/system for my mod finding good help in any modding community can be difficult Thank You SOOO much for your patience with my Noobness :) with help like you in the community i think we will be fine :) ALSO the script works great TY 1 Share this post Link to post Share on other sites
Zombeast250 3 Posted March 4, 2018 not sure if you seen this so i will repost :) i am using this in the players init: and get no errors but it does nothing in game 6 hours ago, Grumpy Old Man said: You could use this, since every player has the money stored on the player object: player addAction ["Open Wallet", { params ["_object","_caller","_ID"]; _cash = _object getVariable ["TAG_fnc_money",0]; hint format ["Money: %1",_cash]; },[],6]; Cheers Share this post Link to post Share on other sites
Zombeast250 3 Posted March 4, 2018 so i changed player addAction ["Open Wallet", {................... to this addAction ["Open Wallet", {.............. and the wallet system is now WORKING!!! ,keeping track of purchases and prompt to check wallet for balance (ALL WORKING) the script for the store system seems to do all CHECKS proper (check carry weight &&& money/balance before allowing purchase) i am soo happy THANK YOU DUDE!!! you are the man!!! now to get to work making the store come to life with items @Grumpy Old Man YOU ARE A TRUE LEGEND glad to have met you friend :) Cheers! 1 Share this post Link to post Share on other sites