Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   New Scripting Engine (GS2) (https://forums.graalonline.com/forums/forumdisplay.php?f=153)
-   -   Some questions (https://forums.graalonline.com/forums/showthread.php?t=134263060)

papajchris 04-30-2011 11:26 PM

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

Quote:

Originally Posted by xXziroXx (Post 1189573)
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 "@"?

cbk1994 04-30-2011 11:32 PM

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.

papajchris 04-30-2011 11:58 PM

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]; 


fowlplay4 05-01-2011 12:16 AM

Quote:

Originally Posted by papajchris (Post 1646760)
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) { }

cbk1994 05-01-2011 12:18 AM

Quote:

Originally Posted by papajchris (Post 1646760)
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.

papajchris 05-01-2011 12:38 AM

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

cbk1994 05-01-2011 04:51 AM

Quote:

Originally Posted by papajchris (Post 1646781)
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.

papajchris 05-01-2011 10:35 PM

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);
    }



cbk1994 05-01-2011 11:14 PM

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.

papajchris 05-03-2011 07:01 AM

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);
    }



cbk1994 05-03-2011 07:03 AM

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); 
  } 



papajchris 05-05-2011 09:06 AM

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;



Mark Sir Link 05-05-2011 09:20 AM

Quote:

Originally Posted by papajchris (Post 1647694)
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

cbk1994 05-05-2011 12:12 PM

Quote:

Originally Posted by papajchris (Post 1647694)
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.

MrOmega 05-05-2011 01:12 PM

Correct me if I'm wrong but float( false) would make it show 0 in the flags list.


All times are GMT +2. The time now is 04:06 PM.

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