View Single Post
  #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), 0, player.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), 0, makevar(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(val, min, max) {
  return (
val < min ? min : (val > max ? max : val));
} 
__________________
Quote:
Reply With Quote