mirror of
https://github.com/evennia/evennia.git
synced 2026-03-19 06:16:31 +01:00
- Set up a global cleaner event to clean all @destroyed objects every 30 minutes (makes their dbrefs available). - Added the @recover command for recovering @destroyed objects up until the point that the cleaner runs and actually destroys them. This can recover @destroyed objects, rooms and exits to the same state as before @destroy. It could easily be made to recover player objects too, but I'm thinking this would be a security issue. - Added to @dig in order to allow for creating rooms with a particular parent. Also auto-creates exits in each room if desired. The only things that is not implemented is the aliases of the exits, I don't really know how to do that. - Changed the @create command format to match the @dig (it uses : to mark the parent instead of = now, since MUX' @dig reserve = to the exit list.) - Added extra security in the example event to guard against the bug that causes the whole scheduler to freak out if the event_function() gives a traceback. - Changed many instances of type to point to the defines_global.OTYPE instead of giving the integer explicitly. /Starkiel
64 lines
2.3 KiB
Python
64 lines
2.3 KiB
Python
"""
|
|
Example of the event system. To try it out, make sure to import it from somewhere
|
|
covered by @reload (like the script parent). Create an object inheriting
|
|
the red_button parent to see its effects (e.g. @create button=examples/red_button)
|
|
|
|
Technically the event don't contain any game logics, all it does is locate all
|
|
objects inheriting to a particular script parent and calls one of its functions
|
|
at a regular interval.
|
|
"""
|
|
|
|
import sys
|
|
from src.events import IntervalEvent
|
|
from src.scheduler import add_event
|
|
from src.objects.models import Object
|
|
|
|
#the logger is useful for debugging
|
|
from src.logger import log_errmsg
|
|
|
|
#Example of the event system. This example adds an event to the red_button parent
|
|
#in parents/examples. It makes the button blink temptingly at a regular interval.
|
|
|
|
class EventBlinkButton(IntervalEvent):
|
|
"""
|
|
This event lets the button flash at regular intervals.
|
|
"""
|
|
def __init__(self):
|
|
"""
|
|
A custom init method also storing the source object.
|
|
|
|
"""
|
|
super(EventBlinkButton, self).__init__()
|
|
self.name = 'event_blink_red_button'
|
|
#how often to blink, in seconds
|
|
self.interval = 30
|
|
#the description is seen when you run @ps in-game.
|
|
self.description = "Blink red buttons regularly."
|
|
|
|
def event_function(self):
|
|
"""
|
|
This stub function is automatically fired every self.interval seconds.
|
|
|
|
In this case we do a search for all objects inheriting from the correct
|
|
parent and call a function on them.
|
|
"""
|
|
#find all objects inheriting from red_button (parents are per definition
|
|
#stored with the gamesrc/parent/ drawer as a base)
|
|
parent = 'examples.red_button'
|
|
buttons = Object.objects.global_object_script_parent_search(parent)
|
|
|
|
for b in buttons:
|
|
try:
|
|
b.scriptlink.blink()
|
|
except AttributeError:
|
|
#button has no blink() method. Just ignore.
|
|
pass
|
|
except:
|
|
#show other tracebacks to log and owner of object.
|
|
#This is important, we must handle these exceptions gracefully!
|
|
b.get_owner().emit_to(sys.exc_info()[1])
|
|
log_errmsg(sys.exc_info()[1])
|
|
|
|
#create and add the event to the global handler
|
|
blink_event = EventBlinkButton()
|
|
add_event(blink_event)
|