* 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:
false_genesis 2008-02-18 22:15:28 +00:00
parent 6ccd48f719
commit 10f0d5962d
15 changed files with 180 additions and 67 deletions

View File

@ -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

View 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!

View File

@ -103,16 +103,6 @@ LOG * Assigning permissions for internal functions...
setscriptpermission,emote 0
// ... 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
// script to be run before all .def files are loaded
@ -124,6 +114,5 @@ endif
if ?{not ${#config::DONE}}
config
endif
register_onguiclose_exit
#/onload

View 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

View File

@ -1,20 +1,13 @@
#permission=0
#script=getuptime
// purpose: pseuwow uptime counter
// args: none
// usage: - load the script to register the uptime counter
// - call the script to say the uptime formatted in hours, mins & secs
// args: @def: "say", "yell", "chan,General", etc. any command that accepts a string in @def and does something with it.
// returns: uptime formatted as 0h 0m 0s
#onload
if ?{not ?{isset #uptime}}
set,#uptime 0
endif
removeevent event_{${@myname}}
addevent,event_{${@myname}},1000 add,#uptime 1
#endonload
set,s ${#uptime}
set,s ${@clock}
div,s 1000
set,s ?{toint ${s}}
set,secs ${s}
set,h ${s}
div,h 3600
@ -27,14 +20,19 @@ toint,m ${m}
mod,s 60
toint,s ${s}
set,str ${h}h ${m}m ${s}s
out UPTIME: ${#uptime} secs = ${str}
out UPTIME: ${secs} secs = ${str}
if ${@inworld}
say UPTIME: ${h} hours, ${m} minutes, ${s} seconds
if ?{strlen ${@def}}
${@def} UPTIME: ${h} hours, ${m} minutes, ${s} seconds
endif
unset h
unset m
unset s
unset secs
return ${str}
return ${str}
#script=uptime
#permission=0
return ?{getuptime say}

View File

@ -442,32 +442,46 @@ DefReturnResult DefScriptPackage::SCGetName(CmdSet& Set)
logerror("Invalid Script call: SCGetName: WorldSession not valid");
DEF_RETURN_ERROR;
}
DefReturnResult r;
uint64 guid=DefScriptTools::toNumber(Set.defaultarg);
r.ret="Unknown Entity";
Object *o = ws->objmgr.GetObj(guid);
if(o)
uint64 id = DefScriptTools::toUint64(Set.defaultarg);
std::string source = DefScriptTools::stringToLower(Set.arg[0]);
// "guid" type can be everything - item, player, unit, gameobject... whatever has this guid.
if(source.empty() || source == "guid")
{
if(o->GetTypeId()==TYPEID_ITEM || o->GetTypeId()==TYPEID_CONTAINER)
{
ItemProto *proto=((PseuInstance*)parentMethod)->GetWSession()->objmgr.GetItemProto(o->GetEntry());
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);
Object *o = ws->objmgr.GetObj(id);
if(o)
return o->GetName();
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)

View File

@ -847,6 +847,11 @@ void WorldSession::_HandleTelePortAckOpcode(WorldPacket& recvPacket)
{
CmdSet Set;
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");
}
}
@ -881,6 +886,11 @@ void WorldSession::_HandleNewWorldOpcode(WorldPacket& recvPacket)
{
CmdSet Set;
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");
}
}