gRoot = getRootElement()
AchievementsName = {
"First Win!", -- 1sze zwyciestwo 1
"First Hunter!", -- 1szy hunter 2
"Top Winner!", -- 300 wins 3
"Awesome Winner!", -- 1000 wins 4
"Top Gamer!", -- 2000 map 5
"Long Time Player!", -- 7 dni 6
"Hunter Owner!", -- hunter 50 razy 7
"Beat my TT kid!", -- pierwszy TT 8
"5 Maps In a Row LOL!", -- 5x 9
"Triple Deathmatch!", -- 3x dm pod rzad 10
"Triple Dest. Derby!", -- 3x DD 11
"Hunter Power", -- hunterfight z 3 graczami 12
"Map Buyer", -- 10 razy kupic mape 13
"Top Times collector!", -- 50 toptimow 14
"Rich player!", -- 1 mln 15
"Rich player I", -- 2 mln 16
"Hunter Owner I", -- hunter 150 razy 17
"Top Times collector I", -- 150 toptimow 18
"Hunter Power I", -- hunterfight z 8 graczami 19
"King of Points", -- get 1500 Points 20
"King of Points I", -- get 500.000 Points 21
}
LastWinnersDD={"","","","",""}
LastWinnersDM={"","","","",""}
LastWinners={"","","","",""}
HunterCount = 0
------------------------------------------
-- Settings
------------------------------------------
mapCost = 5000 -- The price for setting maps.
playerCash = 200000 -- Limits the amount of money you can bet. (playerCash = maxBet)
betTimeLimit = 40 -- Duration of the betting period in seconds.
minPlayers = 1 -- Minimum required players to bet.
buyjant = 50000 -- Buy Rims,cost 50.000$
skinLevel = 0 -- Minimum level required to buy skins. (3000 Points)
skinCost = 1300 -- The price of skins.
nametagLevel = 0 -- Minimum level to buy a nametag color. (2000 Points)
nametagPrice = 2000 -- Price for buying a nametag color.
hornLevel = 0 -- Minimum level to buy different horn styles.
moneyEarnPart = 30 -- The amount of money to calculate with to get the final money to give to the player.
function startResource ()
exports.scoreboard:removeScoreboardColumn("race rank")
exports.scoreboard:removeScoreboardColumn("checkpoint")
exports.scoreboard:addScoreboardColumn("Money",gRoot,5,100)
exports.scoreboard:addScoreboardColumn("Points",gRoot,5,100)
mapIsAlreadySet = false
for i,pla in ipairs(getElementsByType("player")) do
scoreboardRefresh(pla)
end
end
addEventHandler ( "onResourceStart", getResourceRootElement(getThisResource()), startResource )
addEventHandler ("onPlayerRaceWasted",getRootElement(),
function()
killPed (source)
setElementHealth (source,0)
if (isPedInVehicle(source)) then
blowVehicle (getPedOccupiedVehicle(source))
end
end)
-- Prices for each horn
hornPrice={2000,4000,6000,8000,10000,15000,20000}
------------------------------------------
-- Load All Stats on Join
------------------------------------------
function scoreboardRefresh(thePlayer)
local playerCash = loadPlayerData(thePlayer,"cash")
local playerPoint = loadPlayerData(thePlayer,"point")
setElementData(thePlayer,"Money","$"..playerCash)
setElementData(thePlayer,"Points",""..playerPoint)
callClientFunction(thePlayer, "refreshCash", playerCash, playerPoint)
end
function playerJoin ( )
outputChatBox("#00AAFF# #FFFFFFPress '#00AAFFF7#FFFFFF' to open your User Panel#00AAFF!",source,255,255,255,true)
outputChatBox("#ecececWelcome,To The #c1ff17??? #ececec24/7 #abcdef[DD/DM] #ecececRace Server. Have Fun During Your Stay!",source,255,255,255,true)
outputChatBox ( "#ffffffThere are now '#abcdef" .. getPlayerCount() .. "/32#ffffff' players on this server!",source,255,255,255,true )
scoreboardRefresh(source)
end
addEventHandler ( "onPlayerJoin", gRoot, playerJoin )
addEventHandler ( "onPlayerQuit", getRootElement(), playerJoin )
------------------------------------------
-- DD/DM/FUN checking
------------------------------------------
addEvent("onMapStarting")
addEventHandler("onMapStarting", getRootElement(),
function(mapInfo, mapOptions, gameOptions)
CurrentMap = nil
HunterCount = 0
MaxI = 0
for i,thePlayer in ipairs(getElementsByType("player")) do
MaxI = i
end
if MaxI >=1 then
if (checkMapType(mapInfo.name) == 1) then
CurrentMap = 1
for i,thePlayer in ipairs(getElementsByType("player")) do
local mapsPlayedDM = tonumber(loadPlayerData(thePlayer,"mapsPlayedDM"))
savePlayerData(thePlayer,"mapsPlayedDM", mapsPlayedDM+1)
CheckAchievement(thePlayer,5)
end
elseif (checkMapType(mapInfo.name) == 2) then
CurrentMap = 2
for i,thePlayer in ipairs(getElementsByType("player")) do
local mapsPlayedDD = tonumber(loadPlayerData(thePlayer,"mapsPlayedDD"))
savePlayerData(thePlayer,"mapsPlayedDD", mapsPlayedDD+1)
CheckAchievement(thePlayer,5)
end
end
else
exports.box:outputMiniBox("#FFFFFF Min. 3 players to get #abcdefStats #FFFFFFand #abcdefCash#ececec!",gRoot)
end
end)
function checkMapType(mapname)
if string.find(mapname, "[DM]", 1, true) then
return 1
elseif string.find(mapname, "[DD]", 1,true) then
return 2
elseif string.find(mapname, "[FUN]", 1,true) then
return 3
end
end
function getRaceAlivePlayers()
local result = {}
local _getAlivePlayers = getElementsByType("player")
for i,v in ipairs(_getAlivePlayers) do
if getElementData(v,"state") == "alive" then
table.insert(result,v)
end
end
return result
end
------------------------------------------
-- Wins Stats
------------------------------------------
function onPlayerDeadInRace()
local thePlayer = source
local dPlayers = getDeadRacePlayers()
local aPlayers = getAliveRacePlayers()
local Position = aPlayers + 1
if dPlayers + aPlayers >= 1 then -- Set Minimum Players
local cashForPlayer = math.floor((200/Position)*(dPlayers + aPlayers))
local pointForPlayer = math.floor((7/Position)*(dPlayers + aPlayers))
local playerCash = loadPlayerData(thePlayer,"cash")
local playerPoint = loadPlayerData(thePlayer,"point")
savePlayerData(thePlayer,"cash",playerCash+cashForPlayer)
savePlayerData(thePlayer,"point",playerPoint+pointForPlayer)
CheckAchievement(thePlayer,15)
CheckAchievement(thePlayer,16)
CheckAchievement(thePlayer,20)
CheckAchievement(thePlayer,21)
scoreboardRefresh(thePlayer)
if Position == 1 then
outputChatBox("#ffffff "..getPlayerName(thePlayer).." #FFFFFFHas Won The Map Earned $#00AAFF" .. cashForPlayer.. " #ffffffand #00aaff"..pointForPlayer.." #FFFFFFPoints!",gRoot,255,255,255,true)
--triggerClientEvent ( "showWinMessage", getRootElement(), thePlayer, cashForPlayer, pointForPlayer)
if LastWinners[1] == "" then
if LastWinners[2] == "" then
if LastWinners[3] == "" then
if LastWinners[4] == "" then
if LastWinners[5] == "" then
LastWinners[5] = thePlayer
else
LastWinners[4] = thePlayer
end
else
LastWinners[3] = thePlayer
end
else
LastWinners[2] = thePlayer
end
else
LastWinners[1] = thePlayer
end
else
LastWinners[5] = LastWinners[4]
LastWinners[4] = LastWinners[3]
LastWinners[3] = LastWinners[2]
LastWinners[2] = LastWinners[1]
LastWinners[1] = thePlayer
CheckAchievement(thePlayer,9)
end
if CurrentMap and CurrentMap == 1 then
local mapsWonDM = tonumber(loadPlayerData(thePlayer,"mapsWonDM"))
savePlayerData(thePlayer,"mapsWonDM", mapsWonDM+1)
CheckAchievement(thePlayer,1)
CheckAchievement(thePlayer,3)
CheckAchievement(thePlayer,4)
if LastWinnersDM[1] == ""then
if LastWinnersDM[2] == "" then
if LastWinnersDM[3] == "" then
LastWinnersDM[3] = thePlayer
else
LastWinnersDM[2] = thePlayer
end
else
LastWinnersDM[1] = thePlayer
end
else
LastWinnersDM[3] = LastWinnersDM[2]
LastWinnersDM[2] = LastWinnersDM[1]
LastWinnersDM[1] = thePlayer
CheckAchievement(thePlayer,10)
end
if HunterCount >= 3 then
unlockedAC(thePlayer,12)
end
if HunterCount >= 8 then
unlockedAC(thePlayer,19)
end
elseif CurrentMap and CurrentMap == 2 then
local mapsWonDD = tonumber(loadPlayerData(thePlayer,"mapsWonDD"))
savePlayerData(thePlayer,"mapsWonDD", mapsWonDD+1)
CheckAchievement(thePlayer,1)
CheckAchievement(thePlayer,3)
CheckAchievement(thePlayer,4)
if LastWinnersDD[1] == "" then
if LastWinnersDD[2] == "" then
if LastWinnersDD[3] == "" then
LastWinnersDD[3] = thePlayer
else
LastWinnersDD[2] = thePlayer
end
else
LastWinnersDD[1] = thePlayer
end
else
LastWinnersDD[3] = LastWinnersDD[2]
LastWinnersDD[2] = LastWinnersDD[1]
LastWinnersDD[1] = thePlayer
CheckAchievement(thePlayer,11)
end
end
else
outputChatBox("#FFFFFFYou Have Recieved $#00AAFF" .. cashForPlayer .. " #FFFFFFand #00aaff" .. pointForPlayer .. " #ffffffPoints!",thePlayer,255,255,255,true)
end
else
outputChatBox("#FFFFFF Min. 3 players to get #abcdefStats #FFFFFFand #abcdefCash#ececec!",thePlayer,255,255,255,true)
end
end
addEvent("onPlayerWasted", true)
addEventHandler("onPlayerWasted", gRoot , onPlayerDeadInRace)
------------------------------------------
-- Statystyki
------------------------------------------
function showStats(thePlayer,CMD,targetPlayer)
if targetPlayer then
if (findPlayerByName(targetPlayer)) then
local targetPlayer = findPlayerByName(targetPlayer)
local c,p,ddw,ddp,ddr,dmw,dmp,dmr,pt,h,mb,ac,tt = loadPlayerStats(targetPlayer)
outputChatBox("#C1FF17# #FFFFFF"..getPlayerName(targetPlayer).."#FFFFFF's Stats:",thePlayer,255,255,255,true)
outputChatBox("#00AAFF# [DM] #FFFFFFPlayed: "..dmp.." | Wins: "..dmw.." | Ratio: "..dmr.."%",thePlayer,255,255,255,true)
outputChatBox("#00AAFF# [DD] #FFFFFFPlayed: "..ddp.." | Wins: "..ddw.." | Ratio: "..ddr.."%",thePlayer,255,255,255,true)
outputChatBox("#00AAFF# #FFFFFFCash: $"..c.." | Points: "..p.." | Hunters: "..h.." | Map Buys: "..mb,thePlayer,255,255,255,true)
outputChatBox("#00AAFF# #FFFFFFPlayed Time: "..convertTime(pt),thePlayer,255,255,255,true)
ACCOUNT = 0
for i=1,#ac do
if ac[i] == 1 then
ACCOUNT = ACCOUNT+1
end
end
outputChatBox("#00AAFF# #FFFFFFAchievements: "..ACCOUNT.."/21 | TopTimes: "..tt,thePlayer,255,255,255,true)
else
outputChatBox("#00AAFF# #FFFFFFERROR! The player you specified does not exist!",thePlayer,255,255,255,true)
end
else
local c,p,ddw,ddp,ddr,dmw,dmp,dmr,pt,h,mb,ac,tt = loadPlayerStats(thePlayer)
outputChatBox("#00AAFF# #FFFFFF"..getPlayerName(thePlayer).."#FFFFFF's stats:",thePlayer,255,255,255,true)
outputChatBox("#00AAFF# [DM] #FFFFFFPlayed: "..dmp.." | Wins: "..dmw.." | Ratio: "..dmr.."%",thePlayer,255,255,255,true)
outputChatBox("#00AAFF# [DD] #FFFFFFPlayed: "..ddp.." | Wins: "..ddw.." | Ratio: "..ddr.."%",thePlayer,255,255,255,true)
outputChatBox("#00AAFF# #FFFFFFCash: $"..c.." | Points: "..p.." | Hunters: "..h.." | Map Buys: "..mb,thePlayer,255,255,255,true)
outputChatBox("#00AAFF# #FFFFFFPlayed Time: "..convertTime(pt),thePlayer,255,255,255,true)
ACCOUNT = 0
for i=1,#ac do
if ac[i] == 1 then
ACCOUNT = ACCOUNT+1
end
end
outputChatBox("#00AAFF# #FFFFFFAchievements: "..ACCOUNT.."/21 | TopTimes: "..tt,thePlayer,255,255,255,true)
end
end
addCommandHandler("stats", showStats)
addCommandHandler("st", showStats)
------------------------------------------
-- Shaders
------------------------------------------
function ShadersUpdate(Who,Shader,Data)
savePlayerData(Who,"Shader"..Shader,Data)
end
function ClientStarted ( who )
for i=1,2 do
local data = loadPlayerData(who,"Shader"..i)
if i == 1 then callClientFunction(who,"CarShaderToggle",who,data)
elseif i == 2 then callClientFunction(who,"WaterShaderToggle",who,data)
elseif i == 3 then callClientFunction(who,"ShineShaderToogle",who,data)
elseif i == 4 then callClientFunction(who,"ContrastShaderToggle",who,data)
elseif i == 5 then callClientFunction(who,"SnowShaderToggle",who,data)
elseif i == 6 then callClientFunction(who,"GoldShaderToggle",who,data)
elseif i == 7 then callClientFunction(who,"SkidmarksShaderToggle",who,data)
end
end
end
------------------------------------------
-- SPD GPD
------------------------------------------
addCommandHandler("spd",
function(player,command,toplayername,datatype,amount)
if hasObjectPermissionTo ( player, "function.kickPlayer", false ) then
if (toplayername) and (datatype) and (amount) then
if datatype == "cash" or datatype == "point" or datatype == "mapsWonDD" or datatype == "mapsPlayedDD" or datatype == "mapsWonDM" or datatype == "mapsPlayedDM" or datatype == "playedTime" or datatype == "hunters" or datatype == "mapBuys" then
if (findPlayerByName (toplayername)) then
toplayer = findPlayerByName (toplayername)
savePlayerData(toplayer,datatype,amount)
outputChatBox ("#00AAFF# #FFFFFFsetPlayerData: " .. getPlayerName(toplayer) .. " #FF0000|#FFFFFF Player's #00AAFF" .. datatype .. "#FFFFFF Has Been Set To: #00AAFF" .. amount, player,255,0,0,true)
outputChatBox ("#00AAFF# #FFFFFF" .. getPlayerName (player) .. " #FFFFFFHas Set Your #ABCDEF" .. datatype .."#FFFFFF To: #00AAFF" .. amount, toplayer,255,0,0,true)
local playerCash = loadPlayerData(toplayer,"cash")
local playerPoint = loadPlayerData(toplayer,"point")
local playerLevel = loadPlayerData(toplayer,"level")
local thePlayer = toplayer
scoreboardRefresh(thePlayer)
end
else
outputChatBox ("#00AAFF# #FF0000ERROR! #FFFFFFDatatype: cash/point/mapsWonDD/mapsPlayedDD/mapsWonDM/mapsPlayedDM/playedTime/hunters/mapBuys",player,255,255,255,true)
end
else
outputChatBox ("#00AAFF# #FF0000ERROR!#FFFFFF Syntax: /setPlayerData [playername] [datatype] [new_amount]",player,255,255,255,true)
end
else
end
end)
addCommandHandler("gpd",
function(player,command,toplayername,datatype)
if hasObjectPermissionTo ( player, "function.kickPlayer", false ) then
if (toplayername) and (datatype) then
if datatype == "cash" or datatype == "point" or datatype == "mapsWonDD" or datatype == "mapsPlayedDD" or datatype == "mapsWonDM" or datatype == "mapsPlayedDM" or datatype == "playedTime" or datatype == "hunters" or datatype == "mapBuys" then
if (findPlayerByName (toplayername)) then
toplayer = findPlayerByName (toplayername)
local amount = loadPlayerData(toplayer,datatype)
outputChatBox ("#00AAFF# #FFFFFFgetPlayerData: " .. getPlayerName(toplayer) .. " #FF0000|#FFFFFF " .. datatype .."#FFFFFF: #00AAFF" .. amount,player,255,255,255,true)
end
else
outputChatBox ("#00AAFF# #FF0000ERROR! #FFFFFFDatatype: cash/point/mapsWonDD/mapsPlayedDD/mapsWonDM/mapsPlayedDM/playedTime/hunters/mapBuys",player,255,255,255,true)
end
else
outputChatBox ("#00AAFF# #FF0000ERROR!#FFFFFF Syntax: /getPlayerData [playername] [datatype]",player,255,255,255,true)
end
end
end)
------------------------------------------
-- loadStats
------------------------------------------
function loadStats(thePlayer,whoask)
local playerCash = tonumber(loadPlayerData(thePlayer,"cash"))
setElementData(thePlayer,"Money","$"..playerCash)
local playerPoint = tonumber(loadPlayerData(thePlayer,"point"))
setElementData(thePlayer,"Points",""..playerPoint)
local mapsWonDD = tonumber(loadPlayerData(thePlayer,"mapsWonDD"))
local mapsPlayedDD = tonumber(loadPlayerData(thePlayer,"mapsPlayedDD"))
local mapsWonDM = tonumber(loadPlayerData(thePlayer,"mapsWonDM"))
local mapsPlayedDM = tonumber(loadPlayerData(thePlayer,"mapsPlayedDM"))
local totalBets = tonumber(loadPlayerData(thePlayer,"totalBets"))
local totalBetsEarned = tonumber(loadPlayerData(thePlayer,"totalBetsEarned"))
local totalBetsWon = tonumber(loadPlayerData(thePlayer,"totalBetsWon"))
------ playedTime
local PlayerCheckTime = getTickCount ()
local PlayerTodayTime = math.floor((PlayerCheckTime - getElementData(thePlayer,"joinTime"))/1000)
local PlayerOldTime = loadPlayerData(thePlayer,"playedTime")
savePlayerData(thePlayer,"playedTime", PlayerOldTime + PlayerTodayTime)
CheckAchievement(thePlayer,6)
setElementData(thePlayer,"joinTime", PlayerCheckTime)
------
local playedTime = PlayerOldTime + PlayerTodayTime
local hunters = tonumber(loadPlayerData(thePlayer,"hunters"))
local mapBuys = tonumber(loadPlayerData(thePlayer,"mapBuys"))
AC = {}
for i=1,15 do
AC[i] = tonumber(loadPlayerData(thePlayer,"ac"..i))
end
local toptimes = tonumber(loadPlayerData(thePlayer,"TopTimes"))
--[[UData = {}
for j=1,20 do
UData[j] = loadPlayerData(thePlayer,"ud"..j)
end]]--
local winRatioDD = 0
local winRatioDM = 0
if mapsPlayedDD == 0 and mapsWonDD == 0 then
winRatioDD = 0
elseif mapsPlayedDD ~= 0 and mapsWonDD == 0 then
winRatioDD = 0
elseif mapsPlayedDD ~= 0 and mapsWonDD ~= 0 then
winRatioDD = math.round(((100/mapsPlayedDD)*mapsWonDD),2)
elseif mapsWonDD > mapsPlayedDD then
winRatioDD = 0
end
if mapsPlayedDM == 0 and mapsWonDM == 0 then
winRatioDM = 0
elseif mapsPlayedDM ~= 0 and mapsWonDM == 0 then
winRatioDM = 0
elseif mapsPlayedDM ~= 0 and mapsWonDM ~= 0 then
winRatioDM = math.round(((100/mapsPlayedDM)*mapsWonDM),2)
elseif mapsWonDM > mapsPlayedDM then
winRatioDM = 0
end
callClientFunction(whoask, "refreshPanelData", thePlayer ,playerCash, playerPoint, mapsWonDD, mapsPlayedDD, winRatioDD, mapsWonDM, mapsPlayedDM, winRatioDM, playedTime, hunters, mapBuys, AC, toptimes, totalBets, totalBetsEarned, totalBetsWon)
end
function loadPlayerStats(thePlayer)
local playerCash = tonumber(loadPlayerData(thePlayer,"cash"))
setElementData(thePlayer,"Money","$"..playerCash)
local playerPoint = tonumber(loadPlayerData(thePlayer,"point"))
setElementData(thePlayer,"Points"..playerPoint)
local mapsWonDD = tonumber(loadPlayerData(thePlayer,"mapsWonDD"))
local mapsPlayedDD = tonumber(loadPlayerData(thePlayer,"mapsPlayedDD"))
local mapsWonDM = tonumber(loadPlayerData(thePlayer,"mapsWonDM"))
local mapsPlayedDM = tonumber(loadPlayerData(thePlayer,"mapsPlayedDM"))
local totalBets = tonumber(loadPlayerData(thePlayer,"totalBets"))
local totalBetsEarned = tonumber(loadPlayerData(thePlayer,"totalBetsEarned"))
local totalBetsWon = tonumber(loadPlayerData(thePlayer,"totalBetsWon"))
local playedTime = tonumber(loadPlayerData(thePlayer,"playedTime"))
local hunters = tonumber(loadPlayerData(thePlayer,"hunters"))
local mapBuys = tonumber(loadPlayerData(thePlayer,"mapBuys"))
AC = {}
for i=1,15 do
local name = "ac"..i
AC[i] = tonumber(loadPlayerData(thePlayer,name))
end
local toptimes = tonumber(loadPlayerData(thePlayer,"TopTimes"))
local winRatioDD = 0
local winRatioDM = 0
if mapsPlayedDD == 0 and mapsWonDD == 0 then
winRatioDD = 0
elseif mapsPlayedDD ~= 0 and mapsWonDD == 0 then
winRatioDD = 0
elseif mapsPlayedDD ~= 0 and mapsWonDD ~= 0 then
winRatioDD = math.round(((100/mapsPlayedDD)*mapsWonDD),2)
elseif mapsWonDD > mapsPlayedDD then
winRatioDD = 0
end
if mapsPlayedDM == 0 and mapsWonDM == 0 then
winRatioDM = 0
elseif mapsPlayedDM ~= 0 and mapsWonDM == 0 then
winRatioDM = 0
elseif mapsPlayedDM ~= 0 and mapsWonDM ~= 0 then
winRatioDM = math.round(((100/mapsPlayedDM)*mapsWonDM),2)
elseif mapsWonDM > mapsPlayedDM then
winRatioDM = 0
end
return playerCash, playerPoint, mapsWonDD, mapsPlayedDD, winRatioDD, mapsWonDM, mapsPlayedDM, winRatioDM, playedTime, hunters, mapBuys, AC, toptimes, totalBets, totalBetsEarned, totalBetsWon
end
--[[function NewUserDataFromPanel(ud,thePlayer)
for i=1,20 do
savePlayerData (thePlayer,"ud"..i,ud[i])
end
end
function getUserStats(whoask,who)
UData = {}
for j=1,20 do
UData[j] = loadPlayerData(who,"ud"..j)
end
callClientFunction(whoask,"UserStats",UData)
end]]--
------------------------------------------
-- Load & Save Data
------------------------------------------
function loadPlayerData (player,datatype)
local playerSerial = getPlayerSerial (player)
if (playerSerial) then
local root = xmlLoadFile ("DataBase.xml")
if (root) then
local usersNode = xmlFindChild (root,"user",0)
if (usersNode) then
local playerRootNode = xmlFindChild (usersNode,"SERIAL_" .. playerSerial,0)
if not (playerRootNode == false) then
local playerData = xmlNodeGetAttribute (playerRootNode,datatype)
if (playerData) then
xmlUnloadFile (root)
--outputDebugString("---- LoadD: "..getPlayerName(player).." , "..datatype.." , "..playerData)
return playerData
else
xmlNodeSetAttribute (playerRootNode,datatype,0)
xmlSaveFile (root)
xmlUnloadFile (root)
--outputDebugString("---- LoadD: "..getPlayerName(player).." , "..datatype.." , 0")
return 0
end
else
local playerRootNode = xmlCreateChild (usersNode,"SERIAL_" .. playerSerial)
xmlNodeSetAttribute (playerRootNode,datatype,0)
xmlSaveFile (root)
xmlUnloadFile (root)
--outputDebugString("---- LoadD: "..getPlayerName(player).." , "..datatype.." , 0")
return 0
end
end
end
end
end
function savePlayerData (player,datatype,newvalue)
local playerSerial = getPlayerSerial (player)
if (playerSerial) then
local root = xmlLoadFile ("DataBase.xml")
if (root) then
local usersNode = xmlFindChild (root,"user",0)
if (usersNode) then
local playerRootNode = xmlFindChild (usersNode,"SERIAL_" .. playerSerial,0)
if not (playerRootNode == false) then
local newNodeValue = xmlNodeSetAttribute (playerRootNode,datatype,newvalue)
xmlSaveFile (root)
xmlUnloadFile (root)
--outputDebugString("---- SaveD: "..getPlayerName(player).." , "..datatype.." , "..newvalue)
return newNodeValue
else
local playerRootNode = xmlCreateChild (usersNode,"SERIAL_" .. playerSerial)
local newNodeValue = xmlNodeSetAttribute (playerRootNode,datatype,newvalue)
xmlSaveFile (root)
xmlUnloadFile (root)
--outputDebugString("---- SaveD: "..getPlayerName(player).." , "..datatype.." , "..newvalue)
return newNodeValue
end
end
end
end
end
------------------------------------------
-- Achievementy
------------------------------------------
function CheckAchievement(thePlayer,achiev)
local name = "ac"..achiev
local LockedUnlocked = tonumber(loadPlayerData(thePlayer,name))
if LockedUnlocked == 0 then
if achiev == 1 then -- 1st win
local mapsWonDD = tonumber(loadPlayerData(thePlayer,"mapsWonDD"))
local mapsWonDM = tonumber(loadPlayerData(thePlayer,"mapsWonDM"))
if mapsWonDD > 0 or mapsWonDM > 0 then
unlockedAC(thePlayer,achiev)
end
elseif achiev == 2 then -- 1st hunter
local hunters = tonumber(loadPlayerData(thePlayer,"hunters"))
if hunters > 0 then
unlockedAC(thePlayer,achiev)
end
elseif achiev == 3 then -- 300+ wins
local mapsWonDD = tonumber(loadPlayerData(thePlayer,"mapsWonDD"))
local mapsWonDM = tonumber(loadPlayerData(thePlayer,"mapsWonDM"))
if mapsWonDD + mapsWonDM >= 300 then
unlockedAC(thePlayer,achiev)
end
elseif achiev == 4 then -- 1000+wins
local mapsWonDD = tonumber(loadPlayerData(thePlayer,"mapsWonDD"))
local mapsWonDM = tonumber(loadPlayerData(thePlayer,"mapsWonDM"))
if mapsWonDD + mapsWonDM >= 1000 then
unlockedAC(thePlayer,achiev)
end
elseif achiev == 5 then -- 2000 played
local mapsPlayedDD = tonumber(loadPlayerData(thePlayer,"mapsPlayedDD"))
local mapsPlayedDM = tonumber(loadPlayerData(thePlayer,"mapsPlayedDM"))
if mapsPlayedDD + mapsPlayedDM >= 2000 then
unlockedAC(thePlayer,achiev)
end
elseif achiev == 6 then -- 7days
local playedTime = tonumber(loadPlayerData(thePlayer,"playedTime"))
if playedTime >= 604800 then
unlockedAC(thePlayer,achiev)
end
elseif achiev == 7 then -- 50+ hunters
local hunters = tonumber(loadPlayerData(thePlayer,"hunters"))
if hunters >= 50 then
unlockedAC(thePlayer,achiev)
end
elseif achiev == 8 then--beat TT
local toptimes = tonumber(loadPlayerData(thePlayer,"TopTimes"))
if toptimes > 0 then
unlockedAC(thePlayer,achiev)
end
elseif achiev == 9 then-- 5x in a row
if LastWinners[1] == thePlayer and LastWinners[2] == thePlayer and LastWinners[3] == thePlayer and LastWinners[4] == thePlayer and LastWinners[5] == thePlayer then
unlockedAC(thePlayer,achiev)
end
elseif achiev == 10 then --3x DM
if LastWinnersDM[1] == thePlayer and LastWinnersDM[2] == thePlayer and LastWinnersDM[3] == thePlayer then
unlockedAC(thePlayer,achiev)
end
elseif achiev == 11 then --3x DD
if LastWinnersDD[1] == thePlayer and LastWinnersDD[2] == thePlayer and LastWinnersDD[3] == thePlayer then
unlockedAC(thePlayer,achiev)
end
elseif achiev == 13 then --10x mapbuy
local mapBuys = tonumber(loadPlayerData(thePlayer,"mapBuys"))
if mapBuys >= 10 then
unlockedAC(thePlayer,achiev)
end
elseif achiev == 14 then --50 toptimow
local toptimes = tonumber(loadPlayerData(thePlayer,"TopTimes"))
if toptimes >= 50 then
unlockedAC(thePlayer,achiev)
end
elseif achiev == 15 then --1mln
local playerCash = tonumber(loadPlayerData(thePlayer,"cash"))
if playerCash >= 1000000 then
unlockedAC(thePlayer,achiev)
end
elseif achiev == 16 then --2mln
local playerCash = tonumber(loadPlayerData(thePlayer,"cash"))
if playerCash >= 2000000 then
unlockedAC(thePlayer,achiev)
end
elseif achiev == 17 then --150+ hunters
local hunters = tonumber(loadPlayerData(thePlayer,"hunters"))
if hunters >= 150 then
unlockedAC(thePlayer,achiev)
end
elseif achiev == 18 then --150 toptimow
local toptimes = tonumber(loadPlayerData(thePlayer,"TopTimes"))
if toptimes >= 150 then
unlockedAC(thePlayer,achiev)
end
elseif achiev == 20 then --1500 points
local playerPoint = tonumber(loadPlayerData(thePlayer,"point"))
if playerPoint >= 1500 then
unlockedAC(thePlayer,achiev)
end
elseif achiev == 21 then --500.000 points
local playerPoint = tonumber(loadPlayerData(thePlayer,"point"))
if playerPoint >= 500000 then
unlockedAC(thePlayer,achiev)
end
end
else
if achiev == 15 then
local playerCash = tonumber(loadPlayerData(thePlayer,"cash"))
if playerCash < 1000000 then
savePlayerData(thePlayer,"ac"..achiev,0)
end
elseif achiev == 16 then
local playerCash = tonumber(loadPlayerData(thePlayer,"cash"))
if playerCash < 2000000 then
savePlayerData(thePlayer,"ac"..achiev,0)
end
elseif achiev == 20 then
local playerPoint = tonumber(loadPlayerData(thePlayer,"point"))
if playerPoint < 1500 then
savePlayerData(thePlayer,"ac"..achiev,0)
end
elseif achiev == 21 then
local playerPoint = tonumber(loadPlayerData(thePlayer,"point"))
if playerPoint < 500000 then
savePlayerData(thePlayer,"ac"..achiev,0)
end
elseif achiev == 13 then
local mapBuys = tonumber(loadPlayerData(thePlayer,"mapBuys"))
if mapBuys <= 10 then
unlockedAC(thePlayer,achiev)
end
end
end
end
function unlockedAC(thePlayer,achiev)
callClientFunction(thePlayer,"unlockAChievement", achiev)
outputChatBox("#FFFFFFAC: #00AAFF"..getPlayerName(thePlayer).."#FFFFFF Has Unlocked An Achievement!",getRootElement(),255,255,255,true)
outputChatBox("#FFFFFFAC: #00AAFF"..AchievementsName[achiev],getRootElement(),255,255,255,true)
savePlayerData(thePlayer,"ac"..achiev,1)
end
addEvent("onPlayerToptimeImprovement",true)
addEventHandler("onPlayerToptimeImprovement",getRootElement(),
function (player)
local totalToptimes = tonumber(loadPlayerData(source,"TopTimes"))
savePlayerData(source,"TopTimes",totalToptimes+1)
CheckAchievement(source,8)
CheckAchievement(source,14)
CheckAchievement(source,18)
end)
------------------------------------------------
-- Set headlights on map start and on veh-change
------------------------------------------------
function setPlayerHeadlightColor(number, sort, model)
if sort == "vehiclechange" then
local hlcRed = getElementData(source,"hlcRed")
local hlcGreen = getElementData(source,"hlcGreen")
local hlcBlue = getElementData(source,"hlcBlue")
if (hlcRed) and (hlcGreen) and (hlcBlue) then
local car = getPedOccupiedVehicle(source)
setVehicleHeadLightColor(car,hlcRed,hlcGreen,hlcBlue)
--outputChatBox("Data sucessfully retrieved, headlights color has been set!",getRootElement(),0,255,0)
else
end
end
end
function setPlayerHeadlightColor2()
local hlcRed = getElementData(source,"hlcRed")
local hlcGreen = getElementData(source,"hlcGreen")
local hlcBlue = getElementData(source,"hlcBlue")
if (hlcRed) and (hlcGreen) and (hlcBlue) then
local car = getPedOccupiedVehicle(source)
setVehicleHeadLightColor(car,hlcRed,hlcGreen,hlcBlue)
--outputChatBox("Data sucessfully retrieved, headlights color has been set!",getRootElement(),0,255,0)
else
end
end
addEvent("onNotifyPlayerReady", true)
addEventHandler("onNotifyPlayerReady", getRootElement(), setPlayerHeadlightColor2)
addEventHandler("onPlayerPickUpRacePickup",getRootElement(),setPlayerHeadlightColor)
------------------
-- Save headlights
------------------
function saveHeadlights ( thePlayer, colorRed, colorGreen, colorBlue )
--outputChatBox("SERVER: Event triggered! Saving headlights...")
local red = colorRed
local green = colorGreen
local blue = colorBlue
local car = getPedOccupiedVehicle(thePlayer)
setVehicleHeadLightColor(car,red,green,blue)
savePlayerData(thePlayer,"hlcRed",red)
savePlayerData(thePlayer,"hlcGreen",green)
savePlayerData(thePlayer,"hlcBlue",blue)
setElementData(thePlayer,"hlcRed",red)
setElementData(thePlayer,"hlcGreen",green)
setElementData(thePlayer,"hlcBlue",blue)
outputChatBox("#0095FF* #FFFFFFYour data has been saved!",thePlayer,255,255,255,true)
--outputChatBox("SERVER: Account found! Data has been saved.")
end
addEvent("saveHeadlights", true)
addEventHandler("saveHeadlights", getRootElement(), saveHeadlights)
---------------------
-- Save vehicle color
---------------------
function saveVehColor(player,c1,c2,c3,c4)
savePlayerData(player,"c1",c1)
savePlayerData(player,"c2",c2)
savePlayerData(player,"c3",c3)
savePlayerData(player,"c4",c4)
setElementData(player,"c1",c1)
setElementData(player,"c2",c2)
setElementData(player,"c3",c3)
setElementData(player,"c4",c4)
end
root = getRootElement()
function executecolor(c1,c2,c3,c4)
carcolor(source,true,c1,c2,c3,c4)
end
function executealpha(player,_,alpha)
alpha = alpha or 255
setElementAlpha(getPedOccupiedVehicle(player),tonumber(alpha))
end
function carcolor(thePlayer,_,arg1,arg2,arg3,arg4)
local vehicle = getPedOccupiedVehicle(thePlayer)
if (vehicle) then
local old,old2,old3,old4=getVehicleColor(vehicle)
local arg11,arg22,arg33,arg44=tonumber(arg1),tonumber(arg2) or old2,tonumber(arg3) or old3,tonumber(arg4) or old4
setVehicleColor(vehicle,arg11,arg22,arg33,arg44)
outputChatBox("#0095FF* #FFFFFFYour data has been saved!",thePlayer,255,255,255,true)
savePlayerData(thePlayer,"everSetCustomVehicleColor",1)
setElementData(thePlayer,"everSetCustomVehicleColor",1)
else
end
end
addEvent("colorchange",true)
addEventHandler("colorchange",root, executecolor)
addEvent("alphachange",true)
addEventHandler("alphachange",root, executealpha)
----------------------------------------------------------
-- Set vehicle color on player-ready and on vehicle change
----------------------------------------------------------
function setPlayerVehicleColor(number, sort, model)
if sort == "vehiclechange" then
local ifSet = tonumber(getElementData(source,"everSetCustomVehicleColor"))
if ifSet == 1 then
local useColor = tostring(getElementData(source,"useCustomVehicleColor"))
if (useColor == "true") then
local c1 = tonumber(getElementData(source,"c1"))
local c2 = tonumber(getElementData(source,"c2"))
local c3 = tonumber(getElementData(source,"c3"))
local c4 = tonumber(getElementData(source,"c4"))
local car = getPedOccupiedVehicle(source)
exc1, exc2, exc3, exc4 = getVehicleColor (car)
if not c1 then c1 = exc1 end
if not c2 then c2 = exc2 end
if not c3 then c3 = exc3 end
if not c4 then c4 = exc4 end
setVehicleColor(car,c1,c2,c3,c4)
else
local car = getPedOccupiedVehicle(source)
setVehicleColor(car,math.random(1,126),math.random(1,126),math.random(1,126),math.random(1,126))
end
else
local car = getPedOccupiedVehicle(source)
setVehicleColor(car,math.random(1,126),math.random(1,126),math.random(1,126),math.random(1,126))
end
end
end
function setPlayerVehicleColor2()
local ifSet = tonumber(getElementData(source,"everSetCustomVehicleColor"))
if ifSet == 1 then
local useColor = tostring(getElementData(source,"useCustomVehicleColor"))
if (useColor == "true") then
local c1 = tonumber(getElementData(source,"c1"))
local c2 = tonumber(getElementData(source,"c2"))
local c3 = tonumber(getElementData(source,"c3"))
local c4 = tonumber(getElementData(source,"c4"))
local car = getPedOccupiedVehicle(source)
exc1, exc2, exc3, exc4 = getVehicleColor (car)
if not c1 then c1 = exc1 end
if not c2 then c2 = exc2 end
if not c3 then c3 = exc3 end
if not c4 then c4 = exc4 end
setVehicleColor(car,c1,c2,c3,c4)
else
local car = getPedOccupiedVehicle(source)
setVehicleColor(car,math.random(1,126),math.random(1,126),math.random(1,126),math.random(1,126))
end
else
local car = getPedOccupiedVehicle(source)
setVehicleColor(car,math.random(1,126),math.random(1,126),math.random(1,126),math.random(1,126))
end
end
addEventHandler("onNotifyPlayerReady", getRootElement(), setPlayerVehicleColor2)
addEventHandler("onPlayerPickUpRacePickup", getRootElement(), setPlayerVehicleColor)
---------------------------------------------
-- Set most widely used stats as element data
---------------------------------------------
function setElementDataOnStart(source)
thePlayer = source
local a = loadPlayerData(thePlayer,"everPurchasedSkin")
local b = loadPlayerData(thePlayer,"everPurchasedNametagColor")
local c = loadPlayerData(thePlayer,"everSetCustomVehicleColor")
local d = loadPlayerData(thePlayer,"useCustomVehicleColor")
local e = loadPlayerData(thePlayer,"c1")
local f = loadPlayerData(thePlayer,"c2")
local g = loadPlayerData(thePlayer,"c3")
local h = loadPlayerData(thePlayer,"c4")
local i = loadPlayerData(thePlayer,"hlcRed")
local j = loadPlayerData(thePlayer,"hlcGreen")
local k = loadPlayerData(thePlayer,"hlcBlue")
local adminredo = loadPlayerData(thePlayer,"admin_redo")
local adminnextmap = loadPlayerData(thePlayer,"admin_nextmap")
setElementData(thePlayer,"everPurchasedSkin",a)
setElementData(thePlayer,"everPurchasedNametagColor",b)
setElementData(thePlayer,"everSetCustomVehicleColor",c)
setElementData(thePlayer,"useCustomVehicleColor",d)
setElementData(thePlayer,"c1",e)
setElementData(thePlayer,"c2",f)
setElementData(thePlayer,"c3",g)
setElementData(thePlayer,"c4",h)
setElementData(thePlayer,"hlcRed",i)
setElementData(thePlayer,"hlcGreen",j)
setElementData(thePlayer,"hlcBlue",k)
setElementData(thePlayer,"admin_redo",adminredo)
setElementData(thePlayer,"admin_nextmap",adminnextmap)
end
------------------------------------------
-- Join - PlayedTime
------------------------------------------
function PlayedTimeJoin()
local thePlayer = source
local PlayerJoinTime = getTickCount ()
setElementData(thePlayer,"joinTime", PlayerJoinTime)
end
addEventHandler ("onPlayerJoin",getRootElement(), PlayedTimeJoin)
function PlayedTimeQuit()
local thePlayer = source
local PlayerQuitTime = getTickCount ()
local PlayerTodayTime = math.floor((PlayerQuitTime - getElementData(thePlayer,"joinTime"))/1000)
local PlayerOldTime = loadPlayerData(thePlayer,"playedTime")
savePlayerData(thePlayer,"playedTime", PlayerOldTime + PlayerTodayTime)
end
addEventHandler ("onPlayerQuit",getRootElement(), PlayedTimeQuit)
function convertTime(timeinseconds)
Days = math.floor(timeinseconds/86400)
timeinseconds = timeinseconds - Days*86400
Hours = math.floor(timeinseconds/3600)
timeinseconds = timeinseconds - Hours*3600
Minutes = math.floor(timeinseconds/60)
timeinseconds = timeinseconds - Minutes*60
Seconds = timeinseconds
if Days > 0 then
Time = Days.." days "..Hours.."h "..Minutes.."m "..Seconds.."s"
elseif Hours > 0 then
Time = Hours.."h "..Minutes.."m "..Seconds.."s"
elseif Minutes > 0 then
Time = Minutes.."m "..Seconds.."s"
else
Time = Seconds.."s"
end
return Time
end
------------------------------------------
-- Hunters
------------------------------------------
function checkForHunter(number,sort,model)
thePlayer = source
if sort == "vehiclechange" then
if model == 425 then
if getElementData(thePlayer,"playerGotHunter") == false then
setElementData(thePlayer,"playerGotHunter",true)
local oldhunters = loadPlayerData(thePlayer,"hunters")
savePlayerData(thePlayer,"hunters", oldhunters + 1)
CheckAchievement(thePlayer,2)
CheckAchievement(thePlayer,7)
CheckAchievement(thePlayer,17)
HunterCount = HunterCount + 1
end
end
end
end
addEventHandler("onPlayerPickUpRacePickup",getRootElement(),checkForHunter)
----------------------
-- Shop (buy repair/nos...)
----------------------
function nos()
if getGameType() == "Race" then
if isPedInVehicle(source) then
local playerMoney = loadPlayerData (source,"cash")
if (tonumber(playerMoney) > 7500) then
savePlayerData (source,"cash",loadPlayerData(source,"cash") -25000)
addVehicleUpgrade(getPedOccupiedVehicle(source),1010)
setTimer(outputChatBox,50,1,"#ff6464[SHOP]: #ffffff"..getPlayerName (source) .. " #ffffffhas bought nitro! (#abcdef7500$#ffffff)",getRootElement(),0,136,255,true)
else
outputChatBox("#0fc0fcYou dont have money for buy this.",source, 0,136,255,true)
end
else
outputChatBox("#0fc0fcYou are not in a vehicle.",source,0,136,255,true)
end
else
outputChatBox("#0fc0fcYou are not in race mode.",source,0,136,255,true)
end
end
addCommandHandler("bn",nos)
function repair()
if getGameType() == "Race" then
if isPedInVehicle(source) then
local playerMoney = loadPlayerData (source,"cash")
if (tonumber(playerMoney) > 3000) then
savePlayerData (source,"cash",loadPlayerData(source,"cash") -2500)
fixVehicle(getPedOccupiedVehicle(source))
setTimer(outputChatBox,50,1,"#ff6464[SHOP]: #ffffff"..getPlayerName (source) .. " #ffffffhas bought fix! (#abcdef3000$#ffffff)",getRootElement(),0,136,255,true)
else
outputChatBox("#0fc0fcYou dont have money for buy this.",source, 0,136,255,true)
end
else
outputChatBox("#0fc0fcYou are not in a vehicle.",source,0,136,255,true)
end
else
outputChatBox("#0fc0fcYou are not in race mode.",source,0,136,255,true)
end
end
addCommandHandler("br",repair)
function flip()
if getGameType() == "Race" then
if isPedInVehicle(source) then
local playerMoney = loadPlayerData (source,"cash")
if (tonumber(playerMoney) > 3500) then
savePlayerData (source,"cash",loadPlayerData(source,"cash") -2500)
rx, ry, rz = getVehicleRotation (getPedOccupiedVehicle(source))
setVehicleRotation (getPedOccupiedVehicle(source), rx +180, ry, rz +180)
setTimer(outputChatBox,50,1,"#ff6464[SHOP]: #ffffff"..getPlayerName (source) .. " #ffffffhas bought flip! (#abcdef3500$#ffffff)",getRootElement(),0,136,255,true)
else
outputChatBox("#0fc0fcYou dont have money for buy this.",source, 0,136,255,true)
end
else
outputChatBox("#0fc0fcYou are not in a vehicle.",source,0,136,255,true)
end
else
outputChatBox("#0fc0fcYou are not in race mode.",source,0,136,255,true)
end
end
addCommandHandler("bf",flip)
----------------------
-- Roll (spin/flip Comming soon)
----------------------
addEventHandler ("onPlayerChat",getRootElement(),
function(message,type)
if (string.find(message,"!roll")) and not (string.find(message," !roll")) then
local playerCash = loadPlayerData (source,"cash")
if (tonumber(playerCash) > 100) then
if not (rollLimitCheckPlayerIsIn (source)) then
savePlayerData (source,"cash",loadPlayerData (source,"cash") -100)
local firstRollNumber = math.random (1,4)
local secondRollNumber = math.random (0,1000)
rollLimitAddPlayer (source)
if (firstRollNumber == 1) then
setTimer(outputChatBox,500,1,"#ff8800[ROLL]: #ffffff"..getPlayerName( source ).." #ffffffhas rolled and #00ff00won #abcdef[#ffffff" .. tostring (secondRollNumber) .. "$#abcdef]#ffffff!",getRootElement(),0,153,255,true)
setTimer(savePlayerData,500,1,source,"cash",loadPlayerData(source,"cash") +secondRollNumber)
elseif (firstRollNumber == 2) then
setTimer(outputChatBox,500,1,"#ff8800[ROLL]: #ffffff"..getPlayerName( source ).." #ffffffhas rolled and #00ff00won #abcdef[#ffffff" .. tostring (secondRollNumber) .. "$#abcdef]#ffffff!",getRootElement(),0,153,255,true)
setTimer(savePlayerData,500,1,source,"cash",loadPlayerData(source,"cash") +secondRollNumber)
elseif (firstRollNumber == 3) then
setTimer(outputChatBox,500,1,"#ff8800[ROLL]: #ffffff"..getPlayerName( source ).." #ffffffhas rolled and #ff0000lost #abcdef[#ffffff" .. tostring (secondRollNumber) .. "$#abcdef]#ffffff!",getRootElement(),0,153,255,true)
setTimer(savePlayerData,500,1,source,"cash",loadPlayerData(source,"cash") -secondRollNumber)
elseif (firstRollNumber == 4) then
setTimer(outputChatBox,500,1,"#ff8800[ROLL]: #ffffff"..getPlayerName( source ).." #ffffffhas rolled and #ff0000lost #abcdef[#ffffff" .. tostring (secondRollNumber) .. "$#abcdef]#ffffff!",getRootElement(),0,153,255,true)
setTimer(savePlayerData,500,1,source,"cash",loadPlayerData(source,"cash") -secondRollNumber)
end
else
outputChatBox ("#0099ffYou only can use !roll once a minute!",source,0,153,255,true)
cancelEvent()
end
else
setTimer(outputChatBox,50,1,"#0099ffYou don't have got 100$, you need that before rolling!",source,0,153,255,true)
end
end
end)
rollusers = {}
function rollLimitCheckPlayerIsIn (player)
for i,v in ipairs (rollusers) do
if (v == player) then
return true
end
end
end
function rollLimitAddPlayer (player)
table.insert (rollusers,player)
end
function rollLimitCleanUp2 ()
for i,v in ipairs (rollusers) do
table.remove (rollusers,i)
end
end
addEventHandler("onResourceStart",getResourceRootElement(getThisResource()),
function()
if (rollLimitTimer2) then
killTimer (rollLimitTimer2)
rollLimitTimer2 = setTimer (rollLimitCleanUp2,60000,0)
else
rollLimitTimer2 = setTimer (rollLimitCleanUp2,60000,0)
end
end)
addEventHandler("onPlayerChat", getRootElement(),
function (text)
if string.sub(text, 1, 1) == "!" then
local command = string.gsub(gettok(text, 1, 32), "!", "")
local args = string.gsub(text, "!"..command, "")
executeCommandHandler(command, source, args)
end
end
)
------------------------------------------
-- Mapy
------------------------------------------
local maps = { }
for _, map in ipairs ( exports.mapmanager:getMapsCompatibleWithGamemode(exports.mapmanager:getRunningGamemode())) do
maps[ getResourceInfo ( map, 'name' ) ] = true;
end
function buyMap(thePlayer,mapName)
mapName = tostring(mapName)
if ( mapName ~= "" ) then
if ( maps[mapName] ) then
if mapIsAlreadySet == false then
local playerCash = tonumber(loadPlayerData(thePlayer,"cash"));
if playerCash >= mapCost then
executeCommandHandler("pnfnsdhasd3w7432jhdsbw3ersdncsdir",thePlayer,mapName)
maps[mapName] = false;
setTimer (
function ( map )
maps[map] = true;
outputChatBox ( "#ff6464[MAP]:#ffffff'#abcdef" .. map .. "#ffffff' can be bought again!", root, 255, 255, 255, true );
end, 1800000, 1,
mapName );
savePlayerData(thePlayer,"cash",playerCash-mapCost)
outputChatBox("#ff6464[MAP]: "..getPlayerName(thePlayer).."#FFFFFF Has Bought a Next Map! #ABCDEF"..mapName,root, 255, 255, 255, true)
outputChatBox("#FF6464[MAP]: #ABCDEF"..mapName.." #ffffffAdded in base!",root,255,255,255,true)
--outputChatBox("#FFFFFF[MAP]: #ABCDEF "..mapName,root,255,255,255,true)
mapIsAlreadySet = true;
local oldmapbuys = loadPlayerData(thePlayer,"mapBuys")
savePlayerData(thePlayer,"mapBuys", oldmapbuys + 1)
CheckAchievement(thePlayer,13)
scoreboardRefresh(thePlayer)
else
outputChatBox("#00AAFF# #FFFFFFYou Don't Have Enough Money To Set a Map!",thePlayer,255,255,255,true)
end
else
outputChatBox("#00AAFF# #FFFFFFA Map is Already Set At The Moment! Please Try Again Later.",thePlayer,255,255,255,true)
end
else
outputChatBox("#00AAFF# #FFFFFFThis map can't be bought yet! Wait some time and try again.",thePlayer,255,255,255,true)
end
else
outputChatBox("#00AAFF# #FFFFFFSelect a map from list first!", thePlayer, 255, 255, 255, true );
end
end
function unbuyMap(thePlayer)
if mapIsAlreadySet ~= false then
if mapIsAlreadySet == thePlayer then
executeCommandHandler("pnfnsdhasd3w7432jhdsbw3ersdncsdir",thePlayer,nil)
local playerCash = tonumber(loadPlayerData(thePlayer,"cash"))
savePlayerData(thePlayer,"cash",playerCash+(mapCost/4)*3)
outputChatBox("#FF6464[MAP]: #FFFFFF"..getPlayerName(thePlayer).."#ABCDEF Has Unbought a Next Map!",getRootElement())
mapIsAlreadySet = false
local oldmapbuys = loadPlayerData(thePlayer,"mapBuys")
savePlayerData(thePlayer,"mapBuys", oldmapbuys - 1)
CheckAchievement(thePlayer,13)
scoreboardRefresh(thePlayer)
else
outputChatBox("#00AAFF# #FFFFFFYou Didn't Buy That Map!",thePlayer,255,255,255,true)
end
else
outputChatBox("#00AAFF# #FFFFFFNo Map Has Been Bought!",thePlayer,255,255,255,true)
end
end
function resetMapSetStatus()
mapIsAlreadySet = false
end
addEventHandler("onMapStarting",getRootElement(),resetMapSetStatus)
function getServerMaps (loadList,s)
local tableOut
if loadList then
tableOut = {}
-- local deletedMaps = {}
local gamemodes = {}
gamemodes = call(getResourceFromName("mapmanager"), "getGamemodes")
for id,gamemode in ipairs (gamemodes) do
tableOut[id] = {}
tableOut[id].name = getResourceInfo(gamemode, "name") or getResourceName(gamemode)
tableOut[id].resname = getResourceName(gamemode)
tableOut[id].maps = {}
local maps = call(getResourceFromName("mapmanager"), "getMapsCompatibleWithGamemode" , gamemode)
for _,map in ipairs (maps) do
table.insert(tableOut[id]["maps"] ,{name = getResourceInfo(map, "name") or getResourceName(map), resname = getResourceName(map)})
end
table.sort(tableOut[id]["maps"], sortCompareFunction)
end
table.sort((tableOut), sortCompareFunction)
table.insert(tableOut, {name = "no gamemode", resname = "no gamemode", maps = {}})
local countGmodes = #tableOut
local maps = call(getResourceFromName("mapmanager"), "getMapsCompatibleWithGamemode")
for id,map in ipairs (maps) do
-- if fileOpen(":"..getResourceName(map).."/deleted") then
-- table.insert(deletedMaps ,{name = getResourceInfo(map, "name") or getResourceName(map), resname = getResourceName(map)})
-- else
table.insert(tableOut[countGmodes]["maps"] ,{name = getResourceInfo(map, "name") or getResourceName(map), resname = getResourceName(map)})
-- end
end
-- table.sort(deletedMaps, sortCompareFunction)
table.sort(tableOut[countGmodes]["maps"], sortCompareFunction)
-- table.insert(tableOut, {name = "deleted maps", resname = "deleted maps", maps = {}})
-- local countGmodes = countGmodes + 1
-- tableOut[countGmodes]["maps"] = deletedMaps
end
local map = call(getResourceFromName("mapmanager"), "getRunningGamemodeMap")
local gamemode = call(getResourceFromName("mapmanager"), "getRunningGamemode")
gamemode = gamemode and getResourceName(gamemode) or "N/A"
map = map and getResourceName(map) or "N/A"
callClientFunction(loadList,"loadMaps", tableOut, gamemode, map, s)
end
function sortCompareFunction(s1, s2)
if type(s1) == "table" and type(s2) == "table" then
s1, s2 = s1.name, s2.name
end
s1, s2 = s1:lower(), s2:lower()
if s1 == s2 then
return false
end
local byte1, byte2 = string.byte(s1:sub(1,1)), string.byte(s2:sub(1,1))
if not byte1 then
return true
elseif not byte2 then
return false
elseif byte1 < byte2 then
return true
elseif byte1 == byte2 then
return sortCompareFunction(s1:sub(2), s2:sub(2))
else
return false
end
end
---------------------
-- Skin handler
---------------------
function saveSkin(thePlayer,skinID)
if (tonumber(loadPlayerData(thePlayer,"cash")) >= skinCost) then
savePlayerData(thePlayer,"skin",skinID)
savePlayerData(thePlayer,"cash",tonumber(loadPlayerData(thePlayer,"cash"))-skinCost)
skinEnabled = loadPlayerData(thePlayer,"useCustomSkin")
if skinEnabled == "true" then
setElementModel(thePlayer,skinID)
end
outputChatBox("#0095FF* #FFFFFFYou have sucessfuly purchased the skin! #FFFF00[#FFFFFFID:"..skinID.."#FFFF00]",thePlayer,255,255,255,true)
setTimer(outputChatBox,700,1,"#0095FF* #FFFFFFThe skin has been saved to your account.",thePlayer,255,255,255,true)
savePlayerData(thePlayer,"everPurchasedSkin",1)
setElementData(thePlayer,"everPurchasedSkin",1)
scoreboardRefresh(thePlayer)
else
outputChatBox("#0095FF* #FFFFFFERROR! You don't have enough money!",thePlayer,255,255,255,true)
end
end
function setSkinOnMapStart()
if tonumber(getElementData(source,"everPurchasedSkin")) == 1 then
skinEnabled = loadPlayerData(source,"useCustomSkin")
if skinEnabled == "true" then
skinID = loadPlayerData(source,"skin")
setElementModel(source,skinID)
end
end
end
addEventHandler("onNotifyPlayerReady",getRootElement(),setSkinOnMapStart)
function checkSkinLevel(thePlayer)
local playerLevel = tonumber(loadPlayerData(thePlayer,"level"))
if playerLevel >= skinLevel then
callClientFunction(thePlayer,"openSkinsWindow")
else
outputChatBox("#0095FF* #FFFFFFERROR! You need to be level #ABCDEF"..skinLevel.."#FFFFFF or more to change skins!",thePlayer,255,255,255,true)
end
end
---------------------
-- Rims handler
---------------------
function buyjant(thePlayer,buyjant)
if (tonumber(loadPlayerData(thePlayer,"cash")) >= buyjant) then
savePlayerData(thePlayer,"rim",buyjant)
savePlayerData(thePlayer,"cash",tonumber(loadPlayerData(thePlayer,"cash"))-buyjant)
--skinEnabled = loadPlayerData(thePlayer,"useCustomSkin")
--if skinEnabled == "true" then
--setElementModel(thePlayer,skinID)
end
outputChatBox("#0095FF* #FFFFFFYou have sucessfuly purchased the Rim!",thePlayer,255,255,255,true)
setTimer(outputChatBox,700,1,"#0095FF* #FFFFFFThe rim has been saved to your account.",thePlayer,255,255,255,true)
--savePlayerData(thePlayer,"everPurchasedSkin",1)
--setElementData(thePlayer,"everPurchasedSkin",1)
scoreboardRefresh(thePlayer)
else
outputChatBox("#0095FF* #FFFFFFERROR! You don't have enough money!",thePlayer,255,255,255,true)
end
end
--[[function setSkinOnMapStart()
if tonumber(getElementData(source,"everPurchasedSkin")) == 1 then
skinEnabled = loadPlayerData(source,"useCustomSkin")
if skinEnabled == "true" then
skinID = loadPlayerData(source,"skin")
setElementModel(source,skinID)
end
end
end
addEventHandler("onNotifyPlayerReady",getRootElement(),setSkinOnMapStart)
function checkSkinLevel(thePlayer)
local playerLevel = tonumber(loadPlayerData(thePlayer,"level"))
if playerLevel >= skinLevel then
callClientFunction(thePlayer,"openSkinsWindow")
else
outputChatBox("#0095FF* #FFFFFFERROR! You need to be level #ABCDEF"..skinLevel.."#FFFFFF or more to change skins!",thePlayer,255,255,255,true)
end
end]]--
--------------------------
-- Options handler
--------------------------
function saveClientSettings(thePlayer,a,b,c,d,e,f,g,h,i,j)
outputChatBox("#0095FF* #FFFFFFYour settings have been saved!",thePlayer,255,255,255,true)
savePlayerData(thePlayer,"useCustomNametag",c)
savePlayerData(thePlayer,"useCustomSkin",d)
savePlayerData(thePlayer,"useCustomVehicleColor",e)
savePlayerData(thePlayer,"useHunterSkin",i)
end
function getClientSettings(thePlayer)
c = loadPlayerData(thePlayer,"useCustomNametag")
d = loadPlayerData(thePlayer,"useCustomSkin")
e = loadPlayerData(thePlayer,"useCustomVehicleColor")
i = loadPlayerData(thePlayer,"useHunterSkin")
callClientFunction(thePlayer,"configureOptions",true,a,b,c,d,e,f,g,h,i,j)
end
function showUserpanelOnDeath()
if (loadPlayerData(source,"showOnDeath") == "true") then
callClientFunction(source,"displayUserpanel")
end
end
addEventHandler("onPlayerWasted",getRootElement(),showUserpanelOnDeath)
-- Nametag color
function saveNametagColor(thePlayer,r,g,b)
local playerCash = tonumber(loadPlayerData(thePlayer,"cash"))
savePlayerData(thePlayer,"cash",playerCash-nametagPrice)
savePlayerData(thePlayer,"nametagRed",r)
savePlayerData(thePlayer,"nametagGreen",g)
savePlayerData(thePlayer,"nametagBlue",b)
setNametagColor(thePlayer)
outputChatBox("#0095FF* #FFFFFFYou have purchased a new nametag color for #ABCDEF$"..nametagPrice.."#FFFFFF!",thePlayer,255,255,255,true)
savePlayerData(thePlayer,"everPurchasedNametagColor",1)
setElementData(thePlayer,"everPurchasedNametagColor",1)
scoreboardRefresh(thePlayer)
end
function getNametagLevel(thePlayer)
local playerCash = tonumber(loadPlayerData(thePlayer,"cash"))
local playerLevel = tonumber(loadPlayerData(thePlayer,"level"))
if playerLevel >= nametagLevel then
if playerCash >= nametagPrice then
callClientFunction(thePlayer,"showNametagWindow")
else
outputChatBox("#0095FF* #FFFFFFERROR! You don't have enough money!",thePlayer,255,255,255,true)
end
else
outputChatBox("#0095FF* #FFFFFFERROR! You need to be level #ABCDEF"..nametagLevel.."#FFFFFF or higher to change your nametag color!",thePlayer,255,255,255,true)
end
end
function setNametagColor(thePlayer)
local ifSet = tonumber(getElementData(thePlayer,"everPurchasedNametagColor"))
if ifSet == 1 then
local useColor = loadPlayerData(thePlayer,"useCustomNametag")
if useColor == "true" then
local r = tonumber(loadPlayerData(thePlayer,"nametagRed"))
local g = tonumber(loadPlayerData(thePlayer,"nametagGreen"))
local b = tonumber(loadPlayerData(thePlayer,"nametagBlue"))
callClientFunction(thePlayer,"setCustomNametagColor",true,r,g,b)
end
end
end
addEventHandler("onPlayerJoin",getRootElement(),setNametagColor)
-- Horns
function getPurchasedHorns(thePlayer)
local airhorn = tonumber(loadPlayerData(thePlayer,"horn1"))
local clown = tonumber(loadPlayerData(thePlayer,"horn2"))
local train = tonumber(loadPlayerData(thePlayer,"horn3"))
local ship = tonumber(loadPlayerData(thePlayer,"horn4"))
local submarine = tonumber(loadPlayerData(thePlayer,"horn5"))
local military = tonumber(loadPlayerData(thePlayer,"horn6"))
local whoopie = tonumber(loadPlayerData(thePlayer,"horn7"))
callClientFunction(thePlayer,"updateHorns",thePlayer,airhorn,clown,train,ship,submarine,military,whoopie)
end
function purchaseHorn(thePlayer,horn,hornName)
local playerCash = tonumber(loadPlayerData(thePlayer,"cash"))
local playerLevel = tonumber(loadPlayerData(thePlayer,"level"))
local checkOwnership = tonumber(loadPlayerData(thePlayer,"horn"..horn))
if checkOwnership == 0 then
if playerLevel >= hornLevel then
if playerCash >= hornPrice[horn] then
savePlayerData(thePlayer,"cash",playerCash-hornPrice[horn])
savePlayerData(thePlayer,tostring("horn"..horn),1)
getPurchasedHorns(thePlayer)
scoreboardRefresh(thePlayer)
achievement39(thePlayer)
outputChatBox("#0095FF* #FFFFFFYou have purchased the #ABCDEF"..hornName.."#FFFFFF horn for #ABCDEF$"..hornPrice[horn].."#FFFFFF!",thePlayer,255,255,255,true)
else
outputChatBox("#0095FF* #FFFFFFERROR! You don't have enough money!",thePlayer,255,255,255,true)
end
else
outputChatBox("#0095FF* #FFFFFFERROR! You need to be level #ABCDEF"..hornLevel.."#FFFFFF or higher to purchase new horns!",thePlayer,255,255,255,true)
end
else
outputChatBox("#0095FF* #FFFFFFERROR! You already own this horn!",thePlayer,255,255,255,true)
end
end
function checkForPurchasedHorn(thePlayer,horn)
local hornStatus = tonumber(loadPlayerData(thePlayer,"horn"..horn))
if hornStatus == 1 then
callClientFunction(thePlayer,"setHorn",horn)
else
outputChatBox("#0095FF* #FFFFFFERROR! You do not own this horn!",thePlayer,255,255,255,true)
end
end
function getLastSetHorn(thePlayer)
local horn = tonumber(loadPlayerData(thePlayer,"lastSetHorn"))
callClientFunction(thePlayer,"setLastUsedHorn",horn)
end
function setLastSetHorn(thePlayer,horn)
savePlayerData(thePlayer,"lastSetHorn",horn)
end
function toggleHornControl()
for _,player in ipairs(getElementsByType("player")) do
if loadPlayerData(player,"lastSetHorn") == 0 then
setTimer(toggleControl,2000,1,player,"horn",true)
else
setTimer(toggleControl,2000,1,player,"horn",false)
end
end
end
addEvent("onMapStarting",true)
addEventHandler("onMapStarting",getRootElement(),toggleHornControl)
function toggleControlOnReady()
if loadPlayerData(source,"lastSetHorn") == 0 then
toggleControl(source,"horn",true)
else
toggleControl(source,"horn",false)
end
end
addEventHandler("onNotifyPlayerReady",getRootElement(),toggleControlOnReady)
function playHornForAllClients(horningPlayer,hornSoundPath,cSetHornSound) -- This function passes on the horn to all players.
triggerClientEvent(getRootElement(),"onRecieveHorn",horningPlayer,horningPlayer,hornSoundPath,cSetHornSound)
end
-- Buy water color and time change
function buyChangeWaterColor(thePlayer,r,g,b)
if type(r) == "number" and r >= 0 and r <= 255 then
if type(g) == "number" and g >= 0 and g <= 255 then
if type(b) == "number" and g >= 0 and g <= 255 then
local playerCash = tonumber(loadPlayerData(thePlayer,"cash"))
if playerCash >= 400 then
callClientFunction(getRootElement(),"cSetWaterColor",r,g,b)
savePlayerData(thePlayer,"cash",playerCash-400)
outputChatBox("#0095FF* #FFFFFF"..getPlayerName(thePlayer).." #FFFFFFhas changed the water color!",getRootElement(),255,255,255,true)
scoreboardRefresh(thePlayer)
else
outputChatBox("#0095FF* #FFFFFFERROR! You don't have enough money!",thePlayer,255,255,255,true)
end
else
outputChatBox("#0095FF* #FFFFFFInvalid BLUE value - Please use a number from 0 to 255.",thePlayer,255,255,255,true)
end
else
outputChatBox("#0095FF* #FFFFFFInvalid GREEN value - Please use a number from 0 to 255.",thePlayer,255,255,255,true)
end
else
outputChatBox("#0095FF* #FFFFFFInvalid RED value - Please use a number from 0 to 255.",thePlayer,255,255,255,true)
end
end
function buyChangeTime(thePlayer,h,m)
if type(h) == "number" and h >= 0 and h <= 23 then
if type(m) == "number" and m >= 0 and m <= 59 then
local playerCash = tonumber(loadPlayerData(thePlayer,"cash"))
if playerCash >= 400 then
setTime(h,m)
savePlayerData(thePlayer,"cash",playerCash-250)
if h < 10 and m < 10 then
outputChatBox("#0095FF* #FFFFFF"..getPlayerName(thePlayer).." #FFFFFFhas changed the time to #ABCDEF0"..h..":0"..m.."#FFFFFF!",getRootElement(),255,255,255,true)
elseif h < 10 then
outputChatBox("#0095FF* #FFFFFF"..getPlayerName(thePlayer).." #FFFFFFhas changed the time to #ABCDEF0"..h..":"..m.."#FFFFFF!",getRootElement(),255,255,255,true)
elseif m < 10 then
outputChatBox("#0095FF* #FFFFFF"..getPlayerName(thePlayer).." #FFFFFFhas changed the time to #ABCDEF"..h..":0"..m.."#FFFFFF!",getRootElement(),255,255,255,true)
end
scoreboardRefresh(thePlayer)
else
outputChatBox("#0095FF* #FFFFFFERROR! You don't have enough money!",thePlayer,255,255,255,true)
end
else
outputChatBox("#0095FF* #FFFFFFInvalid MINUTES - Please use a number from 0 to 59.",thePlayer,255,255,255,true)
end
else
outputChatBox("#0095FF* #FFFFFFInvalid HOURS - Please use a number from 0 to 23.",thePlayer,255,255,255,true)
end
end
------------------------------------------
-- giveMoney
------------------------------------------
function giveMoney(thePlayer,CMD,targetPlayer,amount)
if not (targetPlayer == "") then
if tonumber(amount) then
local playerCash = tonumber(loadPlayerData(thePlayer,"cash"))
if tonumber(amount) > 0 then
if tonumber(amount) <= playerCash then
if (findPlayerByName(targetPlayer)) then
local target = findPlayerByName(targetPlayer)
if target ~= thePlayer then
local amount = math.ceil(amount)
local playerCash = loadPlayerData(thePlayer,"cash")
local targetCash = loadPlayerData(target,"cash")
savePlayerData(thePlayer,"cash",playerCash-tonumber(amount))
CheckAchievement(thePlayer,15)
CheckAchievement(thePlayer,16)
CheckAchievement(thePlayer,20)
CheckAchievement(thePlayer,21)
savePlayerData(target,"cash",targetCash+tonumber(amount))
CheckAchievement(target,15)
CheckAchievement(target,16)
CheckAchievement(thePlayer,20)
CheckAchievement(thePlayer,21)
local playerCash = loadPlayerData(thePlayer,"cash")
local targetCash = loadPlayerData(target,"cash")
scoreboardRefresh(thePlayer)
scoreboardRefresh(target)
outputChatBox("#FFFFFFYou Have Sent #00AAFF$"..amount.."#FFFFFF to "..getPlayerName(target).."#FFFFFF!",thePlayer,255,255,255,true)
outputChatBox("#FFFFFF"..getPlayerName(thePlayer).." #FFFFFFHas Sent You #00AAFF$"..amount.."#FFFFFF!",target,255,255,255,true)
else
outputChatBox("#00AAFF# #FFFFFFERROR! You cannot send money to yourself!",thePlayer,255,255,255,true)
return false
end
else
outputChatBox("#00AAFF# #FFFFFFERROR! The Player You Specified Does Not Exist!",thePlayer,255,255,255,true)
return false
end
else
outputChatBox("#00AAFF# #FFFFFFERROR! You Don't Have Enough Money!",thePlayer,255,255,255,true)
return false
end
else
outputChatBox("#00AAFF# #FFFFFFERROR! Invalid amount! [#00AAFF"..amount.."#FFFFFF]",thePlayer,255,255,255,true)
return false
end
else
outputChatBox("#00AAFF# #FFFFFFERROR! Please specify the amount to send!",thePlayer,255,255,255,true)
return false
end
else
outputChatBox("#00AAFF# #FFFFFFERROR! Please select a player!",thePlayer,255,255,255,true)
return false
end
end
addCommandHandler("givecash", giveMoney)
------------------------------------------
-- givePoints
------------------------------------------
function givePoint(thePlayer,CMD,targetPlayer,amount)
if not (targetPlayer == "") then
if tonumber(amount) then
local playerPoint = tonumber(loadPlayerData(thePlayer,"point"))
if tonumber(amount) > 0 then
if tonumber(amount) <= playerPoint then
if (findPlayerByName(targetPlayer)) then
local target = findPlayerByName(targetPlayer)
if target ~= thePlayer then
local amount = math.ceil(amount)
local playerPoint = loadPlayerData(thePlayer,"point")
local targetPoint = loadPlayerData(target,"point")
savePlayerData(thePlayer,"point",playerPoint-tonumber(amount))
CheckAchievement(thePlayer,15)
CheckAchievement(thePlayer,16)
CheckAchievement(thePlayer,20)
CheckAchievement(thePlayer,21)
savePlayerData(target,"point",targetPoint+tonumber(amount))
CheckAchievement(target,15)
CheckAchievement(target,16)
CheckAchievement(thePlayer,20)
CheckAchievement(thePlayer,21)
local playerPoint = loadPlayerData(thePlayer,"point")
local targetPoint = loadPlayerData(target,"point")
scoreboardRefresh(thePlayer)
scoreboardRefresh(target)
outputChatBox("#FFFFFFYou Have Sent #00AAFF"..amount.."#FFFFFF Points to "..getPlayerName(target).."#FFFFFF!",thePlayer,255,255,255,true)
outputChatBox("#FFFFFF"..getPlayerName(thePlayer).." #FFFFFFHas Sent You #00AAFF"..amount.."#FFFFFF Points!",target,255,255,255,true)
else
outputChatBox("#00AAFF# #FFFFFFERROR! You cannot send points to yourself!",thePlayer,255,255,255,true)
return false
end
else
outputChatBox("#00AAFF# #FFFFFFERROR! The Player You Specified Does Not Exist!",thePlayer,255,255,255,true)
return false
end
else
outputChatBox("#00AAFF# #FFFFFFERROR! You Don't Have Enough Point!",thePlayer,255,255,255,true)
return false
end
else
outputChatBox("#00AAFF# #FFFFFFERROR! Invalid amount! [#00AAFF"..amount.."#FFFFFF]",thePlayer,255,255,255,true)
return false
end
else
outputChatBox("#00AAFF# #FFFFFFERROR! Please specify the amount to send!",thePlayer,255,255,255,true)
return false
end
else
outputChatBox("#00AAFF# #FFFFFFERROR! Please select a player!",thePlayer,255,255,255,true)
return false
end
end
addCommandHandler("givepoint", givePoint)
-- Total bets
function totalBetsAdd(thePlayer)
local totalBets = tonumber(loadPlayerData(thePlayer,"totalBets"))
savePlayerData(thePlayer,"totalBets",totalBets+1)
end
-- Total bets won
function totalBetsWonAdd(thePlayer)
local totalBetsWon = tonumber(loadPlayerData(thePlayer,"totalBetsWon"))
savePlayerData(thePlayer,"totalBetsWon",totalBetsWon+1)
end
-- Total bets earned
function totalBetsEarnedAdd(thePlayer,addAmount)
local totalBetsEarned = tonumber(loadPlayerData(thePlayer,"totalBetsEarned"))
savePlayerData(thePlayer,"totalBetsEarned",totalBetsEarned+addAmount)
end
-----------------
-- Betting system
-----------------
function createNewBet(thePlayer,toPlayer,newAmount,oldAmount,betState)
if getPlayerCount() >= minPlayers then
if bettingEnabled == true then
if (betState == 0) then
if (toPlayer) then
if (newAmount) then
local newAmount = tonumber(math.ceil(newAmount))
if (newAmount >= 1) then
local playerCash = tonumber(loadPlayerData(thePlayer,"cash"))
local maxBet = playerCash
if (findPlayerByName(toPlayer)) then
local toPlayerName = findPlayerByName(toPlayer)
if (newAmount <= playerCash) then
if newAmount <= maxBet then
callClientFunction(thePlayer,"addNewBet",toPlayerName,newAmount)
savePlayerData(thePlayer,"cash",playerCash-newAmount)
scoreboardRefresh(thePlayer)
totalBetsAdd(thePlayer)
--outputChatBox("#00FF00* #FFFFFFYou have placed your bet on "..getPlayerName(toPlayerName).."#FFFFFF for #ABCDEF$"..newAmount.."#FFFFFF!",thePlayer,255,255,255,true)
outputChatBox("#0095FF* #FFFFFF"..getPlayerName(thePlayer).."#FFFFFF has placed a bet on "..getPlayerName(toPlayerName).."#FFFFFF for #ABCDEF$"..newAmount.."#FFFFFF!",getRootElement(),255,255,255,true)
elseif newAmount > maxBet then
--outputChatBox("#FF0000* #FFFFFFYou are allowed to bet a maximum of #ABCDEF$"..maxBet.."#FFFFFF! Levelling up will increase this number.",thePlayer,255,255,255,true)
return false
end
else
outputChatBox("#FF0000* #FFFFFFERROR! You don't have enough money!",thePlayer,255,255,255,true)
end
else
outputChatBox("#FF0000* #FFFFFFERROR! The player you specified has not been found! (#FFFF00"..toPlayer.."#FFFFFF)",thePlayer,255,255,255,true)
return false
end
else
outputChatBox("#FF0000* #FFFFFFERROR! Invalid amount! [#ABCDEF$"..newAmount.."#FFFFFF]",thePlayer,255,255,255,true)
end
else
outputChatBox("#FF0000* #FFFFFFERROR! Please specify an amount to bet! Correct syntax: #ABCDEF/bet [player] [amount]",thePlayer,255,255,255,true)
return false
end
else
outputChatBox("#FF0000* #FFFFFFERROR! Please specify a player! Correct syntax: #ABCDEF/bet [player] [amount]",thePlayer,255,255,255,true)
return false
end
else
outputChatBox("#FF0000* #FFFFFFYou have already placed your bet on "..betState.." #FFFFFFfor #ABCDEF$"..oldAmount.."#FFFFFF!",thePlayer,255,255,255,true)
return false
end
else
outputChatBox("#FF0000* #FFFFFFBetting time is over! You can place your bet on the next map.",thePlayer,255,255,255,true)
end
else
--outputChatBox("#FF0000* #FFFFFFBetting #FF0000disabled.#FFFFFF Minimum required players on server: #ABCDEF" ..minPlayers.."#FF0000 | #FFFFFFConnected: #ABCDEF"..getPlayerCount(),thePlayer,255,255,255,true)
end
end
function onPlayerBetWin(self,betAmount)
outputChatBox("#0095FF* #FFFFFF"..getPlayerName(self).."#FFFFFF has won his bet and has recieved #ABCDEF$".. betAmount*2 .."#FFFFFF!",getRootElement(),255,255,255,true)
local playerCash = loadPlayerData(self,"cash")
savePlayerData(self,"cash",playerCash+betAmount+betAmount*2)
local thePlayer = self
scoreboardRefresh(thePlayer)
local addAmount = betAmount*2
totalMoneyEarnedAdd(thePlayer,addAmount)
totalBetsWonAdd(thePlayer)
totalBetsEarnedAdd(thePlayer,addAmount)
progressBarUpdate(thePlayer)
--totalMoneyAchievements(thePlayer)
end
function bettingTimer()
if isTimer(chatTimer) then killTimer(chatTimer) end
if isTimer(disableTimer) then killTimer(disableTimer) end
if getPlayerCount() >= minPlayers then
chatTimer = setTimer(outputChatBox,3500,1,"#0095FF* #FFFFFFPlace your bets! #FFFFFF[#ABCDEF/bet#FFFFFF]",getRootElement(),255,255,255,true)
bettingEnabled = true
disableTimer = setTimer(disableBetting,betTimeLimit*1000+2000,1)
end
end
addEvent("onMapStarting",true)
addEventHandler("onMapStarting",getRootElement(),bettingTimer)
function disableBetting()
outputChatBox("#0095FF* #FFFFFFBetting time is over#FF0000!",getRootElement(),255,255,255,true)
bettingEnabled = false
end
function checkWin(winner)
callClientFunction( getRootElement(), "compareResult", winner )
end
addEvent("onPlayerDestructionDerbyWin",true)
addEventHandler( "onPlayerDestructionDerbyWin", getRootElement(), checkWin )
function retrieveData(thePlayer,commandName,toPlayer,newAmount)
callClientFunction(thePlayer,"triggerBettingSystem",thePlayer,toPlayer,newAmount)
end
addCommandHandler("bet",retrieveData)
-----------------
-- Hunter handler
-----------------
function hunterBonus(thePlayer)
if getElementData(thePlayer,"playerGotHunter") == false then
setElementData(thePlayer,"playerGotHunter",true)
local cashToWin = 500
if (tonumber(loadPlayerData(thePlayer,"point")) >= 1000) then
cashToWin = cashToWin*1.1
end
outputChatBox("#0095FF* #FFFFFF"..getPlayerName(thePlayer).."#FFFFFF has got the #ABCDEFHunter#FFFFFF! #ABCDEF[#FFFFFF$"..cashToWin.."#ABCDEF]",getRootElement(),255,255,255,true)
playerCash = loadPlayerData(thePlayer,"cash")
savePlayerData(thePlayer,"cash",playerCash+cashToWin)
scoreboardRefresh(thePlayer)
totalHuntersAdd(thePlayer)
totalMoneyAchievements(thePlayer)
local newAmount = cashToWin
totalMoneyEarnedAdd(thePlayer,newAmount)
end
end
function checkForHunter(number,sort,model)
if sort == "vehiclechange" then
if model == 425 then
setTimer(hunterBonus,200,1,source)
end
end
end
addEventHandler("onPlayerPickUpRacePickup",getRootElement(),checkForHunter)
addEvent("onPlayerToptimeImprovement",true)
addEventHandler("onPlayerToptimeImprovement",getRootElement(),
function (player,newPos,newTime,oldPos,oldTime,random1,random2)
if getElementData(source,"playerGotHunter") == false then
if newPos <= 10 then
local cashToWin = 600
if (tonumber(loadPlayerData(source,"point")) >= 1000) then
cashToWin = cashToWin*1.1
end
local playerCash = loadPlayerData(source,"cash")
savePlayerData(player,"cash",playerCash +cashToWin)
local playerCash = loadPlayerData(source,"cash")
outputChatBox ("#0095FF* #FFFFFF" .. getPlayerName(source) .." #FFFFFFhas set a new top time - Place: #0095FF"..newPos.." #ABCDEF[#FFFFFF$"..cashToWin.."#ABCDEF]",getRootElement(),255,255,255,true)
setElementData(source, "playerGotHunter",true)
local newAmount = cashToWin
local thePlayer = source
totalMoneyEarnedAdd(thePlayer,newAmount)
totalHuntersAdd(thePlayer)
scoreboardRefresh(thePlayer)
totalMoneyAchievements(thePlayer)
end
end
end)
function resetHunterData()
setElementData(source,"playerGotHunter",false)
end
addEventHandler("onNotifyPlayerReady",getRootElement(),resetHunterData)
------------------------------------------
-- Tops
------------------------------------------
function getDataFromServerAndSendToClient ( thePlayer , argument)
if ( thePlayer ) then
if argument then
if string.lower(argument) == "cash" then
local tablica = loadAllData ("cash")
callClientFunction(thePlayer,"SortTops","Top Cash!",tablica,thePlayer,"$","")
elseif string.lower(argument) == "achievements" or string.lower(argument) == "ac" then
local tablica = loadAllData ("achievements")
callClientFunction(thePlayer,"SortTops","Top Achievements!",tablica,thePlayer,"","")
elseif string.lower(argument) == "ddwins" then
local tablica = loadAllData ("mapsWonDD")
callClientFunction(thePlayer,"SortTops","Top DD wins!",tablica,thePlayer,"","")
elseif string.lower(argument) == "dmwins" then
local tablica = loadAllData ("mapsWonDM")
callClientFunction(thePlayer,"SortTops","Top DM wins!",tablica,thePlayer,"","")
elseif string.lower(argument) == "dds" then
local tablica = loadAllData ("mapsPlayedDD")
callClientFunction(thePlayer,"SortTops","Top Played DDs!",tablica,thePlayer,"","")
elseif string.lower(argument) == "dms" then
local tablica = loadAllData ("mapsPlayedDM")
callClientFunction(thePlayer,"SortTops","Top Played DMs!",tablica,thePlayer,"","")
elseif string.lower(argument) == "playedtime" or string.lower(argument) == "pt" then
local tablica = loadAllData ("playedTime")
callClientFunction(thePlayer,"SortTops","Top Played Time!",tablica,thePlayer," "," ")
elseif string.lower(argument) == "hunters" then
local tablica = loadAllData ("hunters")
callClientFunction(thePlayer,"SortTops","Top Hunters!",tablica,thePlayer,"","")
elseif string.lower(argument) == "mapbuys" or string.lower(argument) == "mb" then
local tablica = loadAllData ("mapBuys")
callClientFunction(thePlayer,"SortTops","Top Map Buys!",tablica,thePlayer,"","")
elseif string.lower(argument) == "toptimes" or string.lower(argument) == "tt" then
local tablica = loadAllData ("TopTimes")
callClientFunction(thePlayer,"SortTops","Top TopTimes!",tablica,thePlayer,"","")
elseif string.lower(argument) == "ddratio" then
local tablica = loadAllData ("ddratio")
callClientFunction(thePlayer,"SortTops","Top DD Ratio!",tablica,thePlayer,"","%")
elseif string.lower(argument) == "dmratio" then
local tablica = loadAllData ("dmratio")
callClientFunction(thePlayer,"SortTops","Top DM Ratio!",tablica,thePlayer,"","%")
elseif string.lower(argument) == "ddmap" then
local allMaps = call(getResourceFromName("mapmanager"), "getMapsCompatibleWithGamemode" , getResourceFromName("race"))
tablicaMap = {}
for i,map in ipairs(allMaps) do
if checkMapType(getResourceInfo(map, "name")) == 2 then
local mapinfo = getMapInfo(map)
table.insert(tablicaMap,{pName = getResourceInfo(map, "name") or "???",dType = tonumber(mapinfo.playedCount) or 0})
end
end
callClientFunction(thePlayer,"SortTopsMaps","Top DD Map!",tablicaMap,thePlayer,"","")
elseif string.lower(argument) == "dmmap" then
local allMaps = call(getResourceFromName("mapmanager"), "getMapsCompatibleWithGamemode" , getResourceFromName("race"))
tablicaMap = {}
for i,map in ipairs(allMaps) do
if checkMapType(getResourceInfo(map, "name")) == 1 then
local mapinfo = getMapInfo(map)
table.insert(tablicaMap,{pName = getResourceInfo(map, "name") or "???",dType = tonumber(mapinfo.playedCount) or 0})
end
end
callClientFunction(thePlayer,"SortTopsMaps","Top DM Map!",tablicaMap,thePlayer,"","")
elseif string.lower(argument) == "point" then
local tablica = loadAllData ("point")
callClientFunction(thePlayer,"SortTops","Top Points!",tablica,thePlayer,"","")
else
outputChatBox("#00AAFF# #FFFFFFERROR! Invalid argument!",thePlayer,255,255,255,true)
outputChatBox("[cash,point,achievements,ddwins,dmwins,dds,dms,playedtime]",thePlayer,255,255,255,true)
outputChatBox("[hunters,mapbuys,toptimes,ddratio,dmratio,ddmap,dmmap]",thePlayer,255,255,255,true)
end
else
outputChatBox ("#00AAFF# #FF0000ERROR!#FFFFFF Syntax: /top [datatype]",thePlayer,255,255,255,true)
end
end
end
function loadMapInfoAll()
local rows = executeSQLQuery( 'SELECT * FROM ' .. getTableName() )
g_MapInfoList = {}
for i,row in ipairs(rows) do
local map = getResourceFromName( row.resName )
if map then
local mapInfo = getMapInfo( map )
mapInfo.playedCount = row.playedCount
mapInfo.lastTimePlayed = row.lastTimePlayed
end
end
end
function getTableName(value)
return sqlString( 'race_mapmanager_maps' )
end
function sqlString(value)
value = tostring(value) or ''
return "'" .. value:gsub( "(['])", "''" ) .. "'"
end
function getMapInfo( map )
if not g_MapInfoList then
loadMapInfoAll()
end
if not g_MapInfoList[map] then
g_MapInfoList[map] = {}
end
local mapInfo = g_MapInfoList[map]
if mapInfo.loadTime ~= getResourceLoadTime(map) then
-- Reset or clear data that may change between loads
mapInfo.loadTime = getResourceLoadTime( map )
mapInfo.spawnPointCount = false
end
return mapInfo
end
function loadAllData (datatype)
local root = xmlLoadFile ("DataBase.xml")
if (root) then
local usersNode = xmlFindChild (root,"user",0)
if (usersNode) then
local allPlayers = xmlNodeGetChildren(usersNode)
allPlayersData = {}
nrDD = 0
nrDM = 0
for i,data in ipairs(allPlayers) do
if datatype == "achievements" then
AchCount = 0
for j=1,#AchievementsName do
local ac = tonumber(xmlNodeGetAttribute (data,"ac"..j..""))
if ac == 1 then
AchCount = AchCount + 1
end
end
local playerName = xmlNodeGetAttribute (data,"playerName")
allPlayersData[i] = {pName = playerName or "???",dType = AchCount or 0}
elseif datatype == "ddratio" then
local played = tonumber(xmlNodeGetAttribute (data,"mapsPlayedDD")) or 0
local wins = tonumber(xmlNodeGetAttribute (data,"mapsWonDD")) or 0
local ratio = 0
if played == 0 and wins == 0 then
ratio = 0
elseif played ~= 0 and wins == 0 then
ratio = 0
elseif played ~= 0 and wins ~= 0 then
ratio = (100/played)*wins
elseif wins > played then
ratio = 0
end
if played >= 100 then
nrDD = nrDD + 1
local playerName = xmlNodeGetAttribute (data,"playerName")
allPlayersData[nrDD] = {pName = playerName or "???",dType = ratio or 0}
end
elseif datatype == "dmratio" then
local played = tonumber(xmlNodeGetAttribute (data,"mapsPlayedDM")) or 0
local wins = tonumber(xmlNodeGetAttribute (data,"mapsWonDM")) or 0
local ratio = 0
if played == 0 and wins == 0 then
ratio = 0
elseif played ~= 0 and wins == 0 then
ratio = 0
elseif played ~= 0 and wins ~= 0 then
ratio = (100/played)*wins
elseif wins > played then
ratio = 0
end
if played >= 100 then
nrDM = nrDM + 1
local playerName = xmlNodeGetAttribute (data,"playerName")
allPlayersData[nrDM] = {pName = playerName or "???",dType = ratio or 0}
end
else
local playerData = tonumber(xmlNodeGetAttribute (data,datatype))
local playerName = xmlNodeGetAttribute (data,"playerName")
allPlayersData[i] = {pName = playerName or "???",dType = playerData or 0}
end
end
xmlUnloadFile (root)
return allPlayersData
end
end
end
------------------------------------------
-- Kick All
------------------------------------------
function kickAllPlayers ( sourcePlayer, commandname )
if ( hasObjectPermissionTo ( sourcePlayer, "function.kickPlayer" ) ) then
outputChatBox("#00AAFF# #FFFFFFScript restarting... Auto-Reconnecting in 5 seconds!", gRoot, 255,255,255,true)
setTimer(function()
for i,pla in ipairs(getElementsByType("player")) do
redirectPlayer ( pla, "213.189.52.40",22069)
end
end, 5000,1)
end
end
addCommandHandler ( "kickAllPlayers", kickAllPlayers )
--------------------------
-- Retrieve player's point's
--------------------------
function retrievePoint(thePlayer)
local playerPoint = loadPlayerData(thePlayer,"point")
callClientFunction(thePlayer,"checkPoint",playerPoint)
end
function retrievePointVeh(thePlayer)
local playerPoint = loadPlayerData(thePlayer,"point")
callClientFunction(thePlayer,"checkPointVeh",playerPoint)
end
------------------------------------------
-- Triggering
------------------------------------------
function callClientFunction(client, funcname, ...)
local arg = { ... }
if (arg[1]) then
for key, value in next, arg do
if (type(value) == "number") then arg[key] = tostring(value) end
end
end
triggerClientEvent(client, "onServerCallsClientFunction", getResourceRootElement(getThisResource()), funcname, unpack(arg or {}))
end
function callServerFunction(funcname, ...)
local arg = { ... }
if (arg[1]) then
for key, value in next, arg do arg[key] = tonumber(value) or value end
end
loadstring("return "..funcname)()(unpack(arg))
end
addEvent("onClientCallsServerFunction", true)
addEventHandler("onClientCallsServerFunction", getResourceRootElement(getThisResource()) , callServerFunction)
function math.round(number, decimals, method)
decimals = decimals or 0
local factor = 10 ^ decimals
if (method == "ceil" or method == "floor") then return math[method](number * factor) / factor
else return tonumber(("%."..decimals.."f"):format(number)) end
end
--------------------------------------------
-- Get alive and dead players by their STATE
--------------------------------------------
function getAliveRacePlayers()
local alivePlayers = 0
for index,player in ipairs(getElementsByType("player")) do
if getElementData(player,"state") == "alive" then
alivePlayers = alivePlayers + 1
end
end
return alivePlayers
end
function getDeadRacePlayers()
local deadPlayers = 0
for index,player in ipairs(getElementsByType("player")) do
if getElementData(player,"state") == "dead" then
deadPlayers = deadPlayers + 1
end
end
return deadPlayers
end
------------------------------------------
-- Nick
------------------------------------------
addEventHandler ("onPlayerJoin",getRootElement(),
function()
local playerName = getPlayerName(source)
savePlayerData(source,"playerName",string.gsub(playerName,"#%x%x%x%x%x%x", ""))
end)
addEventHandler("onPlayerChangeNick",getRootElement(),
function (olnick,newnick)
savePlayerData(source,"playerName",string.gsub(newnick,"#%x%x%x%x%x%x", ""))
end)
--------------------
--Team Colors Nick--
--------------------
function addTeamColor(player)
local playerTeam = getPlayerTeam ( player )
if ( playerTeam ) then
local r,g,b = getTeamColor ( playerTeam )
local n1 = toHex(r)
local n2 = toHex(g)
local n3 = toHex(b)
if r <= 16 then n1 = "0"..n1 end
if g <= 16 then n2 = "0"..n2 end
if b <= 16 then n3 = "0"..n3 end
return "#"..n1..""..n2..""..n3..""..getPlayerNametagText(player)
else
return getPlayerNametagText(player)
end
end
function toHex ( n )
local hexnums = {"0","1","2","3","4","5","6","7",
"8","9","A","B","C","D","E","F"}
local str,r = "",n%16
if n-r == 0 then str = hexnums[r+1]
else str = toHex((n-r)/16)..hexnums[r+1] end
return str
end
------------------------------------------
-- PlayerNameFunctions
------------------------------------------
function getPlayerNameWithoutColorCode (who)
local name = getPlayerName(who)
local name = string.gsub(name,'#%x%x%x%x%x%x',"")
return name
end
function getPlayerFromNameWithoutColorCode (name)
for i,pla in ipairs(getElementsByType("player")) do
if getPlayerNameWithoutColorCode (pla) == name then
return pla
end
end
end
function findPlayerByName (name)
local player = getPlayerFromName(name)
if player then return player end
for i, player in ipairs(getElementsByType("player")) do
if string.find(string.gsub(getPlayerName(player):lower(),"#%x%x%x%x%x%x", ""), name:lower(), 1, true) then
return player
end
end
return false
end
------------------
-- Reaction
------------------
function generateRandomString( charsCount )
local str = ""
for i = 1, charsCount do
local c = string.char( math.random( 100, 122 ) )
if i % 2 == 1 then c = string.upper( c ); end
str = str .. c
end
return str
end
function Starter( _, _, count )
WIN_WORD = generateRandomString( tonumber( count ) or 10 )
outputChatBox("#ffffffType #ABCDEF'".. WIN_WORD .."' #ffffffto win money#abcdef!",getRootElement(),0,255,0,true)
end
setTimer(Starter,300000,0)
addEventHandler( "onPlayerChat", getRootElement(),
function( msg, msgType )
if msgType == 0 then
if WIN_WORD and msg == WIN_WORD then
WIN_WORD = nil;
local test_random = math.random(100,500)
setTimer(outputChatBox,1000,1,"[Reaction] #FFFFFF".. getPlayerName( source ) .. "#ffffff has won [#abcdef"..tostring(test_random).."$#FFFFFF] for reaction!", getRootElement(), 0, 255, 0, true )
savePlayerData (source,"cash",loadPlayerData(source,"cash") +test_random)
end
end
end
)