Quote:
Originally Posted by iskenderkebab33
thanks, can you add also, a Player can only do it 3 times. after 3 times a Text will come like: you had your attempts. or something like that.
|
PHP Code:
#include <sourcemod>
#include <sdkhooks>
#pragma semicolon 1
#pragma newdecls required
#define INVIS_MAX_AMOUNT 3
bool gB_Invisiblity[MAXPLAYERS + 1];
int gI_InvisCount[MAXPLAYERS + 1];
Handle gH_InvisTimer[MAXPLAYERS + 1];
public void OnPluginStart()
{
HookEvent("round_start", Event_RoundStart, EventHookMode_Post);
}
public void OnMapEnd()
{
for (int i = 1; i <= MaxClients; ++i)
if (IsClientInGame(i))
DeleteTimer(i);
}
public void OnClientPutInServer(int client)
{
if (!IsFakeClient(client))
SDKHook(client, SDKHook_SetTransmit, OnSetTransmit);
}
public void Event_RoundStart(Event hEvent, const char[] sEventName, bool bDontBroadcast)
{
for (int i = 1; i <= MaxClients; ++i)
{
if (IsClientInGame(i))
{
DeleteTimer(i);
gB_Invisiblity[i] = false;
gI_InvisCount[i] = 0;
SetEntProp(i, Prop_Send, "m_bDrawViewmodel", true);
}
}
}
public Action OnSetTransmit(int entity, int client)
{
if (client != entity && gB_Invisiblity[entity])
return Plugin_Handled;
return Plugin_Continue;
}
public Action OnPlayerRunCmd(int client, int &buttons)
{
if (IsPlayerAlive(client))
{
if (buttons & IN_RELOAD)
{
if (!gB_Invisiblity[client])
{
if (gI_InvisCount[client] < INVIS_MAX_AMOUNT)
{
gB_Invisiblity[client] = true;
++gI_InvisCount[client];
DeleteTimer(client);
gH_InvisTimer[client] = CreateTimer(5.0, Timer_Visible, GetClientUserId(client));
SetEntProp(client, Prop_Send, "m_bDrawViewmodel", false);
PrintCenterText(client, "You're now Invisible");
}
else PrintCenterText(client, "You've had your %i attempts.", INVIS_MAX_AMOUNT);
}
}
else if (gB_Invisiblity[client])
{
DeleteTimer(client);
gB_Invisiblity[client] = false;
SetEntProp(client, Prop_Send, "m_bDrawViewmodel", true);
PrintCenterText(client, "You're now Visible");
}
}
}
public Action Timer_Visible(Handle hTimer, any iUser)
{
int client = GetClientOfUserId(iUser);
if (0 < client <= MaxClients && IsClientInGame(client) && IsPlayerAlive(client))
{
gH_InvisTimer[client] = null;
gB_Invisiblity[client] = false;
SetEntProp(client, Prop_Send, "m_bDrawViewmodel", true);
PrintCenterText(client, "You're now Visible");
}
}
void DeleteTimer(int client)
{
if (gH_InvisTimer[client] != null)
{
delete gH_InvisTimer[client];
gH_InvisTimer[client] = null;
}
}
__________________