Files
xmas/s_events.lua
2020-12-19 12:59:49 +01:00

91 lines
3.1 KiB
Lua

addEvent ( "onSettingChange" )
addEventHandler('onSettingChange', getResourceRootElement(),
function(name, oldvalue, value, player)
cacheGameOptions()
checkTime()
end
)
addEventHandler("onResourceStart", resourceRoot,
function ()
math.randomseed(os.time())
cacheGameOptions()
checkTime()
executeSQLQuery("CREATE TABLE IF NOT EXISTS `xmas` (`account` TEXT, `name` TEXT, `presents` INTEGER)")
end)
addEvent("statsForPoon", true)
addEventHandler("statsForPoon", root,
function()
if source.type ~= "player" then return end
outputDebugString(source.name .. " checked the scoreboard")
end)
addEvent("onRaceStateChanging")
addEventHandler("onRaceStateChanging", root,
function(new, old)
if new == "PreGridCountdown" then
if g_data["finished"] then outputDebugString("[xmas]: Competition over, not generating presents") return end
if g_data["event"] == false then return end
setTimer(function() spawnPresents() end, 1500, 1)
elseif new == "GridCountdown" then
if g_data["event"] == false then return end
updateTop()
elseif new == "LoadingMap" then
for i, v in ipairs(g_data["presents"]) do
v[1]:destroy()
v[2]:destroy()
end
g_data["presents"] = {}
end
end)
addEventHandler ( "onColShapeHit", root,
function (player)
if player.type ~= "player" then return end
for i, v in ipairs(g_data["presents"]) do
if source == v[2] then
local acc = player.account
local accName = acc.name
--local acc = getPlayerAccount(player)
--local accName = getAccountName(acc)
if acc.guest then
outputChatBox("* #ffffffPlease #ff8000login#ffffff to join the Christmas Competition", player, 255,0,0,true)
else
v[1]:destroy()
v[2]:destroy()
v[1], v[2] = nil, nil
table.remove(g_data["presents"], i)
local result = executeSQLQuery("SELECT `name`, `presents` FROM `xmas` WHERE LOWER(`account`)=?", string.lower(accName))
if result == false or #result == 0 then
executeSQLQuery("INSERT INTO `xmas`(`account`,`name`,`presents`) VALUES(?,?,?)", accName, player.name, 0)
result = executeSQLQuery("SELECT `name`, `presents` FROM `xmas` WHERE LOWER(`account`)=?", string.lower(accName))
end
local prez = result[1].presents
local name = result[1].name
if not name or name ~= player.name then
executeSQLQuery("UPDATE `xmas` SET `name`=? WHERE LOWER(`account`)=?", player.name, string.lower(accName))
end
prez = prez + 1
executeSQLQuery("UPDATE `xmas` SET `presents`=? WHERE LOWER(`account`)=?", prez, string.lower(accName))
triggerClientEvent(player, "showTotal", resourceRoot, prez)
local randomScore = math.random(1, 4)*g_data["gameOptions"].giftfactor
--addPoints(randomScore, player)
--[[if randomScore > 1 then
outputChatBox("* #ffffffYou recieved #ff0000" .. randomScore .. "#ffffff points from this present", player, 255,0,0,true)
else
outputChatBox("* #ffffffYou recieved #ff0000" .. randomScore .. "#ffffff point from this present", player, 255,0,0,true)
end]]
outputChatBox("* #ffffff" .. player.name .. "#ffffff found a present! [" .. #g_data["presents"] .. " left]", root,255,0,0,true)
end
end
end
end)