1
+ local info = getElementData (root , " WhoWas" , info ) or {}
2
+ removeElementData (root , " WhoWas" )
3
+
4
+ addEventHandler (" onPlayerJoin" , root , function ()
5
+ local name = getPlayerName (source )
6
+ local serial = getPlayerSerial (source )
7
+ for i , data in pairs (info ) do
8
+ if (data [1 ] == name and data [2 ] == serial ) then
9
+ return true
10
+ end
11
+ end
12
+ info [# info + 1 ] = {name , serial , accName , getPlayerIP (source )}
13
+ end )
14
+
15
+ addEventHandler (" onPlayerLogin" , root , function (old , new )
16
+ local name = getPlayerName (source )
17
+ local serial = getPlayerSerial (source )
18
+ local accName = getAccountName (new )
19
+ for i , data in pairs (info ) do
20
+ if (data [1 ] == name and data [2 ] == serial and data [3 ] == accName ) then
21
+ return true
22
+ end
23
+ end
24
+ info [# info + 1 ] = {name , serial , accName , getPlayerIP (source )}
25
+ end )
26
+
27
+ addEventHandler (" onPlayerChangeNick" , root , function (old , name )
28
+ local serial = getPlayerSerial (source )
29
+ for i , data in pairs (info ) do
30
+ if data [1 ] == name and data [2 ] == serial then
31
+ return true
32
+ end
33
+ end
34
+ local acc = getPlayerAccount (plr )
35
+ if isGuestAccount (acc ) then
36
+ acc = nil
37
+ else
38
+ acc = getAccountName (acc )
39
+ end
40
+ info [# info + 1 ] = {name , serial , acc , getPlayerIP (source )}
41
+ end )
42
+
43
+ function cmdWhoWas (plr , cmd , name )
44
+ if not hasObjectPermissionTo (plr , " command.whowas" , false ) and not hasObjectPermissionTo (plr , " command.listbans" , false ) then
45
+ outputChatBox (" You don't have access to 'command.whowas' or 'command.listbans'" , plr , 255 , 0 , 0 )
46
+ return false
47
+ end
48
+ local found = 0
49
+ outputChatBox (" Players who had " .. name .. " in their name/serial/account/IP:" , plr , 0 , 255 , 0 )
50
+ for i , data in pairs (info ) do
51
+ if string.find (data [1 ], name , 1 , true ) or string.find (data [2 ], name , 1 , true ) or string.find (data [3 ], name , 1 , true ) or string.find (data [4 ], name , 1 , true ) then
52
+ outputChatBox (data [1 ].. " #F7FF00" .. data [2 ].. " #FDC11C" .. data [3 ].. " #FD581C" .. data [4 ], plr , 0 , 255 , 0 , true )
53
+ found = found + 1
54
+ if (found > 100 ) then
55
+ outputChatBox (" Reached limit of 100 returns, refine your search." , plr , 0 , 255 , 0 , true )
56
+ return true
57
+ end
58
+ end
59
+ end
60
+ end
61
+ addCommandHandler (" whowas" , cmdWhoWas )
62
+
63
+ -- Add players when script starts
64
+ for i , plr in pairs (getElementsByType (" player" )) do
65
+ local alreadyIn = false
66
+ for i2 , data in pairs (info ) do
67
+ if data [1 ] == getPlayerName (plr ) and data [2 ] == getPlayerSerial (plr ) then
68
+ alreadyIn = true
69
+ break
70
+ end
71
+ end
72
+ if not alreadyIn then
73
+ local acc = getPlayerAccount (plr )
74
+ if isGuestAccount (acc ) then
75
+ acc = nil
76
+ else
77
+ acc = getAccountName (acc )
78
+ end
79
+ info [# info + 1 ] = {getPlayerName (plr ), getPlayerSerial (plr ), acc , getPlayerIP (plr )}
80
+ end
81
+ end
82
+
83
+ local function onStop ()
84
+ setElementData (root , " WhoWas" , info , false ) -- This preserves whowas data from resource restarts.
85
+ end
86
+ addEventHandler (" onResourceStop" , resourceRoot , onStop )
0 commit comments