forked from VANCOLD/fm_drive
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FM_MESSAGE_FACTS.sma
69 lines (56 loc) · 1.26 KB
/
FM_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
66
67
68
69
#include "feckinmad/fm_global"
new const g_sFactFile[] = "fm_message_facts.ini"
new Array:g_MessageList
new g_iMessageCount
new g_iCurrentMessage
public plugin_init()
{
fm_RegisterPlugin()
g_MessageList = ArrayCreate(MAX_HUDMSG_LEN)
ReadFactFile()
g_iCurrentMessage = random(g_iMessageCount)
}
public plugin_end()
{
ArrayDestroy(g_MessageList)
}
ReadFactFile()
{
new sFile[128]; fm_BuildAMXFilePath(g_sFactFile, sFile, charsmax(sFile), "amxx_configsdir")
new iFileHandle = fopen(sFile, "rt")
if (!iFileHandle)
{
fm_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 fm_ScreenMessage(sBuffer[], iSize)
{
if (!g_iMessageCount)
{
// Error handling needs to be added to FM_MESSAGE.amxx
formatex(sBuffer, iSize, "")
return PLUGIN_HANDLED
}
if (g_iCurrentMessage >= g_iMessageCount)
{
g_iCurrentMessage = 0
}
ArrayGetString(g_MessageList, g_iCurrentMessage, sBuffer, iSize)
g_iCurrentMessage++
return PLUGIN_HANDLED
}