-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy path8ball.sp
81 lines (62 loc) · 2.16 KB
/
8ball.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
#pragma semicolon 1
#include <sourcemod>
#include <colors>
#pragma newdecls required
#define MAXMSG 192
Handle hAnswers = INVALID_HANDLE;
public Plugin myinfo = {
name = "8Ball",
description = "Simple 8Ball Game Plugin. Works the same as Coinflip / Dice Roll.",
author = "spoon, devilesk",
version = "1.4.0",
url = "https://github.com/devilesk/rl4d2l-plugins"
};
public void OnPluginStart() {
RegConsoleCmd("sm_8ball", Command_8ball);
Handle hAnswersFile = INVALID_HANDLE;
char sFile[PLATFORM_MAX_PATH];
BuildPath(Path_SM, sFile, sizeof(sFile), "configs/8ball.ini");
hAnswersFile = OpenFile(sFile, "r");
if (hAnswersFile == INVALID_HANDLE) {
SetFailState("[OnPluginStart] \"%s\" not found!", sFile);
return;
}
if (hAnswers == INVALID_HANDLE)
hAnswers = CreateArray(MAXMSG);
char sBuffer[MAXMSG];
while(ReadFileLine(hAnswersFile, sBuffer, sizeof(sBuffer))) {
TrimString(sBuffer);
if((StrContains(sBuffer, "//") == -1) && (!StrEqual(sBuffer, ""))) {
PushArrayString(hAnswers, sBuffer);
}
}
CloseHandle(hAnswersFile);
}
public Action Command_8ball(int client, int args) {
if (args == 0) {
CPrintToChat(client, "{default}[{green}8Ball{default}] Usage: !8ball <question>");
return;
}
else {
char question[MAXMSG];
char answer[MAXMSG];
char client_name[32];
GetClientName(client, client_name, 32);
GetCmdArgString(question, sizeof(question));
StripQuotes(question);
PrintToChatAll("\x01[\x048Ball\x01] \x03%s\x01 Asked: \x05%s\x01", client_name, question[0]);
int maxIndex = GetArraySize(hAnswers) - 1;
int rndIndex = Math_GetRandomInt(0, maxIndex);
GetArrayString(hAnswers, rndIndex, answer, sizeof(answer));
CPrintToChatAll(answer);
}
}
#define SIZE_OF_INT 2147483647 // without 0
stock int Math_GetRandomInt(int min, int max)
{
int random = GetURandomInt();
if (random == 0) {
random++;
}
return RoundToCeil(float(random) / (float(SIZE_OF_INT) / float(max - min + 1))) + min - 1;
}