* added script funcs: getobjectvalue, getclass, getrace as requested by thetourist. getobjectvalue syntax:

"getobjectvalue,index[,type]" works exactly like Object::GetUInt32Value(). default type treatment is uint32, set type to "f" to return floatvalue, or "i64", to return uint64value.
This commit is contained in:
False.Genesis 2007-10-25 15:12:05 +00:00
parent 484fc0d4f1
commit 6857827169
3 changed files with 77 additions and 1 deletions

View File

@ -47,6 +47,9 @@ void DefScriptPackage::_InitDefScriptInterface(void)
AddFunc("getscriptperm",&DefScriptPackage::SCGetScriptPerm);
AddFunc("lgetfiles",&DefScriptPackage::SCGetFileList);
AddFunc("printscript",&DefScriptPackage::SCPrintScript);
AddFunc("getobjectvalue",&DefScriptPackage::SCGetObjectValue);
AddFunc("getrace",&DefScriptPackage::SCGetRace);
AddFunc("getclass",&DefScriptPackage::SCGetClass);
}
DefReturnResult DefScriptPackage::SCshdn(CmdSet& Set)
@ -786,6 +789,74 @@ DefReturnResult DefScriptPackage::SCPrintScript(CmdSet &Set)
return "";
}
DefReturnResult DefScriptPackage::SCGetObjectValue(CmdSet &Set)
{
WorldSession *ws = ((PseuInstance*)parentMethod)->GetWSession();
if(!ws)
{
logerror("Invalid Script call: SCGetObjectValue: WorldSession not valid");
DEF_RETURN_ERROR;
}
uint64 guid = DefScriptTools::toNumber(Set.defaultarg);
Object *o = ws->objmgr.GetObj(guid);
if(o)
{
uint32 v = (uint32)DefScriptTools::toNumber(Set.arg[0]);
if(v > o->GetValuesCount())
{
logerror("SCGetObjectValue ["I64FMTD", type %u]: invalid value index: %u",guid,o->GetTypeId(),v);
return "";
}
else
{
if(DefScriptTools::stringToLower(Set.arg[1]) == "f")
return toString((ldbl)o->GetFloatValue(v));
else if(DefScriptTools::stringToLower(Set.arg[1]) == "i64")
return toString(o->GetUInt64Value(v));
else
return toString((uint64)o->GetUInt32Value(v));
}
}
return "";
}
DefReturnResult DefScriptPackage::SCGetRace(CmdSet &Set)
{
WorldSession *ws = ((PseuInstance*)parentMethod)->GetWSession();
if(!ws)
{
logerror("Invalid Script call: SCGetObjectValue: WorldSession not valid");
DEF_RETURN_ERROR;
}
uint64 guid = DefScriptTools::toNumber(Set.defaultarg);
Object *o = ws->objmgr.GetObj(guid);
if(o && (o->GetTypeId() == TYPEID_UNIT || o->GetTypeId() == TYPEID_PLAYER))
{
return DefScriptTools::toString((uint64)((Unit*)o)->GetRace());
}
return "";
}
DefReturnResult DefScriptPackage::SCGetClass(CmdSet &Set)
{
WorldSession *ws = ((PseuInstance*)parentMethod)->GetWSession();
if(!ws)
{
logerror("Invalid Script call: SCGetObjectValue: WorldSession not valid");
DEF_RETURN_ERROR;
}
uint64 guid = DefScriptTools::toNumber(Set.defaultarg);
Object *o = ws->objmgr.GetObj(guid);
if(o && (o->GetTypeId() == TYPEID_UNIT || o->GetTypeId() == TYPEID_PLAYER))
{
return DefScriptTools::toString((uint64)((Unit*)o)->GetClass());
}
return "";
}

View File

@ -37,6 +37,9 @@ DefReturnResult SCObjectKnown(CmdSet&);
DefReturnResult SCGetPlayerPerm(CmdSet&);
DefReturnResult SCGetScriptPerm(CmdSet&);
DefReturnResult SCGetFileList(CmdSet&);
DefReturnResult SCPrintScript(CmdSet &Set);
DefReturnResult SCPrintScript(CmdSet&);
DefReturnResult SCGetObjectValue(CmdSet&);
DefReturnResult SCGetRace(CmdSet&);
DefReturnResult SCGetClass(CmdSet&);
#endif

View File

@ -51,6 +51,8 @@ public:
uint8 GetGender(void);
void SetSpeed(uint8 speednr, float speed) { _speed[speednr] = speed; }
float GetSpeed(uint8 speednr) { return _speed[speednr]; }
uint8 GetRace() const { return (uint8)(GetUInt32Value(UNIT_FIELD_BYTES_0) & 0xFF); };
uint8 GetClass() const { return (uint8)((GetUInt32Value(UNIT_FIELD_BYTES_0) >> 8) & 0xFF); };
protected:
float _speed[MAX_MOVE_TYPE];