Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
  • 0
Legion6k

Checking and setting integers for specific players?

Question

Hi guys, basically what I would like to achieve is to keep track of, and later check, integers based on the player who activated the script. 

So the script's actions to set the integers would read as follows ;

 

Quote

If player one is the activator, then int X = Y

If player two is activator, then int A = B

 

And then to check the integer;

 

Quote

If player one is the activator, and if X = Y, then do something

if player two is the activator, and if A = B, then do something

else print error message

 

To be clear, the "do something" is the same thing either way, but I only want a player who has set one of integers to be able to check it and thus trigger the event.

I feel like perhaps I'm overthinking it and that's it's a simple solution, or that it's too complicated and I'm not thinking hard enough, haha. Maybe a give inventory/check inventory function would be an elegant solution, but that would require creating a dummy inventory item, and I'd rather not, but of course if that's a viable option, then I'll look into it. 

Either way, any help or alternative suggestions would be much appreciated. 

Share this post


Link to post

2 answers to this question

Recommended Posts

  • 1

You can use an array and the PlayerNumber function to set/check if a specific player triggered the scripts. Like this:
 

#include "zcommon.acs"

int triggered[16];

script 1 (void)
{
    if(triggered[PlayerNumber()] == 0) {
        Print(s:"You can now use the right switch!");
        triggered[PlayerNumber()] = 1;
    }
}

script 2 (void)
{
    int pn = PlayerNumber();

    if(triggered[pn] == 1) {
        Print(s:"Do something here!");
        triggered[pn] = 2;
    } else if(triggered[pn] == 2)
        Print(s:"You already used the right switch!");
    else
        Print(s:"You need to use the left switch first!");
}

I didn't test it in multiplayer, but it should still work. Example attached.

mp_trigger.zip

Share this post


Link to post
  • 0
Posted (edited)

Awesome thank for the reply. 

Ill give that a go asap and let you know how it goes 🙂

 

Update:
Yeah that works, thank you.

One thing though, would a switch statement work for instances where there are only two players?

Edited by Legion6k : Update

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×