Added example bodyfunctions script back to contrib. Fixed the default lookup-paths of scripts.
This commit is contained in:
parent
fa8e8b7543
commit
a34312245a
3 changed files with 77 additions and 9 deletions
63
evennia/contrib/tutorial_examples/bodyfunctions.py
Normal file
63
evennia/contrib/tutorial_examples/bodyfunctions.py
Normal file
|
|
@ -0,0 +1,63 @@
|
||||||
|
"""
|
||||||
|
Example script for testing. This adds a simple timer that
|
||||||
|
has your character make observations and noices at irregular
|
||||||
|
intervals.
|
||||||
|
|
||||||
|
To test, use
|
||||||
|
@script me = examples.bodyfunctions.BodyFunctions
|
||||||
|
|
||||||
|
The script will only send messages to the object it
|
||||||
|
is stored on, so make sure to put it on yourself
|
||||||
|
or you won't see any messages!
|
||||||
|
|
||||||
|
"""
|
||||||
|
import random
|
||||||
|
from evennia import Script
|
||||||
|
|
||||||
|
class BodyFunctions(Script):
|
||||||
|
"""
|
||||||
|
This class defines the script itself
|
||||||
|
"""
|
||||||
|
|
||||||
|
def at_script_creation(self):
|
||||||
|
self.key = "bodyfunction"
|
||||||
|
self.desc = "Adds various timed events to a character."
|
||||||
|
self.interval = 20 # seconds
|
||||||
|
#self.repeats = 5 # repeat only a certain number of times
|
||||||
|
self.start_delay = True # wait self.interval until first call
|
||||||
|
#self.persistent = True
|
||||||
|
|
||||||
|
def at_repeat(self):
|
||||||
|
"""
|
||||||
|
This gets called every self.interval seconds. We make
|
||||||
|
a random check here so as to only return 33% of the time.
|
||||||
|
"""
|
||||||
|
|
||||||
|
if random.random() < 0.66:
|
||||||
|
# no message this time
|
||||||
|
return
|
||||||
|
rand = random.random()
|
||||||
|
# return a random message
|
||||||
|
if rand < 0.1:
|
||||||
|
string = "You tap your foot, looking around."
|
||||||
|
elif rand < 0.2:
|
||||||
|
string = "You have an itch. Hard to reach too."
|
||||||
|
elif rand < 0.3:
|
||||||
|
string = "You think you hear someone behind you. ... but when you look there's noone there."
|
||||||
|
elif rand < 0.4:
|
||||||
|
string = "You inspect your fingernails. Nothing to report."
|
||||||
|
elif rand < 0.5:
|
||||||
|
string = "You cough discreetly into your hand."
|
||||||
|
elif rand < 0.6:
|
||||||
|
string = "You scratch your head, looking around."
|
||||||
|
elif rand < 0.7:
|
||||||
|
string = "You blink, forgetting what it was you were going to do."
|
||||||
|
elif rand < 0.8:
|
||||||
|
string = "You feel lonely all of a sudden."
|
||||||
|
elif rand < 0.9:
|
||||||
|
string = "You get a great idea. Of course you won't tell anyone."
|
||||||
|
else:
|
||||||
|
string = "You suddenly realize how much you love Evennia!"
|
||||||
|
|
||||||
|
# echo the message to the object
|
||||||
|
self.obj.msg(string)
|
||||||
|
|
@ -277,10 +277,10 @@ SERVER_SESSION_CLASS = "evennia.server.serversession.ServerSession"
|
||||||
# Base paths for typeclassed object classes. These paths must be
|
# Base paths for typeclassed object classes. These paths must be
|
||||||
# defined relative evennia's root directory. They will be searched in
|
# defined relative evennia's root directory. They will be searched in
|
||||||
# order to find relative typeclass paths.
|
# order to find relative typeclass paths.
|
||||||
OBJECT_TYPECLASS_PATHS = ["typeclasses", "contrib"]
|
OBJECT_TYPECLASS_PATHS = ["typeclasses", "evennia.contrib", "evennia.contrib.tutorial_examples"]
|
||||||
SCRIPT_TYPECLASS_PATHS = ["typeclasses" "contrib"]
|
SCRIPT_TYPECLASS_PATHS = ["typeclasses" "evennia.contrib", "evennia.contrib.tutorial_examples"]
|
||||||
PLAYER_TYPECLASS_PATHS = ["typeclasses", "contrib"]
|
PLAYER_TYPECLASS_PATHS = ["typeclasses", "evennia.contrib", "evennia.contrib.tutorial_examples"]
|
||||||
CHANNEL_TYPECLASS_PATHS = ["typeclasses", "contrib"]
|
CHANNEL_TYPECLASS_PATHS = ["typeclasses", "evennia.contrib", "evennia.contrib.tutorial_examples"]
|
||||||
|
|
||||||
# Typeclass for player objects (linked to a character) (fallback)
|
# Typeclass for player objects (linked to a character) (fallback)
|
||||||
BASE_PLAYER_TYPECLASS = "typeclasses.players.Player"
|
BASE_PLAYER_TYPECLASS = "typeclasses.players.Player"
|
||||||
|
|
@ -320,7 +320,7 @@ TYPECLASS_AGGRESSIVE_CACHE = True
|
||||||
|
|
||||||
# Python path to a directory to be searched for batch scripts
|
# Python path to a directory to be searched for batch scripts
|
||||||
# for the batch processors (.ev and/or .py files).
|
# for the batch processors (.ev and/or .py files).
|
||||||
BASE_BATCHPROCESS_PATHS = ['world', 'contrib']
|
BASE_BATCHPROCESS_PATHS = ['world', 'evennia.contrib']
|
||||||
|
|
||||||
######################################################################
|
######################################################################
|
||||||
# Game Time setup
|
# Game Time setup
|
||||||
|
|
|
||||||
|
|
@ -936,12 +936,12 @@ def class_from_module(path, defaultpaths=None):
|
||||||
if "." in path:
|
if "." in path:
|
||||||
testpath, clsname = testpath.rsplit(".", 1)
|
testpath, clsname = testpath.rsplit(".", 1)
|
||||||
else:
|
else:
|
||||||
testpath, clsname = ".", testpath
|
raise ImportError("the path '%s' is not on the form modulepath.Classname." % path)
|
||||||
try:
|
try:
|
||||||
mod = import_module(testpath)
|
mod = import_module(testpath, package="evennia")
|
||||||
except ImportError, ex:
|
except ImportError, ex:
|
||||||
# normally this is due to a not-found property
|
# normally this is due to a not-found property
|
||||||
if not str(ex).startswith("No module named"):
|
if not str(ex).startswith("No module named"):# %s" % path):
|
||||||
exc = sys.exc_info()
|
exc = sys.exc_info()
|
||||||
raise exc[1], None, exc[2]
|
raise exc[1], None, exc[2]
|
||||||
continue
|
continue
|
||||||
|
|
@ -953,7 +953,12 @@ def class_from_module(path, defaultpaths=None):
|
||||||
exc = sys.exc_info()
|
exc = sys.exc_info()
|
||||||
raise exc[1], None, exc[2]
|
raise exc[1], None, exc[2]
|
||||||
if not cls:
|
if not cls:
|
||||||
raise ImportError("Could not load typeclass '%s'." % path)
|
err = "Could not load typeclass '%s'" % path
|
||||||
|
if defaultpaths:
|
||||||
|
err += " (paths searched: %s)" % ", ".join(paths)
|
||||||
|
else:
|
||||||
|
err += "."
|
||||||
|
raise ImportError(err)
|
||||||
return cls
|
return cls
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue