-
Notifications
You must be signed in to change notification settings - Fork 46
Defscript:functions
shlainn edited this page Sep 14, 2010
·
1 revision
Importing these tables will need more work
{| style=”width:75%;border-collapse: collapse;” border=”1”
| ”’Basic functions”’ | ||
|---|---|---|
| out text | Prints “text” to the console of PseuW@W | |
| set,value name | Sets variable “name” to the value of “value” | |
| default,value name | Sets variable “name” to the value of “value” | |
| unset name | Unsets the variable with the name of “name” | |
| shdn | Shuts down the client and saves all data | |
| loaddef name | Loads the DefScript file with the name of “name” and extension “.def” in folder scripts. if you want to use different extension, supply full patch, e.g. ./scripts/xyz.df. This function loads the scripts only if they were not loaded before. | |
| reloaddef | Same like loaddef, but will always (re-)load scripts. | |
| setscriptpermission,name level | Set the permission level of the DefScript or internal script function with the name: “name” to be run only if permission is higher than or equal to “level” | |
| addevent,name,interval script | register an event with a unique name. interval is in msecs. script is the DefScript command that will be periodically excuted. if an event with the given name already exists, the old event will remain and NOT be replaced (= the current addevent call will be ignored) | |
| removeevent name | removes an event. if the event with that name does not exist, nothing will happen. Note: to change properties (e.g. the interval) of a currently registered event, you have to remove it and add it again with the new properties. | |
| gui | starts gui if closed | |
| } |
{| style=”width:75%;border-collapse: collapse;” border=”1”
| ”’Mathematical functions”’ | |||
|---|---|---|---|
| toint var | truncates the value of var to an integer value; or sets var to 0 if it could not be converted to a valid number | ||
| tohex[,full] number | returns HEX format of number (if full is set, all preceding zeroes are included) | ||
| abs number | returns absolute value of number | ||
| add,var x | adds x to var (var=var+x) | ||
| sub,var x | substracts x from var (var=var-x) | ||
| mul,var x | multiplies var with x (var=var*x) | ||
| div,var x | divides var by x (var=var/x). NOTE: division by zero results var beeing zero! | ||
| mod,var x | var modulo x (var=var%x) | ||
| pow,var x | (var=pow(var,x)) | ||
| bitor,var x | <nowiki>(var=var | x)</nowiki> | |
| bitand,var x | (var=var&x) | ||
| bitxor,var x | (var=var^x) | ||
| random[,min] max | returns random number between min and max. default: min = 0 | ||
| } |
{| style=”width:75%;border-collapse: collapse;” border=”1”
| ”’String functions”’ | note that the first char in strings always has the index 0, like in C++ | |
|---|---|---|
| uppercase str | returns str in uppercase (str -> STR) | |
| lowercase str | returns str in lowercase (STR -> str) | |
| substr,length[,start] str | returns part of str. default: start = 0. if length is out of bounds, the entire sustring beginning from start is returned. | |
| strfind,findme[,start] str | returns index of first found “findme” in str. starts searching at start position (0 by default) | |
| strlen str | returns length of string str | |
| } |
{| style=”width:75%;border-collapse: collapse;” border=”1”
| ”’Logical operands”’ | ||||
|---|---|---|---|---|
| smaller,a b | returns a < b | |||
| bigger,a b | returns a > b | |||
| smaller_eq,a b | returns a <= b | |||
| bigger_eq,a b | returns a >= b | |||
| not a | returns !a | |||
| equal,a[,ignore] b | returns a == b (if ignore is set then ignores case) | |||
| isset var | returns true if var is set | |||
| and,a b | returns a && b | |||
| or,a b | returns a <nowiki> | </nowiki> b | ||
| xor,a b | returns A xor B | |||
| } |
{| style=”width:75%;border-collapse: collapse;” border=”1”
| ”’List functions”’ | ||
|---|---|---|
| lpushback,listName value | adds value to list at the end | |
| lappend,listName value | alias for lpushback | |
| lpushfront,listName value | adds value to list at the beggining | |
| lpopback,listName value | pops value from list from back, and returns it | |
| lpopfront listName | pops value from list from beggining, and returns it | |
| ldelete listName | delete and clear memory of list | |
| lexists listName | returns true if list exists. note: the list can be empty. it just needs to be in memory. | |
| llen listName | returns number of elements in list | |
| linsert,listName,position value | inserts element at specified position and returns true. if the list is too short to append at given position, the value is added to the end, and false is returned. | |
| lsplit,listName,delimiter string | splits string by delimiter and insert it to list. previous list content is erased. (returns number of elements in list, if delimiter not set splits by character) | |
| lcsplit,listName,delimiterChars string | splits string by single characters in delimiterChars (works same as above) | |
| ljoin,listName str | returns joined string from list, using str as delimiter | |
| lindex,listName index | returns element at index | |
| lclean,listName cleanStr | deletes all elements that are equal to cleanStr (if cleanStr is empty or not set, all empty entries (stringlen=0) are deleted) | |
| lmclean,listName[,arg1][,arg2]… [argx] | like lclean, but every arg after the list name is treated as cleanStr (lmclean saves multiple calls of lclean if there are more elements to delete). can not be used to remove emptry strings from the list. ? | |
| lerase,listName index | erases element at index and returns it | |
| lsort listName | sorts list alphabetically (A-Z, a-z). more sorting possibilities will be added later. | |
| } |
{| style=”width:75%;border-collapse: collapse;” border=”1”
| ”’File functions”’ | ||
|---|---|---|
| fopen,fid,mode filename | opens file, returns true on sucess. mode can be r - read, w - write, a - append, b - binary. fid is internal identifier of opened file | |
| fclose fid | flushes and closes file | |
| fisopen fid | returns true if file is opened | |
| feof fid | returns true if EOF rearched (end of file) | |
| frpos fid | returns read position | |
| fwpos fid | returns write position | |
| fdel filename | deletes filename | |
| fflush fid | flushes buffers | |
| fwrite,fid text | writes text to file | |
| fread,fid bytescount | read bytescount bytes from file (if bytescount is “all” then reads all from current position till end) | |
| freadb,fid type | reads binary data (types same as in bytebuffers reading) | |
| fwriteb,fid,type data | writes binary data (same as before) | |
| freadbb,fid[,bytescount] bb | reads bytescount bytes from file to bytebuffer bb (if bytescount not setted reads remaining bytes from file) | |
| fwritebb,fid[,bytescount] bb | writes bytescount bytes from bytebuffer bb to file (if bytescount not setted writes whole bytebuffer) | |
| fsize filename | returns size of file | |
| fexists filename | return true if file exists | |
| freadline fid | returns one line from file (stops at character \n or at EOF) | |
| fseekw,fid[,begin/end] pos | sets write position at pos from begin/end of file (default: begin) | |
| fseekr,fid[,begin/end] pos | sets readposition at pos from begin/end of file (default: begin) | |
| } |
{| style=”width:75%;border-collapse: collapse;” border=”1”
| ”’ByteBuffer functions”’ | ||
|---|---|---|
| bbinit[,initsize] bbName | inicializes empty ByteBuffer? (if initsize is set, bytebuffer will have reserved initsize capacity). | |
| bbdelete bbName | delete and clean memory of bytebuffer. | |
| bbappend,bbName,type value | adds value at end of bytebuffer (type can be: string/uint8/uint16/uint32/uint64/float/double/strnz). | |
| bbread,bbName type | returns value at end of bytebuffer (type can be: string/uint8/uint16/uint32/uint64/float/double/strnz). | |
| bbsetrpos,bbName newrpos | sets read position pointer to newrpos value (if newrpos = end, automatically sets to end). | |
| bbsetwpos,bbName newwpos | sets write position pointer to newwpos value (if newwpos = end, automatically sets to end). | |
| bbhexlike bbName | HEX-like output of bytebuffer to console. | |
| bbtextlike bbName | text-like output of bytebuffer to console. | |
| bbsize bbName | returns size of bytebuffer. | |
| } |
{| style=”width:75%;border-collapse: collapse;” border=”1”
| ”’Object interaction functions”’ | ||
|---|---|---|
| objectknown guid | returns true if object is known. (means that the object must be near, or somehow else important so that the server didnt delete it from our memory). (guid is uint64) | |
| getobjecttype guid | returns TypeId? of object. | |
| getitemprotovalue,entry what | returns itemproto value of “what” (name, class, reqlevel,…) | |
| getentry guid | returns entry of object | |
| getname guid | returns name of object | |
| getrace guid | returns race of NPC/player | |
| getclass guid | returns class of NPC/player | |
| getplayerguid playerName | returns guid of player | |
| target playerName | targets player. npc targeting wil be adeded later. | |
| queryitem entry | queries server for item | |
| castspell spellId | casts spell (on your current target, only single target spells work now). if the spell is not in spellbook, it is not casted (because the server might think its cheating). override this protection with a setting in PseuWoW.conf. | |
| sendwho,minlvl,maxlvl,racemask,classmask,name,guild | sends “who” packet with specified properties | |
| getobjectdist,guid1,[2d/3d] guid2 | calculates distance between two objects. default: 2d distance | |
| sendworldpacket,opcode bytebufferName | sends worldpacket | |
| getopcodeid opcodeName | returns id of opcode (or empty string if not find) | |
| getopcodename opcodeId | returns name of opcode | |
| bbgetpackedguid bb | returns read packet GUID from bytebuffer | |
| bbputpackedguid,bb guid | store packed GUID to bytebuffer | |
| spoofworldpacket,opcodenumber bb | spoofs world packet (pseuwow will process it as it was sent by server) | |
| switchopcodehandler,opcode true/false | switches internal handler of opcodes to handle or not setted opcode (useful if opcode is handled by scripts by better way) | |
| opcodedisabled opcode | returns true if internal handler of opcode is disabled | |
| } |
{| style=”width:75%;border-collapse: collapse;” border=”1”
| ”’Other functions”’ | ||
|---|---|---|
| fileexists filename | return true if file exists | |
| getfilelist,listName[,extension] path | lists all files from “path” to listName (if extension is set, then only files with this extension are added into list) | |
| printscript scriptName | prints source code of script to screen | |
| funcexists function | returns true if function exists (functions are internally defined) | |
| scriptexists scriptname | returns true if script exists | |
| } |
{| style=”width:75%;border-collapse: collapse;” border=”1”
| ”’User functions”’ | ||
|---|---|---|
| help | help | |
| pause ms | pauses execution for some milliseconds. note that it stops the whole program! | |
| emote id | perform an emote. id can either be a number, or the emote name (check data/scp/emote.scp for that) | |
| (follow) | removed for now, because it crashed mangos | |
| savecache | saves current cache data | |
| sendchatmessage,type,lang,msg,to | send a chat message to the world. use the included scripts say,whisper,yell and chan.def, they capsule this function for you and are easier to use. | |
| joinchannel name | joins a channel | |
| leavechannel name | leaves a channel | |
| listchannel name | lists all characters who are in this channel, asks the server for their names, and stores guids in list @ChannelList? | |
| loadconf fn | loads a conf file. if you dont specify a path, the file will be searched in the ./conf/ folder. | |
| applyconf | converts DefScript variables into program configuration variables. | |
| applypermissions | converts DefScript variables (var names beginning with “USERS::”) into DefScript permission data and stores them. | |
| log text | output a text to console and write it to the logfile. equal to the log() c++ function | |
| logdetail text | output a text to console and write it to the logfile if debug>0. equal to the logdetail() c++ function | |
| logdebug text | output a text to console and write it to the logfile if debug>1. equal to the logdebug() c++ function | |
| loaddb dbname | loads specified SCP database | |
| adddbpath | adds path for finding SCP databases | |
| getscpvalue,db,keyid entry | gets value for entry in specified database. db and keyid is stored, next calls can omit these values | |
| } |
{| style=”width:75%;border-collapse: collapse;” border=”1”
| ”’Predefined Scripts (.def files)”’ | ||
|---|---|---|
| chan,channame[,lang] text | says text on channel channame (in language lang) | |
| makechatitem,var[,color] id | writes a ready-to-say, in-chat clickable item into a variable. color must be supplied in hex format RRGGBB. (check also sayitem.def for usage) | |
| quit | Shuts down client (alias for shdn) | |
| reply[,lang] text | replies to the player that last whispered to us. if no language is given, the language of the player is used to whisper back. | |
| say[,lang] text | says text in a language. lang can either be the language number or the language name. default language is 0 (universal) | |
| sayitem id | says a chatmessage with an item link of item nr. [id]. | |
| sayparty[,lang] text | says text to your party | |
| sayguild[,lang] text | says text to your guild | |
| sayred[,lang] text | says text in red color | |
| uptime | output the time pseuwow is running both in console and in game. | |
| whisper,name[,lang] text | whispers text to a player | |
| yell[,lang] text | yells text. same as say. | |
| ”’Hooking helper functions”’ | ||
| IsHooked[,hookname] script | returns true if script is already hooked by calling script (or hookname if set) | |
| HookStart[,hookname] script | starts hooking of script (default: hookname is name of calling script) | |
| HookEnd[,hookname] script | ends hooking | |
| HookAdd[,scriptname] scriptline | adds text to script (default: scriptname is name of script that called HookStart last time) | |
| HookAddList[,scriptname][,caller] listname | appends list to script (default: scriptname is name of script that called HookStart last time, caller is name of calling script) | |
| HookStartOpcode[,caller] opcodeName | starts hooking of opcode handler | |
| UnHook[,hookname] script | unhooks script (default: hookname is name of caller script) | |
| UnHookOpcode[,caller] opcodeName | unhooks opcode handler | |
| UnHookAll[,caller] script | unhooks all | |
| } |