Graal Forums  

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

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 08-24-2009, 06:36 PM
sssssssssss sssssssssss is offline
Cyril Rain
sssssssssss's Avatar
Join Date: May 2003
Location: Texas, USA
Posts: 1,134
sssssssssss will become famous soon enough
Very VERY simple donation box.

Uses a serverr.flag. Noticed there wasen't one here at all. I know this is simple and easy, but soom scriptin newbie will be happy it's here.
Has access for only one person to get rupees out. Keep my name in it or else.

PHP Code:
//created by Cyril (SDE)
function onCreated(){
  
this.setshape(13232);
  
server.myrupees;
}
function 
onPlayerChats()
  {
  if (
player.chat.starts("donate"))
    {
    
temp.takerupees player.chat.tokenize()[1];
    
serverr.myrupees += temp.takerupees;
    
player.rupees -= temp.takerupees;
    
clientr.myrupees += temp.takerupees;
  }
  if (
player.chat.starts("take"))
    {
    if (
player.account == "Account Name")
      {
      if (!(
serverr.myrupees 0))
        {
        
temp.prupees player.chat.tokenize()[1];
        if (!(
serverr.myrupees temp.prupees))
          {
          
player.rupees += temp.prupees;
          
serverr.myrupees -= temp.prupees;
        }
      }
    }
  }
}

//#CLIENTSIDE
function onPlayerEnters(){
  
this.chat "Rupees: " serverr.myrupees "";
}
function 
onPlayerTouchsMe(){
  
say2("You have contributed
  " 
clientr.myrupees "
  Rupees"
);

__________________
Cyril Rain
Creator and leader of SLX
Admin of Elysium
Elysium's Facebook Page: http://facebook.com/GraalOnlineElysium
Graal Forum Thread: http://forums.graalonline.com...
Graalians Thread: http://www.graalians.com...



Last edited by sssssssssss; 08-24-2009 at 07:53 PM..
Reply With Quote
  #2  
Old 08-24-2009, 07:24 PM
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
there's alot of room for improvement but at the very least add else between your two player.chat checks so that it doesn't check every if statement every time.
Reply With Quote
  #3  
Old 08-24-2009, 07:29 PM
LoneAngelIbesu LoneAngelIbesu is offline
master of infinite loops
LoneAngelIbesu's Avatar
Join Date: May 2007
Location: Toldeo, Ohio
Posts: 1,049
LoneAngelIbesu has a spectacular aura aboutLoneAngelIbesu has a spectacular aura about
Send a message via AIM to LoneAngelIbesu
Quote:
Originally Posted by Mark Sir Link View Post
there's alot of room for improvement but at the very least add else between your two player.chat checks so that it doesn't check every if statement every time.
It's going to check both, either way.
__________________
"We are all in the gutter, but some of us are looking at the stars."
— Oscar Wilde, Lady Windermere's Fan
Reply With Quote
  #4  
Old 08-24-2009, 07:30 PM
sssssssssss sssssssssss is offline
Cyril Rain
sssssssssss's Avatar
Join Date: May 2003
Location: Texas, USA
Posts: 1,134
sssssssssss will become famous soon enough
ya I know it could be better. like i said, easy, simple, complete for the avg n00b.
__________________
Cyril Rain
Creator and leader of SLX
Admin of Elysium
Elysium's Facebook Page: http://facebook.com/GraalOnlineElysium
Graal Forum Thread: http://forums.graalonline.com...
Graalians Thread: http://www.graalians.com...


Reply With Quote
  #5  
Old 08-24-2009, 07:37 PM
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 LoneAngelIbesu View Post
It's going to check both, either way.
unless, you know, someone says donate
Reply With Quote
  #6  
Old 08-25-2009, 12:30 AM
Twinny Twinny is offline
My empire of dirt
Twinny's Avatar
Join Date: Mar 2006
Location: Australia
Posts: 2,422
Twinny is just really niceTwinny is just really nice
Send a message via AIM to Twinny
One of the major problems here is that it doesn't check whether the player has the rupees to donate. This is pretty bad but easy enough to fix with a simple if condition.
Reply With Quote
  #7  
Old 08-25-2009, 09:27 AM
sssssssssss sssssssssss is offline
Cyril Rain
sssssssssss's Avatar
Join Date: May 2003
Location: Texas, USA
Posts: 1,134
sssssssssss will become famous soon enough
forgot about that lol. here.

PHP Code:
//created by Cyril (SDE) 
function onCreated(){ 
  
this.setshape(13232); 
  
server.myrupees

function 
onPlayerChats() 
  { 
  if (
player.chat.starts("donate")) 
    { 
    
temp.takerupees player.chat.tokenize()[1]; 
      if (!(
player.rupees temp.takerupees))
       {
    
serverr.myrupees += temp.takerupees
    
player.rupees -= temp.takerupees
    
clientr.myrupees += temp.takerupees
      }
  } 
  if (
player.chat.starts("take")) 
    { 
    if (
player.account == "Account Name"
      { 
      if (!(
serverr.myrupees 0)) 
        { 
        
temp.prupees player.chat.tokenize()[1]; 
        if (!(
serverr.myrupees temp.prupees)) 
          { 
          
player.rupees += temp.prupees
          
serverr.myrupees -= temp.prupees
        } 
      } 
    } 
  } 


//#CLIENTSIDE 
function onPlayerEnters(){ 
  
this.chat "Rupees: " serverr.myrupees ""

function 
onPlayerTouchsMe(){ 
  
say2("You have contributed 
  " 
clientr.myrupees 
  Rupees"
); 

__________________
Cyril Rain
Creator and leader of SLX
Admin of Elysium
Elysium's Facebook Page: http://facebook.com/GraalOnlineElysium
Graal Forum Thread: http://forums.graalonline.com...
Graalians Thread: http://www.graalians.com...


Reply With Quote
  #8  
Old 08-25-2009, 05:26 PM
maximus_asinus maximus_asinus is offline
RIP DarkCloud_PK
Join Date: Oct 2001
Location: Canada
Posts: 3,749
maximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond repute
I'm not great at reading scripts but what would stop me from donating a decimal value? I realize that it wouldn't subtract the decimal value from the player's rupees but since variables aren't so strict...
__________________
Save Classic!
Reply With Quote
  #9  
Old 08-25-2009, 05:45 PM
Pelikano Pelikano is offline
Registered User
Pelikano's Avatar
Join Date: Oct 2008
Posts: 1,133
Pelikano has a little shameless behaviour in the past
Quote:
Originally Posted by maximus_asinus View Post
I'm not great at reading scripts but what would stop me from donating a decimal value? I realize that it wouldn't subtract the decimal value from the player's rupees but since variables aren't so strict...
ROFL nice idea
Reply With Quote
  #10  
Old 08-25-2009, 06:00 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
You can also donate negative values. Here's an example of a donation box I had laying around.

PHP Code:
function onCreated() {
  
// Variable to Store Donation In
  
this.bankvar "server.donationbox";
  
// Accounts allowed to take Donations
  
this.allowed = {
    
"account1""account2""and_so_on"
  
};
  
// Display Donation Chat
  
updateBox();
}

// Donation Box Commands

function onPlayerChats() {
  if (
player.chat.starts("donate")) {
    
addDonation(player.chat.substring("donate ".length()));
  }
  else if (
player.chat.starts("take")) {
    if (
player.account in this.allowed) {
      
takeDonation(player.chat.substring("take ".length()));
    }
  }
}

function 
addDonation(value) {
  
// Validate Donation
  
temp.donation limit(int(value), 0player.rupees);
  if (
temp.donation 0) {
    
// Increment Donations
    
makevar(this.bankvar) += temp.donation;
    
// Decrement Player Rupees
    
player.rupees -= temp.donation;
    
// Update Boxes Chat
    
updateBox();
  }  
}

function 
takeDonation(value) {
  
// Validate Donation
  
temp.donation limit(int(value), 0makevar(this.bankvar));
  if (
temp.donation 0) {
    
// Decrement Donations
    
makevar(this.bankvar) -= temp.donation;
    
// Increment Rupees
    
player.rupees += temp.donation;
    
// Update Boxes Chat
    
updateBox();
  }
}

function 
updateBox() {
  
// Displays Donation Chat Text
  
this.chat format("Donations: %s rupees"0+makevar(this.bankvar));
}

// Basic limit function

function limit(valminmax) {
  return (
val min min : (val max max val));

__________________
Quote:
Reply With Quote
  #11  
Old 08-25-2009, 06:33 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 fowlplay4 View Post
You can also donate negative values. Here's an example of a donation box I had laying around.
This is what I see a lot of programmers and such forget about when they make things like this that handle money. Insta-cash for the player!
Reply With Quote
  #12  
Old 08-25-2009, 07:29 PM
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 maximus_asinus View Post
I'm not great at reading scripts but what would stop me from donating a decimal value? I realize that it wouldn't subtract the decimal value from the player's rupees but since variables aren't so strict...
too lazy to check but I THINK the built in rupees variable is an int, not a float/double/etc.

always cast the serverr into an int also.
Reply With Quote
  #13  
Old 08-25-2009, 07:42 PM
WhiteDragon WhiteDragon is offline
Banned
Join Date: Feb 2007
Posts: 1,002
WhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to behold
Quote:
Originally Posted by Mark Sir Link View Post
too lazy to check but I THINK the built in rupees variable is an int, not a float/double/etc.

always cast the serverr into an int also.
Technically there is no type-casting in GScript since it's dynamically-typed. I assume you're talking about the int() function though.
Reply With Quote
  #14  
Old 08-25-2009, 08:05 PM
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 WhiteDragon View Post
Technically there is no type-casting in GScript since it's dynamically-typed. I assume you're talking about the int() function though.
Yes
Reply With Quote
  #15  
Old 08-26-2009, 04:54 AM
sssssssssss sssssssssss is offline
Cyril Rain
sssssssssss's Avatar
Join Date: May 2003
Location: Texas, USA
Posts: 1,134
sssssssssss will become famous soon enough
well again, simple, not perfect, but now theres a better one in here
__________________
Cyril Rain
Creator and leader of SLX
Admin of Elysium
Elysium's Facebook Page: http://facebook.com/GraalOnlineElysium
Graal Forum Thread: http://forums.graalonline.com...
Graalians Thread: http://www.graalians.com...


Reply With Quote
  #16  
Old 08-26-2009, 04:57 AM
Gambet Gambet is offline
Registered User
Join Date: Oct 2003
Posts: 2,712
Gambet is on a distinguished road
Not sure why you would use a serverr. flag, though, do you need to send the information clientside? Seems like you can do everything serverside (like in Jerret's example).
Reply With Quote
  #17  
Old 08-26-2009, 05:36 AM
sssssssssss sssssssssss is offline
Cyril Rain
sssssssssss's Avatar
Join Date: May 2003
Location: Texas, USA
Posts: 1,134
sssssssssss will become famous soon enough
and actually, just tested with mine, you can do -, but it will still take it from you as a regular in donating, in taking it wont do anyting.
there isnt a reason, ya i could have used this. and saved it on the npc.
__________________
Cyril Rain
Creator and leader of SLX
Admin of Elysium
Elysium's Facebook Page: http://facebook.com/GraalOnlineElysium
Graal Forum Thread: http://forums.graalonline.com...
Graalians Thread: http://www.graalians.com...


Reply With Quote
  #18  
Old 08-27-2009, 01:38 PM
Gambet Gambet is offline
Registered User
Join Date: Oct 2003
Posts: 2,712
Gambet is on a distinguished road
Quote:
Originally Posted by sssssssssss View Post
there isnt a reason, ya i could have used this. and saved it on the npc.

No, that would have been a bad idea because then the this. var would have been reset whenever the level was updated.
Reply With Quote
  #19  
Old 08-27-2009, 11:05 PM
sssssssssss sssssssssss is offline
Cyril Rain
sssssssssss's Avatar
Join Date: May 2003
Location: Texas, USA
Posts: 1,134
sssssssssss will become famous soon enough
o ya xD
sorry, I usually end up posting here after drinking for some reason, every time. :/
Thats probably a bad idea.
__________________
Cyril Rain
Creator and leader of SLX
Admin of Elysium
Elysium's Facebook Page: http://facebook.com/GraalOnlineElysium
Graal Forum Thread: http://forums.graalonline.com...
Graalians Thread: http://www.graalians.com...


Reply With Quote
  #20  
Old 08-28-2009, 05:12 PM
Pelikano Pelikano is offline
Registered User
Pelikano's Avatar
Join Date: Oct 2008
Posts: 1,133
Pelikano has a little shameless behaviour in the past
Such things are really not needed in this Code Gallery.

I understand you tho, I was very excited too with my first few scripts
Reply With Quote
  #21  
Old 08-28-2009, 07:58 PM
sssssssssss sssssssssss is offline
Cyril Rain
sssssssssss's Avatar
Join Date: May 2003
Location: Texas, USA
Posts: 1,134
sssssssssss will become famous soon enough
Definitely not one of my first few, just one of my first few within the last 4-5 years.
__________________
Cyril Rain
Creator and leader of SLX
Admin of Elysium
Elysium's Facebook Page: http://facebook.com/GraalOnlineElysium
Graal Forum Thread: http://forums.graalonline.com...
Graalians Thread: http://www.graalians.com...


Reply With Quote
  #22  
Old 08-28-2009, 09:21 PM
Pelikano Pelikano is offline
Registered User
Pelikano's Avatar
Join Date: Oct 2008
Posts: 1,133
Pelikano has a little shameless behaviour in the past
Quote:
Originally Posted by sssssssssss View Post
Definitely not one of my first few, just one of my first few within the last 4-5 years.
Then you're progressing very slow yet have a lot of motivation, that's the way to go!
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 02:17 PM.


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