* changed GetName script to support types: guid,player,item,unit with guid/entry depeding on type
* restructured event scripts, some organisation
This commit is contained in:
parent
6ccd48f719
commit
10f0d5962d
@ -1,18 +1,3 @@
|
|||||||
// -------------------------------------------
|
|
||||||
#script=_onchatmessage
|
|
||||||
// purpose: do something if specific chat messages are recieved.
|
|
||||||
// args:
|
|
||||||
// @def: chat message text
|
|
||||||
// @0: message type id (check ChatMsg enum in src/Client/SharedDefines.h)
|
|
||||||
// @1: language id (also defined in SharedDefines.h), alternatively look up bin/data/scp/language.scp
|
|
||||||
// @2: GUID of the player or creature this msg came from
|
|
||||||
// @3: channel name. empty string if the chat message was not sent in a channel (for example say, yell or whisper)
|
|
||||||
//--------------------------------------------
|
|
||||||
|
|
||||||
processchatai,{${@0}},{${@1}},{${@2}},{${@3}} ${@def}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// -----------------------------------
|
// -----------------------------------
|
||||||
#script=FlushChatAI
|
#script=FlushChatAI
|
||||||
|
|||||||
96
bin/scripts/__core_eventstubs.def
Normal file
96
bin/scripts/__core_eventstubs.def
Normal file
@ -0,0 +1,96 @@
|
|||||||
|
|
||||||
|
// ----==== CHAT MESSAGES ====----
|
||||||
|
// -------------------------------------------
|
||||||
|
#script=_onchatmessage
|
||||||
|
// purpose: do something if specific chat messages are recieved.
|
||||||
|
// args:
|
||||||
|
// @def: chat message text
|
||||||
|
// @0: message type id (check ChatMsg enum in src/Client/SharedDefines.h)
|
||||||
|
// @1: language id (also defined in SharedDefines.h), alternatively look up bin/data/scp/language.scp
|
||||||
|
// @2: GUID of the player or creature this msg came from
|
||||||
|
// @3: channel name. empty string if the chat message was not sent in a channel (for example say, yell or whisper)
|
||||||
|
//--------------------------------------------
|
||||||
|
processchatai,{${@0}},{${@1}},{${@2}},{${@3}} ${@def} // this is required for the ChatAI script to work
|
||||||
|
|
||||||
|
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
|
||||||
|
|
||||||
|
|
||||||
|
// ----==== TELEPORTATION ====----
|
||||||
|
|
||||||
|
#script=_onteleport
|
||||||
|
// @def: [far teleport=true, else false]
|
||||||
|
// @0: [far teleport: map ID, else teleported GUID]
|
||||||
|
// @1: X position
|
||||||
|
// @2: Y position
|
||||||
|
// @3: Z position
|
||||||
|
// @4: Orientation
|
||||||
|
|
||||||
|
//- script content here...
|
||||||
|
|
||||||
|
|
||||||
|
// ----==== GUI RELATED ====----
|
||||||
|
|
||||||
|
#script=_onguiclose
|
||||||
|
// no args. gets called when the GUI is closed.
|
||||||
|
if ?{GetVar #EXITONGUICLOSE}
|
||||||
|
exit
|
||||||
|
endif
|
||||||
|
|
||||||
|
|
||||||
|
// ----==== OBJECT HANDLING ====----
|
||||||
|
|
||||||
|
#script=_onobjectcreate
|
||||||
|
// @def: GUID of created object
|
||||||
|
// @0 TypeID of created object
|
||||||
|
// The object can be accessed with GetName, GetEntry, GetObjectType, GetObjectValue, GetRace, GetClass, ... via the guid
|
||||||
|
|
||||||
|
//- script content here...
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#script=_onobjectdelete
|
||||||
|
// @def: GUID of deleted object
|
||||||
|
// @0: [out of range object deletion=true, else false]
|
||||||
|
// The object can be accessed with the object handling functions listed above.
|
||||||
|
// It will be deleted right after handling this script.
|
||||||
|
|
||||||
|
//- script content here...
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// ----==== ENTERING/LEAVING WORLD ====----
|
||||||
|
|
||||||
|
#script=_leaveworld
|
||||||
|
// no args. gets called when the world is left.
|
||||||
|
|
||||||
|
//- script content here...
|
||||||
|
|
||||||
|
|
||||||
|
#script=_enterworld
|
||||||
|
// no args. called when the world is entered
|
||||||
|
log * World entered!
|
||||||
|
say [${@version_short}] login successful.
|
||||||
|
emote 126 // = TEXTEMOTE_READY
|
||||||
|
joinchannel General
|
||||||
|
joinchannel Trade
|
||||||
|
joinchannel LookingForGroup
|
||||||
|
castspell 836 // LoginEffect
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// ----==== IN-GAME SCRIPT COMMANDS ====----
|
||||||
|
|
||||||
|
#script=_nopermission
|
||||||
|
// this script gets executed if a player tries to give pseuwow a command but is not allowed to
|
||||||
|
// Arguments:
|
||||||
|
// ==========
|
||||||
|
// @0 : name of the player who wanted to execute a command
|
||||||
|
// @1 : permission level of this user
|
||||||
|
// @2 : permission level needed to execute the script
|
||||||
|
// @3 : name of the script that should get executed
|
||||||
|
|
||||||
|
SAY Forget it, ${@0}, you have only permission ${@1} but need ${@2} to run the script '${@3}'
|
||||||
|
LOG Player '${@0}' (p:${@1}) wanted to execute '${@3}' (p:${@2})
|
||||||
|
EMOTE 66 // say NO!
|
||||||
|
|
||||||
@ -103,16 +103,6 @@ LOG * Assigning permissions for internal functions...
|
|||||||
setscriptpermission,emote 0
|
setscriptpermission,emote 0
|
||||||
// ... set more permissions here ...
|
// ... set more permissions here ...
|
||||||
|
|
||||||
//-------------------------------------------------
|
|
||||||
#script=register_onguiclose_exit
|
|
||||||
//-------------------------------------------------
|
|
||||||
if ?{not ?{ScriptHasLine,_onguiclose #tag:hook:${@myname}}}
|
|
||||||
appenddef,_onguiclose #tag:hook:${@myname}
|
|
||||||
appenddef,_onguiclose if ?\{GetVar #EXITONGUICLOSE\}
|
|
||||||
appenddef,_onguiclose exit
|
|
||||||
appenddef,_onguiclose endif
|
|
||||||
endif
|
|
||||||
|
|
||||||
|
|
||||||
// this dummy script does nothing actually but since its loaded last in this file it causes the config
|
// this dummy script does nothing actually but since its loaded last in this file it causes the config
|
||||||
// script to be run before all .def files are loaded
|
// script to be run before all .def files are loaded
|
||||||
@ -124,6 +114,5 @@ endif
|
|||||||
if ?{not ${#config::DONE}}
|
if ?{not ${#config::DONE}}
|
||||||
config
|
config
|
||||||
endif
|
endif
|
||||||
register_onguiclose_exit
|
|
||||||
#/onload
|
#/onload
|
||||||
|
|
||||||
|
|||||||
21
bin/scripts/optional/dump_playercache.def
Normal file
21
bin/scripts/optional/dump_playercache.def
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
#script=dumppcache
|
||||||
|
fopen,fh,rb ./cache/playernames.cache
|
||||||
|
freadbb,fh bb
|
||||||
|
set,size ?{bbread,bb uint32}
|
||||||
|
log PlayerNameCache: ${size} entries.
|
||||||
|
set,i 0
|
||||||
|
loop
|
||||||
|
if ?{bigger_eq,${i} ${size}}
|
||||||
|
exitloop
|
||||||
|
endif
|
||||||
|
set,guid ?{bbread,bb uint64}
|
||||||
|
set,len ?{bbread,bb uint8}
|
||||||
|
set,name ?{bbread,bb,${len} strnz}
|
||||||
|
log PlayerNameCache[${i}]: ${guid} = ${name} (${len})
|
||||||
|
add,i 1
|
||||||
|
endloop
|
||||||
|
|
||||||
|
#script=dummy
|
||||||
|
#onload
|
||||||
|
dumppcache
|
||||||
|
#/onload
|
||||||
@ -1,20 +1,13 @@
|
|||||||
#permission=0
|
#script=getuptime
|
||||||
|
|
||||||
// purpose: pseuwow uptime counter
|
// purpose: pseuwow uptime counter
|
||||||
// args: none
|
// args: @def: "say", "yell", "chan,General", etc. any command that accepts a string in @def and does something with it.
|
||||||
// usage: - load the script to register the uptime counter
|
|
||||||
// - call the script to say the uptime formatted in hours, mins & secs
|
|
||||||
// returns: uptime formatted as 0h 0m 0s
|
// returns: uptime formatted as 0h 0m 0s
|
||||||
|
|
||||||
#onload
|
set,s ${@clock}
|
||||||
if ?{not ?{isset #uptime}}
|
div,s 1000
|
||||||
set,#uptime 0
|
set,s ?{toint ${s}}
|
||||||
endif
|
set,secs ${s}
|
||||||
removeevent event_{${@myname}}
|
|
||||||
addevent,event_{${@myname}},1000 add,#uptime 1
|
|
||||||
#endonload
|
|
||||||
|
|
||||||
set,s ${#uptime}
|
|
||||||
|
|
||||||
set,h ${s}
|
set,h ${s}
|
||||||
div,h 3600
|
div,h 3600
|
||||||
@ -27,14 +20,19 @@ toint,m ${m}
|
|||||||
mod,s 60
|
mod,s 60
|
||||||
toint,s ${s}
|
toint,s ${s}
|
||||||
set,str ${h}h ${m}m ${s}s
|
set,str ${h}h ${m}m ${s}s
|
||||||
out UPTIME: ${#uptime} secs = ${str}
|
out UPTIME: ${secs} secs = ${str}
|
||||||
|
|
||||||
if ${@inworld}
|
if ?{strlen ${@def}}
|
||||||
say UPTIME: ${h} hours, ${m} minutes, ${s} seconds
|
${@def} UPTIME: ${h} hours, ${m} minutes, ${s} seconds
|
||||||
endif
|
endif
|
||||||
|
|
||||||
unset h
|
unset h
|
||||||
unset m
|
unset m
|
||||||
unset s
|
unset s
|
||||||
|
unset secs
|
||||||
|
|
||||||
return ${str}
|
return ${str}
|
||||||
|
|
||||||
|
#script=uptime
|
||||||
|
#permission=0
|
||||||
|
return ?{getuptime say}
|
||||||
@ -442,32 +442,46 @@ DefReturnResult DefScriptPackage::SCGetName(CmdSet& Set)
|
|||||||
logerror("Invalid Script call: SCGetName: WorldSession not valid");
|
logerror("Invalid Script call: SCGetName: WorldSession not valid");
|
||||||
DEF_RETURN_ERROR;
|
DEF_RETURN_ERROR;
|
||||||
}
|
}
|
||||||
DefReturnResult r;
|
uint64 id = DefScriptTools::toUint64(Set.defaultarg);
|
||||||
uint64 guid=DefScriptTools::toNumber(Set.defaultarg);
|
std::string source = DefScriptTools::stringToLower(Set.arg[0]);
|
||||||
r.ret="Unknown Entity";
|
|
||||||
Object *o = ws->objmgr.GetObj(guid);
|
// "guid" type can be everything - item, player, unit, gameobject... whatever has this guid.
|
||||||
if(o)
|
if(source.empty() || source == "guid")
|
||||||
{
|
{
|
||||||
if(o->GetTypeId()==TYPEID_ITEM || o->GetTypeId()==TYPEID_CONTAINER)
|
Object *o = ws->objmgr.GetObj(id);
|
||||||
{
|
if(o)
|
||||||
ItemProto *proto=((PseuInstance*)parentMethod)->GetWSession()->objmgr.GetItemProto(o->GetEntry());
|
return o->GetName();
|
||||||
r.ret=proto->Name[0]; // and whats with Name[1] - Name[3]?
|
|
||||||
}
|
|
||||||
else if(o->GetTypeId()==TYPEID_UNIT || o->GetTypeId()==TYPEID_PLAYER || o->GetTypeId()==TYPEID_GAMEOBJECT || o->GetTypeId()==TYPEID_CORPSE)
|
|
||||||
{
|
|
||||||
r.ret=((WorldObject*)o)->GetName();
|
|
||||||
}
|
|
||||||
// TODO: add support for gameobjects etc.
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// if no object with that guid is near, it might exist in the cache, check it and use that if present
|
|
||||||
if(ws->plrNameCache.IsKnown(guid))
|
|
||||||
r.ret = ws->plrNameCache.GetName(guid);
|
|
||||||
else
|
else
|
||||||
logerror("SCGetName: Object "I64FMT" not known",guid);
|
{
|
||||||
|
// fallback if that guid is player guid, its maybe stored, so check that
|
||||||
|
if(IS_PLAYER_GUID(id))
|
||||||
|
{
|
||||||
|
if(ws->plrNameCache.IsKnown(id))
|
||||||
|
return ws->plrNameCache.GetName(id);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return r;
|
else if(source == "player")
|
||||||
|
{
|
||||||
|
if(ws->plrNameCache.IsKnown(id))
|
||||||
|
return ws->plrNameCache.GetName(id);
|
||||||
|
else
|
||||||
|
return "";
|
||||||
|
|
||||||
|
}
|
||||||
|
else if(source == "item")
|
||||||
|
{
|
||||||
|
ItemProto *iproto = ws->objmgr.GetItemProto((uint32)id);
|
||||||
|
return iproto ? iproto->Name : "";
|
||||||
|
}
|
||||||
|
else if(source == "unit")
|
||||||
|
{
|
||||||
|
CreatureTemplate *ct = ws->objmgr.GetCreatureTemplate((uint32)id);
|
||||||
|
return ct ? ct->name : "";
|
||||||
|
}
|
||||||
|
// TODO: add gameobject, dynamicobject
|
||||||
|
|
||||||
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
DefReturnResult DefScriptPackage::SCGetEntry(CmdSet& Set)
|
DefReturnResult DefScriptPackage::SCGetEntry(CmdSet& Set)
|
||||||
|
|||||||
@ -847,6 +847,11 @@ void WorldSession::_HandleTelePortAckOpcode(WorldPacket& recvPacket)
|
|||||||
{
|
{
|
||||||
CmdSet Set;
|
CmdSet Set;
|
||||||
Set.defaultarg = "false"; // teleported to other map = false
|
Set.defaultarg = "false"; // teleported to other map = false
|
||||||
|
Set.arg[0] = toString(guid);
|
||||||
|
Set.arg[1] = toString(x);
|
||||||
|
Set.arg[2] = toString(y);
|
||||||
|
Set.arg[3] = toString(z);
|
||||||
|
Set.arg[4] = toString(o);
|
||||||
GetInstance()->GetScripts()->RunScriptIfExists("_onteleport");
|
GetInstance()->GetScripts()->RunScriptIfExists("_onteleport");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -881,6 +886,11 @@ void WorldSession::_HandleNewWorldOpcode(WorldPacket& recvPacket)
|
|||||||
{
|
{
|
||||||
CmdSet Set;
|
CmdSet Set;
|
||||||
Set.defaultarg = "true"; // teleported to other map = false
|
Set.defaultarg = "true"; // teleported to other map = false
|
||||||
|
Set.arg[0] = toString(mapid);
|
||||||
|
Set.arg[1] = toString(x);
|
||||||
|
Set.arg[2] = toString(y);
|
||||||
|
Set.arg[3] = toString(z);
|
||||||
|
Set.arg[4] = toString(o);
|
||||||
GetInstance()->GetScripts()->RunScriptIfExists("_onteleport");
|
GetInstance()->GetScripts()->RunScriptIfExists("_onteleport");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user