Home   Help Search Login Register  

Author Topic: player needs magazine in order to buy other magazine help  (Read 2030 times)

0 Members and 1 Guest are viewing this topic.

Offline danturn

  • Members
  • *
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

Code: [Select]
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?

Offline bedges

  • Administrator
  • *****
    • OFPEC The Editing Center
Re: player needs magazine in order to buy other magazine help
« Reply #1 on: 06 Jul 2008, 23:05:46 »
The answer lies yet again in our beloved COMREF;)

Offline danturn

  • Members
  • *
Re: player needs magazine in order to buy other magazine help
« Reply #2 on: 06 Jul 2008, 23:13:34 »
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.

Offline bedges

  • Administrator
  • *****
    • OFPEC The Editing Center
Re: player needs magazine in order to buy other magazine help
« Reply #3 on: 06 Jul 2008, 23:26:56 »
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

Code: [Select]
_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

Offline Cheetah

  • Former Staff
  • ****
Re: player needs magazine in order to buy other magazine help
« Reply #4 on: 06 Jul 2008, 23:31:09 »
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.

Code: [Select]
_mags = magazines theGuy;
if ("rpo_obj3" in _mags) then
{
    hint "code to buy";
}
else
{
    hint "don't let this one buy the rifle";
};
Like missions? Help with Beta Testing! or take a look at the OFPEC Missions Depot for reviewed missions!

Offline bedges

  • Administrator
  • *****
    • OFPEC The Editing Center
Re: player needs magazine in order to buy other magazine help
« Reply #5 on: 06 Jul 2008, 23:36:31 »
What he said  ;)

Offline danturn

  • Members
  • *
Re: player needs magazine in order to buy other magazine help
« Reply #6 on: 07 Jul 2008, 00:19:49 »
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;

Code: [Select]
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

Code: [Select]
ammobox addweaponcargo ["m4", 1]
bob removemagazine "rpo_obj3"

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Re: player needs magazine in order to buy other magazine help
« Reply #7 on: 07 Jul 2008, 00:56:33 »
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:
Code: (dealer init) [Select]
this addaction ["Buy m4 $100", "buyweapon.sqs", ["m4", 1]]

Code: (buyweapon.sqs) [Select]
; 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, but always a chance you didn't see it so...).
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)

Offline danturn

  • Members
  • *
Re: player needs magazine in order to buy other magazine help
« Reply #8 on: 07 Jul 2008, 00:59:42 »
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?

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Re: player needs magazine in order to buy other magazine help
« Reply #9 on: 07 Jul 2008, 01:29:19 »
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:

Code: [Select]
; 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.
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)

Offline danturn

  • Members
  • *
Re: player needs magazine in order to buy other magazine help
« Reply #10 on: 07 Jul 2008, 01:41:56 »
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.

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Re: player needs magazine in order to buy other magazine help
« Reply #11 on: 07 Jul 2008, 01:57:40 »
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.
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)

Offline danturn

  • Members
  • *
Re: player needs magazine in order to buy other magazine help
« Reply #12 on: 07 Jul 2008, 02:02:06 »
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.