Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Custom Gralat Class (https://forums.graalonline.com/forums/showthread.php?t=134265434)

Gunderak 12-28-2011 03:36 PM

Custom Gralat Class
 
I liked Classic iPhones gralat locking system so much that I made my own.
Anyway here is mine.
It allows you to lock gralats if you're in a level that starts with house_account, you may want to restrict it to a level, if so leave that in.
The only difference is that even if you're the owner they WON'T pick up if they're locked, that was the only thing I hate about Classic iPhone in that regards.
PHP Code:

function onCreated() {
  
this.setshape(0,32,32);
  
dontblock();
  
showcharacter();
  
updategani();
}
function 
onUpdategani() {
  
updategani();
}

function 
updategani() {
  
temp.type 1;
  if (
rupees>=100temp.type 4;
  else if (
rupees>=30temp.type 3;
  else if (
rupees>=5temp.type 2;

  
setcharani("gralats"temp.type);
}

function 
onPlayerTouchsMe() {
  if(
this.locked == 0){
    
player.rupees += rupees;
    
rupees 0;
    
destroy();
  }else{
  
this.chat "(Locked)";
  
sleep(2);
  
this.chat "";
  }
}
function 
onActionLeftMouse(){
  if(
this.locked == 1){
  
this.chat rupees@" (Locked)";
  
sleep(2);
  
this.chat "";
  }else{
  
this.chat rupees;
  
sleep(2);
  
this.chat "";
  }
}
function 
onActionDoubleMouse(){
  
temp.lname player.level.name.substring(6);
  
temp.lname lname.substring(0lname.pos(".nw").trim());
  
//had to use it twice, I tried  player.level.name.substring(6,  lname.pos(".nw").trim());  with no luck.
  
if(player.account == lname){
    
this.locked = !this.locked;
    if(
this.locked == 1){
      
this.chat "Locked!";
      
sleep(2);
      
this.chat "";
    }
    if(
this.locked == 0){
      
this.chat "Unlocked!";
      
sleep(2);
      
this.chat "";
    }
  }



ffcmike 12-28-2011 03:42 PM

Quote:

Originally Posted by Gunderak (Post 1679722)
PHP Code:

if(player.level.starts("house_"@player.account)){ 


I believe this would still work due to the engine coercing it however it should be:

PHP Code:

player.level.name.starts() 

level is an object, not a string.

Gunderak 12-28-2011 04:22 PM

Fixed :)

cbk1994 12-28-2011 05:47 PM

You don't need any clientside code here, just use onActionDoubleMouse, which is sent by the client without you doing anything.

What if my account was "Stef"? I could lock gralats in Stefan's house.

Once again, stop using 0 and 1 as booleans. Use true and false instead. It's much clearer for anyone reading the code.

I'm almost certain that setshape should have '1' as its first parameter (at least according to the wiki—but I've never seen it used any other way).

Where is onUpdateGani being triggered from?

Indent code properly and use whitespace consistently. It's unacceptable not to.

callimuc 12-28-2011 05:54 PM

Quote:

Originally Posted by cbk1994 (Post 1679731)
Where is onUpdateGani being triggered from?

Itīs there by default

Default Gralats:
PHP Code:

function onCreated() {
  
showcharacter();
  
dontblock();
  
updategani();
}
function 
onUpdategani() {
  
updategani();
}

function 
updategani() {
  
temp.type 1;
  if (
rupees>=100temp.type 4;
  else if (
rupees>=30temp.type 3;
  else if (
rupees>=5temp.type 2;

  
setcharani("gralats"temp.type);
}

function 
onPlayerTouchsMe() {
  
player.rupees += rupees;
  
rupees 0;
  
destroy();



Gunderak 12-29-2011 03:29 PM

Quote:

Originally Posted by cbk1994 (Post 1679731)
You don't need any clientside code here, just use onActionDoubleMouse, which is sent by the client without you doing anything.

What if my account was "Stef"? I could lock gralats in Stefan's house.

Once again, stop using 0 and 1 as booleans. Use true and false instead. It's much clearer for anyone reading the code.

I'm almost certain that setshape should have '1' as its first parameter (at least according to the wiki—but I've never seen it used any other way).

Where is onUpdateGani being triggered from?

Indent code properly and use whitespace consistently. It's unacceptable not to.

That's alot, But I will fix it up and re post later.
and why use true or false? 0 and 1 are true and false in binary..

I was in the middle of editing it and it popped up that I can only edit it 1440 minutes after it was created, so here is the new code.
PHP Code:

function onCreated() {
  
this.setshape(03232);
  
dontblock();
  
showcharacter();
  
updategani();
}

function 
onUpdategani() {
  
updategani();
}

function 
updategani() {
  
temp.type 1;
  if (
rupees >= 100temp.type 4;
  else if (
rupees >= 30temp.type 3;
  else if (
rupees >= 5temp.type 2;

  
setcharani("gralats"temp.type);
}

function 
onPlayerTouchsMe() {
  if (
this.locked == 0) {
    
player.rupees += rupees;
    
rupees 0;
    
destroy();
  } else {
    
this.chat "(Locked)";
    
sleep(2);
    
this.chat "";
  }
}

function 
onActionLeftMouse() {
  if (
this.locked == true) {
    
this.chat rupees " (Locked)";
    
sleep(2);
    
this.chat "";
  } else {
    
this.chat rupees;
    
sleep(2);
    
this.chat "";
  }
}

function 
onActionDoubleMouse() {
  
temp.lname player.level.name.substring(6);
  
temp.lname lname.substring(0lname.pos(".nw").trim());
  
//had to use it twice, I tried  player.level.name.substring(6,  lname.pos(".nw").trim());  with no luck.
  
if (player.account == lname) {
    
this.locked = !this.locked;
    if (
this.locked == true) {
      
this.chat "Locked!";
      
sleep(2);
      
this.chat "";
    } else {
      
this.chat "Unlocked!";
      
sleep(2);
      
this.chat "";
    }
  }



Crow 12-29-2011 03:54 PM

Quote:

Originally Posted by Gunderak (Post 1679911)
and why use true or false? 0 and 1 are true and false in binary..

Readability. This does not apply to all languages either.

Gunderak 12-29-2011 04:15 PM

Ok, I'll do that in GS2 from now on.
But I'm still going to do it my way in AS2 lol.

cbk1994 12-29-2011 05:48 PM

Quote:

Originally Posted by Gunderak (Post 1679911)
PHP Code:

  temp.lname player.level.name.substring(6);
  
temp.lname lname.substring(0lname.pos(".nw").trim());
  
//had to use it twice, I tried  player.level.name.substring(6,  lname.pos(".nw").trim());  with no luck. 


That's because the second parameter is the length to cut, not the index of the last character to cut.

PHP Code:

temp.account player.level.name.substring(6player.level.name.length() - 9); 

That should work.

Why are you trimming the position of ".nw"? It doesn't make any sense to trim output from a function which always returns integers.

Gunderak 12-29-2011 07:55 PM

So that it checks the player account part of the levenll name vs the players account.
You can't exactly compare Graal123456 to Graal123456.nw unless you use .starts which you said not to.

cbk1994 12-29-2011 08:11 PM

Quote:

Originally Posted by Gunderak (Post 1679938)
So that it checks the player account part of the levenll name vs the players account.
You can't exactly compare Graal123456 to Graal123456.nw unless you use .starts which you said not to.

Sure you can, chop the .nw off the end.

PHP Code:

temp.str1 "Graal123456.nw";
temp.str2 "Graal123456";

temp.str1 temp.str1.substring(0temp.str1.length() - 3);

echo(
temp.str1 == temp.str2); // echoes 1 

You can't use starts because it's only checking the first part, i.e. player "cbk" could enter my house.

scriptless 12-29-2011 09:25 PM

Quote:

Originally Posted by Gunderak (Post 1679911)
That's alot, But I will fix it up and re post later.
and why use true or false? 0 and 1 are true and false in binary..

I was in the middle of editing it and it popped up that I can only edit it 1440 minutes after it was created, so here is the new code.

Correct me if I am wrong but, I was always under the impression that each variable, when set to true/false used 8 bit's "0000 0000" for false and "0000 0001" for true... ? Could use a bitwise operator to store 8 true/false values in a single Byte tho !

Tolnaftate2004 12-29-2011 09:34 PM

Quote:

Originally Posted by scriptless (Post 1679948)
Correct me if I am wrong but

When a bool is cast to an int, you have 31* bits to work with.

* Actually 32, but GS "protects" ints from overflow via << or ^.

scriptless 12-29-2011 09:40 PM

Quote:

Originally Posted by Tolnaftate2004 (Post 1679950)
When a bool is cast to an int, you have 31* bits to work with.

* Actually 32, but GS "protects" ints from overflow via << or ^.

31? How would you manipulate the other 30 bits?

Tolnaftate2004 12-29-2011 09:43 PM

Quote:

Originally Posted by scriptless (Post 1679952)
31? How would you manipulate the other 30 bits?

Bit ops work on all the bits...

PHP Code:

-0x7fffffff*((x&0x40000000)>>30)+((x&0x3fffffff)<<1



All times are GMT +2. The time now is 07:21 PM.

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