Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   check if player is staff (https://forums.graalonline.com/forums/showthread.php?t=134261608)

callimuc 01-08-2011 08:17 PM

check if player is staff
 
hey i wanted to ask if there is such a command that checks if a player is staff written in the server options (so i donīt use like
PHP Code:

if (player.guild == "Owner") {
blabla


since i think it would make the script too long to add all staff)

i hope there is such a command since i thought i have already seen it somewhere but could find it. it was like:
PHP Code:

function onCreated() {
  
is.staff();
}
function 
onis.staff() {
  
//here the script īlookedī up in the serverv options
  //if the player is a staff member;



i hope i was clear enough what exactly i need :)

-callimuc

cbk1994 01-08-2011 08:21 PM

There's TServerPlayer.isAdmin and TServerPlayer.isStaff but I'm not sure if either work right—I've had issues with them in the past.

This will always work:
PHP Code:

function isStaff(account) {
  return 
serveroptions.staff.tokenize(",").index(@ account) > (- 1);


You might want to put something like that in a player class for convenience (using this.account instead of account, obviously).

DustyPorViva 01-08-2011 08:23 PM

You don't have to tokenize the serveroptions staff list, it should be read as an array :)

callimuc 01-08-2011 08:32 PM

Quote:

Originally Posted by DustyPorViva (Post 1621346)
You don't have to tokenize the serveroptions staff list, it should be read as an array :)

uhm usually idk how to use arrays... is there any easy example i can look up or does the wiki have it? (pretty sure they hae ^^)

cbk1994 01-08-2011 08:34 PM

Quote:

Originally Posted by DustyPorViva (Post 1621346)
You don't have to tokenize the serveroptions staff list, it should be read as an array :)

It doesn't :(. One of Graal's stupid quirks.

PHP Code:

function onCreated() {
  echo(
"without: " serveroptions.staff[0]);
  echo(
"with: " serveroptions.staff.tokenize(",")[0]);


produces

Quote:

without: Clockwork,[FOUNDER],HoudiniMan,[DIRECTORS],Tigairius,Chompy,... (trimmed the rest off)
with: Clockwork

xXziroXx 01-08-2011 08:38 PM

Serveroptions are a list of strings, so of course you have to tokenize it to produce an array.

fowlplay4 01-08-2011 08:38 PM

Quote:

Originally Posted by callimuc (Post 1621356)
uhm usually idk how to use arrays... is there any easy example i can look up or does the wiki have it? (pretty sure they hae ^^)

Posted not too long ago.

Quote:

Originally Posted by fowlplay4 (Post 1619921)
Here's my quick run-through on Arrays which are useful in managing Collections or Lists of values.

Arrays

PHP Code:

function onCreated() {

  
// Creating an Array
  
this.array = {123};

  
// Reading from an Array (Reading Element in Position 1)
  // Syntax: this.array[element_index]
  // Arrays are 0-based so in our example:
  // this.array[0] is 1
  // this.array[1] is 2
  // this.array[2] is 3
  
temp.element this.array[1];
  echo(
"Element: " temp.element);

  
// Changing a Specific Element in an Array
  
this.array[2] = 3.14;
  
display_array();

  
// Adding to an Array
  
this.array.add(4);
  
display_array();

  
// Removing from an Array
  
this.array.remove(1);
  
display_array();

  
// Inserting into an Array (Inserts 2.5 into Position 1)
  
this.array.insert(12.5);
  
display_array();

  
// Deleting from an Array (Deletes Element in Position 1);
  
this.array.delete(1);
  
display_array();

  
// Combining Arrays
  
temp.newarray = {567};
  
this.array.addarray(temp.newarray);
  
display_array();

  
// Getting the Size / Number of Elements in Array
  
temp.elements this.array.size();
  echo(
"Array contains " temp.elements " elements!");
}

function 
display_array() {
  echo(
"Array: " this.array);




cbk1994 01-08-2011 08:39 PM

Quote:

Originally Posted by xXziroXx (Post 1621361)
Serveroptions are a list of strings, so of course you have to tokenize it to produce an array.

PHP Code:

function onCreated() {
  
temp.myString "one,two,three";
  echo(
myString[0]);


produces:

Quote:

one
Welcome to Graal...

DustyPorViva 01-08-2011 08:41 PM

Quote:

Originally Posted by xXziroXx (Post 1621361)
Serveroptions are a list of strings, so of course you have to tokenize it to produce an array.

O.o this is what I use for parsing a list of Testbed contacts on testbed:
PHP Code:

function onCreated() {
  
this.attr[10] = serveroptions.contacts;
}
//#CLIENTSIDE
function onCreated() {
  
this.contacts = (this.attr[10]);
}

function 
onPlayerTouchsMe() {
  for (
temp.i:this.contacts) {
    
temp.post @= " " "" NL "";
  }


and it works fine.

callimuc 01-08-2011 08:43 PM

so can i use like
PHP Code:

function onPlayerChats() {
if (
player.chat == "/test") {
function 
isStaff(account) {
  return 
serveroptions.staff.tokenize(",").index(@ account) > (- 1);
  
dothestuff;
}
}



cbk1994 01-08-2011 08:45 PM

Quote:

Originally Posted by callimuc (Post 1621366)
so can i use like
PHP Code:

function onPlayerChats() {
if (
player.chat == "/test") {
function 
isStaff(account) {
  return 
serveroptions.staff.tokenize(",").index(@ account) > (- 1);
  
dothestuff;
}
}



PHP Code:

function onPlayerChats() {
  if (
player.chat == "/test") {
    if (
isStaff(player.account)) {
      
// do stuff
    
}
  }
}

function 
isStaff(account) {
  return 
serveroptions.staff.tokenize(",").index(@ account) > (- 1);


Functions have to go outside of any other function.

callimuc 01-08-2011 08:48 PM

whoops ok thanks.

Quote:

Originally Posted by fowlplay4 (Post 1621362)
Posted not too long ago.

jea i couldnt really understand it but now ill try it xP

fowlplay4 01-08-2011 09:02 PM

When checking if they're Staff I like to use a clientr variable and add Staff weapons and tools accordingly.

In your Control-NPC:

PHP Code:

function onActionPlayerOnline() {
  
// Check if Player Is Staff
  
clientr.isStaff isStaff(player.account);
  
// Add Staff Weapons if Neccesary
  
if (clientr.isStaff) {
    
player.addweapon("-Staff/SuperSecretAwesomeTool");
  }
}

function 
isStaff(account) { 
  return 
serveroptions.staff.tokenize(",").index(@ account) > (- 1); 


Then in your other scripts you can use:

PHP Code:

if (clientr.isStaff) {
  
// do this because they're staff



Skyld 01-08-2011 09:07 PM

Quote:

Originally Posted by fowlplay4
PHP Code:

function isStaff(account) { 
  return 
serveroptions.staff.tokenize(",").index(@ account) > (- 1); 



PHP Code:

function isStaff(temp.account)
{
  return 
temp.account in serveroptions.staff;


... just to save you from all that ridiculous index() nonsense.

salesman 01-08-2011 09:10 PM

Quote:

Originally Posted by Skyld (Post 1621373)
PHP Code:

function isStaff(temp.account)
{
  return 
temp.account in serveroptions.staff;


... just to save you from all that ridiculous index() nonsense.

Doesn't work.
PHP Code:

temp.acc "salesman";
echo(
temp.acc in serveroptions.staff); // echoes 0
echo(serveroptions.staff.size()); // echoes 0 



All times are GMT +2. The time now is 05:11 AM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.