Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting > New Scripting Engine (GS2)
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 04-30-2011, 11:26 PM
papajchris papajchris is offline
Zeus Condero
papajchris's Avatar
Join Date: Jan 2006
Location: Michigan
Posts: 1,600
papajchris is a splendid one to beholdpapajchris is a splendid one to beholdpapajchris is a splendid one to beholdpapajchris is a splendid one to behold
Some questions

So im looking at one of xXziroXx's old scripts and i had some questions

Quote:
Originally Posted by xXziroXx View Post
PHP Code:
function onPlayerChats()
{
  
tokens player.chat.tokenize();
  
BodyParts = { "skin""coat""sleeves""shoes""belt""all"};
  
BodyColors = { "white""yellow""orange""pink""red",
    
"darkred""lightgreen""green""darkgreen""lightblue",
      
"blue""darkblue""brown""cynober""purple",
        
"darkpurple""lightgray""gray""black"};
  if (
BodyParts.indextokens[0]) > -&& BodyColors.indextokens[1]) > -1) {
    if (
tokens[0] != "all"player.colorsBodyParts.indextokens[0])] = tokens[1];
    else {
      for (
iBodyPartsplayer.colorsBodyParts.indexi)] = tokens[1];
    }
    
player.chat "Changed " tokens[0] @ " to " tokens[1] @ "!";
  }

PHP Code:
 if (BodyParts.indextokens[0]) > -&& BodyColors.indextokens[1]) > -1
What does the -1 do? Assuming its the word number, how can words be less than first word (which is number 0).


PHP Code:
for (iBodyPartsplayer.colorsBodyParts.indexi)] = tokens[1]; 
What does the "i" do? My guess is its a variable?

Lastly can SPC be used instead of "@"?
__________________
Reply With Quote
  #2  
Old 04-30-2011, 11:32 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
SPC is another option for concatenating strings, yes, but I think most scripters prefer to avoid it. I could be wrong.

This post should help explain the foreach loop he used.

The index function returns -1 if the item does not appear in the array.
__________________
Reply With Quote
  #3  
Old 04-30-2011, 11:58 PM
papajchris papajchris is offline
Zeus Condero
papajchris's Avatar
Join Date: Jan 2006
Location: Michigan
Posts: 1,600
papajchris is a splendid one to beholdpapajchris is a splendid one to beholdpapajchris is a splendid one to beholdpapajchris is a splendid one to behold
Thanks that link had great examples, final question and i think i got this part understood.

Could you do this

PHP Code:
for player.colorsBodyParts.index(BodyParts)] = tokens[1]; 
instead of

PHP Code:
for (iBodyPartsplayer.colorsBodyParts.indexi)] = tokens[1]; 
__________________
Reply With Quote
  #4  
Old 05-01-2011, 12:16 AM
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 papajchris View Post
Thanks that link had great examples, final question and i think i got this part understood.

Could you do this

PHP Code:
for player.colorsBodyParts.index(BodyParts)] = tokens[1]; 
instead of

PHP Code:
for (iBodyPartsplayer.colorsBodyParts.indexi)] = tokens[1]; 
no.

for (element: array) { }
__________________
Quote:
Reply With Quote
  #5  
Old 05-01-2011, 12:18 AM
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 papajchris View Post
Thanks that link had great examples, final question and i think i got this part understood.

Could you do this

PHP Code:
for player.colorsBodyParts.index(BodyParts)] = tokens[1]; 
instead of

PHP Code:
for (iBodyPartsplayer.colorsBodyParts.indexi)] = tokens[1]; 
No. It might help if I pick apart his example.

PHP Code:
for (iBodyParts) {
  
player.colors[BodyParts.index(i)] = tokens[1];

This is the example with braces added to clarify it.

I don't really like how he's doing that anyway. This is how I would have done it:

PHP Code:
for (temp.0BodyParts.size(); ++) {
  
player.colors[i] = tokens[1];

Basically, i is starting at zero and increasing until it reaches the number of body parts. For each body part, it sets that part's color to tokens[1].

I'm not really sure how to explain the problems with yours except that it's just not following the right format. If you've got more questions I can try to answer them.

Also check out Jer's post on arrays.
__________________
Reply With Quote
  #6  
Old 05-01-2011, 12:38 AM
papajchris papajchris is offline
Zeus Condero
papajchris's Avatar
Join Date: Jan 2006
Location: Michigan
Posts: 1,600
papajchris is a splendid one to beholdpapajchris is a splendid one to beholdpapajchris is a splendid one to beholdpapajchris is a splendid one to behold
When you say it reaches the number of bodyparts you mean the number assigned from the array? So skin would be 0, coat 1, etc..

Im hoping to get a RC on testbed soon so that i can trial and error this myself
__________________
Reply With Quote
  #7  
Old 05-01-2011, 04:51 AM
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 papajchris View Post
When you say it reaches the number of bodyparts you mean the number assigned from the array? So skin would be 0, coat 1, etc..

Im hoping to get a RC on testbed soon so that i can trial and error this myself
Yes. TGaniObject.colors is an array, where the first element is skin, second is shoes, etc. See here.
__________________
Reply With Quote
  #8  
Old 05-01-2011, 10:35 PM
papajchris papajchris is offline
Zeus Condero
papajchris's Avatar
Join Date: Jan 2006
Location: Michigan
Posts: 1,600
papajchris is a splendid one to beholdpapajchris is a splendid one to beholdpapajchris is a splendid one to beholdpapajchris is a splendid one to behold
Im trying to do a script where if someone with a staff level 2 or higher says "/kill <account>" it does so.

The script worked before I added the staff level requirement. Also can you show me where i would add an else statement for those who aren't level 2 or higher? I am trying to make it say "Not Allowed". At one point it was making my text "Not Allowed" no matter what i said unless i said "/kill <account>" so i think i was close.

PHP Code:
function onActionServerSide(tokens){
    if (
tokens[0] == "/kill") {
        
temp.pl findPlayerByCommunityName(tokens[1]);
        
temp.pl.hearts 0;
        
temp.pl.chat player.account SPC "killed you!";
        
player.chat "You killed" SPC temp.pl SPC "!";
    }
}

//#CLIENTSIDE
function onPlayerChats() {
    if(
tokens[0] == "/kill" && (player.clientr.stafflvl) > 1) {
        
temp.tokens player.chat.tokenize();
        
triggerServer("gui"this.nametokens);
    }

__________________
Reply With Quote
  #9  
Old 05-01-2011, 11:14 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
Nothing wrong with it that I can see, except that you'll want to do the checks serverside.

PHP Code:
function onActionServerSide(tokens){
    if (
tokens[0] == "/kill") {
        if (
player.clientr.stafflvl 1) {
          
temp.pl findPlayerByCommunityName(tokens[1]);
          
temp.pl.hearts 0;
          
temp.pl.chat player.account SPC "killed you!";
          
player.chat "You killed" SPC temp.pl SPC "!";
        } else {
          
player.chat "Not authorized!";
        }
    }
}

//#CLIENTSIDE
function onPlayerChats() {
    if(
tokens[0] == "/kill") {
        
temp.tokens player.chat.tokenize();
        
triggerServer("gui"this.nametokens);
    }

Also, there's no reason to do (player.clientr.stafflvl)—just player.clientr.stafflvl works fine.

The reason I inserted another if statement was so you could use the else clause properly. If you'd used && instead, then the else would also apply if the command wasn't "/kill".

Also, be sure to work on your styling. Two spaces is an indent.
__________________
Reply With Quote
  #10  
Old 05-03-2011, 07:01 AM
papajchris papajchris is offline
Zeus Condero
papajchris's Avatar
Join Date: Jan 2006
Location: Michigan
Posts: 1,600
papajchris is a splendid one to beholdpapajchris is a splendid one to beholdpapajchris is a splendid one to beholdpapajchris is a splendid one to behold
Hm i can't seem to get the script to work. I made sure i have a high enough staff level and i even swapper that part out for my account name to see if that would work, but still no luck

PHP Code:
function onCreated(){
  
findplayer("papajchris").addweapon("Personal/papajchris/Staff");
}
function 
onActionServerSide(tokens){
    if (
tokens[0] == "/kill") {
        if (
player.account == "papajchris") {
          
temp.pl findPlayerByCommunityName(tokens[1]);
          
temp.pl.hearts 0;
          
temp.pl.chat player.account SPC "killed you!";
          
player.chat "You killed" SPC temp.pl SPC "!";
        } else {
          
player.chat "Not authorized!";
        }
    }
}

//#CLIENTSIDE
function onPlayerChats() {
    if(
tokens[0] == "/kill") {
        
temp.tokens player.chat.tokenize();
        
triggerServer("gui"this.nametokens);
    }

__________________
Reply With Quote
  #11  
Old 05-03-2011, 07:03 AM
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
You have to tokenize the player's chat before you check tokens[0]—otherwise, the array doesn't exist yet.

PHP Code:
//#CLIENTSIDE 
function onPlayerChats() { 
  
temp.tokens player.chat.tokenize(); 
  
  if(
tokens[0] == "/kill") { 
      
triggerServer("gui"this.nametokens); 
  } 

__________________
Reply With Quote
  #12  
Old 05-05-2011, 09:06 AM
papajchris papajchris is offline
Zeus Condero
papajchris's Avatar
Join Date: Jan 2006
Location: Michigan
Posts: 1,600
papajchris is a splendid one to beholdpapajchris is a splendid one to beholdpapajchris is a splendid one to beholdpapajchris is a splendid one to behold
Can strings like clientr. and client only be numbers? When I do scripts such as the following, they don't appear in attributes.

PHP Code:
function onPlayerTouchsme() {
 
client.high3=false;

__________________
Reply With Quote
  #13  
Old 05-05-2011, 09:20 AM
Mark Sir Link Mark Sir Link is offline
Kevin Azite
Mark Sir Link's Avatar
Join Date: Sep 2005
Posts: 1,489
Mark Sir Link is just really niceMark Sir Link is just really nice
Send a message via AIM to Mark Sir Link
Quote:
Originally Posted by papajchris View Post
Can strings like clientr. and client only be numbers? When I do scripts such as the following, they don't appear in attributes.

PHP Code:
function onPlayerTouchsme() {
 
client.high3=false;

if a var is set to false, it will no longer appear if you view a player's flags to prevent that var from taking up memory

since client.high3 wouldn't exist, evaluating

if(client.high3)

would return false since no value is attached to it
Reply With Quote
  #14  
Old 05-05-2011, 12:12 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 papajchris View Post
Can strings like clientr. and client only be numbers? When I do scripts such as the following, they don't appear in attributes.

PHP Code:
function onPlayerTouchsme() {
 
client.high3=false;

client and clientr variables can be anything but objects.

PHP Code:
player.clientr.foo "bar"// string
player.clientr.bar 10 3// number
player.clientr.baz = {"one""two"}; // array
player.clientr.baa true// boolean 
Unlike languages like Java, Graal is a dynamically-typed language, which means you don't have to tell Graal what type of variable you want something to be. In Java, you would have to do

PHP Code:
String foo "bar";
int bar 10 3;
String[] baz = {"one""two"};
boolean baa true
Since you don't have to do that in Graal, the engine internally converts certain values to others. This doesn't affect behavior in this case.

Setting a value to true will show it equal to 1. Setting it to false will either show it equal to 0 or remove it from attributes altogether. Either works.

If a variable has never been set to false, it will by default be false.
__________________
Reply With Quote
  #15  
Old 05-05-2011, 01:12 PM
MrOmega MrOmega is offline
One More Time
MrOmega's Avatar
Join Date: Aug 2010
Location: TN, USA
Posts: 631
MrOmega is an unknown quantity at this point
Send a message via AIM to MrOmega Send a message via MSN to MrOmega Send a message via Yahoo to MrOmega
Correct me if I'm wrong but float( false) would make it show 0 in the flags list.
__________________
Time is the fire in which we burn...
Up, Up, Down, Down, Left, Right, Left, Right, B, A, Select, Start! Now I got 99 LIVES!!!
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 09:43 AM.


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