cfpython
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
cfpython [2013/07/23 14:28] – external edit 127.0.0.1 | cfpython [2018/03/30 09:01] (current) – moved to :cfpython: namespace karl | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | (Note: It would be nice if there were more code examples on this page. | ||
- | For instance bla.WriteKey(" | ||
- | Python plugin is a [[server plugin]] able to run Python scripts that manipulate Crossfire items, monsters, players, maps, ... | ||
- | |||
- | The latest version, 2.0, is a major rewrite which introduces Python objects to represent maps, Crossfire objects and players. The hooking system also changed. | ||
- | |||
- | Note that this guide doesn' | ||
- | |||
- | Also, advanced functions can require some knowledge of Crossfire' | ||
- | |||
- | |||
- | Old plugin' | ||
- | |||
- | **Important note:** the API, and other parts, are valid for code's '' | ||
- | |||
- | |||
- | |||
- | ====== General information ====== | ||
- | The plugin has access to all built-in functions of Python, and its regular libraries. Python version being used depends on the platform the server was built, but should be 2.3 or higher. FIXME {is that always true?} | ||
- | |||
- | Using a library not part of Python' | ||
- | |||
- | Scripts execute in their own context, and their state information is not kept between runs. There are functions to persist data, or share between scripts. Note that data persisted through those functions will not survive a server restart. | ||
- | |||
- | Scripts should import the '' | ||
- | |||
- | Calling Crossfire functions with invalid arguments will result in a Python exception being raised. A function failure will also result in an exception. | ||
- | |||
- | Scripts will have the same access rights as the server itself. It may be able to write to some directories, | ||
- | |||
- | Data that should survive a server restart should be persisted in the '' | ||
- | |||
- | Scripts for server releases after 9 November 2007 should prefer the use of new [[cfpython# | ||
- | |||
- | ===== How do I hook a script to an object? ===== | ||
- | Python plugin is a [[server plugin]], thus you need to insert in this object one of the // | ||
- | * **title**: should be //Python// to call the Python plugin. | ||
- | * **slaying**: | ||
- | |||
- | A script can then use '' | ||
- | |||
- | ===== How do I hook a script to a global event? ===== | ||
- | Create a script, and put it in the ''/ | ||
- | In addition, there is a special event, '' | ||
- | |||
- | ===== How do I register a custom command? ===== | ||
- | Check '' | ||
- | |||
- | ===== Return value ===== | ||
- | The return value of the script can be manipulated through the '' | ||
- | |||
- | ====== Scripts part of Crossfire default maps ====== | ||
- | Those Python scripts reside in the [[http:// | ||
- | FIXME {describe existing ones} | ||
- | |||
- | ===== Dialog Helper ===== | ||
- | Script location: ''/ | ||
- | |||
- | This script provides two utility classes a map maker can use to easily create complex dialogs. | ||
- | Go [[cfdialog# | ||
- | |||
- | ===== Death message ===== | ||
- | Script location: ''/ | ||
- | |||
- | This script makes the monster/ | ||
- | |||
- | Message is specified in event object' | ||
- | |||
- | ===== Greeting message ===== | ||
- | Script location: ''/ | ||
- | |||
- | This script makes the monster/ | ||
- | |||
- | Message is specified in event object' | ||
- | |||
- | |||
- | ===== Experience rewarder ===== | ||
- | Script location: ''/ | ||
- | |||
- | This script will give experience to the " | ||
- | |||
- | Options are specified in the event object' | ||
- | |||
- | A key/value will be used to store in the player if she activated the item already. | ||
- | |||
- | Available options are: | ||
- | * exp: experience to gain | ||
- | * skill: skill to add experience to. Can be empty, in which case exp is given to the general exp only | ||
- | * wc: what to do when the player doesn' | ||
- | * 0: give the player the skill | ||
- | * 1: give player exp to total, no skill | ||
- | * 2: player gets nothing | ||
- | * race: if set, the player can only use once this item. | ||
- | |||
- | ===== Time of the day ===== | ||
- | Scripts location: ''/ | ||
- | |||
- | Those scripts add behaviour to items based on time of the day. Want to open doors at specific time, make werewolfes, deactivate a magic_mouth during the Season of Winter? Those scripts are ready to use. See [[cfpython: | ||
- | |||
- | |||
- | ===== Hall of fame ===== | ||
- | Script location: ''/ | ||
- | |||
- | This script is intended to be bound to event objects, generally the apply one. | ||
- | |||
- | If the item this script is bound to is a SIGN, then it will display its list of players, preceded by the own item's message (as header). | ||
- | |||
- | For any other item, the player is added to the list, with her title. If the event object itself has a message, it will be displayed to the player if she is added to the list. | ||
- | |||
- | The script' | ||
- | |||
- | ===== Quest support scripts ===== | ||
- | Scripts location: ''/ | ||
- | |||
- | Those scripts are intended to help write quests. See [[: | ||
- | |||
- | ====== Crossfire module ====== | ||
- | |||
- | To use the crossfire module, add to your python script: | ||
- | <code python> | ||
- | import Crossfire | ||
- | </ | ||
- | |||
- | |||
- | The following functions and objects are available to all scripts using the Crossfire module through '' | ||
- | |||
- | **Convention: | ||
- | |||
- | |||
- | ===== Constants ===== | ||
- | Constants are available to wrap values used in Crossfire code like object types, movements, ... | ||
- | They are available through '' | ||
- | |||
- | For each constant group '' | ||
- | |||
- | The following constant types exist: | ||
- | * '' | ||
- | * '' | ||
- | * '' | ||
- | * '' | ||
- | * '' | ||
- | * '' | ||
- | * '' | ||
- | * '' | ||
- | * '' | ||
- | * '' | ||
- | |||
- | |||
- | '' | ||
- | |||
- | {FIXME} do a nice table, with link to values? | ||
- | |||
- | Example: | ||
- | < | ||
- | whoami.Say(" | ||
- | </ | ||
- | will write < | ||
- | |||
- | **Warning**: | ||
- | |||
- | ===== Methods ===== | ||
- | ==== WhoAmI ==== | ||
- | Returns the '' | ||
- | |||
- | ==== WhoIsActivator ==== | ||
- | Returns the '' | ||
- | === Examples === | ||
- | * [[cfpython# | ||
- | |||
- | ==== WhoIsOther ==== | ||
- | Returns the '' | ||
- | ==== WhatIsMessage ==== | ||
- | Returns the '' | ||
- | ==== ScriptName ==== | ||
- | Returns the absolute path of the currently executing script. | ||
- | ==== ScriptParameters ==== | ||
- | This '' | ||
- | * for a global event, the name of the event ('' | ||
- | * for an event hooked to an object, the '' | ||
- | * for a custom command, the parameters the player sent | ||
- | ==== WhatIsEvent ==== | ||
- | '' | ||
- | |||
- | ==== GetReturnValue ==== | ||
- | Return current return value. | ||
- | ==== SetReturnValue ==== | ||
- | Parameters: | ||
- | * return value (integer) | ||
- | |||
- | Sets the value the plugin will return to the server when the script exits. Value and effect depend on the event being handled. | ||
- | ==== PluginVersion ==== | ||
- | Returns an integer representing the Python plugin version. | ||
- | ==== MapDirectory ==== | ||
- | Returns the system directory containing the maps. Note that it is relative to the '' | ||
- | ==== UniqueDirectory ==== | ||
- | Returns the system directory where unique items and maps are stored. | ||
- | ==== TempDirectory ==== | ||
- | Returns the system directory where temporary files are stored. | ||
- | ==== ConfigDirectory ==== | ||
- | Returns the system directory containing configuration files. | ||
- | ==== LocalDirectory ==== | ||
- | Returns the system directory containing read/write files. | ||
- | ==== PlayerDirectory ==== | ||
- | Returns the system directory containing player files. | ||
- | ==== DataDirectory ==== | ||
- | Returns the system directory containing read-only data. | ||
- | |||
- | ==== FindPlayer ==== | ||
- | Parameter: | ||
- | * player name (string) | ||
- | |||
- | Returns a '' | ||
- | ==== GetArchetypes ==== | ||
- | Returns a Python '' | ||
- | ==== GetMaps ==== | ||
- | Returns a Python '' | ||
- | ==== GetParties ==== | ||
- | Returns a Python '' | ||
- | |||
- | ==== GetRegions ==== | ||
- | Returns a Python '' | ||
- | ==== GetFriendlyList ==== | ||
- | Returns a '' | ||
- | ==== GetPlayers ==== | ||
- | Returns a '' | ||
- | ==== GetTime ==== | ||
- | Returns a Python '' | ||
- | - year | ||
- | - month | ||
- | - day | ||
- | - hour | ||
- | - minute | ||
- | - day of week | ||
- | - week of month | ||
- | - season | ||
- | ==== MapHasBeenLoaded ==== | ||
- | Parameter: | ||
- | * map path ('' | ||
- | |||
- | Returns the '' | ||
- | |||
- | ==== FindFace ==== | ||
- | Parameter: | ||
- | * face name ('' | ||
- | |||
- | Returns the number of the specified face, 0 if it doesn' | ||
- | |||
- | ==== FindAnimation ==== | ||
- | Parameter: | ||
- | * animation name ('' | ||
- | |||
- | Returns the number of the specified animation, 0 if it doesn' | ||
- | |||
- | |||
- | ==== ReadyMap ==== | ||
- | Loads specified map, and returns a '' | ||
- | |||
- | Parameter: | ||
- | * '' | ||
- | * '' | ||
- | * 2: map is a player' | ||
- | * 16: map is reloaded anyway, even if it is already loaded | ||
- | === Examples === | ||
- | * [[cfpython# | ||
- | |||
- | ==== CreateObject ==== | ||
- | Returns an empty object which can then be manipulated and inserted in a map. | ||
- | |||
- | ==== CreateObjectByName ==== | ||
- | Parameters: | ||
- | * object or archetype name ('' | ||
- | |||
- | Returns object with specified archetype or object name, or '' | ||
- | ==== CreateMap ==== | ||
- | Parameters: | ||
- | * map width ('' | ||
- | * map height ('' | ||
- | |||
- | Returns an empty map of specified dimensions. Unless map is removed immediately, | ||
- | |||
- | |||
- | ==== Log ==== | ||
- | Parameters: | ||
- | * level (Crossfire.LogError, | ||
- | * message (string) | ||
- | |||
- | Use the server logging facilities to output script messages in server console. This is the **recommended** method, instead of using the | ||
- | python build-in " | ||
- | have access to the error level, mentioning to admin serious troubles. | ||
- | |||
- | Example: | ||
- | < | ||
- | ==== RegisterCommand ==== | ||
- | Parameters: | ||
- | * command name (string) | ||
- | * script (string) | ||
- | * speed (decimal, must be positive or 0) | ||
- | |||
- | Registers a server command which will be mapped to specified script. See [[server plugin# | ||
- | |||
- | The script path is relative to the '' | ||
- | When the command is called, the following methods will provide information: | ||
- | * '' | ||
- | * '' | ||
- | * '' | ||
- | ==== RegisterGlobalEvent ==== | ||
- | Parameters: | ||
- | * event code ('' | ||
- | |||
- | This instructs the server to call the Python plugin for all events of specified type. Python will then call scripts in the ''/ | ||
- | |||
- | This function should not be used except in special circumstances, | ||
- | ==== UnregisterGlobalEvent ==== | ||
- | Parameters: | ||
- | * event code ('' | ||
- | |||
- | This instructs the server to stop calling the Python plugin for all events of specified type. | ||
- | |||
- | This function should not be used, except in special circumstances, | ||
- | ==== DestroyTimer ==== | ||
- | Removes a timer created through a call to '' | ||
- | |||
- | Arguments: | ||
- | * '' | ||
- | |||
- | Returns: | ||
- | * 0: no error. | ||
- | * -1: invalid timer identifier. | ||
- | ==== GetPrivateDictionary ==== | ||
- | Returns a Python '' | ||
- | |||
- | Note that data will be lost in case of server restart. | ||
- | ==== GetSharedDictionary ==== | ||
- | Returns a Python '' | ||
- | |||
- | Note that data will be lost in case of server restart. | ||
- | |||
- | ==== MatchString ==== | ||
- | Parameters: | ||
- | * string to be searched | ||
- | * pattern to search for | ||
- | |||
- | Returns '' | ||
- | |||
- | Pattern can be a regular expression FIXME specifications | ||
- | |||
- | ==== AddReply ==== | ||
- | Parameters: | ||
- | * string that is the word the player can say | ||
- | * string that is the description of the choice | ||
- | |||
- | This method can only be called in a EVENT_SAY context. | ||
- | |||
- | Will generate an error if too many replies defined or not in an EVENT_SAY context. | ||
- | |||
- | ==== SetPlayerMessage ==== | ||
- | Parameters: | ||
- | * string that is what the player will be seen as saying | ||
- | * optional '' | ||
- | |||
- | This method can only be called in a EVENT_SAY context. | ||
- | |||
- | ==== NPCSay ==== | ||
- | Parameters: | ||
- | * '' | ||
- | * string that is the message to say | ||
- | |||
- | This method can only be called in a EVENT_SAY context. | ||
- | |||
- | Will add an NPC reply, that will be displayed to the player when the dialog processing ends. | ||
- | |||
- | Will generate an error if too many messages defined or not in an EVENT_SAY context. | ||
- | |||
- | ==== CostStringFromValue ==== | ||
- | (trunk only) | ||
- | |||
- | Parameters: | ||
- | * '' | ||
- | |||
- | Return value: formatted string describing the amount, with coin descriptions. | ||
- | |||
- | Will return " | ||
- | |||
- | ====== Crossfire module classes ===== | ||
- | All classes below are part of Crossfire module | ||
- | ===== Archetype ===== | ||
- | This represents an archetype, from which all objects are derived. | ||
- | Pointer to such item can be obtained through the '' | ||
- | |||
- | ==== Clone ==== | ||
- | A '' | ||
- | |||
- | ==== Head ==== | ||
- | archetype to which this archetype is linked. Will be '' | ||
- | |||
- | ==== Name ==== | ||
- | archetype' | ||
- | ==== Next ==== | ||
- | next archetype in the archetype list. Will be '' | ||
- | ==== More ==== | ||
- | next archetype linked to current archetype. Will be '' | ||
- | ==== NewObject() ==== | ||
- | Returns a '' | ||
- | |||
- | |||
- | |||
- | |||
- | |||
- | ===== Object ===== | ||
- | FIXME link to dev:objects 's fields? split flag & such info. Make a table with property / mapping to object / Python type | ||
- | |||
- | Properties in **bold** are read-write, others are read-only. Most properties are mapped to fields of the '' | ||
- | * **Name**: '' | ||
- | * **NamePl**: '' | ||
- | * **Title**: '' | ||
- | * **Race**: '' | ||
- | * **Map**: '' | ||
- | * **Cha**: charisma | ||
- | * **Con**: constitution | ||
- | * **Dex**: dexterity | ||
- | * **Int**: intelligence | ||
- | * **Pow**: power | ||
- | * **Str**: strength | ||
- | * **Wis**: wisdom | ||
- | * **HP**: hitpoints | ||
- | * **MaxHP**: maximum hitpoints | ||
- | * **SP**: spellpoints | ||
- | * **MaxSP**: maximum spellpoints | ||
- | * **Grace**: grace | ||
- | * **MaxGrace**: | ||
- | * **Food**: food | ||
- | * **AC**: armour class | ||
- | * **WC**: weapon class | ||
- | * **Dam** | ||
- | * Luck | ||
- | * **Exp** | ||
- | * PermExp | ||
- | * ExpMul | ||
- | * **Message**: | ||
- | * **Slaying**: | ||
- | * **Cursed**: '' | ||
- | * **Damned**: '' | ||
- | * **Weight**: '' | ||
- | * **WeightLimit**: | ||
- | * Above: '' | ||
- | * Below: '' | ||
- | * Inventory: '' | ||
- | * X: '' | ||
- | * Y: '' | ||
- | * **Direction**: | ||
- | * **Facing**: '' | ||
- | * **Unaggressive**: | ||
- | * **God**: '' | ||
- | * **Pickable**: | ||
- | * **Quantity**: | ||
- | * **Invisible**: | ||
- | * **Speed**: '' | ||
- | * **SpeedLeft**: | ||
- | * **LastSP**: '' | ||
- | * **LastGrace**: | ||
- | * Level: '' | ||
- | * **Face**: | ||
- | * on '' | ||
- | * on '' | ||
- | * **Anim**: | ||
- | * on '' | ||
- | * on '' | ||
- | * **AnimSpeed**: | ||
- | * **AttackType**: | ||
- | * BeenApplied: | ||
- | * Identified: '' | ||
- | * **Alive**: '' | ||
- | * DungeonMaster: | ||
- | * WasDungeonMaster: | ||
- | * **Applied**: | ||
- | * **Unpaid**: '' | ||
- | * Monster: '' | ||
- | * **Friendly**: | ||
- | * Generator: '' | ||
- | * Thrown: '' | ||
- | * **CanSeeInvisible**: | ||
- | * **Rollable**: | ||
- | * **Turnable**: | ||
- | * **UsedUp**: '' | ||
- | * Splitting: '' | ||
- | * **Blind**: '' | ||
- | * CanUseHorn: '' | ||
- | * CanUseRod: '' | ||
- | * CanUseSkill: | ||
- | * **KnownCursed**: | ||
- | * **Stealthy**: | ||
- | * **Confused**: | ||
- | * **Sleeping**: | ||
- | * **Lifesaver**: | ||
- | * Floor: '' | ||
- | * HasXRays: '' | ||
- | * CanUseRing: '' | ||
- | * CanUseBow: '' | ||
- | * CanUseWand: '' | ||
- | * **CanSeeInDark**: | ||
- | * **KnownMagical**: | ||
- | * CanUseWeapon: | ||
- | * CanUseArmour: | ||
- | * CanUseScroll: | ||
- | * CanCastSpell: | ||
- | * **ReflectSpells**: | ||
- | * **ReflectMissiles**: | ||
- | * **Unique**: '' | ||
- | * CanPickUp: '' | ||
- | * **RunAway**: | ||
- | * **Scared**: '' | ||
- | * **Undead**: '' | ||
- | * **BlocksView**: | ||
- | * **HitBack**: | ||
- | * **StandStill**: | ||
- | * **OnlyAttack**: | ||
- | * **MakeInvisible**: | ||
- | * Money: '' | ||
- | * Type: '' | ||
- | * Subtype: '' | ||
- | * **Value**: '' | ||
- | * ArchName: '' | ||
- | * Archetype: '' | ||
- | * OtherArchetype: | ||
- | * **NoSave**: '' | ||
- | * Exists (special meaning, False if cf object has been freed from memory, True otherwise) | ||
- | * Env: '' | ||
- | * **MoveType** | ||
- | * **MoveBlock** | ||
- | * **MoveAllow** | ||
- | * **MoveOn** | ||
- | * **MoveOff** | ||
- | * **MoveSlow** | ||
- | * MoveSlowPenalty | ||
- | * **Enemy**: '' | ||
- | * Count | ||
- | * **GodGiven**: | ||
- | * **IsPet**: if the object is on the friendly list or not | ||
- | * **AttackMovement** | ||
- | * **Duration** | ||
- | * **Skill** | ||
- | * **NoDamage**: | ||
- | * **RandomMovement**: | ||
- | * **GlowRadius**: | ||
- | * Container: '' | ||
- | |||
- | FIXME document all parameters. Link to relevant Crossfire function. Split in " | ||
- | |||
- | |||
- | ==== ActivateRune ==== | ||
- | Current object springs like a trap, hitting the victim. | ||
- | |||
- | Arguments: | ||
- | * '' | ||
- | |||
- | ==== AddExp ==== | ||
- | Adds or subtracts experience to current object. | ||
- | |||
- | Arguments: | ||
- | * '' | ||
- | * '' | ||
- | * '' | ||
- | * 0: give the player the skill | ||
- | * 1: give player exp to total, no skill | ||
- | * 2: player gets nothing | ||
- | * 3: used when removing exp | ||
- | |||
- | |||
- | ==== Apply ==== | ||
- | Current object applies specified object. The effect depends on the object being applied, which can be a potion, a trigger, ... | ||
- | |||
- | Arguments: | ||
- | * '' | ||
- | * flag FIXME meaning? | ||
- | |||
- | Return value: | ||
- | * 0: player or monster can't apply objects of that type | ||
- | * 1: has been applied, or there was an error applying the object | ||
- | * 2: objects of that type can't be applied if not in inventory | ||
- | |||
- | ==== Arrest ==== | ||
- | Player is jailed, put in a map defined based on the region. No information is sent to victim. | ||
- | |||
- | Return value: | ||
- | * 0: correctly jailed | ||
- | * -1: no jail could be found (region issue) | ||
- | * -2: failure loading jail, or player already on jail's destination | ||
- | * -3: object is not a player (Type == PLAYER) | ||
- | |||
- | ==== Cast ==== | ||
- | Current object casts a spell. | ||
- | |||
- | Arguments: | ||
- | * '' | ||
- | * '' | ||
- | * '' | ||
- | |||
- | Return value: | ||
- | * 0 if spell wasn't cast | ||
- | * non-zero value if spell was cast | ||
- | |||
- | Note that all checks related to spell-casting apply: enough sp/gp, knowing the skill, sufficient level, spot where magic isn't forbidden, ... | ||
- | |||
- | The spell needn' | ||
- | |||
- | ==== CastAbility ==== | ||
- | |||
- | Equivalent of '' | ||
- | |||
- | ==== ChangeAbil ==== | ||
- | Displays relevant messages about resistances and so on changes. | ||
- | |||
- | Arguments: | ||
- | * '' | ||
- | |||
- | ==== CheckArchInventory ==== | ||
- | Finds an object in current object' | ||
- | |||
- | Arguments: | ||
- | * '' | ||
- | |||
- | Will return the first object in inventory that has the specified name. Name must be the raw name, without bonuses and such. | ||
- | |||
- | |||
- | |||
- | |||
- | |||
- | ==== CheckInventory ==== | ||
- | Finds an object in current object' | ||
- | |||
- | Arguments: | ||
- | * '' | ||
- | |||
- | Will return the first object in inventory that has the specified archetype, or the specified name (partial matches are fine), or the specified " | ||
- | |||
- | |||
- | |||
- | |||
- | ==== CheckTrigger ==== | ||
- | Checks if current object should/can react to another object moving on it. | ||
- | |||
- | Arguments: | ||
- | * '' | ||
- | |||
- | Return value: | ||
- | * for TRIGGER_ALTAR objects, 1 if '' | ||
- | * TRIGGER: 1 if handle could be moved, 0 if not. | ||
- | * TRIGGER_BUTTON, | ||
- | |||
- | ==== CreateObject ==== | ||
- | Create an object inside the current object. | ||
- | |||
- | Arguments: | ||
- | * '' | ||
- | |||
- | Will create a new '' | ||
- | |||
- | ==== CreateTimer ==== | ||
- | Fires an '' | ||
- | |||
- | Arguments: | ||
- | * '' | ||
- | * '' | ||
- | * 1: delay is in seconds | ||
- | * 2: delay is in server cycles | ||
- | |||
- | Returns: timer identifier, which can be used to remove the timer through a call to '' | ||
- | |||
- | ==== Drop ==== | ||
- | Current object drops specified object, which will be put on the ground, or in a container, depending on applied containers. | ||
- | |||
- | Argument: | ||
- | * '' | ||
- | |||
- | ==== Event ==== | ||
- | Generates a '' | ||
- | |||
- | Arguments: | ||
- | * '' | ||
- | * '' | ||
- | * '' | ||
- | * '' | ||
- | |||
- | ==== Fix ==== | ||
- | Current object is reinitialized from its default values, values (ac, wc, Str, ...) are recomputed from items worn, in inventory, ... | ||
- | |||
- | ==== ForgetSpell ==== | ||
- | Player forgets a spell. | ||
- | |||
- | Arguments: | ||
- | * '' | ||
- | |||
- | Object forgetting should be a player. | ||
- | |||
- | ==== GetResist ==== | ||
- | Gets the value of a resistance to an attacktype. | ||
- | |||
- | Arguments: | ||
- | * '' | ||
- | |||
- | Return: '' | ||
- | |||
- | ==== InsertInto ==== | ||
- | Insert the current object into another object. | ||
- | |||
- | Arguments: | ||
- | * '' | ||
- | |||
- | Return: | ||
- | * '' | ||
- | |||
- | After using this function, you should not use the initial '' | ||
- | |||
- | ==== KnowSpell ==== | ||
- | Checks if current object knows a spell. | ||
- | |||
- | Arguments: | ||
- | * '' | ||
- | |||
- | Return: | ||
- | * '' | ||
- | |||
- | ==== LearnSpell ==== | ||
- | Make the current object learn a spell. | ||
- | |||
- | Arguments: | ||
- | * '' | ||
- | |||
- | There is no learning failure. Note that any spell can be learned this way. Player will receive the message that the spell was learnt correctly. | ||
- | |||
- | |||
- | ==== Move ==== | ||
- | Tries to move the object in a direction. | ||
- | |||
- | Arguments: | ||
- | * '' | ||
- | |||
- | Return: | ||
- | * 1 if object could move | ||
- | * 0 else | ||
- | |||
- | ==== MoveTo ==== | ||
- | Tries to move the object towards a specified destination. '' | ||
- | |||
- | Arguments: | ||
- | * '' | ||
- | |||
- | Return: | ||
- | * 2 if the object is blocked or no path to the goal | ||
- | * 1 if object could move towards the goal | ||
- | * 0 else | ||
- | |||
- | ==== OutOfMap ==== | ||
- | Check a position on the object' | ||
- | |||
- | Arguments: | ||
- | * '' | ||
- | |||
- | Return: | ||
- | * 1 if coordinates are in the map the current object is on | ||
- | * 0 else | ||
- | |||
- | Note that this function takes into account maps tiling. | ||
- | |||
- | ==== Pay ==== | ||
- | Buys an item. | ||
- | |||
- | Arguments: | ||
- | * '' | ||
- | |||
- | Return value: | ||
- | * 1 if item could be bought | ||
- | * 0 else | ||
- | |||
- | This function applies bargaining skill if applicable, and will handle shop-based price difference. Note that the object to buy doesn' | ||
- | |||
- | ==== PayAmount ==== | ||
- | Pays money. | ||
- | |||
- | Arguments: | ||
- | * '' | ||
- | |||
- | Return: | ||
- | * 1 if object could pay specified amount | ||
- | * 0 else | ||
- | |||
- | ==== QueryCost ==== | ||
- | Finds the price of an object. | ||
- | |||
- | Arguments: | ||
- | * '' | ||
- | * '' | ||
- | |||
- | Return value: | ||
- | * price of the item | ||
- | |||
- | ==== QueryName ==== | ||
- | Return: '' | ||
- | |||
- | ==== ReadKey ==== | ||
- | Reads key associated to value. | ||
- | |||
- | Arguments: | ||
- | * '' | ||
- | |||
- | Return: '' | ||
- | |||
- | ==== Remove ==== | ||
- | Destroys current object, which then becomes invalid. | ||
- | |||
- | ==== Reposition ==== | ||
- | Moves current object to specified position on its current map. | ||
- | |||
- | Arguments: | ||
- | * '' | ||
- | |||
- | ==== Say ==== | ||
- | Current object says something in current map. If in a dialog context (reacting to a SAY event), the message will be queued to be displayed after the player actually says something, to enable changing her reply. If not in a dialog context, will just display the message. | ||
- | |||
- | Argument: | ||
- | * '' | ||
- | |||
- | ==== Speak ==== | ||
- | Current object says something in current map | ||
- | |||
- | Argument: | ||
- | * '' | ||
- | |||
- | Equivalent to '' | ||
- | |||
- | ==== Split ==== | ||
- | This should only be called on stacks of objects (where Object.Quantity is greater than 1) | ||
- | This takes an object with n items in it's stack, and splits it into two objects, returning the new object. This new object contains the number of items specified by the argument, the original object has its Quantity reduced by the same amount. | ||
- | |||
- | Argument: | ||
- | * '' | ||
- | |||
- | ==== Take ==== | ||
- | Current object picks up specified object, which will be put in inventory, or in a container, depending on applied containers. | ||
- | |||
- | Argument: | ||
- | * '' | ||
- | |||
- | ==== Teleport ==== | ||
- | Teleports the object to specified place. | ||
- | |||
- | Arguments: | ||
- | * '' | ||
- | * '' | ||
- | * '' | ||
- | |||
- | Return value: '' | ||
- | === Examples === | ||
- | * [[cfpython# | ||
- | |||
- | ==== WriteKey ==== | ||
- | Inserts specified key/value in the object. | ||
- | |||
- | Arguments: | ||
- | * '' | ||
- | * '' | ||
- | * '' | ||
- | |||
- | |||
- | **Note**: if you're not sure whether the key exists in the object, you must use '' | ||
- | |||
- | ===== Map ===== | ||
- | Properties in **bold** are read-write, others read only. | ||
- | * Difficulty: '' | ||
- | * **Path**: '' | ||
- | * TempName: '' | ||
- | * Name: '' | ||
- | * ResetTime: '' | ||
- | |||
- | * ResetTimeout: | ||
- | * Players: '' | ||
- | * Light: '' | ||
- | * Darkness: '' | ||
- | * Width: '' | ||
- | * Height: '' | ||
- | * EnterX: '' | ||
- | * EnterY: '' | ||
- | * Message: '' | ||
- | * Region: '' | ||
- | * Unique: '' | ||
- | |||
- | ==== Print ==== | ||
- | Prints the specified message to all players on the map. | ||
- | |||
- | Arguments: | ||
- | * '' | ||
- | * '' | ||
- | |||
- | ==== ObjectAt ==== | ||
- | Returns the first '' | ||
- | |||
- | Arguments: | ||
- | * '' | ||
- | |||
- | Other objects on the position are available through the use of the '' | ||
- | |||
- | ==== CreateObject ==== | ||
- | Creates an object on the map. | ||
- | |||
- | Arguments: | ||
- | * '' | ||
- | * '' | ||
- | |||
- | Equivalent of calling '' | ||
- | |||
- | ==== Check ==== | ||
- | Arguments: | ||
- | * '' | ||
- | * '' | ||
- | |||
- | Return: | ||
- | * the first object at the specified location matching specified name | ||
- | |||
- | ==== Next ==== | ||
- | No arguments. | ||
- | |||
- | Return the next map in the list of active maps. | ||
- | |||
- | ==== ChangeLight ==== | ||
- | Change the map's light level. | ||
- | |||
- | Arguments: | ||
- | * '' | ||
- | |||
- | Note that light will never be negative or over 5 ('' | ||
- | |||
- | ==== Insert ==== | ||
- | Inserts an object at specified location. | ||
- | |||
- | Arguments: | ||
- | * '' | ||
- | * '' | ||
- | |||
- | Return: '' | ||
- | |||
- | ==== InsertAround ==== | ||
- | Inserts an object around a specified location, randomly choosing a free spot. | ||
- | |||
- | Arguments: | ||
- | * '' | ||
- | * '' | ||
- | |||
- | Return: '' | ||
- | |||
- | ==== TriggerConnected ==== | ||
- | Triggers the connected value for the map, this is normally used for activating gates, etc. | ||
- | |||
- | Arguments: | ||
- | * '' | ||
- | * '' | ||
- | * '' | ||
- | |||
- | |||
- | ===== Player ===== | ||
- | This class inherits from Crossfire.Object, | ||
- | * IP: '' | ||
- | * **BedMap**: '' | ||
- | * **BedX** : '' | ||
- | * **BedY** : '' | ||
- | * **MarkedItem**: | ||
- | * **Party**: '' | ||
- | |||
- | ==== CanPay ==== | ||
- | Checks if player can pay for unpaid items in inventory. | ||
- | |||
- | Return value: | ||
- | * 1 if can pay | ||
- | * 0 else | ||
- | |||
- | This will print suitable messages if player can't pay. | ||
- | |||
- | ==== Message ==== | ||
- | Sends a message to the player. | ||
- | |||
- | Arguments: | ||
- | * '' | ||
- | * '' | ||
- | |||
- | ==== Write ==== | ||
- | |||
- | Equivalent of Message. | ||
- | |||
- | ==== QuestStart ==== | ||
- | (trunk only) | ||
- | |||
- | TODO explain quest definitions | ||
- | |||
- | Signal a player that she started a quest. Note that the quest must be correctly defined in the '' | ||
- | |||
- | Arguments: | ||
- | * '' | ||
- | * '' | ||
- | |||
- | ==== QuestGetState ==== | ||
- | (trunk only) | ||
- | |||
- | Query the current state of a quest for the player. Note that the quest must be correctly defined in the '' | ||
- | |||
- | Arguments: | ||
- | * '' | ||
- | |||
- | Return: | ||
- | * quest state, 0 if not started (or was completed previously and not started again) | ||
- | |||
- | ==== QuestSetState ==== | ||
- | (trunk only) | ||
- | |||
- | Signal a player that she advanced in a quest. Note that the quest must be correctly defined in the '' | ||
- | |||
- | Arguments: | ||
- | * '' | ||
- | * '' | ||
- | |||
- | ==== QuestWasCompleted ==== | ||
- | (trunk only) | ||
- | |||
- | Query whether the player completed the quest previously. Note that the quest must be correctly defined in the '' | ||
- | |||
- | Arguments: | ||
- | * '' | ||
- | |||
- | Return: | ||
- | * 0 if the quest was never completed, 1 else | ||
- | |||
- | |||
- | ==== KnowledgeKnown ==== | ||
- | (trunk only) | ||
- | |||
- | Query whether the player knowns through the knowledge system the specified factoid. | ||
- | |||
- | Arguments: | ||
- | * '' | ||
- | |||
- | Return: | ||
- | * 1 if the player knows the item, 0 else. | ||
- | |||
- | ==== GiveKnowledge ==== | ||
- | (trunk only) | ||
- | |||
- | Give a knowledge item to the player. | ||
- | |||
- | Arguments: | ||
- | * '' | ||
- | |||
- | ===== Party ===== | ||
- | This class merely encapsulates a party. Everything is read-only. Attributes: | ||
- | * Name: '' | ||
- | * Password: '' | ||
- | * Next: '' | ||
- | |||
- | ==== GetPlayers ==== | ||
- | Return value: a '' | ||
- | |||
- | |||
- | ===== Region ===== | ||
- | This class encapsulates an in-game region. Properties are read-only. | ||
- | * Name: '' | ||
- | * Longname: '' | ||
- | * Message: '' | ||
- | * Next: '' | ||
- | * JailX, JailY: '' | ||
- | * JailPath: '' | ||
- | |||
- | ==== Parent ==== | ||
- | Return value: a '' | ||
- | |||
- | ====== Example Scripts ====== | ||
- | A section | ||
- | === Move a player onto a map === | ||
- | This script will send its activator to jail, placing them in the 15 minute cell. | ||
- | <code python> | ||
- | import Crossfire | ||
- | |||
- | #we get the the object that triggered this script | ||
- | activator = Crossfire.WhoIsActivator() | ||
- | |||
- | #make sure that the map is loaded, and get the object representing it | ||
- | #we could get the map's default entry coordinates with ' | ||
- | m = Crossfire.ReadyMap('/ | ||
- | |||
- | #teleport the activating object to the x:15 y:1 coordinates of the map (m) we just readied | ||
- | activator.Teleport(m, | ||
- | </ | ||
- | === Object.WriteKey === | ||
- | FIXME write an example | ||
- | |||
- | (see a working example at maps/ |
cfpython.1374607681.txt.gz · Last modified: (external edit)