mirror of
				https://github.com/VCMP-SqMod/SqMod.git
				synced 2025-10-31 14:27:18 +01:00 
			
		
		
		
	Add back some of the entity search functions.
This commit is contained in:
		| @@ -14,6 +14,32 @@ | ||||
| namespace SqMod { | ||||
| namespace Algo { | ||||
|  | ||||
| // ------------------------------------------------------------------------------------------------ | ||||
| static const Object & Blip_FindBySprID(Int32 sprid) | ||||
| { | ||||
|     // Perform a range check on the specified identifier | ||||
|     if (sprid < 0) | ||||
|     { | ||||
|         STHROWF("The specified sprite identifier is invalid: %d", sprid); | ||||
|     } | ||||
|     // Obtain the ends of the entity pool | ||||
|     Core::Blips::const_iterator itr = Core::Get().GetBlips().cbegin(); | ||||
|     Core::Blips::const_iterator end = Core::Get().GetBlips().cend(); | ||||
|     // Process each entity in the pool | ||||
|     for (; itr != end; ++itr) | ||||
|     { | ||||
|         // Does the identifier match the specified one? | ||||
|         if (itr->mSprID == sprid) | ||||
|         { | ||||
|             return itr->mObj; // Stop searching and return this entity | ||||
|         } | ||||
|     } | ||||
|     // Unable to locate a blip matching the specified identifier | ||||
|     return NullObject(); | ||||
| } | ||||
|  | ||||
| // ------------------------------------------------------------------------------------------------ | ||||
|  | ||||
| // ================================================================================================ | ||||
| void Register(HSQUIRRELVM vm) | ||||
| { | ||||
| @@ -25,6 +51,7 @@ void Register(HSQUIRRELVM vm) | ||||
|         .Func(_SC("TagBegins"), &Entity< CBlip >::FirstWhereTagBegins) | ||||
|         .Func(_SC("TagEnds"), &Entity< CBlip >::FirstWhereTagEnds) | ||||
|         .Func(_SC("TagContains"), &Entity< CBlip >::FirstWhereTagContains) | ||||
|         .Func(_SC("WithSprID"), &Blip_FindBySprID) | ||||
|     ); | ||||
|  | ||||
|     fns.Bind(_SC("Checkpoint"), Table(vm) | ||||
|   | ||||
| @@ -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) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user