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
- "Rich player I", -- 2 mln
- "Hunter Owner I", -- Hunter 150
- "Top Times collector I", -- 150
- "Hunter Power I", -- hunterfight z 8 graczami
- }
- LastWinnersDD={"","","","",""}
- LastWinnersDM={"","","","",""}
- LastWinners={"","","","",""}
- HunterCount = 0
- -- String.random characters
- chars = {"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","r","s","t","u","v","w","x","y","z","1","2","3","4","5","6","7","8","9","0"}
- ------------------------------------------
- -- Settings
- ------------------------------------------
- mapCost = 5000 -- The price for setting maps.
- betPerCash = 10000 -- Limits the amount of money you can bet. (playerCash*betPerCash = maxBet).
- betTimeLimit = 40 -- Duration of the betting period in seconds.
- minPlayers = 1 -- Minimum required players to bet.
- --skinLevel = 13 -- Minimum level required to buy skins.
- skinCost = 1300 -- The price of skins.
- nametagLevel = 15 -- Minimum level to buy a nametag color.
- nametagPrice = 2000 -- Price for buying a nametag color.
- --hornLevel = 10 -- Minimum level to buy different horn styles.
- reactionMin = 120 -- Minimum money for the reaction test
- reactionMax = 550 -- Maximum money for the reaction test
- reactionDuration = 20 -- Duration of the reaction test in seconds
- reactionMinRedo = 20 -- Minimum amount of time to pass before a new reaction test is started in seconds (200)
- reactionMaxRedo = 30 -- Maximum amount of time to pass before a new reaction test is started in seconds (300)
- reactionLength = 10 -- Number of characters to use in the reaction test
- local activePlayers = {}
- function startResource ()
- exports.scoreboard:removeScoreboardColumn("race rank")
- exports.scoreboard:removeScoreboardColumn("checkpoint")
- exports.scoreboard:addScoreboardColumn("Money",gRoot,5,100)
- mapIsAlreadySet = false
- reactionString = ""
- reactionMoney = 0
- setTimer(newReactionTest,math.random(reactionMinRedo*1000,reactionMaxRedo*1000),1)
- 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#00AAFF!",source,255,255,255,true)
- outputChatBox("#ecececWelcome To The #c1ff17SGF #ececec24/7 #abcdef[DD/DM] #ecececRace Server. Have Fun During Your Stay!",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
- 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 >= 3 then
- local cashForPlayer = math.floor((200/Position)*(dPlayers + aPlayers))
- local playerCash = loadPlayerData(thePlayer,"cash")
- savePlayerData(thePlayer,"cash",playerCash+cashForPlayer)
- CheckAchievement(thePlayer,15)
- CheckAchievement(thePlayer,16)
- scoreboardRefresh(thePlayer)
- if Position == 1 then
- exports.box:outputMiniBox("#C1FF17# "..getPlayerName(thePlayer).." #FFFFFFHas Won The Map +$#00AAFF" .. cashForPlayer.. "#FFFFFF!",gRoot)
- --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
- exports.box:outputMiniBox("#00AAFF# #FFFFFFYou Have Recieved $#00AAFF" .. cashForPlayer .. "#FFFFFF!",thePlayer)
- end
- else
- exports.box:outputMiniBox("#FFFFFF Min. 3 players to get #abcdefStats #FFFFFFand #abcdefCash#ececec!",thePlayer)
- end
- end
- addEvent("onPlayerWasted", true)
- addEventHandler("onPlayerWasted", gRoot , onPlayerDeadInRace)
- ------------------
- -- SHOP
- ------------------
- -------------------
- -- 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)
- achievement38(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
- -------------------
- -- 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
- ------------------------------------------------
- -- 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)
- ------------------------------------------
- -- 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("#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.." | 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.."/20 | 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.."/20 | 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 == "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 totalReactionTests = tonumber(loadPlayerData(thePlayer,"totalReactionTests"))
- --local bestReactionTime = tonumber(loadPlayerData(thePlayer,"bestReactionTime"))
- 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 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, 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 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, 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
- 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 == 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)
- exports.box:outputMiniBox("#FFFFFFAC: #00AAFF"..getPlayerName(thePlayer).."#FFFFFF Has Unlocked An Achievement!",getRootElement())
- exports.box:outputMiniBox("#FFFFFFAC: #00AAFF"..AchievementsName[achiev],getRootElement())
- 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
- ------------------------------------------
- function buyMap(thePlayer,mapName)
- if mapIsAlreadySet == false then
- if not (mapName == "") then
- local playerCash = tonumber(loadPlayerData(thePlayer,"cash"))
- if playerCash >= mapCost then
- executeCommandHandler("pnfnsdhasd3w7432jhdsbw3ersdncsdir",thePlayer,mapName)
- savePlayerData(thePlayer,"cash",playerCash-mapCost)
- exports.box:outputMiniBox("#FFFFFF[MAP]: "..getPlayerName(thePlayer).."#ABCDEF Has Bought a Next Map!",getRootElement())
- exports.box:outputMiniBox("#FFFFFF[NEXTMAP]: #ABCDEF "..mapName,getRootElement())
- mapIsAlreadySet = thePlayer
- 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# #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 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)
- exports.box:outputMiniBox("#FFFFFF[NEXTMAP]: "..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
- ------------------------------------------
- -- 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)
- exports.box:outputMiniBox("#FFFFFFYou Have Sent #00AAFF$"..amount.."#FFFFFF to "..getPlayerName(target).."#FFFFFF!",thePlayer)
- exports.box:outputMiniBox("#FFFFFF"..getPlayerName(thePlayer).." #FFFFFFHas Sent You #00AAFF$"..amount.."#FFFFFF!",target)
- 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)
- --------------------
- --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
- -- 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 playerLevel = tonumber(loadPlayerData(thePlayer,"level"))
- local playerCash = tonumber(loadPlayerData(thePlayer,"cash"))
- local maxBet = playerCash*betPerCash
- 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)
- --progressBarUpdate(thePlayer)
- --outputChatBox("#00FF00* #FFFFFFYou have placed your bet on "..getPlayerName(toPlayerName).."#FFFFFF for #ABCDEF$"..newAmount.."#FFFFFF!",thePlayer,255,255,255,true)
- exports.box:outputMiniBox("#0095FF* #FFFFFF"..getPlayerName(thePlayer).."#FFFFFF has placed a bet on "..getPlayerName(toPlayerName).."#FFFFFF for #ABCDEF$"..newAmount.."#FFFFFF!",getRootElement())
- elseif newAmount > maxBet then
- exports.box:outputMiniBox("#FF0000* #FFFFFFYou are allowed to bet a maximum of #ABCDEF$"..maxBet.."#FFFFFF! Levelling up will increase this number.",thePlayer)
- return false
- end
- else
- exports.box:outputMiniBox("#FF0000* #FFFFFFERROR! You don't have enough money!",thePlayer)
- 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
- exports.box:outputMiniBox("#FF0000* #FFFFFFYou have already placed your bet on "..betState.." #FFFFFFfor #ABCDEF$"..oldAmount.."#FFFFFF!",thePlayer)
- return false
- end
- else
- exports.box:outputMiniBox("#FF0000* #FFFFFFBetting time is over! You can place your bet on the next map.",thePlayer)
- end
- else
- exports.box:outputMiniBox("#FF0000* #FFFFFFBetting #FF0000disabled.#FFFFFF Minimum required players on server: #ABCDEF" ..minPlayers.."#FF0000 | #FFFFFFConnected: #ABCDEF"..getPlayerCount(),thePlayer)
- end
- end
- function onPlayerBetWin(self,betAmount)
- exports.box:outputMiniBox("#0095FF* #FFFFFF"..getPlayerName(self).."#FFFFFF has won his bet and has recieved #ABCDEF$".. betAmount*2 .."#FFFFFF!",getRootElement())
- 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()
- exports.box:outputMiniBox("#0095FF* #FFFFFFBetting time is over#FF0000!",getRootElement())
- 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,"cash")) >= 0) 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)
- progressBarUpdate(thePlayer)
- --achievement16(thePlayer)
- --achievement17(thePlayer)
- --achievement18(thePlayer)
- --achievement40(thePlayer)
- --achievement41(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 = 1500
- if (tonumber(loadPlayerData(source,"cash")) >= 0) 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#abcdef! #ffffffPosition: #ABCDEF[#ffffff"..newPos.."#abcdef] #ABCDEF[#FFFFFF$"..cashToWin.."#ABCDEF]",getRootElement(),255,255,255,true)
- setElementData(source, "playerGotHunter",true)
- local newAmount = cashToWin
- local thePlayer = source
- totalMoneyEarnedAdd(thePlayer,newAmount)
- totalHuntersAdd(thePlayer)
- progressBarUpdate(thePlayer)
- scoreboardRefresh(thePlayer)
- totalMoneyAchievements(thePlayer)
- --achievement18(thePlayer)
- end
- end
- end)
- function resetHunterData()
- setElementData(source,"playerGotHunter",false)
- end
- addEventHandler("onNotifyPlayerReady",getRootElement(),resetHunterData)
- -----------------
- -- Reaction tests
- -----------------
- function newReactionTest()
- reactionString = string.random(reactionLength)
- reactionMoney = math.random(reactionMin,reactionMax)
- outputChatBox("#0095FF* #FFFFFFSay #ABCDEF"..reactionString.."#FFFFFF to win #ABCDEF$"..reactionMoney.."#FFFFFF!",getRootElement(),255,255,255,true)
- addEventHandler("onPlayerChat",getRootElement(),checkForOpenConsole)
- reactionTimer = setTimer(
- function()
- removeEventHandler("onPlayerChat",getRootElement(),checkForOpenConsole)
- end,reactionDuration*1000,1)
- if isTimer(newReactionTimer) then
- killTimer(newReactionTimer)
- end
- newReactionTimer = setTimer(newReactionTest,math.random(reactionMinRedo*1000,reactionMaxRedo*1000))
- end
- function checkForOpenConsole(message,type)
- callClientFunction(source,"checkForOpenConsole",message,type)
- end
- function checkReactionTest(thePlayer,message,type,isOpen)
- if (isOpen == true) then
- outputChatBox("#0095FF* #FFFFFF"..getPlayerName(thePlayer).."#FFFFFF attempted to cheat at the reaction test!",getRootElement(),255,255,255,true)
- outputChatBox("#0095FF* #FFFFFFMoney decreased by #ABCDEF$1,000#FFFFFF! Do not cheat!",getRootElement(),255,255,255,true)
- local playerCash = loadPlayerData(thePlayer,"cash")
- savePlayerData(thePlayer,"cash",playerCash - 1000)
- scoreboardRefresh(thePlayer)
- end
- message = tostring(message)
- if message == "..." then
- return
- end
- if (message == reactionString) then
- local timeLeft,leftExec,totalExec = getTimerDetails(reactionTimer)
- killTimer(reactionTimer)
- removeEventHandler("onPlayerChat",getRootElement(),checkForOpenConsole)
- setTimer(outputChatBox,200,1,"#0095FF* #FFFFFF"..getPlayerName(thePlayer).." #FFFFFFhas won the reaction test in #ABCDEF"..math.round((reactionDuration*1000 - timeLeft)/1000,2,floor) .." #FFFFFFseconds and wins #ABCDEF$"..reactionMoney,getRootElement(),255,255,255,true)
- local playerCash = loadPlayerData(thePlayer,"cash")
- local totalReactionTests = tonumber(loadPlayerData(thePlayer,"totalReactionTests"))
- local bestReactionTime = tonumber(loadPlayerData(thePlayer,"bestReactionTime"))
- savePlayerData(thePlayer,"cash",playerCash + reactionMoney)
- savePlayerData(thePlayer,"totalReactionTests",totalReactionTests + 1)
- totalMoneyEarnedAdd(thePlayer,reactionMoney)
- if (math.round((reactionDuration*1000 - timeLeft)/1000)) < bestReactionTime or (bestReactionTime == 0) then
- savePlayerData(thePlayer,"bestReactionTime",math.round((reactionDuration*1000 - timeLeft)/1000,2,floor))
- end
- scoreboardRefresh(thePlayer)
- setTimer(achievement36,200,1,thePlayer)
- -- Check for achievement here
- if math.round((reactionDuration*1000 - timeLeft)/1000,2,floor) <= 5 then
- achievement37(thePlayer)
- end
- reactionString = ""
- reactionMoney = 0
- end
- end
- function string.random(len)
- local str = ""
- for i=1,len do
- local getChar = math.random(1,35)
- if getChar <= 25 then
- local caps = math.random(1,2)
- if caps == 1 then
- str = str..string.upper(chars[getChar])
- else
- str = str..string.lower(chars[getChar])
- end
- else
- str = str..chars[getChar]
- end
- end
- return str
- end
- ----------------------------
- -- Lotto [Lottery]
- ----------------------------
- local LOTTO_MAX_TICKETS = 5
- local LOTTO_PRIZE = 10000
- local LOTTO_PRICE = 1000
- local lottoState = 0 -- 0-opened; 1-waiting for prize; 2-closed;
- local lottoTicketsLeft = LOTTO_MAX_TICKETS
- local lottoAnyoneWon = 0
- local lottoTimesTried = 0
- function openLotto()
- lottoState = 0
- lottoTicketsLeft = LOTTO_MAX_TICKETS
- lottoAnyoneWon = 0
- lottoTimesTried = 0
- outputChatBox("#abcdef[LOTTO]:#ffffffLottery is now open! Use #abcdef/buyticket #ffffffor #abcdef/bt #ffffffto buy lottery ticket! (Price: #abcdef1000$#ffffff)", getRootElement(), 255, 255, 255, true)
- end
- function givePrize()
- if(lottoTimesTried == LOTTO_MAX_TICKETS*2) then
- lottoOpenTimer = setTimer(openLotto, 3*60*1000, 1)
- lottoState = 2
- return
- end
- local rticket = math.random(1, LOTTO_MAX_TICKETS)
- local players = getElementsByType("playerCash")
- for i, v in ipairs(players) do
- if(getElementData(v, "TicketID") == rticket) then
- lottoState = 2
- lottoAnyoneWon = 1
- givePlayerMoney(v, LOTTO_PRIZE)
- lottoOpenTimer = setTimer(openLotto, 3*60*1000, 1)
- outputChatBox("#abcdef[LOTTO] " ..getPlayerName(v).. " #ffffffHas Won the lottery! Congratulations! New lottery will open in 3 minutes", getRootElement(), 255, 255, 0, true)
- end
- setElementData(v, "TicketID", 0)
- setElementData(v, "BoughtTicket", false)
- end
- if(lottoAnyoneWon == 0) then
- givePrize()
- lottoTimesTried = lottoTimesTried+1
- end
- end
- function buyticket(playerCash)
- if(lottoState == 2) then
- millisecondsRemaining = getTimerDetails(lottoOpenTimer)
- local minutesRemaining = math.ceil(millisecondsRemaining/60000)
- local secondsRemaining = math.ceil((millisecondsRemaining/1000)%60)
- outputChatBox("#abcdef[LOTTO] Lottery is closed! #ffffffIt will open after " ..minutesRemaining.. " minutes and " ..secondsRemaining.. " seconds.", player, 255, 0, 0, true)
- elseif(lottoState == 1) then
- outputChatBox("#abcdef[LOTTO] #ffffffLottery is closed!", player, 255, 0, 0, true)
- elseif(lottoState == 0) then
- if(getElementData(playerCash, "BoughtTicket") == true) then
- outputChatBox("#abcdef[LOTTO] #ffffffYou already have lottery ticket!", player, 255, 100, 0, true)
- return
- end
- if(getPlayerMoney(playerCash) < LOTTO_PRICE) then
- outputChatBox("[LOTTO] You haven't got enough money! (Price: " ..LOTTO_PRICE.. "$)", player, 255, 100, 0, false)
- return
- end
- takePlayerMoney(playerCash, LOTTO_PRICE)
- setElementData(playerCash, "TicketID", lottoTicketsLeft)
- setElementData(playerCash, "BoughtTicket", true)
- lottoTicketsLeft = lottoTicketsLeft-1
- outputChatBox("#abcdef[LOTTO] " ..getPlayerName(player).." #ffff00has bought lottery ticket! " ..lottoTicketsLeft.. " tickets left!", getRootElement(), 255, 255, 0, true)
- if(lottoTicketsLeft == 0) then
- lottoState = 1
- setTimer(givePrize, 1*60*1000, 1)
- outputChatBox("#abcdef[LOTTO] #ffffff0 tickets left! Random lottery member will get the prize after 1 minute!", getRootElement(), 255, 255, 255, true)
- end
- end
- end
- addCommandHandler("buyticket", buyticket)
- addCommandHandler("bt", buyticket)
- function pQuit(playerCash)
- if(lottoState == 0) then
- if(lottoTicketsLeft > 0 and lottoTicketsLeft < 5) then
- lottoTicketsLeft = lottoTicketsLeft+1
- outputChatBox("#abcdef[LOTTO] #ffffffPlayer who had ticket left the server so now there are #abcdef"..lottoTicketsLeft.." #fffffftickets left!", getRootElement(), 255, 255, 255, true)
- end
- end
- end
- function rStart(playerCash)
- outputDebugString("Martyz lotto v1.0 has been loaded SUCCESSFULLY")
- end
- addEventHandler("onPlayerQuit", getRootElement(), pQuit)
- addEventHandler("onResourceStart", getResourceRootElement(getThisResource()), rStart)
Add Comment
Please, Sign In to add comment