Hi.
I make plugin for ZR mode with which players buy weapons through the chat commands. But I have a question. Due to the fact that I'm new to this, I want to know whether it is possible to load the server because of my plugin and maybe or somehow reduce the code itself without losing functionality.
PHP Code:
new Handle:smoke_limit = INVALID_HANDLE;
new Handle:smoke_price = INVALID_HANDLE;
public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max)
{
MarkNativeAsOptional("ZR_IsClientZombie");
return APLRes_Success;
}
public OnPluginStart()
{
RegConsoleCmd("sm_smoke", Cmd_smoke, "Buy weapon Smoke - VIP Only");
smoke_price = CreateConVar("smoke_price", "2000", "Set price to Smoke", _, true, 0.0, true, 16000.0);
smoke_limit = CreateConVar("smoke_limit", "1", "Set limit to Smoke", _, true, 0.0, true, 16000.0);
HookEvent("round_start", Event_RoundStart);
HookEvent("round_end", Event_RoundEnd);
HookEvent("player_spawn", Event_PlayerSpawn);
for(new i = 1; i <= MaxClients; i++)
{
if(IsClientInGame(i)) OnClientPutInServer(i) && OnClientConnected(i);
}
}
public void OnClientConnected(int client)
{
SmokeCounter[client] = 0;
}
public void OnClientPutInServer(int client)
{
SmokeCounter[client] = 0;
}
public Action Event_RoundStart(Event event, const char[] name, bool dontBroadcast)
{
new client_id = GetEventInt(event, "userid");
new client = GetClientOfUserId(client_id);
SmokeCounter[client] = 0;
}
public Action Event_PlayerSpawn(Event event, const char[] name, bool dontBroadcast)
{
new client_id = GetEventInt(event, "userid");
new client = GetClientOfUserId(client_id);
SmokeCounter[client] = 0;
}
public Action Event_RoundEnd(Event event, const char[] name, bool dontBroadcast)
{
new client_id = GetEventInt(event, "userid");
new client = GetClientOfUserId(client_id);
SmokeCounter[client] = 0;
}
public Action:Cmd_smoke(client, arg)
{
{
if(client == 0)
{
return Plugin_Handled;
}
new money = GetEntProp(client, Prop_Send, "m_iAccount");
new price = GetConVarInt(smoke_price);
if(money < price)
{
if (!GetAdminFlag(GetUserAdmin(client), Admin_Reservation))
{
SendHudMessage(client, 3, -1.0, -0.6, 0xFF0AFF00, 0xFF0AFF00, 1, 0.1, 0.5, 1.5, 5.0, "Only VIP's can buy smoke");
return Plugin_Handled;
}
if(GetClientTeam(client) < 2)
{
SendHudMessage(client, 3, -1.0, -0.6, 0xFF00FF00, 0xFF00FF00,1, 0.1, 0.5, 1.5, 5.0, "You need to be in a team for buy weapons");
return Plugin_Handled;
}
if(!IsPlayerAlive(client))
{
SendHudMessage(client, 3, -1.0, -0.6, 0xFF00FF00, 0xFF00FF00,1, 0.1, 0.5, 1.5, 5.0, "You need to be alive for buy weapons");
return Plugin_Handled;
}
if ((GetFeatureStatus(FeatureType_Native, "ZR_IsClientZombie") == FeatureStatus_Available) && ZR_IsClientZombie(client))
{
SendHudMessage(client, 3, -1.0, -0.6, 0xFF0000FF, 0xFF0000FF,1, 0.1, 0.5, 1.5, 5.0, "You need to be human for buy weapons");
return Plugin_Handled;
}
if(GetConVarInt(smoke_limit) > 0 && SmokeCounter[client] >= GetConVarInt(smoke_limit))
{
SendHudMessage(client, 3, -1.0, -0.6, 0xFF0000FF, 0xFF0000FF,1, 0.1, 0.5, 1.5, 5.0, "You can't buy more smoke in this round");
SendHudMessage(client, 4, -1.5, -0.6, 0xFF00FF00, 0xFF00FF00,1, 0.1, 0.5, 1.5, 4.0, "Limit %i/%i",SmokeCounter[client],GetConVarInt(smoke_limit));
return Plugin_Handled;
}
SendHudMessage(client, 3, -1.0, -0.6, 0xFF008000, 0xFF008000,1, 0.1, 0.5, 1.5, 4.0, "You not have enough money Smoke price %i$", price);
}
if (money > price)
{
if (!GetAdminFlag(GetUserAdmin(client), Admin_Reservation))
{
SendHudMessage(client, 3, -1.0, -0.6, 0xFF0AFF00, 0xFF0AFF00,1, 0.1, 0.5, 1.5, 5.0, "Only VIP's can buy smoke");
return Plugin_Handled;
}
if(GetClientTeam(client) < 2)
{
SendHudMessage(client, 3, -1.0, -0.6, 0xFF00FF00, 0xFF00FF00,1, 0.1, 0.5, 1.5, 5.0, "You need to be in a team for buy weapons");
return Plugin_Handled;
}
if(!IsPlayerAlive(client))
{
SendHudMessage(client, 3, -1.0, -0.6, 0xFF00FF00, 0xFF00FF00,1, 0.1, 0.5, 1.5, 5.0, "You need to be alive for buy weapons");
return Plugin_Handled;
}
if ((GetFeatureStatus(FeatureType_Native, "ZR_IsClientZombie") == FeatureStatus_Available) && ZR_IsClientZombie(client))
{
SendHudMessage(client, 3, -1.0, -0.6, 0xFF0000FF, 0xFF0000FF,1, 0.1, 0.5, 1.5, 5.0, "You need to be human for buy weapons");
return Plugin_Handled;
}
if(GetConVarInt(smoke_limit) > 0 && SmokeCounter[client] >= GetConVarInt(smoke_limit))
{
SendHudMessage(client, 3, -1.0, -0.6, 0xFF0000FF, 0xFF0000FF,1, 0.1, 0.5, 1.5, 5.0, "You can't buy more Smoke in this round - Limit %i/%i",SmokeCounter[client],GetConVarInt(smoke_limit));
return Plugin_Handled;
}
new mb = money - price;
SetEntProp(client, Prop_Send, "m_iAccount", mb);
GivePlayerItem(client, "weapon_smokegrenade");
SendHudMessage(client, 3, -1.0, -0.6, 0x00FF0000, 0x00FF0000,1, 0.1, 0.5, 1.5, 4.0, "You have purchased SMOKE");
CounterSmoke[client]++;
SendHudMessage(client, 4, -0.5, -0.4, 0xFF00FF00, 0xFF00FF00,1, 0.1, 0.5, 1.5, 4.0, "Limit %i/%i",SmokeCounter[client],GetConVarInt(smoke_limit));
}
}
return Plugin_Handled;
}