I have a small problem, namely what time a plugin adds its log error
PHP Code:
L 05/14/2017 - 03:36:18: SourceMod error session started
L 05/14/2017 - 03:36:18: Info (map "de_mirage") (file "errors_20170514.log")
L 05/14/2017 - 03:36:18: [SM] Exception reported: Client index -1 is invalid
L 05/14/2017 - 03:36:18: [SM] Blaming: LosowyVip.smx
L 05/14/2017 - 03:36:18: [SM] Call stack trace:
L 05/14/2017 - 03:36:18: [SM] [0] AddUserFlags
L 05/14/2017 - 03:36:18: [SM] [1] Line 47, LosowyVip.sp::Event_RoundStart
L 05/14/2017 - 08:18:41: Error log file session closed.
PHP Code:
#include <sourcemod>
public Plugin:myinfo =
{
name = "LosowyVip",
author = "Hanys",
description = "Plugin losuje losowa osobe ktora otrzyma flage",
version = "1.0",
url = "http://hanys.dispark.pl"
}
new Handle:Random_round;
new Handle:Random_player;
new Rounds = 0;
public OnPluginStart()
{
CreateConVar("sm_randomvip", "1.0", "Losowy VIP", FCVAR_PLUGIN|FCVAR_SPONLY|FCVAR_REPLICATED|FCVAR_NOTIFY|FCVAR_DONTRECORD);
Random_round = CreateConVar("random_round", "0", "W ktorej rundzie ma losowac losowego vip'a (Uwaga: Rozgrzewka liczona jest jako 1 runda!) 0:Losowy vip wylaczony", FCVAR_NOTIFY);
Random_player = CreateConVar("random_player", "0", "Ile osob wymaganych jest do wylosowania losowego vip'a", FCVAR_NOTIFY);
AutoExecConfig(true, "sm_vip_random");
HookEvent("round_start", Event_RoundStart);
HookEvent("cs_win_panel_match", RestartRound);
}
public Event_RoundStart(Handle:event, const String:name[], bool:dontBroadcast)
{
new winner = GetRandomPlayer(3);
new g_random_round = GetConVarInt(Random_round);
Rounds = Rounds + 1;
if (Rounds == g_random_round)
{
if (winner == -1)
{
PrintToChatAll("\x04[\x04VIP\x01] \x06Na serwerze znajduje sie za malo graczy do wylosowania losowego VIP'a\x01");
}
AddUserFlags(winner, Admin_Custom1);
PrintToChatAll("[\x04VIP\x01] \x06Trwa losowanie VIP'a...\x01");
PrintToChatAll("[\x04VIP\x01] \x06-----\x01");
PrintToChatAll("[\x04VIP\x01] \x06-----\x01");
PrintToChatAll("[\x04VIP\x01] \x06-----\x01");
PrintToChatAll("[\x04VIP\x01] \x06Losowym VIP'em zostaje \x02%N\x01\x06! Gratulujemy!\x01", winner);
}
}
public Action:RestartRound(Handle:event, const String:name[], bool:dontBroadcast)
{
Rounds = 0;
}
stock GetRandomPlayer(team)
{
new g_random_player = GetConVarInt(Random_player);
new clients[MaxClients + 1], clientCount;
for (new i = 1; i <= MaxClients; i++)
if (IsClientInGame(i))
clients[clientCount++] = i;
if (clientCount <= g_random_player)
return -1;
return clients[GetRandomInt(0, clientCount - 1)];
}