Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 01-08-2011, 08:17 PM
callimuc callimuc is offline
callimuc's Avatar
Join Date: Nov 2010
Location: Germany
Posts: 1,015
callimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to behold
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
Reply With Quote
  #2  
Old 01-08-2011, 08:21 PM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
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).
__________________
Reply With Quote
  #3  
Old 01-08-2011, 08:23 PM
DustyPorViva DustyPorViva is offline
Will work for food. Maybe
DustyPorViva's Avatar
Join Date: Sep 2003
Location: Maryland, USA
Posts: 9,589
DustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond repute
Send a message via AIM to DustyPorViva Send a message via MSN to DustyPorViva
You don't have to tokenize the serveroptions staff list, it should be read as an array
Reply With Quote
  #4  
Old 01-08-2011, 08:32 PM
callimuc callimuc is offline
callimuc's Avatar
Join Date: Nov 2010
Location: Germany
Posts: 1,015
callimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to behold
Quote:
Originally Posted by DustyPorViva View Post
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 )
Reply With Quote
  #5  
Old 01-08-2011, 08:38 PM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
Quote:
Originally Posted by callimuc View Post
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 View Post
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);

__________________
Quote:
Reply With Quote
  #6  
Old 01-08-2011, 08:48 PM
callimuc callimuc is offline
callimuc's Avatar
Join Date: Nov 2010
Location: Germany
Posts: 1,015
callimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to behold
whoops ok thanks.

Quote:
Originally Posted by fowlplay4 View Post
Posted not too long ago.
jea i couldnt really understand it but now ill try it xP
Reply With Quote
  #7  
Old 01-08-2011, 08:34 PM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Quote:
Originally Posted by DustyPorViva View Post
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
__________________
Reply With Quote
  #8  
Old 01-08-2011, 08:38 PM
xXziroXx xXziroXx is offline
Malorian
xXziroXx's Avatar
Join Date: May 2004
Posts: 5,289
xXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant future
Serveroptions are a list of strings, so of course you have to tokenize it to produce an array.
__________________
Follow my work on social media post-Graal:Updated august 2025.
Reply With Quote
  #9  
Old 01-08-2011, 08:39 PM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Quote:
Originally Posted by xXziroXx View Post
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...
__________________
Reply With Quote
  #10  
Old 01-08-2011, 08:41 PM
DustyPorViva DustyPorViva is offline
Will work for food. Maybe
DustyPorViva's Avatar
Join Date: Sep 2003
Location: Maryland, USA
Posts: 9,589
DustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond repute
Send a message via AIM to DustyPorViva Send a message via MSN to DustyPorViva
Quote:
Originally Posted by xXziroXx View Post
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.
Reply With Quote
  #11  
Old 01-08-2011, 08:43 PM
callimuc callimuc is offline
callimuc's Avatar
Join Date: Nov 2010
Location: Germany
Posts: 1,015
callimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to behold
so can i use like
PHP Code:
function onPlayerChats() {
if (
player.chat == "/test") {
function 
isStaff(account) {
  return 
serveroptions.staff.tokenize(",").index(@ account) > (- 1);
  
dothestuff;
}
}

Reply With Quote
  #12  
Old 01-08-2011, 08:45 PM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Quote:
Originally Posted by callimuc View Post
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.
__________________
Reply With Quote
  #13  
Old 01-08-2011, 09:02 PM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
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

__________________
Quote:
Reply With Quote
  #14  
Old 01-08-2011, 09:07 PM
Skyld Skyld is offline
Script-fu
Skyld's Avatar
Join Date: Jan 2002
Location: United Kingdom
Posts: 3,914
Skyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud of
Send a message via AIM to Skyld
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.
__________________
Skyld
Reply With Quote
  #15  
Old 01-08-2011, 09:10 PM
salesman salesman is offline
Finger lickin' good.
salesman's Avatar
Join Date: Nov 2008
Location: Colorado
Posts: 1,865
salesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud of
Quote:
Originally Posted by Skyld View Post
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 
__________________
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 12:42 PM.


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