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 12-28-2011, 03:36 PM
Gunderak Gunderak is offline
Coder
Gunderak's Avatar
Join Date: Jun 2011
Location: Australia
Posts: 795
Gunderak is on a distinguished road
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 "";
    }
  }

__________________

Gund for president.

Remote PM {P*}x (Graal813044) from eraiphone -> Stefan: I hav 1 qustion
*Gunderak: he hav 1
*Gunderak: qustion

Last edited by Gunderak; 12-29-2011 at 03:35 PM..
Reply With Quote
  #2  
Old 12-28-2011, 03:42 PM
ffcmike ffcmike is offline
Banned
Join Date: Jul 2004
Location: London
Posts: 2,029
ffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond repute
Send a message via AIM to ffcmike Send a message via MSN to ffcmike
Quote:
Originally Posted by Gunderak View Post
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.
Reply With Quote
  #3  
Old 12-28-2011, 04:22 PM
Gunderak Gunderak is offline
Coder
Gunderak's Avatar
Join Date: Jun 2011
Location: Australia
Posts: 795
Gunderak is on a distinguished road
Fixed
__________________

Gund for president.

Remote PM {P*}x (Graal813044) from eraiphone -> Stefan: I hav 1 qustion
*Gunderak: he hav 1
*Gunderak: qustion
Reply With Quote
  #4  
Old 12-28-2011, 05:47 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
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.
__________________
Reply With Quote
  #5  
Old 12-28-2011, 05:54 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 cbk1994 View Post
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();

__________________
MEEP!
Reply With Quote
  #6  
Old 12-29-2011, 03:29 PM
Gunderak Gunderak is offline
Coder
Gunderak's Avatar
Join Date: Jun 2011
Location: Australia
Posts: 795
Gunderak is on a distinguished road
Quote:
Originally Posted by cbk1994 View Post
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 "";
    }
  }

__________________

Gund for president.

Remote PM {P*}x (Graal813044) from eraiphone -> Stefan: I hav 1 qustion
*Gunderak: he hav 1
*Gunderak: qustion
Reply With Quote
  #7  
Old 12-29-2011, 03:54 PM
Crow Crow is offline
ǝɔɐɹq ʎןɹnɔ
Crow's Avatar
Join Date: Dec 2006
Location: Germany
Posts: 5,153
Crow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond repute
Quote:
Originally Posted by Gunderak View Post
and why use true or false? 0 and 1 are true and false in binary..
Readability. This does not apply to all languages either.
Reply With Quote
  #8  
Old 12-29-2011, 04:15 PM
Gunderak Gunderak is offline
Coder
Gunderak's Avatar
Join Date: Jun 2011
Location: Australia
Posts: 795
Gunderak is on a distinguished road
Ok, I'll do that in GS2 from now on.
But I'm still going to do it my way in AS2 lol.
__________________

Gund for president.

Remote PM {P*}x (Graal813044) from eraiphone -> Stefan: I hav 1 qustion
*Gunderak: he hav 1
*Gunderak: qustion
Reply With Quote
  #9  
Old 12-29-2011, 05:48 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 Gunderak View Post
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.
__________________
Reply With Quote
  #10  
Old 12-29-2011, 07:55 PM
Gunderak Gunderak is offline
Coder
Gunderak's Avatar
Join Date: Jun 2011
Location: Australia
Posts: 795
Gunderak is on a distinguished road
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.
__________________

Gund for president.

Remote PM {P*}x (Graal813044) from eraiphone -> Stefan: I hav 1 qustion
*Gunderak: he hav 1
*Gunderak: qustion
Reply With Quote
  #11  
Old 12-29-2011, 08:11 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 Gunderak View Post
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.
__________________
Reply With Quote
  #12  
Old 12-29-2011, 09:25 PM
scriptless scriptless is offline
Banned
Join Date: Dec 2008
Location: N-Pulse
Posts: 1,412
scriptless is a splendid one to beholdscriptless is a splendid one to beholdscriptless is a splendid one to beholdscriptless is a splendid one to behold
Quote:
Originally Posted by Gunderak View Post
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 !
Reply With Quote
  #13  
Old 12-29-2011, 09:34 PM
Tolnaftate2004 Tolnaftate2004 is offline
penguin.
Join Date: Jul 2004
Location: Berkeley, CA
Posts: 534
Tolnaftate2004 is a jewel in the roughTolnaftate2004 is a jewel in the rough
Send a message via AIM to Tolnaftate2004
Quote:
Originally Posted by scriptless View Post
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 ^.
__________________
◕‿‿◕ · pfa · check yer syntax! · src

Killa Be: when i got that locker in 6th grade the only thing in it was a picture of a midget useing a firehose :/
Reply With Quote
  #14  
Old 12-29-2011, 09:40 PM
scriptless scriptless is offline
Banned
Join Date: Dec 2008
Location: N-Pulse
Posts: 1,412
scriptless is a splendid one to beholdscriptless is a splendid one to beholdscriptless is a splendid one to beholdscriptless is a splendid one to behold
Quote:
Originally Posted by Tolnaftate2004 View Post
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?
Reply With Quote
  #15  
Old 12-29-2011, 09:43 PM
Tolnaftate2004 Tolnaftate2004 is offline
penguin.
Join Date: Jul 2004
Location: Berkeley, CA
Posts: 534
Tolnaftate2004 is a jewel in the roughTolnaftate2004 is a jewel in the rough
Send a message via AIM to Tolnaftate2004
Quote:
Originally Posted by scriptless View Post
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
__________________
◕‿‿◕ · pfa · check yer syntax! · src

Killa Be: when i got that locker in 6th grade the only thing in it was a picture of a midget useing a firehose :/

Last edited by Tolnaftate2004; 12-29-2011 at 10:10 PM..
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 05:04 PM.


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