-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathItemSpawner.lua
72 lines (50 loc) · 1.48 KB
/
ItemSpawner.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
g_Plugin = nil
PluginPrefix = "Itemspawner: "
-- Cache all last used and enabled item spawners
g_ItemSpawners = {}
-- List of items
g_Items = {}
-- The radius in which the items will be spawned
g_DefaultRadius = 25
-- The interval between spawning items, in seconds
g_DefaultInterval = 10
function Initialize(a_Plugin)
a_Plugin:SetName("ItemSpawner")
a_Plugin:SetVersion(1)
g_Plugin = a_Plugin
if not(InitializeStorage(a_Plugin:GetLocalFolder() .. cFile:GetPathSeparator() .. "spawners.sqlite")) then
LOGERROR(PluginPrefix .. " Creating or opening the sqlite database failed!")
return false
end
cPluginManager:AddHook(cPluginManager.HOOK_DISCONNECT, OnDisconnect)
-- Random, random
math.randomseed(os.time())
math.random(); math.random(); math.random()
LoadItems()
LoadAllEnabledSpawnerInfos()
-- Load the InfoReg shared library
dofile(cPluginManager:GetPluginsPath() .. cFile:GetPathSeparator() .. "InfoReg.lua")
-- Bind all the commands
RegisterPluginInfoCommands()
return true
end
function OnDisable()
g_Storage.m_SqliteDB:close()
LOG( "Disabled ItemSpawner!" )
end
-- Remove spawner infos that are not enabled and the
-- player who changed it has disconnected
function OnDisconnect(a_Client, a_Reason)
local player = a_Client:GetPlayer()
if not(player) then
return
end
for name, spawnerInfo in pairs(g_ItemSpawners) do
if
not(spawnerInfo.m_IsEnabled) and
spawnerInfo.m_UpdatedBy == player:GetName()
then
g_ItemSpawners[name] = nil
end
end
end