1
0
mirror of https://github.com/VCMP-SqMod/SqMod.git synced 2025-06-15 22:57:12 +02:00

Add back some of the entity search functions.

This commit is contained in:
Sandu Liviu Catalin
2016-06-21 16:15:25 +03:00
parent 284e1be3f7
commit 66e604cec7
2 changed files with 60 additions and 0 deletions

View File

@ -2061,6 +2061,37 @@ SQInteger CPlayer::AnnounceEx(HSQUIRRELVM vm)
return 0;
}
// ------------------------------------------------------------------------------------------------
static const Object & Player_FindAuto(Object & by)
{
switch (by.GetType())
{
case OT_INTEGER:
{
return Core::Get().GetPlayer(by.Cast< Int32 >()).mObj;
} break;
case OT_FLOAT:
{
return Core::Get().GetPlayer(std::round(by.Cast< Float32 >())).mObj;
} break;
case OT_STRING:
{
// Obtain the argument as a string
String str(by.Cast< String >());
// Attempt to locate the player with this name
Int32 id = _Func->GetPlayerIdFromName(&str[0]);
// Was there a player with this name?
if (VALID_ENTITYEX(id, SQMOD_PLAYER_POOL))
{
Core::Get().GetPlayer(id).mObj;
}
} break;
default: STHROWF("Unsupported search identifier");
}
// Default to a null object
return NullObject();
}
// ================================================================================================
void Register_CPlayer(HSQUIRRELVM vm)
{
@ -2220,6 +2251,8 @@ void Register_CPlayer(HSQUIRRELVM vm)
(_SC("SetAnimation"), &CPlayer::SetAnimation)
.Overload< void (CPlayer::*)(Int32, Int32) const >
(_SC("SetAnimation"), &CPlayer::SetAnimation)
// Static Functions
.StaticFunc(_SC("Find"), &Player_FindAuto)
// Raw Squirrel Methods
.SquirrelFunc(_SC("Msg"), &CPlayer::Msg)
.SquirrelFunc(_SC("MsgP"), &CPlayer::MsgP)