Jump to content
Sign in to follow this  
LilRimmy

Help with a money script

Recommended Posts

Ok, so I am making a zombie kind of campaign at them moment and I need some help with the money system.

Quick explanation of missions:

All of this takes place in Chernarus.

The first one is a mission at the very start of the infection, where you and your brother must escape from the town, blah blah blah, it just sets up the other missions.

The next one (which I am working on at the moment) you are a mercenary hired to plug a hole in the quarantine line. While the first one was well, not rail roaded, but not a sand box mission, this one is a full map sandbox. Once started, you can do anything. This mission is more fighting and rescuing than my survival mission (Through the fog) so instead of scavenging for guns, there are shops set up around the map.

You can do things like rescue people, deal with the zombies, get rid of the raiders looting in the chaos, complete high-priority missions. All for money.

The next missions are all mission number 2 but from different perspectives. They will be things like military, civilian, raider, President bodyguard and personal favourite, a hunter. With a dog. Go dogs.

Anyway, everything is working fine, except for one thing. Gaining money. Now, that does WORK, just not how I want it.

Here is the code for earning money

{_x addeventhandler ["killed", {_this exec "addmoneyHuman.sqf"}]} foreach thislist

In a trigger with OpFor triggering it and repeating

And the add money scripts are all

 MYmoney =  MYmoney + 250
MYmoney2 = MYmoney2 + 250 

Now, it all works, but the problem is that if ANYONE kills Opfor (or independent), we get money. And in a giant full map sandbox involving a line holding back a horde of zombies, that is a huge problem.

So, my question is, how do I only add money when unit 1 unit 2 unit 3 and unit 4 kill the enemy?

Thanks in advance.

Share this post


Link to post
Share on other sites

Anyone?

This is the only thing stopping me from completing my mission.

I really need help with this, so, anyway, please help. Even if you only know half of a script, I need to work out a way to fix this.

Share this post


Link to post
Share on other sites

Could you not add an event handler in each of the units you want to be able to earn money ?

Share this post


Link to post
Share on other sites

Now, I would be happy to. One slight problem.

The fuck is an event handler?

I know a fair bit of scripting, but I am still learning as I go along. Could you post an example code or something like that? I usually learn best from getting a test code then trial and error.

So, when you say event handler, is that like it activates a trigger? Or does the event handler active a trigger which then has to been activated by say, someone dying or someone killing something?

Share this post


Link to post
Share on other sites

Without testing, here is a starting point - if several eventhandlers for the killing of zombies does not work - you could make one eventhandler and call one script that then calls the required part.. e.g if (unit == _killer) then { [] spawn playerkiller;};

this is just a stab in the dark and again hasn't been tested.


playerkiller =

{
 hint "player has killed someone";
 MYmoneyunit1 =  MYmoneyunit1 + 250;
 MYmoney2unit1 = MYmoney2unit1 + 250;
};

playerkiller1 =

{
 hint "player 2 has killed someone";
 MYmoneyunit2 =  MYmoneyunit2 + 250;
 MYmoney2unit2 = MYmoney2unit2 + 250;
};



///start of script....


///if unit1 kills zombie
{_x  addEventHandler["killed", { 
if ((_this select 1) == unit1) then {
[unit1] spawn Playerkiller;};
}];
}foreach thislist ;


///if unit2 kills zombie
{ _x  addEventHandler["killed", { 
if ((_this select 1) == unit2) then {
[] spawn Playerkiller;};
}];
}foreach thislist;


changed - the unitsmoney - to distinguish between the different player amounts plus you can then use publicvariables to assist with JIP. - however as each script needs to be local to that player - leaving it as it is should be fine.

hopefully this is not too confusing and i have not waffled too much rubbish.

Share this post


Link to post
Share on other sites

Forgot to say...

You can also use score instead of the money - just addscore to the player on kill. this would be local to the player.

use the score to minus/plus when you buy things...

makes things easier

Share this post


Link to post
Share on other sites

you forgot one thing: killed eventhandler returns the killer object, so you can actually check if p1 killed a zombie by getting it from the event handler (I believe its the second index)

ex:

{
_x addEventHandler ["killed", {
private ["_dead", "_killer"];
_dead = _this select 0;
_killer = _this select 1;
if (_killer == p1 || _killer == p2 || etc) then {
     addMoney here
};]
} foreach zombies

that would be one way to do it. It might be better though if u create function that handles money, and just call that inside the eventhandler.

or if you dont want to use global variables, just make the money function, then check like this:

_killer = _this select 1; nul = [_killer] call MoneySystem 

now you can check this all inside another script.

---------- Post added at 17:32 ---------- Previous post was at 17:16 ----------

heres a function that I wrote that can take care of the money: rather than using global variables, it uses setVariable on the unit, so its easier to manage.

not tested, but should work

add this to the init.sqf, in the array add all the units you want to receive money

{_x setVariable ["Money", 0, true]} foreach [p1, p2, p3, p4, p5]; // units start with 0 money

and add this function to the init.sqf as well, it needs to be processed first in order to call it.

Fnc_MoneySystem = {
   private ["_MoneyUnits", "_killer"];
   _moneyUnits = [p1, p2, p3, p4]; // this is an array of all the guys that are going to get money based on kills
   _killer = _this; // the killer that was returned from the killed event handler (which is passed here)
   {
       if (_killer == _x) then {
           private ["_curMoney"];
           _curMoney = _x getVariable "Money";
           _x setVariable ["Money", _curMoney + 50]; // adding 50 money to the unit that killed the zombie
       };
   } foreach _moneyUnits;
};

then you can either add the eventhandler to each zombie individually, in a script (if you are spawning zombies) or, if you have an array of all your zombie units, you can use this:

{
   _x addEventHandler ["killed", {
       private ["_killer"];
       _killer = _this select 1;
       0 = _killer call Fnc_MoneySystem;
   };];
} foreach zombie_units;

assuming your array of zombies is named 'zombie_units'

if you are not using an array, just remove the brackets of the foreach:

 this addEventHandler ["killed", {
       private ["_killer"];
       _killer = _this select 1;
       0 = _killer call Fnc_MoneySystem;
   };];

- you can use this in the zombies init.

Share this post


Link to post
Share on other sites

Alright, I will test out those now, again, thanks a ton for the help. I hate running into a brick wall when scripting.

Now, one thing I have to say. All of the shops have already been made, and then all run of a base script I found then modified, then made a template.

 if (Mymoney < ) then
{
   Hint "You do not have enough money";
} else {
   Mymoney = Mymoney -;
   mygunlocker_1 addWeaponCargo ["", 1];
   mygunlocker_1 addMagazineCargo ["", 1];
   Hint "You got a ";
}; 

So, that is the base code for all the shops, with the vehicles templates slightly altered. What I am getting at is I can't, I can not, change this script. If I had to, I would just give up on the mission. I have far too many sqf files to rewrite AGAIN.

Anyway, it just means that I can't change the variables to a global one like money or change it to score. Also, I am using the undead mod, so I am using those module spawners, so I don't think I can put any scripts in their init.

Oh, and a note, the two money scripts (Mymoney and Mymoney2) are actually the teams money. As, at the time of making this mission, I could't get variables to work, I used another way. Every single sqf file has a double, and that is team 2 buying things. Yes, it is crude but it was the best I could do.

And last, just some questions for the code:

Mikie, the code you posted (which I am about to test), where would I put it, and also, did you mean for the code to be used together or spilt into two? Splitting them in two would be better, but I could easily run with together (so if team 2 kills a zombie, team 1 and 2 get money) (Also, when ever I say "Team 1 or 2" I mean the lead unit, and if I can, unit 3 and unit 4.

Alright, I will go test this now. Again, thanks mate!

Share this post


Link to post
Share on other sites

Huh.

my big thank you post got eaten.

Anyway, I just tested your script Mikie, now, it hasn't been fully tested, but it seems to work just fine. I get the message, the money, and in a sec, hopefully, only work for unit 1 + 2.

Again.

Thank you!

---------- Post added at 08:08 AM ---------- Previous post was at 07:57 AM ----------

Ok, I have hit a problem.

For some reason, player 1 can kill enemies and get money ect. ect., but for unit 2, nothing happens...

Will try to fix this asap.

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×