-
Notifications
You must be signed in to change notification settings - Fork 22
/
izcmd.inc
124 lines (104 loc) · 3.69 KB
/
izcmd.inc
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/*******************************************************************************************************************************
Improved ZCMD (iZCMD)
This include is just a re-make of the ZCMD Command Processor ( V0.3.1 31/10/2009) originnaly developed by Zeex.
Version: 0.2.3.0 (August 1st 2016)
GitHub Link: https://github.com/YashasSamaga/I-ZCMD
Credits:
Zeex for ZCMD (the very idea of making publics for each command was introduced by Zeex in ZCMD)
Yashas
*******************************************************************************************************************************/
#if defined _I_ZCMD_INCLUDED
#endinput
#endif
#define _I_ZCMD_INCLUDED
#define _I_ZCMD_INCLUDED_V0_2_3_0_
/******************************************************************************************************************************/
#define MAX_CLIENT_MSG_LENGTH (144)
#define MAX_FUNC_NAME (32)
#define COMMAND:%1(%2) \
forward cmd_%1(%2); \
public cmd_%1(%2)
#define CMD:%1(%2) \
COMMAND:%1(%2)
#define command(%1,%2,%3) \
COMMAND:%1(%2, %3)
#define cmd(%1,%2,%3) \
COMMAND:%1(%2, %3)
#define CMD_SUCCESS 1
#define CMD_FAILURE 0
#if !defined isnull
#define isnull(%1) ((!(%1[0])) || (((%1[0]) == '\1') && (!(%1[1]))))
#endif
/******************************************************************************************************************************/
#if defined OnPlayerCommandReceived
forward OnPlayerCommandReceived(playerid,cmdtext[]);
#endif
#if defined OnPlayerCommandPerformed
forward OnPlayerCommandPerformed(playerid,cmdtext[], success);
#endif
/******************************************************************************************************************************/
public OnPlayerCommandText(playerid, cmdtext[])
{
#if defined OnPlayerCommandReceived
if(!OnPlayerCommandReceived(playerid, cmdtext)) return 1;
#endif
static funcname[MAX_CLIENT_MSG_LENGTH] = "cmd_";
#if defined IZCMD_ENABLE_CASE_SENSITIVITY
static pos;
if((pos = strfind(cmdtext, " ", false, 1)) == -1)
{
funcname[4] = 0;
strcat(funcname, cmdtext[1], MAX_FUNC_NAME - 4);
#if defined OnPlayerCommandPerformed
return OnPlayerCommandPerformed(playerid, cmdtext, CallLocalFunction(funcname, "is", playerid, "\1"));
#else
return CallLocalFunction(funcname, "is", playerid, "\1");
#endif
}
else
{
funcname[4] = 0;
strcat(funcname, cmdtext[1], pos + 4);
while (cmdtext[pos] == ' ') pos++;
if(cmdtext[pos])
{
#if defined OnPlayerCommandPerformed
return OnPlayerCommandPerformed(playerid, cmdtext, CallLocalFunction(funcname, "is", playerid, cmdtext[pos]));
#else
return CallLocalFunction(funcname, "is", playerid, cmdtext[pos]);
#endif
}
else
{
#if defined OnPlayerCommandPerformed
return OnPlayerCommandPerformed(playerid, cmdtext, CallLocalFunction(funcname, "is", playerid, "\1"));
#else
return CallLocalFunction(funcname, "is", playerid, "\1");
#endif
}
}
#else
new pos = 1, tmp;
while((tmp = cmdtext[pos]) > ' ')
if('A' <= tmp <= 'Z') funcname[pos++ + 3] = tmp | 0x20;
else funcname[pos++ + 3] = tmp;
funcname[pos + 3] = 0;
while (cmdtext[pos] == ' ') pos++;
if(cmdtext[pos])
{
#if defined OnPlayerCommandPerformed
return OnPlayerCommandPerformed(playerid, cmdtext, CallLocalFunction(funcname, "is", playerid, cmdtext[pos]));
#else
return CallLocalFunction(funcname, "is", playerid, cmdtext[pos]);
#endif
}
else
{
#if defined OnPlayerCommandPerformed
return OnPlayerCommandPerformed(playerid, cmdtext, CallLocalFunction(funcname, "is", playerid, "\1"));
#else
return CallLocalFunction(funcname, "is", playerid, "\1");
#endif
}
#endif
}