# evennia.scripts.models

Scripts are entities that perform some sort of action, either only once or repeatedly. They can be directly linked to a particular Evennia Object or be stand-alonw (in the latter case it is considered a ‘global’ script). Scripts can indicate both actions related to the game world as well as pure behind-the-scenes events and effects. Everything that has a time component in the game (i.e. is not hard-coded at startup or directly created/controlled by players) is handled by Scripts.

Scripts have to check for themselves that they should be applied at a particular moment of time; this is handled by the is_valid() hook. Scripts can also implement at_start and at_end hooks for preparing and cleaning whatever effect they have had on the game object.

Common examples of uses of Scripts:

- Load the default cmdset to the account object’s cmdhandler when logging in.

- Switch to a different state, such as entering a text editor, start combat or enter a dark room.

- Merge a new cmdset with the default one for changing which commands are available at a particular time

- Give the account/object a time-limited bonus/effect

class `evennia.scripts.models.``ScriptDB`(*args, **kwargs)

  Bases: `evennia.typeclasses.models.TypedObject`

  The Script database representation.

  The TypedObject supplies the following (inherited) properties:

    key - main name name - alias for key typeclass_path - the path to the decorating typeclass typeclass - auto-linked typeclass date_created - time stamp of object creation permissions - perm strings dbref - #id of object db - persistent attribute storage ndb - non-persistent attribute storage

  The ScriptDB adds the following properties:

    desc - optional description of script obj - the object the script is linked to, if any account - the account the script is linked to (exclusive with obj) interval - how often script should run start_delay - if the script should start repeating right away repeats - how many times the script should repeat persistent - if script should survive a server reboot is_active - bool if script is currently running

  `db_desc`

    A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

  `db_obj`

    Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

    In the example:

        class Child(Model):
            parent = ForeignKey(Parent, related_name='children')

    **Child.parent** is a **ForwardManyToOneDescriptor** instance.

  `db_account`

    Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

    In the example:

        class Child(Model):
            parent = ForeignKey(Parent, related_name='children')

    **Child.parent** is a **ForwardManyToOneDescriptor** instance.

  `db_interval`

    A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

  `db_start_delay`

    A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

  `db_repeats`

    A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

  `db_persistent`

    A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

  `db_is_active`

    A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

  `objects` = <evennia.scripts.manager.ScriptDBManager object>
  property `obj`

    Property wrapper that homogenizes access to either the db_account or db_obj field, using the same object property name.

  property `object`

    Property wrapper that homogenizes access to either the db_account or db_obj field, using the same object property name.

  exception `DoesNotExist`

    Bases: `django.core.exceptions.ObjectDoesNotExist`

  exception `MultipleObjectsReturned`

    Bases: `django.core.exceptions.MultipleObjectsReturned`

  property `account`

    A wrapper for getting database field db_account.

  `db_account_id`
  `db_attributes`

    Accessor to the related objects manager on the forward and reverse sides of a many-to-many relation.

    In the example:

        class Pizza(Model):
            toppings = ManyToManyField(Topping, related_name='pizzas')

    **Pizza.toppings** and **Topping.pizzas** are **ManyToManyDescriptor** instances.

    Most of the implementation is delegated to a dynamically defined manager class built by **create_forward_many_to_many_manager()** defined below.

  `db_date_created`

    A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

  `db_key`

    A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

  `db_lock_storage`

    A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

  `db_obj_id`
  `db_tags`

    Accessor to the related objects manager on the forward and reverse sides of a many-to-many relation.

    In the example:

        class Pizza(Model):
            toppings = ManyToManyField(Topping, related_name='pizzas')

    **Pizza.toppings** and **Topping.pizzas** are **ManyToManyDescriptor** instances.

    Most of the implementation is delegated to a dynamically defined manager class built by **create_forward_many_to_many_manager()** defined below.

  `db_typeclass_path`

    A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

  property `desc`

    A wrapper for getting database field db_desc.

  `get_next_by_db_date_created`(*, field=<django.db.models.fields.DateTimeField: db_date_created>, is_next=True, **kwargs)
  `get_previous_by_db_date_created`(*, field=<django.db.models.fields.DateTimeField: db_date_created>, is_next=False, **kwargs)
  `id`

    A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

  property `interval`

    A wrapper for getting database field db_interval.

  property `is_active`

    A wrapper for getting database field db_is_active.

  `path` = 'evennia.scripts.models.ScriptDB'
  property `persistent`

    A wrapper for getting database field db_persistent.

  `receiver_script_set`

    Accessor to the related objects manager on the forward and reverse sides of a many-to-many relation.

    In the example:

        class Pizza(Model):
            toppings = ManyToManyField(Topping, related_name='pizzas')

    **Pizza.toppings** and **Topping.pizzas** are **ManyToManyDescriptor** instances.

    Most of the implementation is delegated to a dynamically defined manager class built by **create_forward_many_to_many_manager()** defined below.

  property `repeats`

    A wrapper for getting database field db_repeats.

  `sender_script_set`

    Accessor to the related objects manager on the forward and reverse sides of a many-to-many relation.

    In the example:

        class Pizza(Model):
            toppings = ManyToManyField(Topping, related_name='pizzas')

    **Pizza.toppings** and **Topping.pizzas** are **ManyToManyDescriptor** instances.

    Most of the implementation is delegated to a dynamically defined manager class built by **create_forward_many_to_many_manager()** defined below.

  property `start_delay`

    A wrapper for getting database field db_start_delay.

  `typename` = 'SharedMemoryModelBase'