Author Topic: How do I tell if a specific playertype is currently in use on the server  (Read 1638 times)

I've got a bunch of custom playertypes whose stats get changed around a lot on my server, I want to be able to make up to five "boosted" players and each one using a different datablock. How do I make it determine whether a specific player datablock is already being used?

Do you mean if someone is using it on the server? Or just if it's possible for someone to use it?
For the first one, just loop through all players and check their data blocks. For the second, use if(isObject(%player.getDataBlock()))

Do you mean if someone is using it on the server? Or just if it's possible for someone to use it?
For the first one, just loop through all players and check their data blocks. For the second, use if(isObject(%player.getDataBlock()))
The first, but I don't know how to loop through all players and check their datablocks; I'm still rather cruddy at scripting and I can only script with what I've seen.

Code: [Select]
for(%i=0;%i<clientGroup.getCount();%i++)
{
    %obj = %clientGroup.getObject(%i).player;
    if(isObject(%obj) && %obj.getDataBlock() $= "YourDataBlockName")
        //do something
}

EDIT: Not locking
« Last Edit: June 19, 2012, 01:52:33 PM by YourBuddyBill »

Good call, Treynolds. How about if there's no player using a given datablock? What should I do for that?

Good call, Treynolds. How about if there's no player using a given datablock? What should I do for that?
What do you mean? What do you want to happen if it's the playertype you're looking for, and what do you want to have happen if nobody is using it? You can also separate this into a different function, like this:

Code: [Select]
function someoneIsUsingThisDataBlock(%datablock)
{
    for(%i=0;%i<clientGroup.getCount();%i++)
    {
        %obj = %clientGroup.getObject(%i).player;
        if(isObject(%obj) && %obj.getDataBlock() $= "%datablock")
            return true;
    }
    return false;
}

And you can then use lines like if(someoneIsUsingThisDataBlock("dataBlockName")) or if(!someoneIsUsingThisDataBlock("dataBlockName"))

What do you mean? What do you want to happen if it's the playertype you're looking for, and what do you want to have happen if nobody is using it? You can also separate this into a different function, like this:

Code: [Select]
function someoneIsUsingThisDataBlock(%datablock)
{
    for(%i=0;%i<clientGroup.getCount();%i++)
    {
        %obj = %clientGroup.getObject(%i).player;
        if(isObject(%obj) && %obj.getDataBlock() $= "%datablock")
            return true;
    }
    return false;
}

And you can then use lines like if(someoneIsUsingThisDataBlock("dataBlockName")) or if(!someoneIsUsingThisDataBlock("dataBlockName"))

Cool, thanks! I want it for a server mod where the server (nicknamed Ted) will every now and again decide to boost a player, and he'll change their datablock to the first datablock in the list that isn't in use and then modify their stats depending on the type of boost. Like the "Lord of Leaping" would get higher jumps and less fall dmg.

What do you mean? What do you want to happen if it's the playertype you're looking for, and what do you want to have happen if nobody is using it? You can also separate this into a different function, like this:

Code: [Select]
function someoneIsUsingThisDataBlock(%datablock)
{
    for(%i=0;%i<clientGroup.getCount();%i++)
    {
        %obj = %clientGroup.getObject(%i).player;
        if(isObject(%obj) && %obj.getDataBlock() $= "%datablock")
            return true;
    }
    return false;
}

And you can then use lines like if(someoneIsUsingThisDataBlock("dataBlockName")) or if(!someoneIsUsingThisDataBlock("dataBlockName"))
Umm, shouldn't the %datablock in if(isObject(%obj) && %obj.getDataBlock() $= "%datablock") not be in quotes?

Umm, shouldn't the %datablock in if(isObject(%obj) && %obj.getDataBlock() $= "%datablock") not be in quotes?
What the hell do you think
He isn't that bad at scripting, you don't need to try to pick out every little thing that isn't exactly perfect in an obvious example. This isn't the first time I've seen you do something like this.

What the **** do you think
He isn't that bad at scripting, you don't need to try to pick out every little thing that isn't exactly perfect in an obvious example. This isn't the first time I've seen you do something like this.
: /

Never try pointing out mistakes, it just gets people angry.

: /

Never try pointing out mistakes, it just gets people angry.
this is surprisingly irrational from treynolds... he's usually good about something like that.

also why is hel l censored in your post? that's dumb. it looks like fuc k.

: /

Never try pointing out mistakes, it just gets people angry.
Don't try pointing out dumb things, it's useless and contributes nothing

this is surprisingly irrational from treynolds... he's usually good about something like that.
Like I said, this isn't an isolated incident, and it's hard to convey the tone I was going for through text alone.

Yeah, I probably would have picked up on it (I was really busy so I just copypasted the example into notepad and went to work on something else) but thanks anyway, jes.

: /

Never try pointing out mistakes, it just gets people angry.
Oh dear, he said the h-word.