×

Langue

Fermer
Atelier 801
  • Forums
  • Dev Tracker
  • Connexion
    • English Français
      Português do Brasil Español
      Türkçe Polski
      Magyar Română
      العربية Skandinavisk
      Nederlands Deutsch
      Bahasa Indonesia Русский
      中文 Filipino
      Lietuvių kalba 日本語
      Suomi עברית
      Italiano Česky
      Hrvatski Slovensky
      Български Latviešu
      Estonian
  • Langue
  • Forums
  • /
  • Transformice
  • /
  • Modules
  • /
  • Rewriting Module Team Functions for debug purposes
Rewriting Module Team Functions for debug purposes
Bolodefchoco
« Sénateur »
1589253300000
    • Bolodefchoco#0095
    • Profil
    • Derniers messages
    • Tribu
#1
  5
  • All functions and events
Common functions

Code Lua

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
function tfm.exec.chatMessage ( message, playerName )
if not message then
print("tfm.exec.chatMessage : argument 1 can't be NIL.")
return
end
message = tostring(message)

return
end

function tfm.exec.lowerSyncDelay ( playerName )
if not playerName then
print("tfm.exec.lowerSyncDelay : argument 1 can't be NIL.")
return
end

return
end

function tfm.exec.setRoomMaxPlayers ( maxPlayers )
if not maxPlayers then
print("Argument error.")
return
end

return
end

function tfm.exec.setRoomPassword ( password )
if not password then
print("Argument error.")
return
end

return
end


Game event functions

Code Lua

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
function system.giveEventGift ( playerName, giftCode )
if not playerName then
print("system.giveEventGift : argument 1 can't be NIL.")
return
end
if not giftCode then
print("system.giveEventGift : argument 2 can't be NIL.")
return
end

return
end

function tfm.exec.giveConsumables ( playerName, consumableId, amount )
if not playerName then
print("tfm.exec.giveConsumables : argument 1 can't be NIL.")
return
end
if not consumableId then
print("tfm.exec.giveConsumables : argument 2 can't be NIL.")
return
end
amount = (type(amount) == "number" and amount) or 1

return
end


File functions and events

Code Lua

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
--[[ File Data ]]--
do
local FILE = { }

local LAST_LOAD_TIME = 0
function system.loadFile ( fileNumber )
local currentTime = os.time()
if LAST_LOAD_TIME > currentTime then
print("You can't call this function [system.loadFile] more than once per 1 minute.")
return false
end
LAST_LOAD_TIME = currentTime + 60000

if type(fileNumber) ~= "number" then
fileNumber = 0
elseif fileNumber > 99 then
fileNumber = 99
elseif fileNumber < 0 then
fileNumber = 0
end

if _G.eventFileLoaded then
local fileData = ( FILE[fileNumber] or '' )

_G.eventFileLoaded ( fileNumber, fileData )
end

return true
end

local LAST_SAVE_TIME = 0
function system.saveFile ( data, fileNumber )
if not data then
print("system.saveFile : argument 1 can't be NIL.")
return false
end
if type(fileNumber) ~= "number" or (fileNumber < 0 or fileNumber > 99) then
print("system.saveFile : argument 2 must be an integer from 0 to 99.")
return false
end

local currentTime = os.time()
if LAST_SAVE_TIME > currentTime then
print("You can't call this function [system.saveFile] more than once per 1 minute.")
return false
end
LAST_SAVE_TIME = currentTime + 60000

FILE[fileNumber] = tostring(data)
if _G.eventFileSaved then
_G.eventFileSaved ( fileNumber )
end

return true
end
end


Player data functions and events

Code Lua

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
--[[ Player Data ]]--
do
local PLAYER = { }

function system.loadPlayerData ( playerName )
if type(playerName) == "string" and _G.eventPlayerDataLoaded then
-- NaMe = name
local lowerPlayerName = string.lower(playerName)

-- name = Name
playerName = string.gsub(lowerPlayerName, '%a', string.upper, 1)
local playerData = PLAYER[lowerPlayerName] or ''

_G.eventPlayerDataLoaded ( playerName, playerData )
end

return true
end

function system.savePlayerData ( playerName, data )
if not playerName then
print("system.savePlayerData : argument 1 can't be NIL.")
return
end
if not data then
print("system.savePlayerData : argument 2 can't be NIL.")
return
end

-- NaMe = name
local lowerPlayerName = string.lower(playerName)

PLAYER[lowerPlayerName] = tostring(data)

return
end
end


Timer functions

Code Lua

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
--[[ Timers ]]--
local _INTERNAL_SYSTEM_TIMER_LOOP
do
local TIMER = { }
local TIMER_ID = 0

local TIMER_GARBAGE = { }
local TIMER_GARBAGE_COUNTER = 0

function _INTERNAL_SYSTEM_TIMER_LOOP ( )
for id = 1, TIMER_GARBAGE_COUNTER do
id = TIMER_GARBAGE[id]
TIMER[id] = nil
--TIMER_GARBAGE_COUNTER = TIMER_GARBAGE_COUNTER - 1
end
TIMER_GARBAGE_COUNTER = 0

for id, timer in pairs(TIMER) do
-- In this case, it is +500 because it is looping in _G.eventLoop,
-- while that in a module it is +1
timer.currentTime = timer.currentTime + 500

if timer.currentTime >= timer.time then
timer.currentTime = 0

timer.callback(timer.arg1, timer.arg2, timer.arg3, timer.arg4)

if not timer.loop then
system.removeTimer(id)
end
end
end
end

function system.newTimer ( callback, time, loop, arg1, arg2, arg3, arg4 )
if not callback then
print("system.newTimer : argument 1 can't be NIL.")
return
end
if not time then
print("system.newTimer : argument 2 can't be NIL.")
return
end
if type(callback) ~= "function" then
print("Argument 1 must be Function.")
return
end
if type(time) ~= "number" or (time < 1000 or time > 130989999999) then
print("A timer interval must be superior than 1000 ms.")
return
end

-- Do not trust the idea of having a crescent ID. Do keep track of the returned ID, instead.
TIMER_ID = TIMER_ID + 1
TIMER[TIMER_ID] = {
callback = callback,
time = time,
currentTime = 0,
loop = not not loop,
arg1 = arg1,
arg2 = arg2,
arg3 = arg3,
arg4 = arg4
}

return TIMER_ID
end

function system.removeTimer ( timerId )
if not timerId then
print("system.removeTimer : argument 1 can't be NIL.")
return
end

if TIMER[timerId] then
TIMER_GARBAGE_COUNTER = TIMER_GARBAGE_COUNTER + 1
TIMER_GARBAGE[TIMER_GARBAGE_COUNTER] = timerId
end

return
end
end

-->> Using eventLoop to run the Timers system <<--
function eventLoop()
_INTERNAL_SYSTEM_TIMER_LOOP()
-- Do not change the line above

end


Image functions

Code Lua

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
--[[ Images ]]--
do
local IMAGE_ID = 0

function tfm.exec.addImage ( imageId, target, xPosition, yPosition, targetPlayer )
if not imageId then
print("tfm.exec.addImage : argument 1 can't be NIL.")
return
end
if not target then
print("tfm.exec.addImage : argument 2 can't be NIL.")
return
end
target = tostring(target)
if #target == 1 or not string.find(string.sub(target, 1, 1), "[#$%?_!&:]") then
print("tfm.exec.addImage : Invalid target.")
return
end

xPosition = (type(xPosition) == "number" and xPosition) or 0
yPosition = (type(yPosition) == "number" and yPosition) or 0

IMAGE_ID = IMAGE_ID + 1
return IMAGE_ID
end

function tfm.exec.removeImage ( imageId )
if not imageId then
print("tfm.exec.removeImage : argument 1 can't be NIL.")
return
end

return
end
end

Code Lua

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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
function tfm.exec.chatMessage ( message, playerName )
if not message then
print("tfm.exec.chatMessage : argument 1 can't be NIL.")
return
end
message = tostring(message)

return
end

function tfm.exec.lowerSyncDelay ( playerName )
if not playerName then
print("tfm.exec.lowerSyncDelay : argument 1 can't be NIL.")
return
end

return
end

function tfm.exec.setRoomMaxPlayers ( maxPlayers )
if not maxPlayers then
print("Argument error.")
return
end

return
end

function tfm.exec.setRoomPassword ( password )
if not password then
print("Argument error.")
return
end

return
end

function system.giveEventGift ( playerName, giftCode )
if not playerName then
print("system.giveEventGift : argument 1 can't be NIL.")
return
end
if not giftCode then
print("system.giveEventGift : argument 2 can't be NIL.")
return
end

return
end

function tfm.exec.giveConsumables ( playerName, consumableId, amount )
if not playerName then
print("tfm.exec.giveConsumables : argument 1 can't be NIL.")
return
end
if not consumableId then
print("tfm.exec.giveConsumables : argument 2 can't be NIL.")
return
end
amount = (type(amount) == "number" and amount) or 1

return
end

--[[ File Data ]]--
do
local FILE = { }

local LAST_LOAD_TIME = 0
function system.loadFile ( fileNumber )
local currentTime = os.time()
if LAST_LOAD_TIME > currentTime then
print("You can't call this function [system.loadFile] more than once per 1 minute.")
return false
end
LAST_LOAD_TIME = currentTime + 60000

if type(fileNumber) ~= "number" then
fileNumber = 0
elseif fileNumber > 99 then
fileNumber = 99
elseif fileNumber < 0 then
fileNumber = 0
end

if _G.eventFileLoaded then
local fileData = ( FILE[fileNumber] or '' )

_G.eventFileLoaded ( fileNumber, fileData )
end

return true
end

local LAST_SAVE_TIME = 0
function system.saveFile ( data, fileNumber )
if not data then
print("system.saveFile : argument 1 can't be NIL.")
return false
end
if type(fileNumber) ~= "number" or (fileNumber < 0 or fileNumber > 99) then
print("system.saveFile : argument 2 must be an integer from 0 to 99.")
return false
end

local currentTime = os.time()
if LAST_SAVE_TIME > currentTime then
print("You can't call this function [system.saveFile] more than once per 1 minute.")
return false
end
LAST_SAVE_TIME = currentTime + 60000

FILE[fileNumber] = tostring(data)
if _G.eventFileSaved then
_G.eventFileSaved ( fileNumber )
end

return true
end
end

--[[ Player Data ]]--
do
local PLAYER = { }

function system.loadPlayerData ( playerName )
if type(playerName) == "string" and _G.eventPlayerDataLoaded then
-- NaMe = name
local lowerPlayerName = string.lower(playerName)

-- name = Name
playerName = string.gsub(lowerPlayerName, '%a', string.upper, 1)
local playerData = PLAYER[lowerPlayerName] or ''

_G.eventPlayerDataLoaded ( playerName, playerData )
end

return true
end

function system.savePlayerData ( playerName, data )
if not playerName then
print("system.savePlayerData : argument 1 can't be NIL.")
return
end
if not data then
print("system.savePlayerData : argument 2 can't be NIL.")
return
end

-- NaMe = name
local lowerPlayerName = string.lower(playerName)

PLAYER[lowerPlayerName] = tostring(data)

return
end
end

--[[ Timers ]]--
local _INTERNAL_SYSTEM_TIMER_LOOP
do
local TIMER = { }
local TIMER_ID = 0

local TIMER_GARBAGE = { }
local TIMER_GARBAGE_COUNTER = 0

function _INTERNAL_SYSTEM_TIMER_LOOP ( )
for id = 1, TIMER_GARBAGE_COUNTER do
id = TIMER_GARBAGE[id]
TIMER[id] = nil
--TIMER_GARBAGE_COUNTER = TIMER_GARBAGE_COUNTER - 1
end
TIMER_GARBAGE_COUNTER = 0

for id, timer in pairs(TIMER) do
-- In this case, it is +500 because it is looping in _G.eventLoop,
-- while that in a module it is +1
timer.currentTime = timer.currentTime + 500

if timer.currentTime >= timer.time then
timer.currentTime = 0

timer.callback(timer.arg1, timer.arg2, timer.arg3, timer.arg4)

if not timer.loop then
system.removeTimer(id)
end
end
end
end

function system.newTimer ( callback, time, loop, arg1, arg2, arg3, arg4 )
if not callback then
print("system.newTimer : argument 1 can't be NIL.")
return
end
if not time then
print("system.newTimer : argument 2 can't be NIL.")
return
end
if type(callback) ~= "function" then
print("Argument 1 must be Function.")
return
end
if type(time) ~= "number" or (time < 1000 or time > 130989999999) then
print("A timer interval must be superior than 1000 ms.")
return
end

-- Do not trust the idea of having a crescent ID. Do keep track of the returned ID, instead.
TIMER_ID = TIMER_ID + 1
TIMER[TIMER_ID] = {
callback = callback,
time = time,
currentTime = 0,
loop = not not loop,
arg1 = arg1,
arg2 = arg2,
arg3 = arg3,
arg4 = arg4
}

return TIMER_ID
end

function system.removeTimer ( timerId )
if not timerId then
print("system.removeTimer : argument 1 can't be NIL.")
return
end

if TIMER[timerId] then
TIMER_GARBAGE_COUNTER = TIMER_GARBAGE_COUNTER + 1
TIMER_GARBAGE[TIMER_GARBAGE_COUNTER] = timerId
end

return
end
end

-->> Using eventLoop to run the Timers system <<--
function eventLoop()
_INTERNAL_SYSTEM_TIMER_LOOP()
-- Do not change the line above

end

--[[ Images ]]--
do
local IMAGE_ID = 0

function tfm.exec.addImage ( imageId, target, xPosition, yPosition, targetPlayer )
if not imageId then
print("tfm.exec.addImage : argument 1 can't be NIL.")
return
end
if not target then
print("tfm.exec.addImage : argument 2 can't be NIL.")
return
end
target = tostring(target)
if #target == 1 or not string.find(string.sub(target, 1, 1), "[#$%?_!&:]") then
print("tfm.exec.addImage : Invalid target.")
return
end

xPosition = (type(xPosition) == "number" and xPosition) or 0
yPosition = (type(yPosition) == "number" and yPosition) or 0

IMAGE_ID = IMAGE_ID + 1
return IMAGE_ID
end

function tfm.exec.removeImage ( imageId )
if not imageId then
print("tfm.exec.removeImage : argument 1 can't be NIL.")
return
end

return
end
end

Dernière modification le 1638369240000
Onkei
« Citoyen »
1589272200000
    • Onkei#0000
    • Profil
    • Derniers messages
    • Tribu
#2
  0
Well done, this is h e l l a useful.
Extremq
« Citoyen »
1591028880000
    • Extremq#0000
    • Profil
    • Derniers messages
    • Tribu
#3
  0
Onkei a dit :
Well done, this is h e l l a useful.

Agreed :'D
  • Forums
  • /
  • Transformice
  • /
  • Modules
  • /
  • Rewriting Module Team Functions for debug purposes
© Atelier801 2018

Equipe Conditions Générales d'Utilisation Politique de Confidentialité Contact

Version 1.27