Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- gRoot = getRootElement()
- AchievementsName = {
- "First Win!", -- 1sze zwyciestwo
- "First Hunter!", -- 1szy hunter
- "Top Winner!", -- 300 wins
- "Awesome Winner!", -- 1000 wins
- "Top Gamer!", -- 2000 map
- "Long Time Player!", -- 7 dni
- "Hunter Owner!", -- hunter 50 razy
- "Beat my TT kid!", -- pobij swoj TT
- "5 Maps In a Row LOL!", -- 5x
- "Triple Deathmatch!", -- 3x dm pod rzad
- "Triple Dest. Derby!", -- 3x DD
- "Hunter Power", -- hunterfight z 3 graczami
- "Map Buyer", -- 10 razy kupic mape
- "Top Times collector!", -- 50 toptimow
- "Rich player!", -- 1 mln
- }
- LastWinnersDD={"","","","",""}
- LastWinnersDM={"","","","",""}
- LastWinners={"","","","",""}
- HunterCount = 0
- ------------------------------------------
- -- Settings
- ------------------------------------------
- mapCost = 5000
- RepairCost = 4000
- local activePlayers = {}
- function startResource ()
- exports.scoreboard:removeScoreboardColumn("race rank")
- exports.scoreboard:removeScoreboardColumn("checkpoint")
- exports.scoreboard:addScoreboardColumn("Money",gRoot,5,100)
- mapIsAlreadySet = false
- repairset = true
- txBMaps = {}
- for i,pla in ipairs(getElementsByType("player")) do
- scoreboardRefresh(pla)
- end
- end
- addEventHandler ( "onResourceStart", getResourceRootElement(getThisResource()), startResource )
- ------------------------------------------
- -- Load All Stats on Join
- ------------------------------------------
- function scoreboardRefresh(thePlayer)
- local playerCash = loadPlayerData(thePlayer,"cash")
- setElementData(thePlayer,"Money","$"..playerCash)
- callClientFunction(thePlayer, "refreshCash", playerCash)
- end
- function playerJoinHandler ( )
- outputChatBox("#00AAFF# #FFFFFFPress '#00AAFFF7#FFFFFF' to open your User Panel!",source,255,255,255,true)
- scoreboardRefresh(source)
- end
- addEventHandler ( "onPlayerJoin", gRoot, playerJoinHandler )
- ------------------------------------------
- -- 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 >=3 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
- outputChatBox("#00AAFF# #FFFFFF Min. 3 players to get stats and cash!",gRoot,255,255,255,true)
- 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
- elseif string.find(mapname, "[HUNTER]", 1,true) then
- return 4
- elseif string.find(mapname, "[SHOOTER]", 1,true) then
- return 5
- 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 >= 3 then
- local cashForPlayer = math.floor((200/Position)*(dPlayers + aPlayers))
- local playerCash = loadPlayerData(thePlayer,"cash")
- savePlayerData(thePlayer,"cash",playerCash+cashForPlayer)
- CheckAchievement(thePlayer,15)
- scoreboardRefresh(thePlayer)
- if Position == 1 then
- outputChatBox("#00AAFF# "..getPlayerName(thePlayer).." #FFFFFFhas won the map +$#00AAFF" .. cashForPlayer.. "#FFFFFF!",gRoot,255,255,255,true)
- --triggerClientEvent ( "showWinMessage", getRootElement(), thePlayer, cashForPlayer)
- 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
- 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("#00AAFF# #FFFFFFYou have recieved $#00AAFF" .. cashForPlayer .. "#FFFFFF!",thePlayer,255,255,255,true)
- end
- else
- outputChatBox("#00AAFF# #FFFFFF Min. 3 players to get stats and cash!",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,ddw,ddp,ddr,dmw,dmp,dmr,pt,h,mb,ac,tt = loadPlayerStats(targetPlayer)
- outputChatBox("#00AAFF# #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.." | 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.."/15 | 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,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.." | 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.."/15 | 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)
- 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 == "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 playerLevel = loadPlayerData(toplayer,"level")
- local thePlayer = toplayer
- scoreboardRefresh(thePlayer)
- end
- else
- outputChatBox ("#00AAFF# #FF0000ERROR! #FFFFFFDatatype: cash/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 == "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/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 mapsWonDD = tonumber(loadPlayerData(thePlayer,"mapsWonDD"))
- local mapsPlayedDD = tonumber(loadPlayerData(thePlayer,"mapsPlayedDD"))
- local mapsWonDM = tonumber(loadPlayerData(thePlayer,"mapsWonDM"))
- local mapsPlayedDM = tonumber(loadPlayerData(thePlayer,"mapsPlayedDM"))
- ------ 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, mapsWonDD, mapsPlayedDD, winRatioDD, mapsWonDM, mapsPlayedDM, winRatioDM, playedTime, hunters, mapBuys, AC,toptimes)
- end
- function loadPlayerStats(thePlayer)
- local playerCash = tonumber(loadPlayerData(thePlayer,"cash"))
- setElementData(thePlayer,"Money","$"..playerCash)
- 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 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, mapsWonDD, mapsPlayedDD, winRatioDD, mapsWonDM, mapsPlayedDM, winRatioDM, playedTime, hunters, mapBuys, AC, toptimes
- 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
- end
- else
- if achiev == 15 then
- local playerCash = tonumber(loadPlayerData(thePlayer,"cash"))
- if playerCash < 1000000 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)
- 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)
- HunterCount = HunterCount + 1
- end
- end
- end
- end
- addEventHandler("onPlayerPickUpRacePickup",getRootElement(),checkForHunter)
- ------------------------------------------
- -- Mapy
- ------------------------------------------executeCommandHandler("nextmap", thePlayer, mapName)
- function buyMap(thePlayer,mapName)
- if mapIsAlreadySet == false then
- if not (mapName == "") then
- local playerCash = tonumber(loadPlayerData(thePlayer,"cash"))
- local theTime = getMsFromMin(5);
- if playerCash >= mapCost then
- if (not txBMaps[mapName]) then
- txBMaps[mapName] = true
- executeCommandHandler("pnfnsdhasd3w7432jhdsbw3ersdncsdir",thePlayer,mapName)
- savePlayerData(thePlayer,"cash",playerCash-mapCost)
- outputChatBox("#FFFFFFNextmap: "..getPlayerName(thePlayer).."#FFFFFF has bought a next map!",getRootElement(),255,255,255,true)
- outputChatBox("#FFFFFFNextmap: #00AAFF"..mapName,getRootElement(),255,255,255,true)
- mapIsAlreadySet = thePlayer
- local oldmapbuys = loadPlayerData(thePlayer,"mapBuys")
- savePlayerData(thePlayer,"mapBuys", oldmapbuys + 1)
- CheckAchievement(thePlayer,13)
- scoreboardRefresh(thePlayer)
- setTimer(removeMapFromList,theTime.ms,1,mapName)
- else
- outputChatBox("#"..mapName.." will be available for 5 minutes",player,254,12,26,true);
- end
- else
- outputChatBox("#00AAFF# #FFFFFFYou don't have enough money to set a map!",thePlayer,255,255,255,true)
- end
- else
- outputChatBox("#00AAFF# #FFFFFFPlease select a map from the list first!",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
- end
- function removeMapFromList(mapName)
- outputChatBox("* #abcdef"..mapName.." #ffffff - #ffffffis now #abcdefavailable #ffffffat the #abcdefMap Shop!",getRootElement(),255,255,255,true);
- txBMaps[mapName] = nil
- end
- function getMsFromMin(pMin)
- local mSeconds = 60 * pMin * 1000;
- return { ms = mSeconds };
- end
- function resetMapSetStatus()
- mapIsAlreadySet = false
- repairset = true
- end
- addEventHandler("onMapStarting",getRootElement(),resetMapSetStatus)
- function buyRepair ( thePlayer )
- if repairset == true and isPedInVehicle ( thePlayer ) then
- local playerCash = tonumber ( loadPlayerData ( thePlayer, "cash" ) )
- local v = getPedOccupiedVehicle ( thePlayer )
- if playerCash >= RepairCost then
- outputChatBox ( getPlayerName ( thePlayer ).." Has bought a Repair for 4000$", root, 0, 255, 0, true)
- fixVehicle ( v )
- repairset = false
- savePlayerData ( thePlayer, "cash", playerCash - RepairCost )
- scoreboardRefresh ( thePlayer )
- else
- outputChatBox ( "You don't have enought money!", thePlayer, 255, 0, 0, true )
- end
- else
- --outputChatBox ( "You need to be in vehicle!", thePlayer, 255, 0, 0, true )
- end
- outputChatBox("You most be wait a nextmap for buy another repair!", p, 255, 3, 19)
- end
- addCommandHandler ( "br", buyRepair )
- addCommandHandler ( "buyrepair", buyRepair )
- 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
- ------------------------------------------
- -- 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)
- savePlayerData(target,"cash",targetCash+tonumber(amount))
- CheckAchievement(target,15)
- local playerCash = loadPlayerData(thePlayer,"cash")
- local targetCash = loadPlayerData(target,"cash")
- scoreboardRefresh(thePlayer)
- scoreboardRefresh(target)
- outputChatBox("#00AAFF# #FFFFFFYou have sent #00AAFF$"..amount.."#FFFFFF to "..getPlayerName(target).."#FFFFFF!",thePlayer,255,255,255,true)
- outputChatBox("#00AAFF# #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)
- ------------------------------------------
- -- 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,"","")
- else
- outputChatBox("#00AAFF# #FFFFFFERROR! Invalid argument!",thePlayer,255,255,255,true)
- outputChatBox("[cash,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 )
- ------------------------------------------
- -- 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)
- ------------------------------------------
- -- 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
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement