Guest User

Untitled

a guest
Aug 18th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 76.64 KB | None | 0 0
  1. gRoot = getRootElement()
  2.  
  3. AchievementsName = {
  4. "First Win!", -- 1sze zwyciestwo
  5. "First Hunter!", -- 1szy hunter
  6. "Top Winner!", -- 300 wins
  7. "Awesome Winner!", -- 1000 wins
  8. "Top Gamer!", -- 2000 map
  9. "Long Time Player!", -- 7 dni
  10. "Hunter Owner!", -- hunter 50 razy
  11. "Beat my TT kid!", -- pobij swoj TT
  12. "5 Maps In a Row LOL!", -- 5x
  13. "Triple Deathmatch!", -- 3x dm pod rzad
  14. "Triple Dest. Derby!", -- 3x DD
  15. "Hunter Power", -- hunterfight z 3 graczami
  16. "Map Buyer", -- 10 razy kupic mape
  17. "Top Times collector!", -- 50 toptimow
  18. "Rich player!", -- 1 mln
  19. "Rich player I", -- 2 mln                          
  20. "Hunter Owner I", -- Hunter 150                        
  21. "Top Times collector I", -- 150                                      
  22. "Hunter Power I", -- hunterfight z 8 graczami                              
  23. }
  24. LastWinnersDD={"","","","",""}
  25. LastWinnersDM={"","","","",""}
  26. LastWinners={"","","","",""}
  27. HunterCount = 0
  28.  
  29.  
  30.  
  31. -- String.random characters
  32. 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"}
  33.  
  34.  
  35.  
  36. ------------------------------------------
  37. -- Settings
  38. ------------------------------------------
  39. mapCost = 5000                        -- The price for setting maps.
  40. betPerCash = 10000      -- Limits the amount of money you can bet. (playerCash*betPerCash = maxBet).
  41. betTimeLimit = 40       -- Duration of the betting period in seconds.
  42. minPlayers = 1      -- Minimum required players to bet.
  43.  
  44. --skinLevel = 13            -- Minimum level required to buy skins.
  45. skinCost = 1300         -- The price of skins.
  46. nametagLevel = 15       -- Minimum level to buy a nametag color.
  47. nametagPrice = 2000     -- Price for buying a nametag color.
  48. --hornLevel = 10            -- Minimum level to buy different horn styles.
  49.  
  50. reactionMin = 120       -- Minimum money for the reaction test
  51. reactionMax = 550       -- Maximum money for the reaction test
  52. reactionDuration = 20   -- Duration of the reaction test in seconds
  53. reactionMinRedo = 20    -- Minimum amount of time to pass before a new reaction test is started in seconds (200)
  54. reactionMaxRedo = 30    -- Maximum amount of time to pass before a new reaction test is started in seconds (300)
  55. reactionLength = 10     -- Number of characters to use in the reaction test
  56.  
  57. local activePlayers = {}
  58.  
  59. function startResource ()
  60.     exports.scoreboard:removeScoreboardColumn("race rank")
  61.     exports.scoreboard:removeScoreboardColumn("checkpoint")
  62.     exports.scoreboard:addScoreboardColumn("Money",gRoot,5,100)
  63.     mapIsAlreadySet = false
  64.     reactionString = ""
  65.     reactionMoney = 0
  66.     setTimer(newReactionTest,math.random(reactionMinRedo*1000,reactionMaxRedo*1000),1)
  67.     for i,pla in ipairs(getElementsByType("player")) do
  68.         scoreboardRefresh(pla)
  69.     end
  70. end
  71. addEventHandler ( "onResourceStart", getResourceRootElement(getThisResource()), startResource )
  72.  
  73. ------------------------------------------
  74. -- Load All Stats on Join
  75. ------------------------------------------
  76. function scoreboardRefresh(thePlayer)
  77.     local playerCash = loadPlayerData(thePlayer,"cash")
  78.     setElementData(thePlayer,"Money","$"..playerCash)
  79.     callClientFunction(thePlayer, "refreshCash", playerCash)
  80. end
  81.  
  82. function playerJoinHandler ( )
  83.     outputChatBox("#00AAFF# #FFFFFFPress '#00AAFFF7#FFFFFF' to open your User Panel#00AAFF!",source,255,255,255,true)
  84.                  outputChatBox("#ecececWelcome To The #c1ff17SGF #ececec24/7 #abcdef[DD/DM] #ecececRace Server. Have Fun During Your Stay!",source,255,255,255,true)
  85.     scoreboardRefresh(source)
  86. end
  87. addEventHandler ( "onPlayerJoin", gRoot, playerJoinHandler )
  88.  
  89. ------------------------------------------
  90. -- DD/DM/FUN checking
  91. ------------------------------------------
  92. addEvent("onMapStarting")
  93. addEventHandler("onMapStarting", getRootElement(),
  94. function(mapInfo, mapOptions, gameOptions)
  95.     CurrentMap = nil
  96.     HunterCount = 0
  97.     MaxI = 0
  98.     for i,thePlayer in ipairs(getElementsByType("player")) do
  99.         MaxI = i
  100.     end
  101.     if MaxI >=3 then
  102.         if (checkMapType(mapInfo.name) == 1) then
  103.             CurrentMap = 1
  104.             for i,thePlayer in ipairs(getElementsByType("player")) do
  105.                 local mapsPlayedDM = tonumber(loadPlayerData(thePlayer,"mapsPlayedDM"))
  106.                 savePlayerData(thePlayer,"mapsPlayedDM", mapsPlayedDM+1)
  107.                 CheckAchievement(thePlayer,5)
  108.             end
  109.         elseif (checkMapType(mapInfo.name) == 2) then
  110.             CurrentMap = 2
  111.             for i,thePlayer in ipairs(getElementsByType("player")) do
  112.                 local mapsPlayedDD = tonumber(loadPlayerData(thePlayer,"mapsPlayedDD"))
  113.                 savePlayerData(thePlayer,"mapsPlayedDD", mapsPlayedDD+1)
  114.                 CheckAchievement(thePlayer,5)
  115.             end
  116.         end
  117.     else
  118.         exports.box:outputMiniBox("#FFFFFF Min. 3 players to get #abcdefStats #FFFFFFand #abcdefCash#ececec!",gRoot)
  119.     end
  120. end)
  121.  
  122. function checkMapType(mapname)
  123. if string.find(mapname, "[DM]", 1, true) then
  124.     return 1
  125. elseif string.find(mapname, "[DD]", 1,true) then
  126.     return 2
  127. elseif string.find(mapname, "[FUN]", 1,true) then
  128.     return 3
  129. end
  130. end
  131.  
  132.  
  133. function getRaceAlivePlayers()
  134.     local result = {}
  135.     local _getAlivePlayers = getElementsByType("player")
  136.     for i,v in ipairs(_getAlivePlayers) do
  137.         if getElementData(v,"state") == "alive" then
  138.             table.insert(result,v)
  139.         end
  140.     end
  141.     return result
  142. end
  143.  
  144.  
  145. ------------------------------------------
  146. -- Wins Stats
  147. ------------------------------------------
  148. function onPlayerDeadInRace()
  149.     local thePlayer = source
  150.     local dPlayers = getDeadRacePlayers()
  151.     local aPlayers = getAliveRacePlayers()
  152.     local Position = aPlayers + 1
  153.     if dPlayers + aPlayers >= 3 then
  154.         local cashForPlayer = math.floor((200/Position)*(dPlayers + aPlayers))
  155.         local playerCash = loadPlayerData(thePlayer,"cash")
  156.         savePlayerData(thePlayer,"cash",playerCash+cashForPlayer)
  157.         CheckAchievement(thePlayer,15)
  158.         CheckAchievement(thePlayer,16)
  159.         scoreboardRefresh(thePlayer)
  160.         if Position == 1 then
  161.             exports.box:outputMiniBox("#C1FF17# "..getPlayerName(thePlayer).." #FFFFFFHas Won The Map +$#00AAFF" .. cashForPlayer.. "#FFFFFF!",gRoot)
  162.             --triggerClientEvent ( "showWinMessage", getRootElement(), thePlayer, cashForPlayer)
  163.            
  164.                 if LastWinners[1] == "" then
  165.                     if LastWinners[2] == "" then
  166.                         if LastWinners[3] == "" then
  167.                             if LastWinners[4] == "" then
  168.                                 if LastWinners[5] == "" then
  169.                                     LastWinners[5] = thePlayer
  170.                                 else
  171.                                     LastWinners[4] = thePlayer
  172.                                 end
  173.                             else
  174.                                 LastWinners[3] = thePlayer
  175.                             end
  176.                         else
  177.                             LastWinners[2] = thePlayer
  178.                         end
  179.                     else
  180.                         LastWinners[1] = thePlayer
  181.                     end
  182.                 else
  183.                     LastWinners[5] = LastWinners[4]
  184.                     LastWinners[4] = LastWinners[3]
  185.                     LastWinners[3] = LastWinners[2]
  186.                     LastWinners[2] = LastWinners[1]
  187.                     LastWinners[1] = thePlayer
  188.                     CheckAchievement(thePlayer,9)
  189.                 end
  190.            
  191.            
  192.            
  193.             if CurrentMap and CurrentMap == 1 then
  194.                 local mapsWonDM = tonumber(loadPlayerData(thePlayer,"mapsWonDM"))
  195.                 savePlayerData(thePlayer,"mapsWonDM", mapsWonDM+1)
  196.                 CheckAchievement(thePlayer,1)
  197.                 CheckAchievement(thePlayer,3)
  198.                 CheckAchievement(thePlayer,4)
  199.                 if LastWinnersDM[1] == ""then
  200.                     if LastWinnersDM[2] == "" then
  201.                         if LastWinnersDM[3] == "" then
  202.                             LastWinnersDM[3] = thePlayer
  203.                         else
  204.                             LastWinnersDM[2] = thePlayer
  205.                         end
  206.                     else
  207.                         LastWinnersDM[1] = thePlayer
  208.                     end
  209.                 else
  210.                     LastWinnersDM[3] = LastWinnersDM[2]
  211.                     LastWinnersDM[2] = LastWinnersDM[1]
  212.                     LastWinnersDM[1] = thePlayer
  213.                     CheckAchievement(thePlayer,10)
  214.                 end
  215.                 if HunterCount >= 3 then
  216.                     unlockedAC(thePlayer,12)
  217.                 end
  218.             elseif CurrentMap and CurrentMap == 2 then
  219.                 local mapsWonDD = tonumber(loadPlayerData(thePlayer,"mapsWonDD"))
  220.                 savePlayerData(thePlayer,"mapsWonDD", mapsWonDD+1)
  221.                 CheckAchievement(thePlayer,1)
  222.                 CheckAchievement(thePlayer,3)
  223.                 CheckAchievement(thePlayer,4)
  224.                 if LastWinnersDD[1] == "" then
  225.                     if LastWinnersDD[2] == "" then
  226.                         if LastWinnersDD[3] == "" then
  227.                             LastWinnersDD[3] = thePlayer
  228.                         else
  229.                             LastWinnersDD[2] = thePlayer
  230.                         end
  231.                     else
  232.                         LastWinnersDD[1] = thePlayer
  233.                     end
  234.                 else
  235.                     LastWinnersDD[3] = LastWinnersDD[2]
  236.                     LastWinnersDD[2] = LastWinnersDD[1]
  237.                     LastWinnersDD[1] = thePlayer
  238.                     CheckAchievement(thePlayer,11)
  239.                 end
  240.             end
  241.         else
  242.             exports.box:outputMiniBox("#00AAFF# #FFFFFFYou Have Recieved $#00AAFF" .. cashForPlayer .. "#FFFFFF!",thePlayer)
  243.         end
  244.     else
  245.         exports.box:outputMiniBox("#FFFFFF Min. 3 players to get #abcdefStats #FFFFFFand #abcdefCash#ececec!",thePlayer)
  246.     end
  247. end
  248. addEvent("onPlayerWasted", true)
  249. addEventHandler("onPlayerWasted", gRoot , onPlayerDeadInRace)
  250.  
  251. ------------------
  252. -- SHOP
  253. ------------------
  254.  
  255.  
  256.  
  257.  
  258. -------------------
  259. -- Skin handler
  260. -------------------
  261. function saveSkin(thePlayer,skinID)
  262.     if (tonumber(loadPlayerData(thePlayer,"cash")) >= skinCost) then
  263.         savePlayerData(thePlayer,"skin",skinID)
  264.         savePlayerData(thePlayer,"cash",tonumber(loadPlayerData(thePlayer,"cash"))-skinCost)
  265.         skinEnabled = loadPlayerData(thePlayer,"useCustomSkin")
  266.         if skinEnabled == "true" then
  267.             setElementModel(thePlayer,skinID)
  268.         end
  269.         outputChatBox("#0095FF* #FFFFFFYou have sucessfuly purchased the skin! #FFFF00[#FFFFFFID:"..skinID.."#FFFF00]",thePlayer,255,255,255,true)
  270.         setTimer(outputChatBox,700,1,"#0095FF* #FFFFFFThe skin has been saved to your account.",thePlayer,255,255,255,true)
  271.         savePlayerData(thePlayer,"everPurchasedSkin",1)
  272.         setElementData(thePlayer,"everPurchasedSkin",1)
  273.         scoreboardRefresh(thePlayer)
  274.         achievement38(thePlayer)
  275.     else
  276.         outputChatBox("#0095FF* #FFFFFFERROR! You don't have enough money!",thePlayer,255,255,255,true)
  277.     end
  278. end
  279.  
  280. function setSkinOnMapStart()
  281.     if tonumber(getElementData(source,"everPurchasedSkin")) == 1 then
  282.         skinEnabled = loadPlayerData(source,"useCustomSkin")
  283.         if skinEnabled == "true" then
  284.             skinID = loadPlayerData(source,"skin")
  285.             setElementModel(source,skinID)
  286.         end
  287.     end
  288. end
  289. addEventHandler("onNotifyPlayerReady",getRootElement(),setSkinOnMapStart)
  290.  
  291.  
  292.  
  293. function checkSkinLevel(thePlayer)
  294.     local playerLevel = tonumber(loadPlayerData(thePlayer,"level"))
  295.     if playerLevel >= skinLevel then
  296.         callClientFunction(thePlayer,"openSkinsWindow")
  297.     else
  298.         outputChatBox("#0095FF* #FFFFFFERROR! You need to be level #ABCDEF"..skinLevel.."#FFFFFF or more to change skins!",thePlayer,255,255,255,true)
  299.     end
  300. end
  301.  
  302.  
  303. -------------------
  304. -- Nametag color
  305. -------------------
  306. function saveNametagColor(thePlayer,r,g,b)
  307.     local playerCash = tonumber(loadPlayerData(thePlayer,"cash"))
  308.     savePlayerData(thePlayer,"cash",playerCash-nametagPrice)
  309.     savePlayerData(thePlayer,"nametagRed",r)
  310.     savePlayerData(thePlayer,"nametagGreen",g)
  311.     savePlayerData(thePlayer,"nametagBlue",b)
  312.     setNametagColor(thePlayer)
  313.     outputChatBox("#0095FF* #FFFFFFYou have purchased a new nametag color for #ABCDEF$"..nametagPrice.."#FFFFFF!",thePlayer,255,255,255,true)
  314.     savePlayerData(thePlayer,"everPurchasedNametagColor",1)
  315.     setElementData(thePlayer,"everPurchasedNametagColor",1)
  316.     scoreboardRefresh(thePlayer)
  317. end
  318.  
  319. function getNametagLevel(thePlayer)
  320.     local playerCash = tonumber(loadPlayerData(thePlayer,"cash"))
  321.     local playerLevel = tonumber(loadPlayerData(thePlayer,"level"))
  322.     if playerLevel >= nametagLevel then
  323.         if playerCash >= nametagPrice then
  324.             callClientFunction(thePlayer,"showNametagWindow")
  325.         else
  326.             outputChatBox("#0095FF* #FFFFFFERROR! You don't have enough money!",thePlayer,255,255,255,true)
  327.         end
  328.     else
  329.         outputChatBox("#0095FF* #FFFFFFERROR! You need to be level #ABCDEF"..nametagLevel.."#FFFFFF or higher to change your nametag color!",thePlayer,255,255,255,true)
  330.     end
  331. end
  332.  
  333.  
  334. function setNametagColor(thePlayer)
  335.     local ifSet = tonumber(getElementData(thePlayer,"everPurchasedNametagColor"))
  336.     if ifSet == 1 then
  337.         local useColor = loadPlayerData(thePlayer,"useCustomNametag")
  338.         if useColor == "true" then
  339.             local r = tonumber(loadPlayerData(thePlayer,"nametagRed"))
  340.             local g = tonumber(loadPlayerData(thePlayer,"nametagGreen"))
  341.             local b = tonumber(loadPlayerData(thePlayer,"nametagBlue"))
  342.             callClientFunction(thePlayer,"setCustomNametagColor",true,r,g,b)
  343.         end
  344.     end
  345. end
  346. addEventHandler("onPlayerJoin",getRootElement(),setNametagColor)
  347.  
  348.  
  349. -------------------
  350. -- Horns
  351. -------------------
  352. function getPurchasedHorns(thePlayer)
  353.     local airhorn = tonumber(loadPlayerData(thePlayer,"horn1"))
  354.     local clown = tonumber(loadPlayerData(thePlayer,"horn2"))
  355.     local train = tonumber(loadPlayerData(thePlayer,"horn3"))
  356.     local ship = tonumber(loadPlayerData(thePlayer,"horn4"))
  357.     local submarine = tonumber(loadPlayerData(thePlayer,"horn5"))
  358.     local military = tonumber(loadPlayerData(thePlayer,"horn6"))
  359.     local whoopie = tonumber(loadPlayerData(thePlayer,"horn7"))
  360.     callClientFunction(thePlayer,"updateHorns",thePlayer,airhorn,clown,train,ship,submarine,military,whoopie)
  361. end
  362.  
  363. function purchaseHorn(thePlayer,horn,hornName)
  364.     local playerCash = tonumber(loadPlayerData(thePlayer,"cash"))
  365.     local playerLevel = tonumber(loadPlayerData(thePlayer,"level"))
  366.     local checkOwnership = tonumber(loadPlayerData(thePlayer,"horn"..horn))
  367.     if checkOwnership == 0 then
  368.         if playerLevel >= hornLevel then
  369.             if playerCash >= hornPrice[horn] then
  370.                 savePlayerData(thePlayer,"cash",playerCash-hornPrice[horn])
  371.                 savePlayerData(thePlayer,tostring("horn"..horn),1)
  372.                 getPurchasedHorns(thePlayer)
  373.                 scoreboardRefresh(thePlayer)
  374.                 achievement39(thePlayer)
  375.                 outputChatBox("#0095FF* #FFFFFFYou have purchased the #ABCDEF"..hornName.."#FFFFFF horn for #ABCDEF$"..hornPrice[horn].."#FFFFFF!",thePlayer,255,255,255,true)
  376.             else
  377.                 outputChatBox("#0095FF* #FFFFFFERROR! You don't have enough money!",thePlayer,255,255,255,true)
  378.             end
  379.         else
  380.             outputChatBox("#0095FF* #FFFFFFERROR! You need to be level #ABCDEF"..hornLevel.."#FFFFFF or higher to purchase new horns!",thePlayer,255,255,255,true)
  381.         end
  382.     else
  383.         outputChatBox("#0095FF* #FFFFFFERROR! You already own this horn!",thePlayer,255,255,255,true)
  384.     end
  385. end
  386.  
  387. function checkForPurchasedHorn(thePlayer,horn)
  388.     local hornStatus = tonumber(loadPlayerData(thePlayer,"horn"..horn))
  389.     if hornStatus == 1 then
  390.         callClientFunction(thePlayer,"setHorn",horn)
  391.     else
  392.         outputChatBox("#0095FF* #FFFFFFERROR! You do not own this horn!",thePlayer,255,255,255,true)
  393.     end
  394. end
  395.  
  396. function getLastSetHorn(thePlayer)
  397.     local horn = tonumber(loadPlayerData(thePlayer,"lastSetHorn"))
  398.     callClientFunction(thePlayer,"setLastUsedHorn",horn)
  399. end
  400.  
  401. function setLastSetHorn(thePlayer,horn)
  402.     savePlayerData(thePlayer,"lastSetHorn",horn)
  403. end
  404.  
  405. function toggleHornControl()
  406.     for _,player in ipairs(getElementsByType("player")) do
  407.         if loadPlayerData(player,"lastSetHorn") == 0 then
  408.             setTimer(toggleControl,2000,1,player,"horn",true)
  409.         else
  410.             setTimer(toggleControl,2000,1,player,"horn",false)
  411.         end
  412.     end
  413. end
  414. addEvent("onMapStarting",true)
  415. addEventHandler("onMapStarting",getRootElement(),toggleHornControl)
  416.  
  417. function toggleControlOnReady()
  418.     if loadPlayerData(source,"lastSetHorn") == 0 then
  419.         toggleControl(source,"horn",true)
  420.     else
  421.         toggleControl(source,"horn",false)
  422.     end
  423. end
  424. addEventHandler("onNotifyPlayerReady",getRootElement(),toggleControlOnReady)
  425.  
  426.  
  427. function playHornForAllClients(horningPlayer,hornSoundPath,cSetHornSound) -- This function passes on the horn to all players.
  428.     triggerClientEvent(getRootElement(),"onRecieveHorn",horningPlayer,horningPlayer,hornSoundPath,cSetHornSound)
  429. end
  430.  
  431.  
  432.  
  433. --------------------------------------
  434. -- Buy water color and time change
  435. --------------------------------------
  436. function buyChangeWaterColor(thePlayer,r,g,b)
  437.     if type(r) == "number" and r >= 0 and r <= 255 then
  438.         if type(g) == "number" and g >= 0 and g <= 255 then
  439.             if type(b) == "number" and g >= 0 and g <= 255 then
  440.                 local playerCash = tonumber(loadPlayerData(thePlayer,"cash"))
  441.                 if playerCash >= 400 then
  442.                     callClientFunction(getRootElement(),"cSetWaterColor",r,g,b)
  443.                     savePlayerData(thePlayer,"cash",playerCash-400)
  444.                     outputChatBox("#0095FF* #FFFFFF"..getPlayerName(thePlayer).." #FFFFFFhas changed the water color!",getRootElement(),255,255,255,true)
  445.                     scoreboardRefresh(thePlayer)
  446.                 else
  447.                     outputChatBox("#0095FF* #FFFFFFERROR! You don't have enough money!",thePlayer,255,255,255,true)
  448.                 end
  449.             else
  450.                 outputChatBox("#0095FF* #FFFFFFInvalid BLUE value - Please use a number from 0 to 255.",thePlayer,255,255,255,true)
  451.             end
  452.         else
  453.             outputChatBox("#0095FF* #FFFFFFInvalid GREEN value - Please use a number from 0 to 255.",thePlayer,255,255,255,true)
  454.         end
  455.     else
  456.         outputChatBox("#0095FF* #FFFFFFInvalid RED value - Please use a number from 0 to 255.",thePlayer,255,255,255,true)
  457.     end
  458. end
  459.  
  460.  
  461. function buyChangeTime(thePlayer,h,m)
  462.     if type(h) == "number" and h >= 0 and h <= 23 then
  463.         if type(m) == "number" and m >= 0 and m <= 59 then
  464.             local playerCash = tonumber(loadPlayerData(thePlayer,"cash"))
  465.             if playerCash >= 400 then
  466.                 setTime(h,m)
  467.                 savePlayerData(thePlayer,"cash",playerCash-250)
  468.                 if h < 10 and m < 10 then
  469.                     outputChatBox("#0095FF* #FFFFFF"..getPlayerName(thePlayer).." #FFFFFFhas changed the time to #ABCDEF0"..h..":0"..m.."#FFFFFF!",getRootElement(),255,255,255,true)
  470.                 elseif h < 10 then
  471.                     outputChatBox("#0095FF* #FFFFFF"..getPlayerName(thePlayer).." #FFFFFFhas changed the time to #ABCDEF0"..h..":"..m.."#FFFFFF!",getRootElement(),255,255,255,true)
  472.                 elseif m < 10 then
  473.                     outputChatBox("#0095FF* #FFFFFF"..getPlayerName(thePlayer).." #FFFFFFhas changed the time to #ABCDEF"..h..":0"..m.."#FFFFFF!",getRootElement(),255,255,255,true)
  474.                 end
  475.                 scoreboardRefresh(thePlayer)
  476.             else
  477.                 outputChatBox("#0095FF* #FFFFFFERROR! You don't have enough money!",thePlayer,255,255,255,true)
  478.             end
  479.         else
  480.             outputChatBox("#0095FF* #FFFFFFInvalid MINUTES - Please use a number from 0 to 59.",thePlayer,255,255,255,true)
  481.         end
  482.     else
  483.         outputChatBox("#0095FF* #FFFFFFInvalid HOURS - Please use a number from 0 to 23.",thePlayer,255,255,255,true)
  484.     end
  485. end
  486.  
  487.  
  488.  
  489.  
  490.  
  491.  
  492.  
  493.  
  494.  
  495. ------------------------------------------------
  496. -- Set headlights on map start and on veh-change
  497. ------------------------------------------------
  498.  
  499. function setPlayerHeadlightColor(number, sort, model)
  500.     if sort == "vehiclechange" then
  501.         local hlcRed = getElementData(source,"hlcRed")
  502.         local hlcGreen = getElementData(source,"hlcGreen")
  503.         local hlcBlue = getElementData(source,"hlcBlue")
  504.         if (hlcRed) and (hlcGreen) and (hlcBlue) then
  505.             local car = getPedOccupiedVehicle(source)
  506.             setVehicleHeadLightColor(car,hlcRed,hlcGreen,hlcBlue)
  507.             --outputChatBox("Data sucessfully retrieved, headlights color has been set!",getRootElement(),0,255,0)
  508.         else
  509.         end
  510.     end
  511. end
  512.  
  513. function setPlayerHeadlightColor2()
  514.     local hlcRed = getElementData(source,"hlcRed")
  515.     local hlcGreen = getElementData(source,"hlcGreen")
  516.     local hlcBlue = getElementData(source,"hlcBlue")
  517.     if (hlcRed) and (hlcGreen) and (hlcBlue) then
  518.         local car = getPedOccupiedVehicle(source)
  519.         setVehicleHeadLightColor(car,hlcRed,hlcGreen,hlcBlue)
  520.         --outputChatBox("Data sucessfully retrieved, headlights color has been set!",getRootElement(),0,255,0)
  521.     else
  522.     end
  523. end
  524. addEvent("onNotifyPlayerReady", true)
  525. addEventHandler("onNotifyPlayerReady", getRootElement(), setPlayerHeadlightColor2)
  526. addEventHandler("onPlayerPickUpRacePickup",getRootElement(),setPlayerHeadlightColor)
  527.  
  528.  
  529.  
  530.  
  531.  
  532. ------------------
  533. -- Save headlights
  534. ------------------
  535.  
  536. function saveHeadlights(thePlayer,colorRed,colorGreen,colorBlue)
  537.     --outputChatBox("SERVER: Event triggered! Saving headlights...")
  538.     local red = colorRed
  539.     local green = colorGreen
  540.     local blue = colorBlue
  541.     local car = getPedOccupiedVehicle(thePlayer)
  542.     setVehicleHeadLightColor(car,red,green,blue)
  543.     savePlayerData(thePlayer,"hlcRed",red)
  544.     savePlayerData(thePlayer,"hlcGreen",green)
  545.     savePlayerData(thePlayer,"hlcBlue",blue)
  546.     setElementData(thePlayer,"hlcRed",red)
  547.     setElementData(thePlayer,"hlcGreen",green)
  548.     setElementData(thePlayer,"hlcBlue",blue)
  549.     outputChatBox("#0095FF* #FFFFFFYour data has been saved!",thePlayer,255,255,255,true)
  550.     --outputChatBox("SERVER: Account found! Data has been saved.")
  551. end
  552. addEvent("saveHeadlights", true)
  553. addEventHandler("saveHeadlights", getRootElement(), saveHeadlights)
  554.  
  555.  
  556.  
  557.  
  558.  
  559. ---------------------
  560. -- Save vehicle color
  561. ---------------------
  562.  
  563. function saveVehColor(player,c1,c2,c3,c4)
  564.     savePlayerData(player,"c1",c1)
  565.     savePlayerData(player,"c2",c2)
  566.     savePlayerData(player,"c3",c3)
  567.     savePlayerData(player,"c4",c4)
  568.     setElementData(player,"c1",c1)
  569.     setElementData(player,"c2",c2)
  570.     setElementData(player,"c3",c3)
  571.     setElementData(player,"c4",c4)
  572. end
  573.  
  574.  
  575. root = getRootElement()
  576.  
  577. function executecolor(c1,c2,c3,c4)
  578.     carcolor(source,true,c1,c2,c3,c4)
  579. end
  580.  
  581. function executealpha(player,_,alpha)
  582.     alpha = alpha or 255
  583.     setElementAlpha(getPedOccupiedVehicle(player),tonumber(alpha))
  584. end
  585.  
  586. function carcolor(thePlayer,_,arg1,arg2,arg3,arg4)
  587.     local vehicle = getPedOccupiedVehicle(thePlayer)
  588.     if (vehicle) then
  589.         local old,old2,old3,old4=getVehicleColor(vehicle)
  590.         local arg11,arg22,arg33,arg44=tonumber(arg1),tonumber(arg2) or old2,tonumber(arg3) or old3,tonumber(arg4) or old4
  591.         setVehicleColor(vehicle,arg11,arg22,arg33,arg44)
  592.         outputChatBox("#0095FF* #FFFFFFYour data has been saved!",thePlayer,255,255,255,true)
  593.         savePlayerData(thePlayer,"everSetCustomVehicleColor",1)
  594.         setElementData(thePlayer,"everSetCustomVehicleColor",1)
  595.     else
  596.     end
  597. end
  598.  
  599.  
  600. addEvent("colorchange",true)
  601. addEventHandler("colorchange",root, executecolor)
  602. addEvent("alphachange",true)
  603. addEventHandler("alphachange",root, executealpha)
  604.  
  605.  
  606.  
  607.  
  608.  
  609.  
  610. ----------------------------------------------------------
  611. -- Set vehicle color on player-ready and on vehicle change
  612. ----------------------------------------------------------
  613.  
  614. function setPlayerVehicleColor(number, sort, model)
  615.     if sort == "vehiclechange" then
  616.         local ifSet = tonumber(getElementData(source,"everSetCustomVehicleColor"))
  617.         if ifSet == 1 then
  618.             local useColor = tostring(getElementData(source,"useCustomVehicleColor"))
  619.             if (useColor == "true") then
  620.                 local c1 = tonumber(getElementData(source,"c1"))
  621.                 local c2 = tonumber(getElementData(source,"c2"))
  622.                 local c3 = tonumber(getElementData(source,"c3"))
  623.                 local c4 = tonumber(getElementData(source,"c4"))
  624.                 local car = getPedOccupiedVehicle(source)
  625.                 exc1, exc2, exc3, exc4 = getVehicleColor (car)
  626.                 if not c1 then c1 = exc1 end
  627.                 if not c2 then c2 = exc2 end
  628.                 if not c3 then c3 = exc3 end
  629.                 if not c4 then c4 = exc4 end
  630.                 setVehicleColor(car,c1,c2,c3,c4)
  631.             else
  632.                 local car = getPedOccupiedVehicle(source)
  633.                 setVehicleColor(car,math.random(1,126),math.random(1,126),math.random(1,126),math.random(1,126))
  634.             end
  635.         else
  636.             local car = getPedOccupiedVehicle(source)
  637.             setVehicleColor(car,math.random(1,126),math.random(1,126),math.random(1,126),math.random(1,126))
  638.         end
  639.     end
  640. end
  641.  
  642.  
  643. function setPlayerVehicleColor2()
  644.     local ifSet = tonumber(getElementData(source,"everSetCustomVehicleColor"))
  645.     if ifSet == 1 then
  646.         local useColor = tostring(getElementData(source,"useCustomVehicleColor"))
  647.         if (useColor == "true") then
  648.             local c1 = tonumber(getElementData(source,"c1"))
  649.             local c2 = tonumber(getElementData(source,"c2"))
  650.             local c3 = tonumber(getElementData(source,"c3"))
  651.             local c4 = tonumber(getElementData(source,"c4"))
  652.             local car = getPedOccupiedVehicle(source)
  653.             exc1, exc2, exc3, exc4 = getVehicleColor (car)
  654.             if not c1 then c1 = exc1 end
  655.             if not c2 then c2 = exc2 end
  656.             if not c3 then c3 = exc3 end
  657.             if not c4 then c4 = exc4 end
  658.             setVehicleColor(car,c1,c2,c3,c4)
  659.         else
  660.             local car = getPedOccupiedVehicle(source)
  661.             setVehicleColor(car,math.random(1,126),math.random(1,126),math.random(1,126),math.random(1,126))
  662.         end
  663.     else
  664.         local car = getPedOccupiedVehicle(source)
  665.         setVehicleColor(car,math.random(1,126),math.random(1,126),math.random(1,126),math.random(1,126))
  666.     end
  667. end
  668.  
  669. addEventHandler("onNotifyPlayerReady", getRootElement(), setPlayerVehicleColor2)
  670. addEventHandler("onPlayerPickUpRacePickup", getRootElement(), setPlayerVehicleColor)
  671.  
  672.  
  673.  
  674.  
  675.  
  676.  
  677.  
  678.  
  679.  
  680.  
  681. ------------------------------------------
  682. -- Statystyki
  683. ------------------------------------------
  684. function showStats(thePlayer,CMD,targetPlayer)
  685.     if targetPlayer then
  686.         if (findPlayerByName(targetPlayer)) then
  687.             local targetPlayer = findPlayerByName(targetPlayer)
  688.             local c,ddw,ddp,ddr,dmw,dmp,dmr,pt,h,mb,ac,tt = loadPlayerStats(targetPlayer)
  689.             outputChatBox("#C1FF17# #FFFFFF"..getPlayerName(targetPlayer).."#FFFFFF's Stats:",thePlayer,255,255,255,true)
  690.             outputChatBox("#00AAFF# [DM] #FFFFFFPlayed: "..dmp.." | Wins: "..dmw.." | Ratio: "..dmr.."%",thePlayer,255,255,255,true)
  691.             outputChatBox("#00AAFF# [DD] #FFFFFFPlayed: "..ddp.." | Wins: "..ddw.." | Ratio: "..ddr.."%",thePlayer,255,255,255,true)
  692.             outputChatBox("#00AAFF# #FFFFFFCash: $"..c.." | Hunters: "..h.." | Map Buys: "..mb,thePlayer,255,255,255,true)
  693.             outputChatBox("#00AAFF# #FFFFFFPlayed Time: "..convertTime(pt),thePlayer,255,255,255,true)
  694.             ACCOUNT = 0
  695.             for i=1,#ac do
  696.                 if ac[i] == 1 then
  697.                     ACCOUNT = ACCOUNT+1
  698.                 end
  699.             end
  700.             outputChatBox("#00AAFF# #FFFFFFAchievements: "..ACCOUNT.."/20 | TopTimes: "..tt,thePlayer,255,255,255,true)
  701.         else
  702.             outputChatBox("#00AAFF# #FFFFFFERROR! The player you specified does not exist!",thePlayer,255,255,255,true)
  703.         end
  704.     else
  705.         local c,ddw,ddp,ddr,dmw,dmp,dmr,pt,h,mb,ac,tt = loadPlayerStats(thePlayer)
  706.         outputChatBox("#00AAFF# #FFFFFF"..getPlayerName(thePlayer).."#FFFFFF's stats:",thePlayer,255,255,255,true)
  707.         outputChatBox("#00AAFF# [DM] #FFFFFFPlayed: "..dmp.." | Wins: "..dmw.." | Ratio: "..dmr.."%",thePlayer,255,255,255,true)
  708.         outputChatBox("#00AAFF# [DD] #FFFFFFPlayed: "..ddp.." | Wins: "..ddw.." | Ratio: "..ddr.."%",thePlayer,255,255,255,true)
  709.         outputChatBox("#00AAFF# #FFFFFFCash: $"..c.." | Hunters: "..h.." | Map Buys: "..mb,thePlayer,255,255,255,true)
  710.         outputChatBox("#00AAFF# #FFFFFFPlayed Time: "..convertTime(pt),thePlayer,255,255,255,true)
  711.         ACCOUNT = 0
  712.         for i=1,#ac do
  713.             if ac[i] == 1 then
  714.                 ACCOUNT = ACCOUNT+1
  715.             end
  716.         end
  717.         outputChatBox("#00AAFF# #FFFFFFAchievements: "..ACCOUNT.."/20 | TopTimes: "..tt,thePlayer,255,255,255,true)
  718.     end
  719. end
  720. addCommandHandler("stats", showStats)
  721. addCommandHandler("st", showStats)
  722.  
  723. ------------------------------------------
  724. -- Shaders
  725. ------------------------------------------
  726.  
  727. function ShadersUpdate(Who,Shader,Data)
  728.     savePlayerData(Who,"Shader"..Shader,Data)
  729. end
  730. function ClientStarted ( who )
  731.     for i=1,2 do
  732.         local data = loadPlayerData(who,"Shader"..i)
  733.         if i == 1 then callClientFunction(who,"CarShaderToggle",who,data)
  734.         elseif i == 2 then callClientFunction(who,"WaterShaderToggle",who,data)
  735.             elseif i == 3 then callClientFunction(who,"ShineShaderToogle",who,data)
  736.             elseif i == 4 then callClientFunction(who,"ContrastShaderToggle",who,data)
  737.             elseif i == 5 then callClientFunction(who,"SnowShaderToggle",who,data)
  738.             elseif i == 6 then callClientFunction(who,"GoldShaderToggle",who,data)
  739.             elseif i == 7 then callClientFunction(who,"SkidmarksShaderToggle",who,data)
  740.         end
  741.     end
  742. end
  743.  
  744. ------------------------------------------
  745. -- SPD GPD
  746. ------------------------------------------
  747. addCommandHandler("spd",
  748. function(player,command,toplayername,datatype,amount)
  749.     if hasObjectPermissionTo ( player, "function.kickPlayer", false ) then
  750.         if (toplayername) and (datatype) and (amount) then
  751.             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
  752.                 if (findPlayerByName (toplayername)) then
  753.                     toplayer = findPlayerByName (toplayername)
  754.                     savePlayerData(toplayer,datatype,amount)
  755.                     outputChatBox ("#00AAFF# #FFFFFFsetPlayerData: " .. getPlayerName(toplayer) .. " #FF0000|#FFFFFF Player's #00AAFF" .. datatype .. "#FFFFFF Has Been Set To: #00AAFF" .. amount, player,255,0,0,true)
  756.                     outputChatBox ("#00AAFF# #FFFFFF" .. getPlayerName (player) .. " #FFFFFFHas Set Your #ABCDEF" .. datatype .."#FFFFFF To: #00AAFF" .. amount, toplayer,255,0,0,true)
  757.                     local playerCash = loadPlayerData(toplayer,"cash")
  758.                     local playerLevel = loadPlayerData(toplayer,"level")
  759.                     local thePlayer = toplayer
  760.                     scoreboardRefresh(thePlayer)
  761.                 end
  762.             else
  763.                 outputChatBox ("#00AAFF# #FF0000ERROR! #FFFFFFDatatype: cash/mapsWonDD/mapsPlayedDD/mapsWonDM/mapsPlayedDM/playedTime/hunters/mapBuys",player,255,255,255,true)
  764.             end
  765.         else
  766.         outputChatBox ("#00AAFF# #FF0000ERROR!#FFFFFF Syntax: /setPlayerData [playername] [datatype] [new_amount]",player,255,255,255,true)
  767.         end
  768.     else
  769.     end
  770. end)
  771.  
  772. addCommandHandler("gpd",
  773. function(player,command,toplayername,datatype)
  774.     if hasObjectPermissionTo ( player, "function.kickPlayer", false ) then
  775.         if (toplayername) and (datatype) then
  776.             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     
  777.                 if (findPlayerByName (toplayername)) then
  778.                     toplayer = findPlayerByName (toplayername)
  779.                     local amount = loadPlayerData(toplayer,datatype)
  780.                     outputChatBox ("#00AAFF# #FFFFFFgetPlayerData: " .. getPlayerName(toplayer) .. " #FF0000|#FFFFFF " .. datatype .."#FFFFFF: #00AAFF" .. amount,player,255,255,255,true)
  781.                 end
  782.             else
  783.                 outputChatBox ("#00AAFF# #FF0000ERROR! #FFFFFFDatatype: cash/mapsWonDD/mapsPlayedDD/mapsWonDM/mapsPlayedDM/playedTime/hunters/mapBuys",player,255,255,255,true)
  784.             end
  785.         else
  786.         outputChatBox ("#00AAFF# #FF0000ERROR!#FFFFFF Syntax: /getPlayerData [playername] [datatype]",player,255,255,255,true)
  787.         end
  788.     end
  789. end)
  790.  
  791.  
  792. ------------------------------------------
  793. -- loadStats
  794. ------------------------------------------
  795. function loadStats(thePlayer,whoask)
  796.                  --local totalReactionTests = tonumber(loadPlayerData(thePlayer,"totalReactionTests"))
  797.     --local bestReactionTime = tonumber(loadPlayerData(thePlayer,"bestReactionTime"))
  798.     local playerCash = tonumber(loadPlayerData(thePlayer,"cash"))
  799.     setElementData(thePlayer,"Money","$"..playerCash)
  800.     local mapsWonDD = tonumber(loadPlayerData(thePlayer,"mapsWonDD"))
  801.     local mapsPlayedDD = tonumber(loadPlayerData(thePlayer,"mapsPlayedDD"))
  802.     local mapsWonDM = tonumber(loadPlayerData(thePlayer,"mapsWonDM"))
  803.     local mapsPlayedDM = tonumber(loadPlayerData(thePlayer,"mapsPlayedDM"))
  804.                  local totalBets = tonumber(loadPlayerData(thePlayer,"totalBets"))
  805.     local totalBetsEarned = tonumber(loadPlayerData(thePlayer,"totalBetsEarned"))
  806.     local totalBetsWon = tonumber(loadPlayerData(thePlayer,"totalBetsWon"))
  807.     ------ playedTime
  808.         local PlayerCheckTime = getTickCount ()
  809.         local PlayerTodayTime = math.floor((PlayerCheckTime - getElementData(thePlayer,"joinTime"))/1000)
  810.         local PlayerOldTime = loadPlayerData(thePlayer,"playedTime")
  811.         savePlayerData(thePlayer,"playedTime", PlayerOldTime + PlayerTodayTime)
  812.         CheckAchievement(thePlayer,6)
  813.         setElementData(thePlayer,"joinTime", PlayerCheckTime)
  814.     ------
  815.     local playedTime = PlayerOldTime + PlayerTodayTime
  816.     local hunters = tonumber(loadPlayerData(thePlayer,"hunters"))  
  817.     local mapBuys = tonumber(loadPlayerData(thePlayer,"mapBuys"))
  818.     AC = {}
  819.     for i=1,15 do
  820.         AC[i] = tonumber(loadPlayerData(thePlayer,"ac"..i))
  821.     end
  822.     local toptimes = tonumber(loadPlayerData(thePlayer,"TopTimes"))
  823.     --[[UData = {}
  824.     for j=1,20 do
  825.         UData[j] = loadPlayerData(thePlayer,"ud"..j)
  826.     end]]--
  827.    
  828.    
  829.     local winRatioDD = 0
  830.     local winRatioDM = 0
  831.     if mapsPlayedDD == 0 and mapsWonDD == 0 then
  832.         winRatioDD = 0
  833.     elseif mapsPlayedDD ~= 0 and mapsWonDD == 0 then
  834.         winRatioDD = 0
  835.     elseif mapsPlayedDD ~= 0 and mapsWonDD ~= 0 then
  836.         winRatioDD = math.round(((100/mapsPlayedDD)*mapsWonDD),2)
  837.     elseif mapsWonDD > mapsPlayedDD then
  838.         winRatioDD = 0
  839.     end
  840.     if mapsPlayedDM == 0 and mapsWonDM == 0 then
  841.         winRatioDM = 0
  842.     elseif mapsPlayedDM ~= 0 and mapsWonDM == 0 then
  843.         winRatioDM = 0
  844.     elseif mapsPlayedDM ~= 0 and mapsWonDM ~= 0 then
  845.         winRatioDM = math.round(((100/mapsPlayedDM)*mapsWonDM),2)
  846.     elseif mapsWonDM > mapsPlayedDM then
  847.         winRatioDM = 0
  848.     end
  849.     callClientFunction(whoask, "refreshPanelData", thePlayer ,playerCash, mapsWonDD, mapsPlayedDD, winRatioDD, mapsWonDM, mapsPlayedDM, winRatioDM, playedTime, hunters, mapBuys, AC, toptimes, totalBets, totalBetsEarned, totalBetsWon)
  850. end
  851.  
  852. function loadPlayerStats(thePlayer)
  853.     local playerCash = tonumber(loadPlayerData(thePlayer,"cash"))
  854.     setElementData(thePlayer,"Money","$"..playerCash)
  855.     local mapsWonDD = tonumber(loadPlayerData(thePlayer,"mapsWonDD"))
  856.     local mapsPlayedDD = tonumber(loadPlayerData(thePlayer,"mapsPlayedDD"))
  857.     local mapsWonDM = tonumber(loadPlayerData(thePlayer,"mapsWonDM"))
  858.     local mapsPlayedDM = tonumber(loadPlayerData(thePlayer,"mapsPlayedDM"))
  859.                  local totalBets = tonumber(loadPlayerData(thePlayer,"totalBets"))
  860.     local totalBetsEarned = tonumber(loadPlayerData(thePlayer,"totalBetsEarned"))
  861.     local totalBetsWon = tonumber(loadPlayerData(thePlayer,"totalBetsWon"))
  862.     local playedTime = tonumber(loadPlayerData(thePlayer,"playedTime"))
  863.     local hunters = tonumber(loadPlayerData(thePlayer,"hunters"))  
  864.     local mapBuys = tonumber(loadPlayerData(thePlayer,"mapBuys"))  
  865.     AC = {}
  866.     for i=1,15 do
  867.         local name = "ac"..i
  868.         AC[i] = tonumber(loadPlayerData(thePlayer,name))
  869.     end
  870.     local toptimes = tonumber(loadPlayerData(thePlayer,"TopTimes"))
  871.    
  872.     local winRatioDD = 0
  873.     local winRatioDM = 0
  874.     if mapsPlayedDD == 0 and mapsWonDD == 0 then
  875.         winRatioDD = 0
  876.     elseif mapsPlayedDD ~= 0 and mapsWonDD == 0 then
  877.         winRatioDD = 0
  878.     elseif mapsPlayedDD ~= 0 and mapsWonDD ~= 0 then
  879.         winRatioDD = math.round(((100/mapsPlayedDD)*mapsWonDD),2)
  880.     elseif mapsWonDD > mapsPlayedDD then
  881.         winRatioDD = 0
  882.     end
  883.     if mapsPlayedDM == 0 and mapsWonDM == 0 then
  884.         winRatioDM = 0
  885.     elseif mapsPlayedDM ~= 0 and mapsWonDM == 0 then
  886.         winRatioDM = 0
  887.     elseif mapsPlayedDM ~= 0 and mapsWonDM ~= 0 then
  888.         winRatioDM = math.round(((100/mapsPlayedDM)*mapsWonDM),2)
  889.     elseif mapsWonDM > mapsPlayedDM then
  890.         winRatioDM = 0
  891.     end
  892.     return playerCash, mapsWonDD, mapsPlayedDD, winRatioDD, mapsWonDM, mapsPlayedDM, winRatioDM, playedTime, hunters, mapBuys, AC, toptimes, totalBets, totalBetsEarned, totalBetsWon
  893. end
  894.  
  895. --[[function NewUserDataFromPanel(ud,thePlayer)
  896.     for i=1,20 do
  897.         savePlayerData (thePlayer,"ud"..i,ud[i])
  898.     end
  899. end
  900.  
  901. function getUserStats(whoask,who)
  902.     UData = {}
  903.     for j=1,20 do
  904.         UData[j] = loadPlayerData(who,"ud"..j)
  905.     end
  906.     callClientFunction(whoask,"UserStats",UData)
  907. end]]--
  908. ------------------------------------------
  909. -- Load & Save Data
  910. ------------------------------------------
  911. function loadPlayerData (player,datatype)
  912.   local playerSerial = getPlayerSerial (player)
  913.   if (playerSerial) then
  914.     local root = xmlLoadFile ("DataBase.xml")
  915.     if (root) then
  916.       local usersNode = xmlFindChild (root,"user",0)
  917.       if (usersNode) then
  918.         local playerRootNode = xmlFindChild (usersNode,"SERIAL_" .. playerSerial,0)
  919.         if not (playerRootNode == false) then
  920.           local playerData = xmlNodeGetAttribute (playerRootNode,datatype)
  921.           if (playerData) then
  922.             xmlUnloadFile (root)
  923.             --outputDebugString("---- LoadD: "..getPlayerName(player).."   ,   "..datatype.."   ,   "..playerData)
  924.             return playerData
  925.           else
  926.             xmlNodeSetAttribute (playerRootNode,datatype,0)
  927.             xmlSaveFile (root)
  928.             xmlUnloadFile (root)
  929.             --outputDebugString("---- LoadD: "..getPlayerName(player).."   ,   "..datatype.."   ,   0")
  930.             return 0       
  931.           end
  932.         else
  933.           local playerRootNode = xmlCreateChild (usersNode,"SERIAL_" .. playerSerial)
  934.           xmlNodeSetAttribute (playerRootNode,datatype,0)
  935.           xmlSaveFile (root)
  936.           xmlUnloadFile (root)
  937.           --outputDebugString("---- LoadD: "..getPlayerName(player).."   ,   "..datatype.."   ,   0")
  938.           return 0
  939.         end
  940.       end
  941.     end
  942.   end
  943. end
  944.  
  945. function savePlayerData (player,datatype,newvalue)
  946.   local playerSerial = getPlayerSerial (player)
  947.   if (playerSerial) then
  948.     local root = xmlLoadFile ("DataBase.xml")
  949.     if (root) then
  950.       local usersNode = xmlFindChild (root,"user",0)
  951.       if (usersNode) then
  952.         local playerRootNode = xmlFindChild (usersNode,"SERIAL_" .. playerSerial,0)
  953.         if not (playerRootNode == false) then
  954.           local newNodeValue = xmlNodeSetAttribute (playerRootNode,datatype,newvalue)
  955.           xmlSaveFile (root)
  956.           xmlUnloadFile (root)
  957.           --outputDebugString("---- SaveD: "..getPlayerName(player).."   ,   "..datatype.."   ,   "..newvalue)
  958.           return newNodeValue
  959.         else
  960.           local playerRootNode = xmlCreateChild (usersNode,"SERIAL_" .. playerSerial)
  961.           local newNodeValue = xmlNodeSetAttribute (playerRootNode,datatype,newvalue)
  962.           xmlSaveFile (root)
  963.           xmlUnloadFile (root)
  964.           --outputDebugString("---- SaveD: "..getPlayerName(player).."   ,   "..datatype.."   ,   "..newvalue)
  965.           return newNodeValue
  966.         end
  967.       end
  968.     end
  969.   end
  970. end
  971. ------------------------------------------
  972. -- Achievementy
  973. ------------------------------------------
  974.  
  975.  
  976. function CheckAchievement(thePlayer,achiev)
  977.     local name = "ac"..achiev
  978.     local LockedUnlocked = tonumber(loadPlayerData(thePlayer,name))
  979.     if LockedUnlocked == 0 then
  980.         if achiev == 1 then -- 1st win
  981.             local mapsWonDD = tonumber(loadPlayerData(thePlayer,"mapsWonDD"))
  982.             local mapsWonDM = tonumber(loadPlayerData(thePlayer,"mapsWonDM"))
  983.             if mapsWonDD > 0 or mapsWonDM > 0 then
  984.                 unlockedAC(thePlayer,achiev)
  985.             end
  986.         elseif achiev == 2 then -- 1st hunter
  987.             local hunters = tonumber(loadPlayerData(thePlayer,"hunters"))
  988.             if hunters > 0 then
  989.                 unlockedAC(thePlayer,achiev)
  990.             end
  991.         elseif achiev == 3 then -- 300+ wins
  992.             local mapsWonDD = tonumber(loadPlayerData(thePlayer,"mapsWonDD"))
  993.             local mapsWonDM = tonumber(loadPlayerData(thePlayer,"mapsWonDM"))
  994.             if mapsWonDD + mapsWonDM >= 300 then
  995.                 unlockedAC(thePlayer,achiev)
  996.             end
  997.         elseif achiev == 4 then -- 1000+wins
  998.             local mapsWonDD = tonumber(loadPlayerData(thePlayer,"mapsWonDD"))
  999.             local mapsWonDM = tonumber(loadPlayerData(thePlayer,"mapsWonDM"))
  1000.             if mapsWonDD + mapsWonDM >= 1000 then
  1001.                 unlockedAC(thePlayer,achiev)
  1002.             end
  1003.         elseif achiev == 5 then -- 2000 played
  1004.             local mapsPlayedDD = tonumber(loadPlayerData(thePlayer,"mapsPlayedDD"))
  1005.             local mapsPlayedDM = tonumber(loadPlayerData(thePlayer,"mapsPlayedDM"))
  1006.             if mapsPlayedDD + mapsPlayedDM >= 2000 then
  1007.                 unlockedAC(thePlayer,achiev)
  1008.             end
  1009.         elseif achiev == 6 then -- 7days
  1010.             local playedTime = tonumber(loadPlayerData(thePlayer,"playedTime"))
  1011.             if playedTime >= 604800 then
  1012.                 unlockedAC(thePlayer,achiev)
  1013.             end
  1014.         elseif achiev == 7 then -- 50+ hunters
  1015.             local hunters = tonumber(loadPlayerData(thePlayer,"hunters"))
  1016.             if hunters >= 50 then
  1017.                 unlockedAC(thePlayer,achiev)
  1018.             end
  1019.         elseif achiev == 8 then--beat TT
  1020.             local toptimes = tonumber(loadPlayerData(thePlayer,"TopTimes"))
  1021.             if toptimes > 0 then
  1022.                 unlockedAC(thePlayer,achiev)
  1023.             end
  1024.         elseif achiev == 9 then-- 5x in a row
  1025.             if LastWinners[1] == thePlayer and LastWinners[2] == thePlayer and LastWinners[3] == thePlayer and LastWinners[4] == thePlayer and LastWinners[5] == thePlayer then
  1026.                 unlockedAC(thePlayer,achiev)
  1027.             end
  1028.         elseif achiev == 10 then --3x DM
  1029.             if LastWinnersDM[1] == thePlayer and LastWinnersDM[2] == thePlayer and LastWinnersDM[3] == thePlayer then
  1030.                 unlockedAC(thePlayer,achiev)
  1031.             end
  1032.         elseif achiev == 11 then --3x DD
  1033.             if LastWinnersDD[1] == thePlayer and LastWinnersDD[2] == thePlayer and LastWinnersDD[3] == thePlayer then
  1034.                 unlockedAC(thePlayer,achiev)
  1035.             end
  1036.         elseif achiev == 13 then --10x mapbuy
  1037.             local mapBuys = tonumber(loadPlayerData(thePlayer,"mapBuys"))
  1038.             if mapBuys >= 10 then
  1039.                 unlockedAC(thePlayer,achiev)
  1040.             end        
  1041.         elseif achiev == 14 then --50 toptimow
  1042.             local toptimes = tonumber(loadPlayerData(thePlayer,"TopTimes"))
  1043.             if toptimes >= 50 then
  1044.                 unlockedAC(thePlayer,achiev)
  1045.             end
  1046.         elseif achiev == 15 then --1mln
  1047.             local playerCash = tonumber(loadPlayerData(thePlayer,"cash"))
  1048.             if playerCash >= 1000000 then
  1049.                 unlockedAC(thePlayer,achiev)
  1050.             end
  1051.         elseif achiev == 16 then --2mln
  1052.             local playerCash = tonumber(loadPlayerData(thePlayer,"cash"))
  1053.             if playerCash >= 2000000 then
  1054.                 unlockedAC(thePlayer,achiev)
  1055.                                                   end
  1056.         elseif achiev == 17 then -- 150+ hunters
  1057.             local hunters = tonumber(loadPlayerData(thePlayer,"hunters"))
  1058.             if hunters >= 150 then
  1059.                 unlockedAC(thePlayer,achiev)
  1060.             end        
  1061.         elseif achiev == 18 then --150 toptimow
  1062.             local toptimes = tonumber(loadPlayerData(thePlayer,"TopTimes"))
  1063.             if toptimes >= 150 then
  1064.                 unlockedAC(thePlayer,achiev)   
  1065.             end
  1066.         end
  1067.     else
  1068.         if achiev == 15 then
  1069.             local playerCash = tonumber(loadPlayerData(thePlayer,"cash"))
  1070.             if playerCash < 1000000 then
  1071.                 savePlayerData(thePlayer,"ac"..achiev,0)
  1072.             end
  1073.         elseif achiev == 16 then
  1074.             local playerCash = tonumber(loadPlayerData(thePlayer,"cash"))
  1075.             if playerCash < 2000000 then
  1076.                 savePlayerData(thePlayer,"ac"..achiev,0)
  1077.             end
  1078.         elseif achiev == 13 then
  1079.             local mapBuys = tonumber(loadPlayerData(thePlayer,"mapBuys"))
  1080.             if mapBuys <= 10 then
  1081.                 unlockedAC(thePlayer,achiev)
  1082.             end
  1083.         end
  1084.     end
  1085. end
  1086.  
  1087. function unlockedAC(thePlayer,achiev)
  1088.     callClientFunction(thePlayer,"unlockAChievement", achiev)
  1089.     exports.box:outputMiniBox("#FFFFFFAC: #00AAFF"..getPlayerName(thePlayer).."#FFFFFF Has Unlocked An Achievement!",getRootElement())
  1090.     exports.box:outputMiniBox("#FFFFFFAC: #00AAFF"..AchievementsName[achiev],getRootElement())
  1091.     savePlayerData(thePlayer,"ac"..achiev,1)
  1092. end
  1093.  
  1094. addEvent("onPlayerToptimeImprovement",true)
  1095. addEventHandler("onPlayerToptimeImprovement",getRootElement(),
  1096. function (player)
  1097.     local totalToptimes = tonumber(loadPlayerData(source,"TopTimes"))
  1098.     savePlayerData(source,"TopTimes",totalToptimes+1)
  1099.     CheckAchievement(source,8)
  1100.     CheckAchievement(source,14)
  1101. end)
  1102. ------------------------------------------
  1103. -- Join - PlayedTime
  1104. ------------------------------------------
  1105. function PlayedTimeJoin()
  1106.     local thePlayer = source
  1107.     local PlayerJoinTime = getTickCount ()
  1108.     setElementData(thePlayer,"joinTime", PlayerJoinTime)
  1109. end
  1110. addEventHandler ("onPlayerJoin",getRootElement(), PlayedTimeJoin)
  1111.  
  1112. function PlayedTimeQuit()
  1113.     local thePlayer = source
  1114.     local PlayerQuitTime = getTickCount ()
  1115.     local PlayerTodayTime = math.floor((PlayerQuitTime - getElementData(thePlayer,"joinTime"))/1000)
  1116.     local PlayerOldTime = loadPlayerData(thePlayer,"playedTime")
  1117.     savePlayerData(thePlayer,"playedTime", PlayerOldTime + PlayerTodayTime)
  1118. end
  1119. addEventHandler ("onPlayerQuit",getRootElement(), PlayedTimeQuit)
  1120.  
  1121. function convertTime(timeinseconds)
  1122.     Days = math.floor(timeinseconds/86400)
  1123.     timeinseconds = timeinseconds - Days*86400
  1124.     Hours =  math.floor(timeinseconds/3600)
  1125.     timeinseconds = timeinseconds - Hours*3600
  1126.     Minutes =  math.floor(timeinseconds/60)
  1127.     timeinseconds = timeinseconds - Minutes*60
  1128.     Seconds = timeinseconds
  1129.     if Days > 0 then
  1130.         Time = Days.." days "..Hours.."h "..Minutes.."m "..Seconds.."s"
  1131.     elseif Hours > 0 then
  1132.         Time = Hours.."h "..Minutes.."m "..Seconds.."s"
  1133.     elseif Minutes > 0 then
  1134.         Time = Minutes.."m "..Seconds.."s"
  1135.     else
  1136.         Time = Seconds.."s"
  1137.     end
  1138.     return Time
  1139. end
  1140.  
  1141. ------------------------------------------
  1142. -- Hunters
  1143. ------------------------------------------
  1144. function checkForHunter(number,sort,model)
  1145.     thePlayer = source
  1146.     if sort == "vehiclechange" then
  1147.         if model == 425 then
  1148.             if getElementData(thePlayer,"playerGotHunter") == false then
  1149.                 setElementData(thePlayer,"playerGotHunter",true)
  1150.                 local oldhunters = loadPlayerData(thePlayer,"hunters")
  1151.                 savePlayerData(thePlayer,"hunters", oldhunters + 1)
  1152.                 CheckAchievement(thePlayer,2)
  1153.                 CheckAchievement(thePlayer,7)
  1154.                 HunterCount = HunterCount + 1
  1155.             end
  1156.         end
  1157.     end
  1158. end
  1159. addEventHandler("onPlayerPickUpRacePickup",getRootElement(),checkForHunter)
  1160.  
  1161. ------------------------------------------
  1162. -- Mapy
  1163. ------------------------------------------
  1164. function buyMap(thePlayer,mapName)
  1165.     if mapIsAlreadySet == false then
  1166.         if not (mapName == "") then
  1167.             local playerCash = tonumber(loadPlayerData(thePlayer,"cash"))
  1168.             if playerCash >= mapCost then
  1169.                 executeCommandHandler("pnfnsdhasd3w7432jhdsbw3ersdncsdir",thePlayer,mapName)
  1170.                 savePlayerData(thePlayer,"cash",playerCash-mapCost)
  1171.                 exports.box:outputMiniBox("#FFFFFF[MAP]: "..getPlayerName(thePlayer).."#ABCDEF Has Bought a Next Map!",getRootElement())
  1172.                 exports.box:outputMiniBox("#FFFFFF[NEXTMAP]: #ABCDEF "..mapName,getRootElement())
  1173.                 mapIsAlreadySet = thePlayer
  1174.                 local oldmapbuys = loadPlayerData(thePlayer,"mapBuys")
  1175.                 savePlayerData(thePlayer,"mapBuys", oldmapbuys + 1)
  1176.                 CheckAchievement(thePlayer,13)
  1177.                 scoreboardRefresh(thePlayer)
  1178.             else
  1179.                 outputChatBox("#00AAFF# #FFFFFFYou Don't Have Enough Money To Set a Map!",thePlayer,255,255,255,true)
  1180.             end
  1181.         else
  1182.             outputChatBox("#00AAFF# #FFFFFFPlease Select a Map From The List First!",thePlayer,255,255,255,true)
  1183.         end
  1184.     else
  1185.         outputChatBox("#00AAFF# #FFFFFFA Map is Already Set At The Moment! Please Try Again Later.",thePlayer,255,255,255,true)
  1186.     end
  1187. end
  1188.  
  1189. function unbuyMap(thePlayer)
  1190.     if mapIsAlreadySet ~= false then
  1191.             if mapIsAlreadySet == thePlayer then
  1192.                 executeCommandHandler("pnfnsdhasd3w7432jhdsbw3ersdncsdir",thePlayer,nil)
  1193.                 local playerCash = tonumber(loadPlayerData(thePlayer,"cash"))
  1194.                 savePlayerData(thePlayer,"cash",playerCash+(mapCost/4)*3)
  1195.                 exports.box:outputMiniBox("#FFFFFF[NEXTMAP]: "..getPlayerName(thePlayer).."#ABCDEF Has Unbought a Next Map!",getRootElement())
  1196.                 mapIsAlreadySet = false
  1197.                 local oldmapbuys = loadPlayerData(thePlayer,"mapBuys")
  1198.                 savePlayerData(thePlayer,"mapBuys", oldmapbuys - 1)
  1199.                 CheckAchievement(thePlayer,13)
  1200.                 scoreboardRefresh(thePlayer)
  1201.             else
  1202.                 outputChatBox("#00AAFF# #FFFFFFYou Didn't Buy That Map!",thePlayer,255,255,255,true)
  1203.             end
  1204.     else
  1205.         outputChatBox("#00AAFF# #FFFFFFNo Map Has Been Bought!",thePlayer,255,255,255,true)
  1206.     end
  1207. end
  1208.  
  1209. function resetMapSetStatus()
  1210.     mapIsAlreadySet = false
  1211. end
  1212. addEventHandler("onMapStarting",getRootElement(),resetMapSetStatus)
  1213.  
  1214. function getServerMaps (loadList,s)
  1215.     local tableOut
  1216.     if loadList then
  1217.        
  1218.         tableOut = {}
  1219.         -- local deletedMaps = {}
  1220.         local gamemodes = {}
  1221.         gamemodes = call(getResourceFromName("mapmanager"), "getGamemodes")
  1222.         for id,gamemode in ipairs (gamemodes) do
  1223.             tableOut[id] = {}
  1224.             tableOut[id].name = getResourceInfo(gamemode, "name") or getResourceName(gamemode)
  1225.             tableOut[id].resname = getResourceName(gamemode)
  1226.             tableOut[id].maps = {}
  1227.             local maps = call(getResourceFromName("mapmanager"), "getMapsCompatibleWithGamemode" , gamemode)
  1228.             for _,map in ipairs (maps) do
  1229.                 table.insert(tableOut[id]["maps"] ,{name = getResourceInfo(map, "name") or getResourceName(map), resname = getResourceName(map)})
  1230.             end
  1231.             table.sort(tableOut[id]["maps"], sortCompareFunction)
  1232.         end
  1233.         table.sort((tableOut), sortCompareFunction)
  1234.         table.insert(tableOut, {name = "no gamemode", resname = "no gamemode", maps = {}})
  1235.         local countGmodes = #tableOut
  1236.         local maps = call(getResourceFromName("mapmanager"), "getMapsCompatibleWithGamemode")
  1237.         for id,map in ipairs (maps) do
  1238.             -- if fileOpen(":"..getResourceName(map).."/deleted") then
  1239.                 -- table.insert(deletedMaps ,{name = getResourceInfo(map, "name") or getResourceName(map), resname = getResourceName(map)})
  1240.             -- else
  1241.                 table.insert(tableOut[countGmodes]["maps"] ,{name = getResourceInfo(map, "name") or getResourceName(map), resname = getResourceName(map)})
  1242.             -- end
  1243.         end
  1244.         -- table.sort(deletedMaps, sortCompareFunction)
  1245.         table.sort(tableOut[countGmodes]["maps"], sortCompareFunction)
  1246.         -- table.insert(tableOut, {name = "deleted maps", resname = "deleted maps", maps = {}})
  1247.         -- local countGmodes = countGmodes + 1
  1248.         -- tableOut[countGmodes]["maps"] = deletedMaps
  1249.     end
  1250.    
  1251.     local map = call(getResourceFromName("mapmanager"), "getRunningGamemodeMap")
  1252.     local gamemode = call(getResourceFromName("mapmanager"), "getRunningGamemode")
  1253.     gamemode = gamemode and getResourceName(gamemode) or "N/A"
  1254.     map = map and getResourceName(map) or "N/A"
  1255.     callClientFunction(loadList,"loadMaps", tableOut, gamemode, map, s)
  1256. end
  1257.  
  1258. function sortCompareFunction(s1, s2)
  1259.     if type(s1) == "table" and type(s2) == "table" then
  1260.         s1, s2 = s1.name, s2.name
  1261.     end
  1262.     s1, s2 = s1:lower(), s2:lower()
  1263.     if s1 == s2 then
  1264.         return false
  1265.     end
  1266.     local byte1, byte2 = string.byte(s1:sub(1,1)), string.byte(s2:sub(1,1))
  1267.     if not byte1 then
  1268.         return true
  1269.     elseif not byte2 then
  1270.         return false
  1271.     elseif byte1 < byte2 then
  1272.         return true
  1273.     elseif byte1 == byte2 then
  1274.         return sortCompareFunction(s1:sub(2), s2:sub(2))
  1275.     else
  1276.         return false
  1277.     end
  1278. end
  1279.  
  1280. ------------------------------------------
  1281. -- giveMoney
  1282. ------------------------------------------
  1283. function giveMoney(thePlayer,CMD,targetPlayer,amount)
  1284.     if not (targetPlayer == "") then
  1285.         if tonumber(amount) then
  1286.             local playerCash = tonumber(loadPlayerData(thePlayer,"cash"))
  1287.             if tonumber(amount) > 0 then
  1288.                 if tonumber(amount) <= playerCash then
  1289.                     if (findPlayerByName(targetPlayer)) then
  1290.                         local target = findPlayerByName(targetPlayer)
  1291.                         if target ~= thePlayer then
  1292.                             local amount = math.ceil(amount)
  1293.                             local playerCash = loadPlayerData(thePlayer,"cash")
  1294.                             local targetCash = loadPlayerData(target,"cash")
  1295.                             savePlayerData(thePlayer,"cash",playerCash-tonumber(amount))
  1296.                             CheckAchievement(thePlayer,15)
  1297.                             savePlayerData(target,"cash",targetCash+tonumber(amount))
  1298.                             CheckAchievement(target,15)
  1299.                             local playerCash = loadPlayerData(thePlayer,"cash")
  1300.                             local targetCash = loadPlayerData(target,"cash")
  1301.                             scoreboardRefresh(thePlayer)
  1302.                             scoreboardRefresh(target)
  1303.                             exports.box:outputMiniBox("#FFFFFFYou Have Sent #00AAFF$"..amount.."#FFFFFF to "..getPlayerName(target).."#FFFFFF!",thePlayer)
  1304.                             exports.box:outputMiniBox("#FFFFFF"..getPlayerName(thePlayer).." #FFFFFFHas Sent You #00AAFF$"..amount.."#FFFFFF!",target)
  1305.                         else
  1306.                             outputChatBox("#00AAFF# #FFFFFFERROR! You cannot send money to yourself!",thePlayer,255,255,255,true)
  1307.                             return false
  1308.                         end
  1309.                     else
  1310.                         outputChatBox("#00AAFF# #FFFFFFERROR! The Player You Specified Does Not Exist!",thePlayer,255,255,255,true)
  1311.                         return false
  1312.                     end
  1313.                 else
  1314.                     outputChatBox("#00AAFF# #FFFFFFERROR! You Don't Have Enough Money!",thePlayer,255,255,255,true)
  1315.                     return false
  1316.                 end
  1317.             else
  1318.                 outputChatBox("#00AAFF# #FFFFFFERROR! Invalid amount! [#00AAFF"..amount.."#FFFFFF]",thePlayer,255,255,255,true)
  1319.                 return false
  1320.             end
  1321.         else
  1322.             outputChatBox("#00AAFF# #FFFFFFERROR! Please specify the amount to send!",thePlayer,255,255,255,true)
  1323.             return false
  1324.         end
  1325.     else
  1326.         outputChatBox("#00AAFF# #FFFFFFERROR! Please select a player!",thePlayer,255,255,255,true)
  1327.         return false
  1328.     end
  1329. end
  1330. addCommandHandler("givecash", giveMoney)
  1331. ------------------------------------------
  1332. -- Tops
  1333. ------------------------------------------
  1334. function getDataFromServerAndSendToClient ( thePlayer , argument)
  1335.     if ( thePlayer ) then
  1336.         if argument then
  1337.             if string.lower(argument) == "cash" then
  1338.                 local tablica = loadAllData ("cash")
  1339.                 callClientFunction(thePlayer,"SortTops","Top Cash!",tablica,thePlayer,"$","")
  1340.             elseif string.lower(argument) == "achievements" or string.lower(argument) == "ac" then
  1341.                 local tablica = loadAllData ("achievements")
  1342.                 callClientFunction(thePlayer,"SortTops","Top Achievements!",tablica,thePlayer,"","")
  1343.             elseif string.lower(argument) == "ddwins" then
  1344.                 local tablica = loadAllData ("mapsWonDD")
  1345.                 callClientFunction(thePlayer,"SortTops","Top DD wins!",tablica,thePlayer,"","")
  1346.             elseif string.lower(argument) == "dmwins" then
  1347.                 local tablica = loadAllData ("mapsWonDM")
  1348.                 callClientFunction(thePlayer,"SortTops","Top DM wins!",tablica,thePlayer,"","")
  1349.             elseif string.lower(argument) == "dds" then
  1350.                 local tablica = loadAllData ("mapsPlayedDD")
  1351.                 callClientFunction(thePlayer,"SortTops","Top Played DDs!",tablica,thePlayer,"","")
  1352.             elseif string.lower(argument) == "dms" then
  1353.                 local tablica = loadAllData ("mapsPlayedDM")
  1354.                 callClientFunction(thePlayer,"SortTops","Top Played DMs!",tablica,thePlayer,"","")
  1355.             elseif string.lower(argument) == "playedtime" or string.lower(argument) == "pt" then
  1356.                 local tablica = loadAllData ("playedTime")
  1357.                 callClientFunction(thePlayer,"SortTops","Top Played Time!",tablica,thePlayer," "," ")
  1358.             elseif string.lower(argument) == "hunters" then
  1359.                 local tablica = loadAllData ("hunters")
  1360.                 callClientFunction(thePlayer,"SortTops","Top Hunters!",tablica,thePlayer,"","")
  1361.             elseif string.lower(argument) == "mapbuys" or string.lower(argument) == "mb" then
  1362.                 local tablica = loadAllData ("mapBuys")
  1363.                 callClientFunction(thePlayer,"SortTops","Top Map Buys!",tablica,thePlayer,"","")
  1364.             elseif string.lower(argument) == "toptimes" or string.lower(argument) == "tt" then
  1365.                 local tablica = loadAllData ("TopTimes")
  1366.                 callClientFunction(thePlayer,"SortTops","Top TopTimes!",tablica,thePlayer,"","")
  1367.             elseif string.lower(argument) == "ddratio" then
  1368.                 local tablica = loadAllData ("ddratio")
  1369.                 callClientFunction(thePlayer,"SortTops","Top DD Ratio!",tablica,thePlayer,"","%")
  1370.             elseif string.lower(argument) == "dmratio" then
  1371.                 local tablica = loadAllData ("dmratio")
  1372.                 callClientFunction(thePlayer,"SortTops","Top DM Ratio!",tablica,thePlayer,"","%")
  1373.             elseif string.lower(argument) == "ddmap" then
  1374.                 local allMaps = call(getResourceFromName("mapmanager"), "getMapsCompatibleWithGamemode" , getResourceFromName("race"))
  1375.                 tablicaMap = {}
  1376.                 for i,map in ipairs(allMaps) do
  1377.                     if checkMapType(getResourceInfo(map, "name")) == 2 then
  1378.                         local mapinfo = getMapInfo(map)                
  1379.                         table.insert(tablicaMap,{pName = getResourceInfo(map, "name") or "???",dType = tonumber(mapinfo.playedCount) or 0})
  1380.                     end
  1381.                 end
  1382.                 callClientFunction(thePlayer,"SortTopsMaps","Top DD Map!",tablicaMap,thePlayer,"","")
  1383.             elseif string.lower(argument) == "dmmap" then
  1384.                 local allMaps = call(getResourceFromName("mapmanager"), "getMapsCompatibleWithGamemode" , getResourceFromName("race"))
  1385.                 tablicaMap = {}
  1386.                 for i,map in ipairs(allMaps) do
  1387.                     if checkMapType(getResourceInfo(map, "name")) == 1 then
  1388.                         local mapinfo = getMapInfo(map)                
  1389.                         table.insert(tablicaMap,{pName = getResourceInfo(map, "name") or "???",dType = tonumber(mapinfo.playedCount) or 0})
  1390.                     end
  1391.                 end
  1392.                 callClientFunction(thePlayer,"SortTopsMaps","Top DM Map!",tablicaMap,thePlayer,"","")
  1393.             else
  1394.                 outputChatBox("#00AAFF# #FFFFFFERROR! Invalid argument!",thePlayer,255,255,255,true)
  1395.                 outputChatBox("[cash,achievements,ddwins,dmwins,dds,dms,playedtime]",thePlayer,255,255,255,true)
  1396.                 outputChatBox("[hunters,mapbuys,toptimes,ddratio,dmratio,ddmap,dmmap]",thePlayer,255,255,255,true)
  1397.             end
  1398.         else
  1399.             outputChatBox ("#00AAFF# #FF0000ERROR!#FFFFFF Syntax: /top [datatype]",thePlayer,255,255,255,true)
  1400.         end
  1401.     end
  1402. end
  1403.  
  1404. function loadMapInfoAll()
  1405.     local rows = executeSQLQuery( 'SELECT * FROM ' .. getTableName() )
  1406.     g_MapInfoList = {}
  1407.     for i,row in ipairs(rows) do
  1408.         local map = getResourceFromName( row.resName )
  1409.         if map then
  1410.             local mapInfo = getMapInfo( map )
  1411.             mapInfo.playedCount = row.playedCount
  1412.             mapInfo.lastTimePlayed = row.lastTimePlayed
  1413.         end
  1414.     end
  1415. end
  1416. function getTableName(value)
  1417.     return sqlString( 'race_mapmanager_maps' )
  1418. end
  1419. function sqlString(value)
  1420.     value = tostring(value) or ''
  1421.     return "'" .. value:gsub( "(['])", "''" ) .. "'"
  1422. end
  1423. function getMapInfo( map )
  1424.     if not g_MapInfoList then
  1425.         loadMapInfoAll()
  1426.     end
  1427.     if not g_MapInfoList[map] then
  1428.         g_MapInfoList[map] = {}
  1429.     end
  1430.     local mapInfo = g_MapInfoList[map]
  1431.     if mapInfo.loadTime ~= getResourceLoadTime(map) then
  1432.         -- Reset or clear data that may change between loads
  1433.         mapInfo.loadTime = getResourceLoadTime( map )
  1434.         mapInfo.spawnPointCount = false
  1435.     end
  1436.     return mapInfo
  1437. end
  1438.  
  1439. function loadAllData (datatype)
  1440.     local root = xmlLoadFile ("DataBase.xml")
  1441.     if (root) then
  1442.         local usersNode = xmlFindChild (root,"user",0)
  1443.         if (usersNode) then
  1444.             local allPlayers = xmlNodeGetChildren(usersNode)
  1445.             allPlayersData = {}
  1446.             nrDD = 0
  1447.             nrDM = 0
  1448.             for i,data in ipairs(allPlayers) do
  1449.                 if datatype == "achievements" then
  1450.                     AchCount = 0
  1451.                     for j=1,#AchievementsName do
  1452.                         local ac = tonumber(xmlNodeGetAttribute (data,"ac"..j..""))
  1453.                         if ac == 1 then
  1454.                             AchCount = AchCount + 1
  1455.                         end
  1456.                     end
  1457.                     local playerName = xmlNodeGetAttribute (data,"playerName")
  1458.                     allPlayersData[i] = {pName = playerName or "???",dType = AchCount or 0}
  1459.                 elseif datatype == "ddratio" then
  1460.                     local played = tonumber(xmlNodeGetAttribute (data,"mapsPlayedDD")) or 0
  1461.                     local wins = tonumber(xmlNodeGetAttribute (data,"mapsWonDD")) or 0
  1462.                     local ratio = 0
  1463.                     if played == 0 and wins == 0 then
  1464.                         ratio = 0
  1465.                     elseif played ~= 0 and wins == 0 then
  1466.                         ratio = 0
  1467.                     elseif played ~= 0 and wins ~= 0 then
  1468.                         ratio = (100/played)*wins
  1469.                     elseif wins > played then
  1470.                         ratio = 0
  1471.                     end
  1472.                     if played >= 100 then
  1473.                         nrDD = nrDD + 1
  1474.                         local playerName = xmlNodeGetAttribute (data,"playerName")
  1475.                         allPlayersData[nrDD] = {pName = playerName or "???",dType = ratio or 0}
  1476.                     end
  1477.                 elseif datatype == "dmratio" then
  1478.                     local played = tonumber(xmlNodeGetAttribute (data,"mapsPlayedDM")) or 0
  1479.                     local wins = tonumber(xmlNodeGetAttribute (data,"mapsWonDM")) or 0
  1480.                     local ratio = 0
  1481.                     if played == 0 and wins == 0 then
  1482.                         ratio = 0
  1483.                     elseif played ~= 0 and wins == 0 then
  1484.                         ratio = 0
  1485.                     elseif played ~= 0 and wins ~= 0 then
  1486.                         ratio = (100/played)*wins
  1487.                     elseif wins > played then
  1488.                         ratio = 0
  1489.                     end
  1490.                     if played >= 100 then
  1491.                         nrDM = nrDM + 1
  1492.                         local playerName = xmlNodeGetAttribute (data,"playerName")
  1493.                         allPlayersData[nrDM] = {pName = playerName or "???",dType = ratio or 0}
  1494.                     end
  1495.                 else
  1496.                     local playerData = tonumber(xmlNodeGetAttribute (data,datatype))
  1497.                     local playerName = xmlNodeGetAttribute (data,"playerName")
  1498.                     allPlayersData[i] = {pName = playerName or "???",dType = playerData or 0}
  1499.                 end
  1500.             end    
  1501.             xmlUnloadFile (root)   
  1502.             return allPlayersData
  1503.         end
  1504.     end
  1505. end
  1506.  
  1507.  
  1508. ------------------------------------------
  1509. -- Kick All
  1510. ------------------------------------------
  1511. function kickAllPlayers ( sourcePlayer, commandname )
  1512.     if ( hasObjectPermissionTo ( sourcePlayer, "function.kickPlayer" ) ) then
  1513.         outputChatBox("#00AAFF# #FFFFFFScript restarting... Auto-Reconnecting in 5 seconds!", gRoot, 255,255,255,true)
  1514.         setTimer(function()
  1515.             for i,pla in ipairs(getElementsByType("player")) do
  1516.                 redirectPlayer (  pla, "213.189.52.40",22069)
  1517.             end
  1518.         end, 5000,1)
  1519.     end
  1520. end
  1521. addCommandHandler ( "kickAllPlayers", kickAllPlayers )
  1522. ------------------------------------------
  1523. -- Triggering
  1524. ------------------------------------------
  1525. function callClientFunction(client, funcname, ...)
  1526.     local arg = { ... }
  1527.     if (arg[1]) then
  1528.         for key, value in next, arg do
  1529.             if (type(value) == "number") then arg[key] = tostring(value) end
  1530.         end
  1531.     end
  1532.     triggerClientEvent(client, "onServerCallsClientFunction", getResourceRootElement(getThisResource()), funcname, unpack(arg or {}))
  1533. end
  1534. function callServerFunction(funcname, ...)
  1535.     local arg = { ... }
  1536.     if (arg[1]) then
  1537.         for key, value in next, arg do arg[key] = tonumber(value) or value end
  1538.     end
  1539.     loadstring("return "..funcname)()(unpack(arg))
  1540. end
  1541. addEvent("onClientCallsServerFunction", true)
  1542. addEventHandler("onClientCallsServerFunction", getResourceRootElement(getThisResource()) , callServerFunction)
  1543.  
  1544. function math.round(number, decimals, method)
  1545.     decimals = decimals or 0
  1546.     local factor = 10 ^ decimals
  1547.     if (method == "ceil" or method == "floor") then return math[method](number * factor) / factor
  1548.     else return tonumber(("%."..decimals.."f"):format(number)) end
  1549.                             end
  1550.        
  1551.  
  1552.  
  1553. --------------------------------------------
  1554. -- Get alive and dead players by their STATE
  1555. --------------------------------------------
  1556. function getAliveRacePlayers()
  1557.     local alivePlayers = 0
  1558.     for index,player in ipairs(getElementsByType("player")) do
  1559.         if getElementData(player,"state") == "alive" then
  1560.             alivePlayers = alivePlayers + 1
  1561.         end
  1562.     end
  1563.     return alivePlayers
  1564. end
  1565.  
  1566.  
  1567. function getDeadRacePlayers()
  1568.     local deadPlayers = 0
  1569.     for index,player in ipairs(getElementsByType("player")) do
  1570.         if getElementData(player,"state") == "dead" then
  1571.             deadPlayers = deadPlayers + 1
  1572.         end
  1573.     end
  1574.     return deadPlayers
  1575. end
  1576.  
  1577. ------------------------------------------
  1578. -- Nick
  1579. ------------------------------------------
  1580. addEventHandler ("onPlayerJoin",getRootElement(),
  1581. function()
  1582.     local playerName = getPlayerName(source)
  1583.     savePlayerData(source,"playerName",string.gsub(playerName,"#%x%x%x%x%x%x", ""))
  1584. end)
  1585. addEventHandler("onPlayerChangeNick",getRootElement(),
  1586. function (olnick,newnick)
  1587.    
  1588.     savePlayerData(source,"playerName",string.gsub(newnick,"#%x%x%x%x%x%x", ""))
  1589. end)
  1590.  
  1591. --------------------
  1592. --Team Colors Nick--
  1593. --------------------
  1594.  
  1595. function addTeamColor(player)
  1596.     local playerTeam = getPlayerTeam ( player )
  1597.     if ( playerTeam ) then
  1598.         local r,g,b = getTeamColor ( playerTeam )
  1599.         local n1 = toHex(r)
  1600.         local n2 = toHex(g)
  1601.         local n3 = toHex(b)
  1602.         if r <= 16 then n1 = "0"..n1 end
  1603.         if g <= 16 then n2 = "0"..n2 end
  1604.         if b <= 16 then n3 = "0"..n3 end
  1605.         return "#"..n1..""..n2..""..n3..""..getPlayerNametagText(player)
  1606.     else
  1607.         return getPlayerNametagText(player)
  1608.     end
  1609. end
  1610.  
  1611. function toHex ( n )
  1612.     local hexnums = {"0","1","2","3","4","5","6","7",
  1613.                      "8","9","A","B","C","D","E","F"}
  1614.     local str,r = "",n%16
  1615.     if n-r == 0 then str = hexnums[r+1]
  1616.     else str = toHex((n-r)/16)..hexnums[r+1] end
  1617.     return str
  1618. end
  1619.  
  1620. ------------------------------------------
  1621. -- PlayerNameFunctions
  1622. ------------------------------------------
  1623. function getPlayerNameWithoutColorCode (who)
  1624.     local name = getPlayerName(who)
  1625.     local name = string.gsub(name,'#%x%x%x%x%x%x',"")
  1626.     return name
  1627. end
  1628.  
  1629. function getPlayerFromNameWithoutColorCode (name)
  1630.     for i,pla in ipairs(getElementsByType("player")) do
  1631.         if getPlayerNameWithoutColorCode (pla) == name then
  1632.             return pla
  1633.         end
  1634.     end
  1635. end
  1636.  
  1637. function findPlayerByName (name)
  1638.     local player = getPlayerFromName(name)
  1639.     if player then return player end
  1640.     for i, player in ipairs(getElementsByType("player")) do
  1641.         if string.find(string.gsub(getPlayerName(player):lower(),"#%x%x%x%x%x%x", ""), name:lower(), 1, true) then
  1642.             return player
  1643.         end
  1644.     end
  1645. return false
  1646. end
  1647.  
  1648. -- Total bets
  1649. function totalBetsAdd(thePlayer)
  1650.     local totalBets = tonumber(loadPlayerData(thePlayer,"totalBets"))
  1651.     savePlayerData(thePlayer,"totalBets",totalBets+1)
  1652. end
  1653.  
  1654.  
  1655. -- Total bets won
  1656. function totalBetsWonAdd(thePlayer)
  1657.     local totalBetsWon = tonumber(loadPlayerData(thePlayer,"totalBetsWon"))
  1658.     savePlayerData(thePlayer,"totalBetsWon",totalBetsWon+1)
  1659. end
  1660.  
  1661.  
  1662. -- Total bets earned
  1663. function totalBetsEarnedAdd(thePlayer,addAmount)
  1664.     local totalBetsEarned = tonumber(loadPlayerData(thePlayer,"totalBetsEarned"))
  1665.     savePlayerData(thePlayer,"totalBetsEarned",totalBetsEarned+addAmount)
  1666. end
  1667.  
  1668. -----------------
  1669. -- Betting system
  1670. -----------------
  1671.  
  1672. function createNewBet(thePlayer,toPlayer,newAmount,oldAmount,betState)
  1673.     if getPlayerCount() >= minPlayers then
  1674.         if bettingEnabled == true then
  1675.             if (betState == 0) then
  1676.                 if (toPlayer) then
  1677.                     if (newAmount) then
  1678.                         local newAmount = tonumber(math.ceil(newAmount))
  1679.                         if (newAmount >= 1) then
  1680.                             --local playerLevel = tonumber(loadPlayerData(thePlayer,"level"))
  1681.                             local playerCash = tonumber(loadPlayerData(thePlayer,"cash"))
  1682.                             local maxBet = playerCash*betPerCash
  1683.                             if (findPlayerByName(toPlayer)) then
  1684.                                 local toPlayerName = findPlayerByName(toPlayer)
  1685.                                 if (newAmount <= playerCash) then
  1686.                                     if newAmount <= maxBet then
  1687.                                         callClientFunction(thePlayer,"addNewBet",toPlayerName,newAmount)
  1688.                                         savePlayerData(thePlayer,"cash",playerCash-newAmount)
  1689.                                         scoreboardRefresh(thePlayer)
  1690.                                         totalBetsAdd(thePlayer)
  1691.                                         --progressBarUpdate(thePlayer)
  1692.                                         --outputChatBox("#00FF00* #FFFFFFYou have placed your bet on "..getPlayerName(toPlayerName).."#FFFFFF for #ABCDEF$"..newAmount.."#FFFFFF!",thePlayer,255,255,255,true)
  1693.                                         exports.box:outputMiniBox("#0095FF* #FFFFFF"..getPlayerName(thePlayer).."#FFFFFF has placed a bet on "..getPlayerName(toPlayerName).."#FFFFFF for #ABCDEF$"..newAmount.."#FFFFFF!",getRootElement())
  1694.                                     elseif newAmount > maxBet then
  1695.                                         exports.box:outputMiniBox("#FF0000* #FFFFFFYou are allowed to bet a maximum of #ABCDEF$"..maxBet.."#FFFFFF! Levelling up will increase this number.",thePlayer)
  1696.                                         return false
  1697.                                     end
  1698.                                 else
  1699.                                     exports.box:outputMiniBox("#FF0000* #FFFFFFERROR! You don't have enough money!",thePlayer)
  1700.                                 end
  1701.                             else
  1702.                                 outputChatBox("#FF0000* #FFFFFFERROR! The player you specified has not been found! (#FFFF00"..toPlayer.."#FFFFFF)",thePlayer,255,255,255,true)
  1703.                                 return false
  1704.                             end
  1705.                         else
  1706.                             outputChatBox("#FF0000* #FFFFFFERROR! Invalid amount! [#ABCDEF$"..newAmount.."#FFFFFF]",thePlayer,255,255,255,true)
  1707.                         end
  1708.                     else
  1709.                         outputChatBox("#FF0000* #FFFFFFERROR! Please specify an amount to bet! Correct syntax: #ABCDEF/bet [player] [amount]",thePlayer,255,255,255,true)
  1710.                         return false
  1711.                     end
  1712.                 else
  1713.                     outputChatBox("#FF0000* #FFFFFFERROR! Please specify a player! Correct syntax: #ABCDEF/bet [player] [amount]",thePlayer,255,255,255,true)
  1714.                     return false
  1715.                 end
  1716.             else
  1717.                 exports.box:outputMiniBox("#FF0000* #FFFFFFYou have already placed your bet on "..betState.." #FFFFFFfor #ABCDEF$"..oldAmount.."#FFFFFF!",thePlayer)
  1718.                 return false
  1719.             end
  1720.         else
  1721.             exports.box:outputMiniBox("#FF0000* #FFFFFFBetting time is over! You can place your bet on the next map.",thePlayer)
  1722.         end
  1723.     else
  1724.         exports.box:outputMiniBox("#FF0000* #FFFFFFBetting #FF0000disabled.#FFFFFF Minimum required players on server: #ABCDEF" ..minPlayers.."#FF0000 | #FFFFFFConnected: #ABCDEF"..getPlayerCount(),thePlayer)
  1725.     end
  1726. end
  1727.  
  1728.  
  1729. function onPlayerBetWin(self,betAmount)
  1730.     exports.box:outputMiniBox("#0095FF* #FFFFFF"..getPlayerName(self).."#FFFFFF has won his bet and has recieved #ABCDEF$".. betAmount*2 .."#FFFFFF!",getRootElement())
  1731.     local playerCash = loadPlayerData(self,"cash")
  1732.     savePlayerData(self,"cash",playerCash+betAmount+betAmount*2)
  1733.     local thePlayer = self
  1734.     scoreboardRefresh(thePlayer)
  1735.     local addAmount = betAmount*2
  1736.     totalMoneyEarnedAdd(thePlayer,addAmount)
  1737.     totalBetsWonAdd(thePlayer)
  1738.     totalBetsEarnedAdd(thePlayer,addAmount)
  1739.     progressBarUpdate(thePlayer)
  1740.     totalMoneyAchievements(thePlayer)
  1741. end
  1742.  
  1743.  
  1744.  
  1745. function bettingTimer()
  1746.     if isTimer(chatTimer) then killTimer(chatTimer) end
  1747.     if isTimer(disableTimer) then killTimer(disableTimer) end
  1748.     if getPlayerCount() >= minPlayers then
  1749.         chatTimer = setTimer(outputChatBox,3500,1,"#0095FF* #FFFFFFPlace your bets! #FFFFFF[#ABCDEF/bet#FFFFFF]",getRootElement(),255,255,255,true)
  1750.         bettingEnabled = true
  1751.         disableTimer = setTimer(disableBetting,betTimeLimit*1000+2000,1)
  1752.     end
  1753. end
  1754. addEvent("onMapStarting",true)
  1755. addEventHandler("onMapStarting",getRootElement(),bettingTimer)
  1756.  
  1757.  
  1758. function disableBetting()
  1759.     exports.box:outputMiniBox("#0095FF* #FFFFFFBetting time is over#FF0000!",getRootElement())
  1760.     bettingEnabled = false
  1761. end
  1762.  
  1763.  
  1764. function checkWin(winner)
  1765.     callClientFunction(getRootElement(),"compareResult",winner)
  1766. end
  1767. addEvent("onPlayerDestructionDerbyWin",true)
  1768. addEventHandler("onPlayerDestructionDerbyWin",getRootElement(),checkWin)
  1769.  
  1770.  
  1771.  
  1772. function retrieveData(thePlayer,commandName,toPlayer,newAmount)
  1773.     callClientFunction(thePlayer,"triggerBettingSystem",thePlayer,toPlayer,newAmount)
  1774. end
  1775. addCommandHandler("bet",retrieveData)
  1776.  
  1777.  
  1778.  
  1779.  
  1780.  
  1781.  
  1782.  
  1783.  
  1784.  
  1785.  
  1786.  
  1787. -----------------
  1788. -- Hunter handler
  1789. -----------------
  1790.  
  1791. function hunterBonus(thePlayer)
  1792.     if getElementData(thePlayer,"playerGotHunter") == false then
  1793.         setElementData(thePlayer,"playerGotHunter",true)
  1794.         local cashToWin = 500
  1795.         if (tonumber(loadPlayerData(thePlayer,"cash")) >= 0) then
  1796.             cashToWin = cashToWin*1.1
  1797.         end
  1798.         outputChatBox("#0095FF* #FFFFFF"..getPlayerName(thePlayer).."#FFFFFF has got the #ABCDEFHunter#FFFFFF! #ABCDEF[#FFFFFF$"..cashToWin.."#ABCDEF]",getRootElement(),255,255,255,true)
  1799.         playerCash = loadPlayerData(thePlayer,"cash")
  1800.         savePlayerData(thePlayer,"cash",playerCash+cashToWin)
  1801.         scoreboardRefresh(thePlayer)
  1802.         totalHuntersAdd(thePlayer)
  1803.         progressBarUpdate(thePlayer)
  1804.         --achievement16(thePlayer)
  1805.         --achievement17(thePlayer)
  1806.         --achievement18(thePlayer)
  1807.         --achievement40(thePlayer)
  1808.         --achievement41(thePlayer)
  1809.         totalMoneyAchievements(thePlayer)
  1810.         local newAmount = cashToWin
  1811.         totalMoneyEarnedAdd(thePlayer,newAmount)
  1812.     end
  1813. end
  1814.  
  1815. function checkForHunter(number,sort,model)
  1816.     if sort == "vehiclechange" then
  1817.         if model == 425 then
  1818.             setTimer(hunterBonus,200,1,source)
  1819.         end
  1820.     end
  1821. end
  1822. addEventHandler("onPlayerPickUpRacePickup",getRootElement(),checkForHunter)
  1823.  
  1824.  
  1825.  
  1826. addEvent("onPlayerToptimeImprovement",true)
  1827. addEventHandler("onPlayerToptimeImprovement",getRootElement(),
  1828. function (player,newPos,newTime,oldPos,oldTime,random1,random2)
  1829.     if getElementData(source,"playerGotHunter") == false then
  1830.         if newPos <= 10 then
  1831.             local cashToWin = 1500
  1832.             if (tonumber(loadPlayerData(source,"cash")) >= 0) then
  1833.                 cashToWin = cashToWin*1.1
  1834.             end
  1835.             local playerCash = loadPlayerData(source,"cash")
  1836.             savePlayerData(player,"cash",playerCash +cashToWin)
  1837.             local playerCash = loadPlayerData(source,"cash")
  1838.             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)
  1839.             setElementData(source, "playerGotHunter",true)
  1840.             local newAmount = cashToWin
  1841.             local thePlayer = source
  1842.             totalMoneyEarnedAdd(thePlayer,newAmount)
  1843.             totalHuntersAdd(thePlayer)
  1844.             progressBarUpdate(thePlayer)
  1845.             scoreboardRefresh(thePlayer)
  1846.             totalMoneyAchievements(thePlayer)
  1847.             --achievement18(thePlayer)
  1848.         end
  1849.     end
  1850. end)
  1851.  
  1852. function resetHunterData()
  1853.     setElementData(source,"playerGotHunter",false)
  1854. end
  1855. addEventHandler("onNotifyPlayerReady",getRootElement(),resetHunterData)
  1856.  
  1857.  
  1858.  
  1859.  
  1860.  
  1861.  
  1862. -----------------
  1863. -- Reaction tests
  1864. -----------------
  1865.  
  1866.  
  1867. function newReactionTest()
  1868.     reactionString = string.random(reactionLength)
  1869.     reactionMoney = math.random(reactionMin,reactionMax)
  1870.     outputChatBox("#0095FF* #FFFFFFSay #ABCDEF"..reactionString.."#FFFFFF to win #ABCDEF$"..reactionMoney.."#FFFFFF!",getRootElement(),255,255,255,true)
  1871.  
  1872.     addEventHandler("onPlayerChat",getRootElement(),checkForOpenConsole)
  1873.  
  1874.     reactionTimer = setTimer(
  1875.     function()
  1876.         removeEventHandler("onPlayerChat",getRootElement(),checkForOpenConsole)
  1877.     end,reactionDuration*1000,1)
  1878.  
  1879.     if isTimer(newReactionTimer) then
  1880.         killTimer(newReactionTimer)
  1881.     end
  1882.  
  1883.     newReactionTimer = setTimer(newReactionTest,math.random(reactionMinRedo*1000,reactionMaxRedo*1000))
  1884.  
  1885. end
  1886.  
  1887.  
  1888. function checkForOpenConsole(message,type)
  1889.     callClientFunction(source,"checkForOpenConsole",message,type)
  1890. end
  1891.  
  1892.  
  1893. function checkReactionTest(thePlayer,message,type,isOpen)
  1894.  
  1895.     if (isOpen == true) then
  1896.         outputChatBox("#0095FF* #FFFFFF"..getPlayerName(thePlayer).."#FFFFFF attempted to cheat at the reaction test!",getRootElement(),255,255,255,true)
  1897.         outputChatBox("#0095FF* #FFFFFFMoney decreased by #ABCDEF$1,000#FFFFFF! Do not cheat!",getRootElement(),255,255,255,true)
  1898.  
  1899.         local playerCash = loadPlayerData(thePlayer,"cash")
  1900.         savePlayerData(thePlayer,"cash",playerCash - 1000)
  1901.         scoreboardRefresh(thePlayer)
  1902.     end
  1903.  
  1904.     message = tostring(message)
  1905.     if message == "..." then
  1906.         return
  1907.     end
  1908.  
  1909.     if (message == reactionString) then
  1910.         local timeLeft,leftExec,totalExec = getTimerDetails(reactionTimer)
  1911.  
  1912.         killTimer(reactionTimer)
  1913.         removeEventHandler("onPlayerChat",getRootElement(),checkForOpenConsole)
  1914.  
  1915.         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)
  1916.  
  1917.         local playerCash = loadPlayerData(thePlayer,"cash")
  1918.         local totalReactionTests = tonumber(loadPlayerData(thePlayer,"totalReactionTests"))
  1919.         local bestReactionTime = tonumber(loadPlayerData(thePlayer,"bestReactionTime"))
  1920.  
  1921.         savePlayerData(thePlayer,"cash",playerCash + reactionMoney)
  1922.         savePlayerData(thePlayer,"totalReactionTests",totalReactionTests + 1)
  1923.         totalMoneyEarnedAdd(thePlayer,reactionMoney)
  1924.  
  1925.         if (math.round((reactionDuration*1000 - timeLeft)/1000)) < bestReactionTime or (bestReactionTime == 0) then
  1926.             savePlayerData(thePlayer,"bestReactionTime",math.round((reactionDuration*1000 - timeLeft)/1000,2,floor))
  1927.         end
  1928.  
  1929.         scoreboardRefresh(thePlayer)
  1930.         setTimer(achievement36,200,1,thePlayer)
  1931.  
  1932.         -- Check for achievement here
  1933.         if math.round((reactionDuration*1000 - timeLeft)/1000,2,floor) <= 5 then
  1934.             achievement37(thePlayer)
  1935.         end
  1936.  
  1937.         reactionString = ""
  1938.         reactionMoney = 0
  1939.  
  1940.     end
  1941. end
  1942.  
  1943.  
  1944. function string.random(len)
  1945.     local str = ""
  1946.     for i=1,len do
  1947.         local getChar = math.random(1,35)
  1948.         if getChar <= 25 then
  1949.             local caps = math.random(1,2)
  1950.             if caps == 1 then
  1951.                 str = str..string.upper(chars[getChar])
  1952.             else
  1953.                 str = str..string.lower(chars[getChar])
  1954.             end
  1955.         else
  1956.             str = str..chars[getChar]
  1957.         end
  1958.     end
  1959.     return str
  1960. end
  1961.  
  1962.  
  1963.  
  1964.  
  1965.  
  1966. ----------------------------
  1967. -- Lotto [Lottery]
  1968. ----------------------------
  1969.  
  1970. local LOTTO_MAX_TICKETS = 5
  1971. local LOTTO_PRIZE = 10000
  1972. local LOTTO_PRICE = 1000
  1973. local lottoState = 0 -- 0-opened; 1-waiting for prize; 2-closed;
  1974. local lottoTicketsLeft = LOTTO_MAX_TICKETS
  1975. local lottoAnyoneWon = 0
  1976. local lottoTimesTried = 0
  1977.  
  1978. function openLotto()
  1979. lottoState = 0
  1980. lottoTicketsLeft = LOTTO_MAX_TICKETS
  1981. lottoAnyoneWon = 0
  1982. lottoTimesTried = 0
  1983. 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)
  1984. end
  1985.  
  1986. function givePrize()
  1987. if(lottoTimesTried == LOTTO_MAX_TICKETS*2) then
  1988. lottoOpenTimer = setTimer(openLotto, 3*60*1000, 1)
  1989. lottoState = 2
  1990. return
  1991. end
  1992. local rticket = math.random(1, LOTTO_MAX_TICKETS)
  1993. local players = getElementsByType("playerCash")
  1994. for i, v in ipairs(players) do
  1995. if(getElementData(v, "TicketID") == rticket) then
  1996. lottoState = 2
  1997. lottoAnyoneWon = 1
  1998. givePlayerMoney(v, LOTTO_PRIZE)
  1999. lottoOpenTimer = setTimer(openLotto, 3*60*1000, 1)
  2000. outputChatBox("#abcdef[LOTTO] " ..getPlayerName(v).. " #ffffffHas Won the lottery! Congratulations! New lottery will open in 3 minutes", getRootElement(), 255, 255, 0, true)
  2001. end
  2002. setElementData(v, "TicketID", 0)
  2003. setElementData(v, "BoughtTicket", false)
  2004. end
  2005. if(lottoAnyoneWon == 0) then
  2006. givePrize()
  2007. lottoTimesTried = lottoTimesTried+1
  2008. end
  2009. end
  2010.  
  2011. function buyticket(playerCash)
  2012. if(lottoState == 2) then
  2013. millisecondsRemaining = getTimerDetails(lottoOpenTimer)
  2014. local minutesRemaining = math.ceil(millisecondsRemaining/60000)
  2015. local secondsRemaining = math.ceil((millisecondsRemaining/1000)%60)
  2016. outputChatBox("#abcdef[LOTTO] Lottery is closed! #ffffffIt will open after " ..minutesRemaining.. " minutes and " ..secondsRemaining.. " seconds.", player, 255, 0, 0, true)
  2017. elseif(lottoState == 1) then
  2018. outputChatBox("#abcdef[LOTTO] #ffffffLottery is closed!", player, 255, 0, 0, true)
  2019. elseif(lottoState == 0) then
  2020. if(getElementData(playerCash, "BoughtTicket") == true) then
  2021. outputChatBox("#abcdef[LOTTO] #ffffffYou already have lottery ticket!", player, 255, 100, 0, true)
  2022. return
  2023. end
  2024. if(getPlayerMoney(playerCash) < LOTTO_PRICE) then
  2025. outputChatBox("[LOTTO] You haven't got enough money! (Price: " ..LOTTO_PRICE.. "$)", player, 255, 100, 0, false)
  2026. return
  2027. end
  2028. takePlayerMoney(playerCash, LOTTO_PRICE)
  2029. setElementData(playerCash, "TicketID", lottoTicketsLeft)
  2030. setElementData(playerCash, "BoughtTicket", true)
  2031. lottoTicketsLeft = lottoTicketsLeft-1
  2032. outputChatBox("#abcdef[LOTTO] " ..getPlayerName(player).." #ffff00has bought lottery ticket! " ..lottoTicketsLeft.. " tickets left!", getRootElement(), 255, 255, 0, true)
  2033. if(lottoTicketsLeft == 0) then
  2034. lottoState = 1
  2035. setTimer(givePrize, 1*60*1000, 1)
  2036. outputChatBox("#abcdef[LOTTO] #ffffff0 tickets left! Random lottery member will get the prize after 1 minute!", getRootElement(), 255, 255, 255, true)
  2037. end
  2038. end
  2039. end
  2040. addCommandHandler("buyticket", buyticket)
  2041. addCommandHandler("bt", buyticket)
  2042.  
  2043. function pQuit(playerCash)
  2044. if(lottoState == 0) then
  2045. if(lottoTicketsLeft > 0 and lottoTicketsLeft < 5) then
  2046. lottoTicketsLeft = lottoTicketsLeft+1
  2047. outputChatBox("#abcdef[LOTTO] #ffffffPlayer who had ticket left the server so now there are #abcdef"..lottoTicketsLeft.." #fffffftickets left!", getRootElement(), 255, 255, 255, true)
  2048. end
  2049. end
  2050. end
  2051.  
  2052. function rStart(playerCash)
  2053.     outputDebugString("Martyz lotto v1.0 has been loaded SUCCESSFULLY")
  2054. end
  2055.  
  2056. addEventHandler("onPlayerQuit", getRootElement(), pQuit)
  2057. addEventHandler("onResourceStart", getResourceRootElement(getThisResource()), rStart)
Add Comment
Please, Sign In to add comment