diff --git a/source/Base/Algo.cpp b/source/Base/Algo.cpp index 448e0ee1..1fb42904 100644 --- a/source/Base/Algo.cpp +++ b/source/Base/Algo.cpp @@ -131,7 +131,7 @@ static const LightObj & Blip_FindBySprID(Int32 sprid) } } // Unable to locate a blip matching the specified identifier - return NullLightObj(); + return Core::Get().GetNullBlip(); } /* ------------------------------------------------------------------------------------------------ diff --git a/source/Constants.cpp b/source/Constants.cpp index 8ec321c6..deebb64b 100644 --- a/source/Constants.cpp +++ b/source/Constants.cpp @@ -143,6 +143,7 @@ static const EnumElement g_EventEnum[] = { {_SC("PlayerKeyPress"), EVT_PLAYERKEYPRESS}, {_SC("PlayerKeyRelease"), EVT_PLAYERKEYRELEASE}, {_SC("PlayerSpectate"), EVT_PLAYERSPECTATE}, + {_SC("PlayerUnspectate"), EVT_PLAYERUNSPECTATE}, {_SC("PlayerCrashReport"), EVT_PLAYERCRASHREPORT}, {_SC("VehicleExplode"), EVT_VEHICLEEXPLODE}, {_SC("VehicleRespawn"), EVT_VEHICLERESPAWN}, diff --git a/source/Core.hpp b/source/Core.hpp index 550c9f63..3edcd0e3 100644 --- a/source/Core.hpp +++ b/source/Core.hpp @@ -530,6 +530,7 @@ protected: SignalPair mOnKeyPress; SignalPair mOnKeyRelease; SignalPair mOnSpectate; + SignalPair mOnUnspectate; SignalPair mOnCrashreport; SignalPair mOnObjectShot; SignalPair mOnObjectTouched; @@ -1159,6 +1160,7 @@ public: void EmitPlayerKeyPress(Int32 player_id, Int32 bind_id); void EmitPlayerKeyRelease(Int32 player_id, Int32 bind_id); void EmitPlayerSpectate(Int32 player_id, Int32 target_player_id); + void EmitPlayerUnspectate(Int32 player_id); void EmitPlayerCrashreport(Int32 player_id, CCStr report); void EmitVehicleExplode(Int32 vehicle_id); void EmitVehicleRespawn(Int32 vehicle_id); @@ -1316,6 +1318,7 @@ public: SignalPair mOnPlayerKeyPress; SignalPair mOnPlayerKeyRelease; SignalPair mOnPlayerSpectate; + SignalPair mOnPlayerUnspectate; SignalPair mOnPlayerCrashreport; SignalPair mOnVehicleExplode; SignalPair mOnVehicleRespawn; diff --git a/source/CoreEvents.cpp b/source/CoreEvents.cpp index 7e9df195..8d082a4b 100644 --- a/source/CoreEvents.cpp +++ b/source/CoreEvents.cpp @@ -594,6 +594,14 @@ void Core::EmitPlayerSpectate(Int32 player_id, Int32 target_player_id) (*mOnPlayerSpectate.first)(_player.mObj, _target.mObj); } +// ------------------------------------------------------------------------------------------------ +void Core::EmitPlayerUnspectate(Int32 player_id) +{ + PlayerInst & _player = m_Players.at(player_id); + (*_player.mOnUnspectate.first)(); + (*mOnPlayerUnspectate.first)(_player.mObj); +} + // ------------------------------------------------------------------------------------------------ void Core::EmitPlayerCrashreport(Int32 player_id, CCStr report) { diff --git a/source/CoreInst.cpp b/source/CoreInst.cpp index 09adf1ee..bde8766c 100644 --- a/source/CoreInst.cpp +++ b/source/CoreInst.cpp @@ -620,6 +620,7 @@ void Core::PlayerInst::InitEvents() InitSignalPair(mOnKeyPress, mEvents, "KeyPress"); InitSignalPair(mOnKeyRelease, mEvents, "KeyRelease"); InitSignalPair(mOnSpectate, mEvents, "Spectate"); + InitSignalPair(mOnUnspectate, mEvents, "Unspectate"); InitSignalPair(mOnCrashreport, mEvents, "Crashreport"); InitSignalPair(mOnObjectShot, mEvents, "ObjectShot"); InitSignalPair(mOnObjectTouched, mEvents, "ObjectTouched"); @@ -698,6 +699,7 @@ void Core::PlayerInst::DropEvents() ResetSignalPair(mOnKeyPress); ResetSignalPair(mOnKeyRelease); ResetSignalPair(mOnSpectate); + ResetSignalPair(mOnUnspectate); ResetSignalPair(mOnCrashreport); ResetSignalPair(mOnObjectShot); ResetSignalPair(mOnObjectTouched); diff --git a/source/CoreUtils.cpp b/source/CoreUtils.cpp index 295c0676..bd560ec9 100644 --- a/source/CoreUtils.cpp +++ b/source/CoreUtils.cpp @@ -127,6 +127,7 @@ void Core::InitEvents() InitSignalPair(mOnPlayerKeyPress, m_Events, "PlayerKeyPress"); InitSignalPair(mOnPlayerKeyRelease, m_Events, "PlayerKeyRelease"); InitSignalPair(mOnPlayerSpectate, m_Events, "PlayerSpectate"); + InitSignalPair(mOnPlayerUnspectate, m_Events, "PlayerUnspectate"); InitSignalPair(mOnPlayerCrashreport, m_Events, "PlayerCrashreport"); InitSignalPair(mOnVehicleExplode, m_Events, "VehicleExplode"); InitSignalPair(mOnVehicleRespawn, m_Events, "VehicleRespawn"); @@ -259,6 +260,7 @@ void Core::DropEvents() ResetSignalPair(mOnPlayerKeyPress); ResetSignalPair(mOnPlayerKeyRelease); ResetSignalPair(mOnPlayerSpectate); + ResetSignalPair(mOnPlayerUnspectate); ResetSignalPair(mOnPlayerCrashreport); ResetSignalPair(mOnVehicleExplode); ResetSignalPair(mOnVehicleRespawn); diff --git a/source/Entity/Player.cpp b/source/Entity/Player.cpp index c73ed006..00b4de8c 100644 --- a/source/Entity/Player.cpp +++ b/source/Entity/Player.cpp @@ -1098,7 +1098,7 @@ LightObj & CPlayer::GetVehicle() const return Core::Get().GetVehicle(id).mObj; } // Default to a null object - return NullLightObj(); + return Core::Get().GetNullVehicle(); } // ------------------------------------------------------------------------------------------------ @@ -1299,7 +1299,7 @@ LightObj & CPlayer::StandingOnVehicle() const return Core::Get().GetVehicle(id).mObj; } // Default to a null object - return NullLightObj(); + return Core::Get().GetNullVehicle(); } // ------------------------------------------------------------------------------------------------ @@ -1316,7 +1316,7 @@ LightObj & CPlayer::StandingOnObject() const return Core::Get().GetObject(id).mObj; } // Default to a null object - return NullLightObj(); + return Core::Get().GetNullObject(); } // ------------------------------------------------------------------------------------------------ @@ -1342,7 +1342,7 @@ LightObj & CPlayer::GetSpectator() const return Core::Get().GetPlayer(id).mObj; } // Default to a null object - return NullLightObj(); + return Core::Get().GetNullPlayer(); } // ------------------------------------------------------------------------------------------------ @@ -2405,7 +2405,7 @@ SQInteger CPlayer::AnnounceEx(HSQUIRRELVM vm) } // ------------------------------------------------------------------------------------------------ -static SQInteger Player_FindAuto(HSQUIRRELVM vm) +SQInteger Player_FindAuto(HSQUIRRELVM vm) { // See if a search token was specified if (sq_gettop(vm) <= 1) @@ -2493,7 +2493,7 @@ static SQInteger Player_FindAuto(HSQUIRRELVM vm) } // ------------------------------------------------------------------------------------------------ -static SQInteger Player_ExistsAuto(HSQUIRRELVM vm) +SQInteger Player_ExistsAuto(HSQUIRRELVM vm) { // See if a search token was specified if (sq_gettop(vm) <= 1) diff --git a/source/Main.cpp b/source/Main.cpp index e34f32d7..4e1120c0 100644 --- a/source/Main.cpp +++ b/source/Main.cpp @@ -676,7 +676,14 @@ static void OnPlayerSpectate(int32_t player_id, int32_t target_player_id) // Attempt to forward the event try { - Core::Get().EmitPlayerSpectate(player_id, target_player_id); + if (target_player_id < 0) + { + Core::Get().EmitPlayerUnspectate(player_id); + } + else + { + Core::Get().EmitPlayerSpectate(player_id, target_player_id); + } } SQMOD_CATCH_EVENT_EXCEPTION(OnPlayerSpectate) // See if a reload was requested diff --git a/source/Misc/Register.cpp b/source/Misc/Register.cpp index c5c45cf1..49664063 100644 --- a/source/Misc/Register.cpp +++ b/source/Misc/Register.cpp @@ -18,35 +18,8 @@ namespace SqMod { // ------------------------------------------------------------------------------------------------ -static const LightObj & FindPlayer(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 NullLightObj(); -} +extern SQInteger Player_FindAuto(HSQUIRRELVM vm); +extern SQInteger Player_ExistsAuto(HSQUIRRELVM vm); // ------------------------------------------------------------------------------------------------ extern void Register_Broadcast(HSQUIRRELVM vm); @@ -150,7 +123,8 @@ void Register_Misc(HSQUIRRELVM vm) RootTable(vm).Bind(_SC("SqServer"), srvns); RootTable(vm) - .Func(_SC("FindPlayer"), &FindPlayer) + .SquirrelFunc(_SC("FindPlayer"), &Player_FindAuto) + .SquirrelFunc(_SC("PlayerExists"), &Player_ExistsAuto) .Func(_SC("GetKeyCodeName"), &GetKeyCodeName) .FmtFunc(_SC("SetKeyCodeName"), &SetKeyCodeName) .Func(_SC("GetModelName"), &GetModelName) diff --git a/source/SqBase.hpp b/source/SqBase.hpp index 39d0f724..56d9e6a5 100644 --- a/source/SqBase.hpp +++ b/source/SqBase.hpp @@ -364,6 +364,7 @@ enum EventType EVT_PLAYERKEYPRESS, EVT_PLAYERKEYRELEASE, EVT_PLAYERSPECTATE, + EVT_PLAYERUNSPECTATE, EVT_PLAYERCRASHREPORT, EVT_VEHICLEEXPLODE, EVT_VEHICLERESPAWN,