-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnwnx_util.NSS
174 lines (143 loc) · 4.65 KB
/
nwnx_util.NSS
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
// Name : NWNX Utility Include
// Purpose : Various utility functions
// Authors : Marc Paradise (Grinning Fool)
// Modified : December 14th, 2006
// This file is licensed under the terms of the
// GNU GENERAL PUBLIC LICENSE (GPL) Version 2
/************************************/
/* Function prototypes */
/************************************/
const int MT_EVENT = 0;
const int MT_TELL = 1;
const int MT_SPEECH = 2;
const int MT_DM = 3;
const int MT_DEATH = 4;
const int MT_RAISE = 5;
int UtilCreateTokenizer(string tokenizerName, string data, string delimiters = " ");
int UtilDeleteTokenizer(string tokenizerName);
string UtilGetNextToken(string tokenizerName);
string UtilGetTokenRemainder(string tokenizerName);
int UtilGetNextIntToken(string tokenizerName);
int UtilGetTokenCount(string tokenizerName);
int UtilCreateTokenizedArray(string tokenizerName, string data, string delimiters = " ");
int UtilDeleteTokenizedArray(string tokenizerName);
int UtilDeleteTokenFromArrayAt(string tokenizerName, int index);
string UtilGetTokenFromArrayAt(string tokenizerName, int index);
int UtilGetIntTokenFromArrayAt(string tokenizerName, int index);
int UtilGetTokenArraySize(string tokenizerName);
string UtilTranslateToLanguage(int languageId, string text);
int UtilInitLanguage(string filename);
void UtilSendStringToIRC(string message);
/** Gets a random number.
* Returns a random number between 0 and nMax-1
* @param nMax the upper limit of the random number to retrieve.
* @return Random number between 0 and nMax-1
*/
int UtilGetRandom(int nMax);
/** Gets current time.
* Returns time as an int.
* @return number of seconds since epoc
*/
int UtilGetTime();
/*
NWNXGetInt:
TC // create tokenizer, name|data|delim
TX // delete tokenizer, name
TI // next INT elt in tok, name (as int)
TN // num elements in tok, name
AC // createarray, name|data|delim
AX // delete array
AI // getinttoken from array, name, index
AD // delete token from array at : mame,index
AN // get token array szie, name
LI // init language, filename
NWNXGetString
TG // get next STR elt in toklist: name, index
TR // get remainder : name
AG // get at array element : nId
LT // translate langage: nId, text to translate
NWNXSetString
IS // send VALUE to irc
/************************************/
/* Implementation */
/************************************/
int UtilCreateTokenizer(string tokenizerName, string data, string delimiters)
{
return NWNXGetInt("UTIL", "TC", tokenizerName + "|" + delimiters + "|" + data, 0);
}
int UtilDeleteTokenizer(string tokenizerName)
{
return NWNXGetInt("UTIL", "TX", tokenizerName, 0);
}
string UtilGetNextToken(string tokenizerName)
{
return NWNXGetString("UTIL", "TG", tokenizerName, 0);
}
string UtilGetTokenRemainder(string tokenizerName)
{
return NWNXGetString("UTIL", "TR", tokenizerName, 0);
}
int UtilGetNextIntToken(string tokenizerName)
{
return NWNXGetInt("UTIL", "TI", tokenizerName, 0);
}
int UtilGetTokenCount(string tokenizerName)
{
return NWNXGetInt("UTIL", "TN", tokenizerName, 0);
}
int UtilCreateTokenizedArray(string tokenizerName, string data, string delimiters = " ")
{
return NWNXGetInt("UTIL", "AC", tokenizerName + "|" + delimiters + "|" + data, 0);
}
int UtilDeleteTokenizedArray(string tokenizerName)
{
return NWNXGetInt("UTIL", "AX", tokenizerName, 0);
}
string UtilGetTokenFromArrayAt(string tokenizerName, int index)
{
return NWNXGetString("UTIL", "AG", tokenizerName, index);
}
int UtilGetIntTokenFromArrayAt(string tokenizerName, int index)
{
return NWNXGetInt("UTIL", "AI", tokenizerName, index);
}
int UtilGetTokenArraySize(string tokenizerName)
{
return NWNXGetInt("UTIL", "AN", tokenizerName, 0);
}
int UtilRemoveFromArrayAt(string tokenizerName, int index)
{
return NWNXGetInt("UTIL", "AD", tokenizerName, index);
}
void UtilLanguageInit(int nCount)
{
NWNXSetInt("UTIL", "LI", "", 0, nCount);
}
void UtilLanguageAdd(int languageId, string sTranslationString)
{
NWNXSetString("UTIL", "LA", "", languageId, sTranslationString);
}
string UtilTranslateToLanguage(int languageId, string text)
{
return NWNXGetString("UTIL", "LT", text, languageId);
}
void IRCConnect(string server, string nick)
{
// NWNXSetString("UTIL", "II", server, 0, nick);
}
void IRCJoin(string channel)
{
//NWNXSetString("UTIL", "IJ", "", 0, channel);
}
void IRCSendMessage(string channel, int nType, string message)
{
//NWNXSetString("UTIL", "IM", channel, nType, message);
}
int UtilGetTime()
{
return NWNXGetInt("UTIL", "TM", "", 0);
}
int UtilGetRandom(int nMax)
{
return NWNXGetInt("UTIL", "RN", IntToString(nMax), 0);
}