Jump to content
Sign in to follow this  
NGagedFX

Credits Script

Recommended Posts

Hey guys, I'm working on mission in which you (should) get a credit for every completed task, storing these up to a maximum of 3. These can be used to purchase vehicles through the action menu of a billboard. However, I can't get the script to work correctly (since I'm new to scripting).

board1 Init:

_nil = [this] execVM "credits.sqf"

credits.sqf:

credits = 0;

switch (credits) do

{
case 0 : { hint "Your team has 0 credits" };
case 1 : { hint "Your team has 1 credits" };
case 2 : { hint "Your team has 2 credits" };
case 3 : { hint "Your team has 3 credits" };
};

It works fine when changing credit = (value), but I think the script sets it at this value ever time it repeats, making other scripts unable to change this value. Also, I'm unsure on how to add or remove a credit through a trigger.

Edited by NGagedFX

Share this post


Link to post
Share on other sites

Hi,

board1 Init:

_nil = [this] execVM "credits.sqf"

credits.sqf:

credits = 0;

switch (credits) do

{
case 0 : { hint "Your team has 0 credits" };
case 1 : { hint "Your team has 1 credits" };
case 2 : { hint "Your team has 2 credits" };
case 3 : { hint "Your team has 3 credits" };
};

All I did was fix the errors you had within the switch statement.

Also, have you noticed that in the beggining of the script you say:

credits = 0;

So the credits variable will always be 0.

_neo_

Edited by neokika

Share this post


Link to post
Share on other sites

I'm sorry neokika, I hadn't had the script at hand so I did it from memory, but my script actually looks like what you posted (I updated the startpost).

The only problems I have, are:

-How to define the credits as starting off at 0

-How to add credits to this value (through ingame triggers)

-How to remove credits of this value (through ingame triggers)

Share this post


Link to post
Share on other sites

Hi again,

Are you used to the setVariable command?

Since you have "Team" lets use groups.

One way to do it would be:

Init.sqf

if (isServer) then
{
  {
     _x setvariable ["groupCredits", 0, true];
  } forEach [_grp1,_grp2];
};

Where _grp1 etc, will be the group names you want to monitor. Just place has many you want inside the array.

Lets say you have a trigger to add 1 credit to a group.

On the OnAct:

_grp setVariable ["groupCredits", ((_grp getVariable "groupCredits") + 1), true];

Where _grp is the group name that will received the credit.

To subtract just use - istead of +.

You can then check the credits of a group, anytime and on any machine because of the third parameter in the setVariable array.

You can use the following line to check how many credits a group has.

_grp getVariable "groupCredits"

Hope that it helps,

_neo_

Edited by neokika

Share this post


Link to post
Share on other sites

So, in the Init of my misson, I put this:

Init.sqf

if (isServer) then
{
  {
     _x setvariable ["groupCredits", 0, true];
  } forEach [_grp1];
}

switch (groupCredits) do

{
case 0 : { hint "Your team has 0 credits" };
case 1 : { hint "Your team has 1 credits" };
case 2 : { hint "Your team has 2 credits" };
case 3 : { hint "Your team has 3 credits" };
};  

And when I try to create a trigger with the following command, it says Local variable in global space :confused:

Trigger OnAct:

_grp setVariable ["groupCredits", ((_grp getVariable "groupCredits") + 1), true];

I replaced both _grp's by just grp and fired the trigger, but there is no hint showing up.

I really have no idea what's going wrong. :(

Share this post


Link to post
Share on other sites

I belive you misunderstood me.

Go in the editor, go to one of the groups/teams you want to monitor, go to the Leader of that group and put the following into his init line:

My_group1 = group this;

init.sqf

if (isServer) then
{
  {
     _x setvariable ["groupCredits", 0, true];
  } forEach [My_group1];
};

credits.sqf

switch ((_this select 0) getVariable "groupCredits") do
{
case 0 : { hint "Your team has 0 credits" };
case 1 : { hint "Your team has 1 credits" };
case 2 : { hint "Your team has 2 credits" };
case 3 : { hint "Your team has 3 credits" };
};

How to add credits to a group:

My_group1 setVariable ["groupCredits", ((My_group1 getVariable "groupCredits") + 1), true];

How to check the credits number:

nil = [My_group1] execVM "credits.sqf";

That should do the job.

_neo_

Share this post


Link to post
Share on other sites

I can't thank you enough, neokika. :)

This script works really nice and is a great addition to my mission.

Thanks.

Share this post


Link to post
Share on other sites
I can't thank you enough, neokika. :)

This script works really nice and is a great addition to my mission.

Thanks.

Glad i could help.

_neo_

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  

×