forked from TFC-Developers/sw_base_plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SW_MESSAGE_FACTS.sma
65 lines (52 loc) · 1.23 KB
/
SW_MESSAGE_FACTS.sma
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
#include "include/global"
new const g_sFactFile[] = "sw_message_facts.txt"
new Array:g_MessageList
new g_iMessageCount
public plugin_init()
{
RegisterPlugin()
g_MessageList = ArrayCreate(MAX_HUDMSG_LEN)
ReadFactFile()
}
public plugin_end()
{
ArrayDestroy(g_MessageList)
}
ReadFactFile()
{
new sFile[128]; BuildAMXFilePath(g_sFactFile, sFile, charsmax(sFile), "amxx_configsdir")
new iFileHandle = fopen(sFile, "rt")
if (!iFileHandle)
{
WarningLog(FM_FOPEN_WARNING, sFile)
return 0
}
new sData[MAX_HUDMSG_LEN]
while (!feof(iFileHandle))
{
fgets(iFileHandle, sData, charsmax(sData))
trim(sData)
if (!fm_Comment(sData))
{
ArrayPushString(g_MessageList, sData)
g_iMessageCount++
}
}
fclose(iFileHandle)
log_amx("Loaded %d facts from %s", g_iMessageCount, sFile)
return g_iMessageCount
}
public fwd_ScreenMessage(sBuffer[], iSize)
{
if (!g_iMessageCount) {
// Error handling needs to be added to FM_MESSAGE.amxx
formatex(sBuffer, iSize, "")
return PLUGIN_HANDLED
}
new iSize = ArraySize(g_MessageList);
if (iSize == 0) return PLUGIN_HANDLED;
new iRand = random(g_iMessageCount);
ArrayGetString(g_MessageList, iRand, sBuffer, iSize);
ArrayDeleteItem(g_MessageList, iRand);
return PLUGIN_HANDLED
}