Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   Code Gallery (https://forums.graalonline.com/forums/forumdisplay.php?f=179)
-   -   Very VERY simple donation box. (https://forums.graalonline.com/forums/showthread.php?t=87588)

sssssssssss 08-24-2009 06:36 PM

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



Mark Sir Link 08-24-2009 07:24 PM

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.

LoneAngelIbesu 08-24-2009 07:29 PM

Quote:

Originally Posted by Mark Sir Link (Post 1518183)
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. ;)

sssssssssss 08-24-2009 07:30 PM

ya I know it could be better. like i said, easy, simple, complete for the avg n00b. :)

Mark Sir Link 08-24-2009 07:37 PM

Quote:

Originally Posted by LoneAngelIbesu (Post 1518186)
It's going to check both, either way. ;)

unless, you know, someone says donate

Twinny 08-25-2009 12:30 AM

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.

sssssssssss 08-25-2009 09:27 AM

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



maximus_asinus 08-25-2009 05:26 PM

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...

Pelikano 08-25-2009 05:45 PM

Quote:

Originally Posted by maximus_asinus (Post 1518359)
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

fowlplay4 08-25-2009 06:00 PM

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



DustyPorViva 08-25-2009 06:33 PM

Quote:

Originally Posted by fowlplay4 (Post 1518368)
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!

Mark Sir Link 08-25-2009 07:29 PM

Quote:

Originally Posted by maximus_asinus (Post 1518359)
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.

WhiteDragon 08-25-2009 07:42 PM

Quote:

Originally Posted by Mark Sir Link (Post 1518388)
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.

Mark Sir Link 08-25-2009 08:05 PM

Quote:

Originally Posted by WhiteDragon (Post 1518395)
Technically there is no type-casting in GScript since it's dynamically-typed. I assume you're talking about the int() function though.

Yes

sssssssssss 08-26-2009 04:54 AM

well again, simple, not perfect, but now theres a better one in here

Gambet 08-26-2009 04:57 AM

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).

sssssssssss 08-26-2009 05:36 AM

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.

Gambet 08-27-2009 01:38 PM

Quote:

Originally Posted by sssssssssss (Post 1518571)
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.

sssssssssss 08-27-2009 11:05 PM

o ya xD
sorry, I usually end up posting here after drinking for some reason, every time. :/
Thats probably a bad idea.

Pelikano 08-28-2009 05:12 PM

Such things are really not needed in this Code Gallery.

I understand you tho, I was very excited too with my first few scripts

sssssssssss 08-28-2009 07:58 PM

Definitely not one of my first few, just one of my first few within the last 4-5 years.

Pelikano 08-28-2009 09:21 PM

Quote:

Originally Posted by sssssssssss (Post 1519192)
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!


All times are GMT +2. The time now is 10:01 AM.

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