Skip to content

Commit

Permalink
Enforce third person
Browse files Browse the repository at this point in the history
  • Loading branch information
Kxnrl committed Jul 27, 2022
1 parent 0e170bf commit 8e8ef69
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 18 deletions.
1 change: 1 addition & 0 deletions include/store.inc
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ native bool Store_HasPlayerSkin(int client);
native bool Store_GetPlayerSkin(int client, char[] skin, int maxLen);
native void Store_SaveClientAll(int client);
native bool Store_IsPlayerTP(int client);
native bool Store_SetPlayerTP(int client, bool state);
native bool Store_IsPlayerHide(int client);
native bool Store_IsStoreSpray(int client);
native bool Store_GetClientPlayerSkins(int client, ArrayList array);
Expand Down
12 changes: 12 additions & 0 deletions store.sp
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,7 @@ public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max
CreateNative("Store_GetSkinLevel", Native_GetSkinLevel);
CreateNative("Store_GetItemList", Native_GetItemList);
CreateNative("Store_IsPlayerTP", Native_IsPlayerTP);
CreateNative("Store_SetPlayerTP", Native_SetPlayerTP);
CreateNative("Store_IsPlayerHide", Native_IsPlayerHide);
CreateNative("Store_IsStoreSpray", Native_IsStoreSpray);
CreateNative("Store_ApplyPlayerSkin", Native_ApplyPlayerSkin);
Expand Down Expand Up @@ -1196,6 +1197,11 @@ static any Native_IsPlayerTP(Handle plugin, int numParams)
return IsPlayerTP(GetNativeCell(1));
}

static any Native_SetPlayerTP(Handle plugin, int numParams)
{
return SetPlayerTP(GetNativeCell(1), !!GetNativeCell(2));
}

static any Native_IsPlayerHide(Handle plugin, int numParams)
{
return false;
Expand Down Expand Up @@ -4395,6 +4401,12 @@ stock bool IsPlayerTP(int client)
return false;
}

stock bool SetPlayerTP(int client, bool state)
{
CheckMirror(client);
return ToggleTp(client, state);
}

static void OnGameOver(Event e, const char[] name, bool dB)
{
g_bInterMission = true;
Expand Down
69 changes: 51 additions & 18 deletions store/tpmode.sp
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,37 @@ bool g_bMirror[MAXPLAYERS+1];
bool g_bThirdperson[MAXPLAYERS+1];

static ConVar store_thirdperson_enabled = null;
static ConVar store_thirdperson_enforce = null;
static ConVar mp_forcecamera = null;

void TPMode_OnPluginStart()
{
#if !defined GM_IS
store_thirdperson_enabled = CreateConVar("store_thirdperson_enabled", "1", "Enable or not third person.", _, true, 0.0, true, 1.0);
store_thirdperson_enabled.AddChangeHook(ConVar_store_thirdperson_enabled);

mp_forcecamera = FindConVar("mp_forcecamera");
store_thirdperson_enabled = CreateConVar("store_thirdperson_enabled", "1", "Enabled or not third person.", _, true, 0.0, true, 1.0);
store_thirdperson_enforce = CreateConVar("store_thirdperson_enforce", "1", "Enforce player third person.", _, true, 0.0, true, 1.0);


#if !defined GM_IS
ConVar sv_allow_thirdperson = FindConVar("sv_allow_thirdperson");
sv_allow_thirdperson.IntValue = 1;
sv_allow_thirdperson.AddChangeHook(ConVar_sv_allow_thirdperson);

mp_forcecamera = FindConVar("mp_forcecamera");
#else
store_thirdperson_enabled.BoolValue = false;
store_thirdperson_enforce.BoolValue = false;
#endif

store_thirdperson_enabled.AddChangeHook(ConVar_store_thirdperson_enabled);

RegConsoleCmd("sm_tp", Command_TP, "Toggle TP Mode");
RegConsoleCmd("sm_seeme", Command_Mirror, "Toggle Mirror Mode");

HookEvent("player_spawn", Event_PlayerSpawn, EventHookMode_Post);
#endif

CreateTimer(0.5, EnforceCamera, _, TIMER_REPEAT);
}

public void ConVar_store_thirdperson_enabled(ConVar convar, const char[] oldValue, const char[] newValue)
static void ConVar_store_thirdperson_enabled(ConVar convar, const char[] oldValue, const char[] newValue)
{
if (!convar.BoolValue || StringToInt(newValue) == 0)
{
Expand All @@ -40,18 +49,20 @@ public void ConVar_store_thirdperson_enabled(ConVar convar, const char[] oldValu
}
}

public void ConVar_sv_allow_thirdperson(ConVar convar, const char[] oldValue, const char[] newValue)
#if !defined GM_IS
static void ConVar_sv_allow_thirdperson(ConVar convar, const char[] oldValue, const char[] newValue)
{
convar.IntValue = 1;
}
#endif

void TPMode_OnClientConnected(int client)
{
g_bThirdperson[client] = false;
g_bMirror[client] = false;
}

public Action Command_TP(int client, int args)
static Action Command_TP(int client, int args)
{
if(!client || !IsClientInGame(client))
return Plugin_Handled;
Expand Down Expand Up @@ -93,7 +104,7 @@ public Action Command_TP(int client, int args)
return Plugin_Handled;
}

public Action Command_Mirror(int client, int args)
static Action Command_Mirror(int client, int args)
{
if(!client || !IsClientInGame(client))
return Plugin_Handled;
Expand Down Expand Up @@ -141,12 +152,12 @@ public Action Command_Mirror(int client, int args)
return Plugin_Handled;
}

public void Event_PlayerSpawn(Event e, const char[] name, bool dontBroadcast)
static void Event_PlayerSpawn(Event e, const char[] name, bool dontBroadcast)
{
CreateTimer(0.3, Timer_TPSpawnPost, e.GetInt("userid"));
}

public Action Timer_TPSpawnPost(Handle timer, int userid)
static Action Timer_TPSpawnPost(Handle timer, int userid)
{
int client = GetClientOfUserId(userid);
if (!client || !IsClientInGame(client) || !IsPlayerAlive(client) || IsFakeClient(client))
Expand All @@ -158,13 +169,14 @@ public Action Timer_TPSpawnPost(Handle timer, int userid)
return Plugin_Stop;
}

void ToggleTp(int client, bool state)
bool ToggleTp(int client, bool state)
{
ClientCommand(client, state ? "thirdperson" : "firstperson");
ClientCommand(client, state ? "cam_collision 0; cam_idealpitch 0; cam_idealdist 150; cam_idealdistright 0; cam_idealdistup 0; thirdperson;" : "firstperson");
g_bThirdperson[client] = state;
return g_bThirdperson[client];
}

void ToggleMirror(int client, bool state)
static void ToggleMirror(int client, bool state)
{
if(state)
{
Expand Down Expand Up @@ -192,11 +204,11 @@ void CheckMirror(int client)
{
if (IsFakeClient(client) || !g_bMirror[client])
return;

ToggleMirror(client, false);
}

bool IsImmunityClient(int client)
static bool IsImmunityClient(int client)
{
AdminId admin = GetUserAdmin(client);
if (admin == INVALID_ADMIN_ID || admin.ImmunityLevel <= 80)
Expand All @@ -205,10 +217,31 @@ bool IsImmunityClient(int client)
return true;
}

bool AllowTP()
static bool AllowTP()
{
if (store_thirdperson_enabled == null)
return false;

return store_thirdperson_enabled.BoolValue;
}

static Action EnforceCamera(Handle timer)
{
if (!store_thirdperson_enforce.BoolValue)
return Plugin_Continue;

for(int i = 1; i <= MaxClients; i++)
{
if (!IsClientInGame(i) || IsFakeClient(i))
continue;

// in state -> skipped
if (g_bThirdperson[i] || g_bMirror[i])
continue;

// every think we enforce to firstperson
ToggleTp(i, false);
}

return Plugin_Continue;
}

0 comments on commit 8e8ef69

Please sign in to comment.