User Tools

Site Tools


cfpython:cfpython

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
cfpython:cfpython [2018/03/30 09:05]
karl [How do I hook a script to an object?] Fix internal link
cfpython:cfpython [2021/07/27 14:47] (current)
partmedia Document Player.Transport
Line 46: Line 46:
  
 ===== How do I hook a script to a global event? ===== ===== How do I hook a script to a global event? =====
-Create a script, and put it in the ''/​python/​events/​xxx''​ subdirectory or the ''​maps''​ directory, where ''​xxx''​ is the event'​s name in lowercase (create the directory if it doesn'​t exist). Available events are listed [[server_plugin#​Hooking to global events|on the server_plugin page]].+Create a script, and put it in the ''/​python/​events/​xxx''​ subdirectory or the ''​maps''​ directory, where ''​xxx''​ is the event'​s name in lowercase (create the directory if it doesn'​t exist). Available events are listed [[:server_plugin#​Hooking to global events|on the server_plugin page]].
 In addition, there is a special event, ''​init'',​ which is called just after the plugin has been loaded. It behaves like other events in every aspect, but is called only once when the plugin finished loading. In addition, there is a special event, ''​init'',​ which is called just after the plugin has been loaded. It behaves like other events in every aspect, but is called only once when the plugin finished loading.
  
Line 166: Line 166:
 ===== Methods ===== ===== Methods =====
 ==== WhoAmI ==== ==== WhoAmI ====
-Returns the ''​Crossfire.Object''​ from which the event being handled was raised, corresponds to the ''​[[server_plugin#​Hooking to an object-specific event|op]]''​ parameter of the event. Can be ''​None''​. For a map event, this is a ''​Crossfire.Map''​+Returns the ''​Crossfire.Object''​ from which the event being handled was raised, corresponds to the ''​[[server_plugin#​Hooking to an object-specific event|op]]''​ parameter of the event. Can be ''​None''​. For a map event, this is a ''​Crossfire.Map''​.  For example, if the script was activated by a player applying an item, then WhoAmI points to the item.
  
 ==== WhoIsActivator ==== ==== WhoIsActivator ====
-Returns the ''​Crossfire.Object''​ having caused the event being handled, corresponds to the ''​[[server_plugin#​Hooking to an object-specific event|activator]]''​ parameter of the event. Can be ''​None''​.+Returns the ''​Crossfire.Object''​ having caused the event being handled, corresponds to the ''​[[server_plugin#​Hooking to an object-specific event|activator]]''​ parameter of the event. Can be ''​None''​. ​ For example, if the script was activated by a player applying an item, then WhoIsActivator points to the player. 
 === Examples === === Examples ===
   * [[cfpython#​Move a player onto a map]]   * [[cfpython#​Move a player onto a map]]
Line 194: Line 195:
  
 Sets the value the plugin will return to the server when the script exits. Value and effect depend on the event being handled. Sets the value the plugin will return to the server when the script exits. Value and effect depend on the event being handled.
 +
 +For "​apply"​ events, ''​Crossfire.SetReturnValue(0)''​ will cause both the script to run and the item to be applied. ​ ''​Crossfire.SetReturnValue(1)''​ will instead cause only the script to run - the apply to the item will be intercepted. ​ For example, if a script is attached to a carrot, then ''​0''​ will run the script and eat the carrot, and ''​1''​ will run the script without eating the carrot.
 ==== PluginVersion ==== ==== PluginVersion ====
 Returns an integer representing the Python plugin version. Returns an integer representing the Python plugin version.
Line 259: Line 262:
  
 ==== ReadyMap ==== ==== ReadyMap ====
-Loads specified map, and returns a ''​Crossfire.Map''​ object wrapping it. Will return ''​None''​ if map couldn'​t be found.+Loads specified map, and returns a ''​Crossfire.Map''​ object wrapping it. Will return ''​None''​ if map couldn'​t be found.  Should be used before handling that map, including when you want to teleport something.
  
 Parameter: Parameter:
Line 530: Line 533:
   * **NoSave**: ''​Boolean'',​ if set this Object will never be saved to disk, even if map is temporary swapped out   * **NoSave**: ''​Boolean'',​ if set this Object will never be saved to disk, even if map is temporary swapped out
   * Exists (special meaning, False if cf object has been freed from memory, True otherwise)   * Exists (special meaning, False if cf object has been freed from memory, True otherwise)
-  * Env: ''​[[cfpython#​Crossfire.Object methods and attributes|Crossfire.Object]]''​. Can be ''​None''​.+  * Env: ''​[[cfpython#​Crossfire.Object methods and attributes|Crossfire.Object]]''​. ​Points to the object that contains this object. ​ For example, if a player is holding a sword, that sword'​s Env is the player.  ​Can be ''​None''​.
   * **MoveType**   * **MoveType**
   * **MoveBlock**   * **MoveBlock**
Line 804: Line 807:
  
 ==== ReadKey ==== ==== ReadKey ====
-Reads key associated to value.+Reads key associated to value.  See ''​[[cfpython#​writekey|Crossfire.WriteKey]]''​ for an example of use.
  
 Arguments: Arguments:
Line 860: Line 863:
  
 ==== WriteKey ==== ==== WriteKey ====
-Inserts specified key/value in the object.+Inserts specified key/value in the object.  If the object is persistent (such as a player, or an item with the unique attribute set to 1), then the key will persist between server restarts.
  
 Arguments: Arguments:
Line 869: Line 872:
  
 **Note**: if you're not sure whether the key exists in the object, you must use ''​1''​ for the last argument, else the key will not be created if it doesn'​t exist. **Note**: if you're not sure whether the key exists in the object, you must use ''​1''​ for the last argument, else the key will not be created if it doesn'​t exist.
 +
 +**Example**:​ <​code>​Crossfire.WhoAmI.WriteKey('​charged_status',​ '​overcharged',​ 1)</​code>​
 +<​code>​Crossfire.WhoAmI.ReadKey('​charged_status'​)</​code>​
 +This example first sets a key on the WhoAmI object, and then gets that key (returning the string '​overcharged'​).
  
 ===== Map ===== ===== Map =====
Line 909: Line 916:
  
 Arguments: Arguments:
-  * ''​String'',​ name of object to create +  * ''​String'', ​arch name of object to create 
-  * ''​Integer'',​ ''​x''​ and ''​y'',​ coordinates+  * ''​Tuple'', ​containing an ''​x''​ ''​Integer''​ and ''​y''​ ''​Integer'', ​as coordinates
  
-Equivalent of calling ''​Crossfire.CreateObjectByName()''​ (creates an item from archetype or name) and inserting it in the map at the specified location+Equivalent of calling ''​Crossfire.CreateObjectByName()''​ (creates an item from archetype or name) and inserting it in the map at the specified location.   
 + 
 +Example of format: 
 +<​code>​examplemap.CreateObject('​tree5',​ (3, 8))</​code>​
  
 ==== Check ==== ==== Check ====
 Arguments: Arguments:
-  * ''​String'',​ name of object to check for. Should be a raw name, without the bonuses and title and such. +  * ''​String'',​ name of object to check for. Should be a raw arch name, without the bonuses and title and such. 
-  * ''​Integer'', ​optional ​''​x''​ and ''​y''​ coordinates+  * ''​Tuple'', ​containing an ''​x''​ ''​Integer''​ and ''​y'' ​''​Integer'',​ as coordinates
  
 Return: Return:
-  * the first object at the specified location matching specified name+  * the first object at the specified location matching specified ​arch name 
 + 
 +Example of format: 
 +<​code>​examplemap.Check('​tree5',​ (3, 8))</​code>​
  
 ==== Next ==== ==== Next ====
Line 970: Line 983:
   * **MarkedItem**:​ ''​Crossfire.Object'',​ item the player has marked.   * **MarkedItem**:​ ''​Crossfire.Object'',​ item the player has marked.
   * **Party**: ''​Crossfire.Party'',​ party in which the player is. Note that changing it bypasses a potential party'​s password.   * **Party**: ''​Crossfire.Party'',​ party in which the player is. Note that changing it bypasses a potential party'​s password.
 +  * **Transport**:​ ''​Crossfire.Object''​ read-only field for the transport object that the player is currently controlling or aboard
  
 ==== CanPay ==== ==== CanPay ====
cfpython/cfpython.1522418736.txt.gz · Last modified: 2018/03/30 09:05 by karl