Author Topic: Baseball code (example with a simple add_action)  (Read 2030 times)

Offline tigwyk

  • Acquaintance
  • *
  • Posts: 45
    • View Profile
Baseball code (example with a simple add_action)
« on: September 14, 2006, 12:46:02 PM »
A simple baseball, complete with an add_action. This is the simplest add_action example I could think of. LEARN!



LPC code:

#include <lib.h>

inherit LIB_ITEM;


static void create() {
    item::create();
    SetKeyName("baseball");
    SetId( ({ "baseball", "ball" }) );
    SetShort("a baseball");
    SetLong("It's a real Spalding baseball!");
    SetMass(5);
    SetBaseCost(1);
}
void init(){
::init();
   add_action("throw_ball", "throw");
}

int throw_ball(string str){
   if(!str || !id(str)){
      write("Throw what? The baseball?");
      return 1;
   }
   write("You throw the baseball at the wall.\nYou walk over and pick up the baseball from where it dropped.");
   say(this_player()->GetName()+" throws a baseball at the wall!\n"+this_player()->GetName()+" walks over and picks up the ball from where it dropped.");
   return 1;
}

Offline Tacitus

  • Acquaintance
  • *
  • Posts: 21
    • View Profile
Baseball code (example with a simple add_action)
« Reply #1 on: September 14, 2006, 03:51:50 PM »
LPC code:

inherit OBJECT;

void create()
{
    set_id(({"baseball", "ball"}));
    set_short("a baseball");
    set_long("It's a real Spalding baseball!\n");
}

void init()
{
    add_action("throw_ball", "throw");
}

int throw_ball(string str){
    if(!str || !id(str)){
        write("Throw what? The baseball?\n");
        return 1;
    }
    write("You throw the baseball at the wall.\nYou walk over and pick up the baseball from where it dropped.");
    say(this_player()->GetName()+" throws a baseball at the wall!\n"+this_player()->GetName()+" walks over and picks up the ball from where it dropped.\n");
    return 1;
}
Cody A.W. Somerville