forked from Walderr/ZE-Plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
random.sp
83 lines (63 loc) · 1.81 KB
/
random.sp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#include <cstrike>
bool alreadyWon[MAXPLAYERS+1];
public void OnPluginStart()
{
RegAdminCmd("sm_random", Command_Random, ADMFLAG_BAN);
RegAdminCmd("sm_testrandom", Command_TestRandom, ADMFLAG_BAN);
}
public void OnMapStart()
{
for(int i = 1; i <= MaxClients; i++) alreadyWon[i] = false;
}
public Action Command_Random(int client, int args)
{
CreateTimer(0.1, Timer_PrintCalculation);
CreateTimer(1.5, Timer_PrintWinner);
return Plugin_Handled;
}
public Action Timer_PrintCalculation(Handle timer)
{
PrintToChatAll(" \x03[Random] \x0BCalculation...");
}
public Action Timer_PrintWinner(Handle timer)
{
int players = 0, index[MAXPLAYERS+1];
for(int i = 1; i <= MaxClients; i++)
{
if(IsClientInGame(i) && !IsFakeClient(i) && !alreadyWon[i] && CS_GetClientContributionScore(i) > 10)
{
players++;
index[players] = i;
}
}
if(!players)
{
PrintToChatAll(" \x03[Random] \x0BNo matching players!");
return;
}
int winner = index[GetRandomInt(1, players)];
alreadyWon[winner] = true;
PrintToChatAll(" \x03[Random] \x0BThe winner is \x09%N", winner);
return;
}
//============================================================
public Action Command_TestRandom(int client, int args)
{
int players = 0, index[MAXPLAYERS+1];
for(int i = 1; i <= MaxClients; i++)
{
if(IsClientInGame(i) && !IsFakeClient(i) && !alreadyWon[i] && CS_GetClientContributionScore(i) > 10)
{
players++;
index[players] = i;
}
}
if(!players)
{
PrintToChat(client, " \x03[Random Test] \x0BНет подходящих игроков!");
return Plugin_Handled;
}
int winner = index[GetRandomInt(1, players)];
PrintToChat(client, " \x03[Random Test] \x0BПобедителем бы стал \x09%N", winner);
return Plugin_Handled;
}