OFPEC Forum
Editors Depot - Mission Editing and Scripting => ArmA - Editing/Scripting General => Topic started by: danturn on 06 Jul 2008, 22:58:36
-
Basically, I have an arms dealer who as addactions to enable the player to buy weapons, on using the action the weapon is added to a weapons crate for simplicities sake. However, i want the weapons to come at a price. I am using the roleplay objects pack and this contains a magazine to represent money "rpo_obj3".
In the mission, an m4 costs £100, this is equal to one "rpo_obj3", i understand how to remove "rpo_obj3" from the player and add the M4 to the ammo crate in the script
ammobox1 addweaponcargo ["m24",1];
player removemagazine "rpo_obj3";
what i need to know is, if the player doesnt happen to have the correct amount of "rpo_obj3", how do i stop the action taking place?
-
The answer lies yet again in our beloved COMREF (http://www.ofpec.com/COMREF/index.php?action=list&game=All&letter=m#209). ;)
-
I know it probably does, but I stuggle to understand the COMREF at the best of times.
Just like now, you have pointed me to "magazines" but i don't have a clue what any of the description for it means.
Thanks, but I'm still stuck.
-
Your problem involves removing the "buy stuff" action if the player doesn't have enough money. They money comes in the form of a magazine. So what you want to do is get an array of the player's magazines and check if the money magazine is present in sufficient quantity.
Not sure about the ArmA parlance, but
_mags = magazines player
_money_count = 0
_i = 0
#loop
? (_mags select _i) == "the_money_magazine" : _money_count += 1
goto "loop"
? _money_count == _enough : add the action
-
The cost is 100, which equals one money object. Therefore, if the player has this item in his inventory, he should be able to buy the rifle.
With the magazines command you get an array with the names of a unit's magazines in his inventory which is bound to include the rpo_obj3 is he has some money with him. So what you want to check is if rpo_obj3 is in the array returned by the magazines command.
To use the code below, you have to use an .sqf scriptfile.
_mags = magazines theGuy;
if ("rpo_obj3" in _mags) then
{
hint "code to buy";
}
else
{
hint "don't let this one buy the rifle";
};
-
What he said ;)
-
Ok, so how do i use this in concunction to the rest of the script?
here is what i have so far.
A unit called "weaponsdealer", in his init field the following;
this addaction ["Buy m4 $100", "buym4.sqs"]
$100 is equal to one magazine named "rpo_obj3", unit is named bob.
in the script "buym4.sqs" i have
ammobox addweaponcargo ["m4", 1]
bob removemagazine "rpo_obj3"
-
That looks fine, but let me save you making a lot of scripts, one for every weapon possible, by having a single script for all weapon purchases:
this addaction ["Buy m4 $100", "buyweapon.sqs", ["m4", 1]]
; List of params passed in from addAction.
_params = _this select 3;
; Class-name of weapon.
_weapon = _params select 0;
; Cost in $100 items required.
_cost = _params select 1;
ammobox addweaponcargo [_weapon, 1];
#pay
_i = 0;
player removemagazine "rpo_obj3";
_i = _i + 1;
? _i >= _cost : goto "end"
goto "pay"
#end
This still doesn't check how much cash the player has before you make the purchase, but I'll leave that for you to sort out.
(If you weren't using the RP objects for money, I'd just point you at SPON Money (http://www.ofpec.com/forum/index.php?topic=30551), but always a chance you didn't see it so...).
-
I had concidered using SPON, but thought i mite try something myself first.
So will what you wrote stop the player from being able to make the purchase if they dont have the correct mag balance?
-
No problem if you don't want to use SPON Money. Just thought it might have been overlooked and save you a lot of headaches.
No, the script won't prevent the player from spending money he doesn't have, just like a said it wouldn't. This is mainly because I couldn't be bothered writing that out in SQS :whistle: Here is a starter so you can work out how much cash the player actually has:
; Number of $100 objects in player's inventory.
_playerCash = { _x == "rpo_obj3" } count (magazines player);
I hope that you are taking the simple route and just using one type of cash object (the $100 one mentioned so far). Having to work out purchases and working out change, etc. would be an unnecessary, though not impossible, hassle otherwise.
-
Ahh, i thought that was what you meant just unsure, No, everything is simply in multiples of $100, to be honest Iv just downloaded Spon money gonna give it a try tomorrow, will make so much more sense.
Is there away to set up custom magazines to run with Spon money with prices?
I'm basically trying out (like alot of people) a MP roleplay game, which has things like vodka and passports and phones things like that. I have a lot of ideas for it which will be quite complex, and i have little knowledge of editing, stupid of me to start big, think it would make more sense just to use a money script that has alreaedy been invented to save time haha.
-
You have to edit the prices.sqf file to add more items, since I've only added a subset of the vanilla ArmA weapons, vehicles and ammo in the SPON Money demo. See the demo and documentation in the zip and the associated beta thread for more info on that. The problem for you might be that you would have to just set the value of the bank notes so that they could be sold to get "real money" to enable you to buy other things (SPON Money doesn't understand the concept of barter of one type of object for another and just manages your cash and bank balance as script variables).
You aren't the only person who's tried to make a hugely complex RPG mission as your first mission and I'm sure you won't be the last. I'm definitely not saying to not learn to script, but definitely don't learn to script on such a complex project, unless you are mostly using pre-written scripts.
-
If i used SPON money i would just totally forget about the cash in forms of magazines, would make more sense that way. To be honest the RPG should be pretty straight forward, two rival clans (obv opfor and blufor) but instead of everything being 'free', you need to earn cash by buying and selling stuff to be able to afford to by better vehicles/weapons/ammo.
the objective of the game is simply to Kill the clan leader so far, just to keep it simple, once iv done that i can always upgrade and add more things to it.