Alter Aeon Community Forum
July 21, 2018, 09:36:57 pm *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Registration is enabled!  Please register using the name of your primary character in-game.
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: gdata dproc example  (Read 43281 times)
Draak
Jr. Member
**
Posts: 85


god of ice


View Profile
« on: March 12, 2013, 06:43:56 pm »

This is a fairly simple example of a dproc, which is special custom code builders can put on objects and mobs for a variety of effects.

A beeswax candle loads in the mini-mudschool in Vemarken. When first picked up, it sends the player a message instructing them how to use it. It then replaces itself with a version of the candle that lacks the dproc. The color flags are missing from the text for the sake of simplicity.

Code:
event get_object(character user,object o){
       print_to_char(user,NULL,o,"\nThe wick of a beeswax candle lights itself.")
       print_to_char(user,NULL,o,"\n ")
       print_to_char(user,NULL,o,"\n(You can light the candle using the 'light' command, for example")
       print_to_char(user,NULL,o,"\n'light candle'. You can extinguish it with the extinguish command, for" )
       print_to_char(user,NULL,o,"\n example, 'extinguish candle'.)")
       print_to_char(user,NULL,o,"\n ")
       print_to_char(user,NULL,o,"\n(Be aware that when lit, the candle will eventually burn out. Extinguishing")
       print_to_char(user,NULL,o,"\n it when you don't need light and relighting it when dark will extend its" )
       print_to_char(user,NULL,o,"\n lifespan.)" )
       destroy_entity(o)
       o=create_object(53189,user)
       put_into_inventory(o,user)
}

The beeswax candle predates global variables for dprocs. If I were to build this object today I would have it check a gdata value. Gdata variables are local values that save between uses. If the value of gdata_candle is greater than 0, nothing happens. Since the first time you pick it up, the value is 0, the message is sent, and gdata_candle is then set to a value of 1.  Because the value is now greater than 0, the dproc will not trigger for the candle in the future:

Code:
event get_object(character user,object o){
       if(gdata_candle > 0) { return }
       print_to_char(user,NULL,o,"\n(You can light the candle using the 'light' command, for example")
       print_to_char(user,NULL,o,"\n'light candle'. You can extinguish it with the extinguish command, for" )
       print_to_char(user,NULL,o,"\n example, 'extinguish candle'.)")
       print_to_char(user,NULL,o,"\n ")
       print_to_char(user,NULL,o,"\n(Be aware that when lit, the candle will eventually burn out. Extinguishing")
       print_to_char(user,NULL,o,"\n it when you don't need light and relighting it when dark will extend its" )
       print_to_char(user,NULL,o,"\n lifespan.)" )
       gdata_candle = 1
       return
}
Logged

Nothing special there.
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines Valid XHTML 1.0! Valid CSS!
Page created in 0.102 seconds with 17 queries.