Guest User

panel_server

a guest
Dec 4th, 2012
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 125.24 KB | None | 0 0
  1. --~~~~~~~~~~~~~~~~~~~~~
  2. -- Levels
  3. --~~~~~~~~~~~~~~~~~~~~~
  4.  
  5. -- Set prices
  6. level1 = 0
  7. level2 = 1000
  8. level3 = 2000
  9. level4 = 3000
  10. level5 = 4000
  11. level6 = 5000
  12. level7 = 6000
  13. level8 = 7000
  14. level9 = 8000
  15. level10 = 9000
  16. level11 = 10000
  17. level12 = 11000
  18. level13 = 12000
  19. level14 = 13000
  20. level15 = 14000
  21. level16 = 15000
  22. level17 = 16000
  23. level18 = 17000
  24. level19 = 18000
  25. level20 = 19000
  26. level21 = 20000
  27. level22 = 21000
  28. level23 = 22000
  29. level24 = 23000
  30. level25 = 24000
  31. level26 = 25000 -- Level 10 ELITE
  32. level27 = 28000
  33. level28 = 31000
  34. level29 = 34000
  35. level30 = 37000
  36. level31 = 40000
  37. level32 = 43000
  38. level33 = 46000
  39. level34 = 49000
  40. level35 = 52000
  41. level36 = 55000
  42. level37 = 58000
  43. level38 = 61000
  44. level39 = 64000
  45. level40 = 67000
  46. level41 = 70000 -- Level 25 ELITE
  47.  
  48.  
  49. -- Prices for levels again [new version of level system requires this]
  50. levelPrices = {0,1000,2000,3000,4000,5000,6000,7000,8000,9000,10000,11000,12000,13000,14000,15000,16000,17000,18000,19000,20000,21000,22000,23000,24000,25000,28000,31000,34000,37000,40000,43000,46000,49000,52000,55000,58000,61000,64000,67000,70000}
  51.  
  52.  
  53. -- String.random characters
  54. 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"}
  55.  
  56.  
  57.  
  58. specialLevelNames = {
  59. "10 ELITE",
  60. "11 ELITE",
  61. "12 ELITE",
  62. "13 ELITE",
  63. "14 ELITE",
  64. "15 ELITE",
  65. "16 ELITE",
  66. "17 ELITE",
  67. "18 ELITE",
  68. "19 ELITE",
  69. "20 ELITE",
  70. "21 ELITE",
  71. "22 ELITE",
  72. "23 ELITE",
  73. "24 ELITE",
  74. "25 ELITE"}
  75.  
  76.  
  77.  
  78. -- Set special names - display
  79. nlevel26 = "10 ELITE"
  80. nlevel27 = "11 ELITE"
  81. nlevel28 = "12 ELITE"
  82. nlevel29 = "13 ELITE"
  83. nlevel30 = "14 ELITE"
  84. nlevel31 = "15 ELITE"
  85. nlevel32 = "16 ELITE"
  86. nlevel33 = "17 ELITE"
  87. nlevel34 = "18 ELITE"
  88. nlevel35 = "19 ELITE"
  89. nlevel36 = "20 ELITE"
  90. nlevel37 = "21 ELITE"
  91. nlevel38 = "22 ELITE"
  92. nlevel39 = "23 ELITE"
  93. nlevel40 = "24 ELITE"
  94. nlevel41 = "25 ELITE"
  95.  
  96. -- Set special names - image
  97. ilevel1 = "levels/LEVEL1.png"
  98. ilevel2 = "levels/LEVEL2.png"
  99. ilevel3 = "levels/LEVEL3.png"
  100. ilevel4 = "levels/LEVEL4.png"
  101. ilevel5 = "levels/LEVEL5.png"
  102. ilevel6 = "levels/LEVEL6.png"
  103. ilevel7 = "levels/LEVEL7.png"
  104. ilevel8 = "levels/LEVEL8.png"
  105. ilevel9 = "levels/LEVEL9.png"
  106. ilevel10 = "levels/LEVEL10.png"
  107. ilevel11 = "levels/LEVEL11.png"
  108. ilevel12 = "levels/LEVEL12.png"
  109. ilevel13 = "levels/LEVEL13.png"
  110. ilevel14 = "levels/LEVEL14.png"
  111. ilevel15 = "levels/LEVEL15.png"
  112. ilevel16 = "levels/LEVEL16.png"
  113. ilevel17 = "levels/LEVEL17.png"
  114. ilevel18 = "levels/LEVEL18.png"
  115. ilevel19 = "levels/LEVEL19.png"
  116. ilevel20 = "levels/LEVEL20.png"
  117. ilevel21 = "levels/LEVEL21.png"
  118. ilevel22 = "levels/LEVEL22.png"
  119. ilevel23 = "levels/LEVEL23.png"
  120. ilevel24 = "levels/LEVEL24.png"
  121. ilevel25 = "levels/LEVEL25.png"
  122. ilevel26 = "levels/LEVEL10ELITE.png"
  123. ilevel27 = "levels/LEVEL11ELITE.png"
  124. ilevel28 = "levels/LEVEL12ELITE.png"
  125. ilevel29 = "levels/LEVEL13ELITE.png"
  126. ilevel30 = "levels/LEVEL14ELITE.png"
  127. ilevel31 = "levels/LEVEL15ELITE.png"
  128. ilevel32 = "levels/LEVEL16ELITE.png"
  129. ilevel33 = "levels/LEVEL17ELITE.png"
  130. ilevel34 = "levels/LEVEL18ELITE.png"
  131. ilevel35 = "levels/LEVEL19ELITE.png"
  132. ilevel36 = "levels/LEVEL20ELITE.png"
  133. ilevel37 = "levels/LEVEL21ELITE.png"
  134. ilevel38 = "levels/LEVEL22ELITE.png"
  135. ilevel39 = "levels/LEVEL23ELITE.png"
  136. ilevel40 = "levels/LEVEL24ELITE.png"
  137. ilevel41 = "levels/LEVEL25ELITE.png"
  138. --~~~~~~~~~~~~~~
  139. -- max 41 levels
  140. --~~~~~~~~~~~~~~
  141.  
  142.  
  143.  
  144.  
  145. -----------
  146. -- Settings
  147. -----------
  148. betPerLevel = 30        -- Limits the amount of money you can bet. (PlayerLevel*betPerLevel = maxBet).
  149. betTimeLimit = 40       -- Duration of the betting period in seconds.
  150. minPlayers = 1          -- Minimum required players to bet.
  151. mapLevel = 10           -- Minimum level required to set maps.
  152. mapCost = 4000          -- The price for setting maps.
  153. skinLevel = 13          -- Minimum level required to buy skins.
  154. skinCost = 1300         -- The price of skins.
  155. nametagLevel = 15       -- Minimum level to buy a nametag color.
  156. nametagPrice = 2000     -- Price for buying a nametag color.
  157. hornLevel = 10          -- Minimum level to buy different horn styles.
  158. moneyEarnPart = 30      -- The amount of money to calculate with to get the final money to give to the player.
  159.  
  160. reactionMin = 320       -- Minimum money for the reaction test
  161. reactionMax = 660       -- Maximum money for the reaction test
  162. reactionDuration = 20   -- Duration of the reaction test in seconds
  163. reactionMinRedo = 100   -- Minimum amount of time to pass before a new reaction test is started in seconds
  164. reactionMaxRedo = 200   -- Maximum amount of time to pass before a new reaction test is started in seconds
  165. reactionLength = 6      -- Number of characters to use in the reaction test
  166.  
  167.  
  168. function onResourceStart()
  169.     mapIsAlreadySet = false
  170.     reactionString = ""
  171.     reactionMoney = 0
  172.     setTimer(newReactionTest,math.random(reactionMinRedo*1000,reactionMaxRedo*1000),1)
  173.  
  174.     outputDebugString("Resource is restarting, please stand by...")
  175.     setTimer(outputDebugString,700,1,"Resource sucessfully started: ~AG~ Script [Author: NeXTreme] ")
  176. end
  177. addEventHandler("onResourceStart",getResourceRootElement(getThisResource()),onResourceStart)
  178.  
  179.  
  180.  
  181. -- Prices for each horn
  182. hornPrice={2000,4000,6000,8000,10000,15000,20000}
  183.  
  184.  
  185.  
  186. ---------------
  187. -- Level system
  188. ---------------
  189.  
  190. function newLevelSystem(thePlayer)
  191.     local playerCash = tonumber(loadPlayerData(thePlayer,"cash"))
  192.     local playerLevel = tonumber(loadPlayerData(thePlayer,"level"))
  193.     if not (playerLevel == 41) then
  194.         if (playerCash >= levelPrices[playerLevel+1]) then
  195.             savePlayerData(thePlayer,"cash",playerCash-levelPrices[playerLevel+1])
  196.             savePlayerData(thePlayer,"level",playerLevel+1)
  197.             if (playerLevel+1 > 25) then
  198.                 outputChatBox("#00BFFF* #FFFFFFCongratulations#00BFFF!#FFFFFF You are now level #ABCDEF"..specialLevelNames[playerLevel-24].."#FFFFFF!",thePlayer,255,255,255,true)
  199.                 outputChatBox("#00BFFF* #FFFFFF"..getPlayerName(thePlayer).."#FFFFFF has levelled up! He/She is now level#FF0000 "..specialLevelNames[playerLevel-24].."#FFFFFF!",getRootElement(),255,255,255,true)
  200.             else
  201.                 outputChatBox("#00BFFF* #FFFFFFCongratulations#00BFFF!#FFFFFF You are now level #ABCDEF"..playerLevel+1 .."#FFFFFF!",thePlayer,255,255,255,true)
  202.                 outputChatBox("#00BFFF* #FFFFFF"..getPlayerName(thePlayer).."#FFFFFF has levelled up! He/She is now level#FF0000 "..playerLevel+1 .."#FFFFFF!",getRootElement(),255,255,255,true)
  203.             end
  204.         else
  205.             outputChatBox("#00BFFF* #FFFFFFYou need another #ABCDEF$"..levelPrices[playerLevel+1]-playerCash.."#FFFFFF to advance to the next level!",thePlayer,255,255,255,true)
  206.             levelAchievements(thePlayer)
  207.             return false
  208.         end
  209.     else
  210.         outputChatBox("#00BFFF* #FFFFFFYou have reached the maximum possible level! #00BFFF[#FFFFFF Level 25 #FFFF00ELITE #00BFFF]",thePlayer,255,255,255,true)
  211.         return false
  212.     end
  213.     local playerLevel = tonumber(loadPlayerData(thePlayer,"level"))
  214.     if (playerLevel == 25) then
  215.         outputChatBox("#00BFFF",thePlayer,255,255,255,true)
  216.         outputChatBox("#00BFFF",thePlayer,255,255,255,true)
  217.         outputChatBox("#00BFFF",thePlayer,255,255,255,true)
  218.         outputChatBox("#00BFFF",thePlayer,255,255,255,true)
  219.         outputChatBox("#00BFFF",thePlayer,255,255,255,true)
  220.         outputChatBox("#00BFFF",thePlayer,255,255,255,true)
  221.         outputChatBox("#FF0000-------------------------------------",thePlayer,255,255,255,true)
  222.         outputChatBox("#00BFFF* #FFFFFFYou have reached level #FF000025#FFFFFF!",thePlayer,255,255,255,true)
  223.         outputChatBox("#00BFFF* #FFFFFFYou can now start again from level 10 in #FFFF00ELITE #FFFFFFmode!",thePlayer,255,255,255,true)
  224.         outputChatBox("#FF0000-------------------------------------",thePlayer,255,255,255,true)
  225.         outputChatBox("#00BFFF",thePlayer,255,255,255,true)
  226.         outputChatBox("#00BFFF",thePlayer,255,255,255,true)
  227.     elseif (playerLevel == 26) then
  228.         outputChatBox("#00BFFF* #FFFFFFYou now earn more money from winning and setting new top hunter times!",thePlayer,255,255,255,true)
  229.     elseif (playerLevel == 41) then
  230.         outputChatBox("#00BFFF",thePlayer,255,255,255,true)
  231.         outputChatBox("#00BFFF",thePlayer,255,255,255,true)
  232.         outputChatBox("#00BFFF",thePlayer,255,255,255,true)
  233.         outputChatBox("#00BFFF",thePlayer,255,255,255,true)
  234.         outputChatBox("#00BFFF",thePlayer,255,255,255,true)
  235.         outputChatBox("#00BFFF",thePlayer,255,255,255,true)
  236.         outputChatBox("#00BFFF",thePlayer,255,255,255,true)
  237.         outputChatBox("#00BFFF",thePlayer,255,255,255,true)
  238.         outputChatBox("#00BFFF",thePlayer,255,255,255,true)
  239.         outputChatBox("#00BFFF",thePlayer,255,255,255,true)
  240.         outputChatBox("#00BFFF",thePlayer,255,255,255,true)
  241.         outputChatBox("#00BFFF",thePlayer,255,255,255,true)
  242.         outputChatBox("#00BFFF---------------------------------------",thePlayer,255,255,255,true)
  243.         outputChatBox("#00BFFF* Congratulations on reaching level #FFFF0025 ELITE#00BFFF!",thePlayer,255,255,255,true)
  244.         outputChatBox("#00BFFF",thePlayer,255,255,255,true)
  245.         outputChatBox("#00BFFF* You have reached the maximum level!",thePlayer,255,255,255,true)
  246.         outputChatBox("#00BFFF---------------------------------------",thePlayer,255,255,255,true)
  247.         outputChatBox("#00BFFF",thePlayer,255,255,255,true)
  248.     end
  249.     scoreboardRefresh(thePlayer)
  250.     refreshStats(thePlayer)
  251.     progressBarUpdate(thePlayer)
  252.     levelAchievements(thePlayer)
  253. end
  254.  
  255.  
  256.  
  257. -- Disable voting
  258. function disableVote()
  259.     cancelEvent()
  260. end
  261. addCommandHandler("voteredo",disableVote)
  262. addCommandHandler("new",disableVote)
  263.  
  264.  
  265.  
  266. -----------------------------------------------------------------------------------
  267. -----------------------------------| USERPANEL |-----------------------------------
  268. -----------------------------------------------------------------------------------
  269.  
  270. ----------------------------
  271. -- Userpanel - Refresh stats
  272. ----------------------------
  273. function refreshStats(thePlayer)
  274.     local playerLevel = tonumber(loadPlayerData(thePlayer,"level"))
  275.     local playerCash = tonumber(loadPlayerData(thePlayer,"cash"))
  276.     local unlockedAchievements = tonumber(loadPlayerData(thePlayer,"unlockedAchievements"))
  277.     local totalTimesJoined = tonumber(loadPlayerData(thePlayer,"totalTimesJoined"))
  278.     local mapsWon = tonumber(loadPlayerData(thePlayer,"mapsWon"))
  279.     local mapsPlayed = tonumber(loadPlayerData(thePlayer,"mapsPlayed"))
  280.     local totalHunters = tonumber(loadPlayerData(thePlayer,"totalHunters"))
  281.     local totalToptimes = tonumber(loadPlayerData(thePlayer,"totalToptimes"))
  282.     local totalMoneyEarned = tonumber(loadPlayerData(thePlayer,"totalMoneyEarned"))
  283.     local totalMoneySent = tonumber(loadPlayerData(thePlayer,"totalMoneySent"))
  284.     local totalBets = tonumber(loadPlayerData(thePlayer,"totalBets"))
  285.     local totalBetsEarned = tonumber(loadPlayerData(thePlayer,"totalBetsEarned"))
  286.     local totalBetsWon = tonumber(loadPlayerData(thePlayer,"totalBetsWon"))
  287.     local totalDeaths = tonumber(loadPlayerData(thePlayer,"totalDeaths"))
  288.     local totalPlayingTimeMinutes = tonumber(loadPlayerData(thePlayer,"totalPlayingTimeMinutes"))
  289.     local totalPlayingTimeHours = tonumber(loadPlayerData(thePlayer,"totalPlayingTimeHours"))
  290.     local totalReactionTests = tonumber(loadPlayerData(thePlayer,"totalReactionTests"))
  291.     local bestReactionTime = tonumber(loadPlayerData(thePlayer,"bestReactionTime"))
  292.  
  293.     levelImage = getRankingImage(playerLevel)
  294.     levelDisplay = getEliteName(playerLevel)
  295.     local winRatio = 0
  296.     if mapsPlayed == 0 and mapsWon == 0 then
  297.         winRatio = 0
  298.     elseif mapsPlayed ~= 0 and mapsWon == 0 then
  299.         winRatio = 0
  300.     elseif mapsPlayed ~= 0 and mapsWon ~= 0 then
  301.         winRatio = math.round(((100/mapsPlayed)*mapsWon),2)
  302.     elseif mapsWon > mapsPlayed then
  303.         winRatio = 0
  304.     end
  305.     callClientFunction(thePlayer,"refreshStats",levelDisplay,levelImage,playerCash,unlockedAchievements,totalTimesJoined,mapsWon,mapsPlayed,winRatio,totalHunters,totalToptimes,totalMoneyEarned,totalMoneySent,totalBets,totalBetsEarned,totalBetsWon,totalDeaths,totalPlayingTimeMinutes,totalPlayingTimeHours,totalReactionTests,bestReactionTime)
  306. end
  307.  
  308. function getEliteName(playerLevel)
  309.     local levelDisplay = ""
  310.     if playerLevel == 26 then
  311.         levelDisplay = nlevel26
  312.     elseif playerLevel == 27 then
  313.         levelDisplay = nlevel27
  314.     elseif playerLevel == 28 then
  315.         levelDisplay = nlevel28
  316.     elseif playerLevel == 29 then
  317.         levelDisplay = nlevel29
  318.     elseif playerLevel == 30 then
  319.         levelDisplay = nlevel30
  320.     elseif playerLevel == 31 then
  321.         levelDisplay = nlevel31
  322.     elseif playerLevel == 32 then
  323.         levelDisplay = nlevel32
  324.     elseif playerLevel == 33 then
  325.         levelDisplay = nlevel33
  326.     elseif playerLevel == 34 then
  327.         levelDisplay = nlevel34
  328.     elseif playerLevel == 35 then
  329.         levelDisplay = nlevel35
  330.     elseif playerLevel == 36 then
  331.         levelDisplay = nlevel36
  332.     elseif playerLevel == 37 then
  333.         levelDisplay = nlevel37
  334.     elseif playerLevel == 38 then
  335.         levelDisplay = nlevel38
  336.     elseif playerLevel == 39 then
  337.         levelDisplay = nlevel39
  338.     elseif playerLevel == 40 then
  339.         levelDisplay = nlevel40
  340.     elseif playerLevel == 41 then
  341.         levelDisplay = nlevel41
  342.     else
  343.         levelDisplay = playerLevel
  344.     end
  345.     return levelDisplay
  346. end
  347.  
  348. function getRankingImage(playerLevel)
  349.     local levelImage = ""
  350.     if playerLevel == 1 then
  351.         levelImage = ilevel1
  352.     elseif playerLevel == 2 then
  353.         levelImage = ilevel2
  354.     elseif playerLevel == 3 then
  355.         levelImage = ilevel3
  356.     elseif playerLevel == 4 then
  357.         levelImage = ilevel4
  358.     elseif playerLevel == 5 then
  359.         levelImage = ilevel5
  360.     elseif playerLevel == 6 then
  361.         levelImage = ilevel6
  362.     elseif playerLevel == 7 then
  363.         levelImage = ilevel7
  364.     elseif playerLevel == 8 then
  365.         levelImage = ilevel8
  366.     elseif playerLevel == 9 then
  367.         levelImage = ilevel9
  368.     elseif playerLevel == 10 then
  369.         levelImage = ilevel10
  370.     elseif playerLevel == 11 then
  371.         levelImage = ilevel11
  372.     elseif playerLevel == 12 then
  373.         levelImage = ilevel12
  374.     elseif playerLevel == 13 then
  375.         levelImage = ilevel13
  376.     elseif playerLevel == 14 then
  377.         levelImage = ilevel14
  378.     elseif playerLevel == 15 then
  379.         levelImage = ilevel15
  380.     elseif playerLevel == 16 then
  381.         levelImage = ilevel16
  382.     elseif playerLevel == 17 then
  383.         levelImage = ilevel17
  384.     elseif playerLevel == 18 then
  385.         levelImage = ilevel18
  386.     elseif playerLevel == 19 then
  387.         levelImage = ilevel19
  388.     elseif playerLevel == 20 then
  389.         levelImage = ilevel20
  390.     elseif playerLevel == 21 then
  391.         levelImage = ilevel21
  392.     elseif playerLevel == 22 then
  393.         levelImage = ilevel22
  394.     elseif playerLevel == 23 then
  395.         levelImage = ilevel23
  396.     elseif playerLevel == 24 then
  397.         levelImage = ilevel24
  398.     elseif playerLevel == 25 then
  399.         levelImage = ilevel25
  400.     elseif playerLevel == 26 then
  401.         levelImage = ilevel26
  402.     elseif playerLevel == 27 then
  403.         levelImage = ilevel27
  404.     elseif playerLevel == 28 then
  405.         levelImage = ilevel28
  406.     elseif playerLevel == 29 then
  407.         levelImage = ilevel29
  408.     elseif playerLevel == 30 then
  409.         levelImage = ilevel30
  410.     elseif playerLevel == 31 then
  411.         levelImage = ilevel31
  412.     elseif playerLevel == 32 then
  413.         levelImage = ilevel32
  414.     elseif playerLevel == 33 then
  415.         levelImage = ilevel33
  416.     elseif playerLevel == 34 then
  417.         levelImage = ilevel34
  418.     elseif playerLevel == 35 then
  419.         levelImage = ilevel35
  420.     elseif playerLevel == 36 then
  421.         levelImage = ilevel36
  422.     elseif playerLevel == 37 then
  423.         levelImage = ilevel37
  424.     elseif playerLevel == 38 then
  425.         levelImage = ilevel38
  426.     elseif playerLevel == 39 then
  427.         levelImage = ilevel39
  428.     elseif playerLevel == 40 then
  429.         levelImage = ilevel40
  430.     elseif playerLevel == 41 then
  431.         levelImage = ilevel41
  432.     else
  433.         levelImage = ""
  434.     end
  435.     return levelImage
  436. end
  437.  
  438.  
  439.  
  440.  
  441. function refreshStatsCall()
  442.     local thePlayer = source
  443.     refreshStats(thePlayer)
  444. end
  445.  
  446. addEventHandler("onPlayerJoin",getRootElement(),refreshStatsCall)
  447. addEventHandler("onPlayerWasted",getRootElement(),refreshStatsCall)
  448.  
  449.  
  450. function triggerRebuildPlayerGridlist()
  451.     setTimer(callClientFunction,1000,1,getRootElement(),"refreshConnectedPlayers")
  452. end
  453. addEventHandler("onPlayerChangeNick",getRootElement(),triggerRebuildPlayerGridlist)
  454. addEventHandler("onPlayerJoin",getRootElement(),triggerRebuildPlayerGridlist)
  455. addEventHandler("onPlayerQuit",getRootElement(),triggerRebuildPlayerGridlist)
  456.  
  457.  
  458.  
  459.  
  460.  
  461.  
  462. -------------------------------------------
  463. -- Userpanel - handle requests from clients
  464. -------------------------------------------
  465.  
  466. function checkForFirstTimeJoined(thePlayer)
  467.     local joinedBefore = tonumber(loadPlayerData(thePlayer,"joinedBefore"))
  468.     if joinedBefore == 0 then
  469.         callClientFunction(thePlayer,"welcomeProcedureHandler","openWindow")
  470.         setTimer(callClientFunction,1000,1,thePlayer,"performSettingsUpdate")
  471.         savePlayerData(thePlayer,"joinedBefore",1)
  472.         outputChatBox("#00BFFF* #FFFFFFWelcome to AG Race DD/DM server, "..getPlayerName(thePlayer.."#FFFFFF!",thePlayer,255,255,255,true))
  473.     end
  474. end
  475.  
  476.  
  477. function getDataOnStart(thePlayer)
  478.     local pName = loadPlayerData(thePlayer,"pName")
  479.     local pAge = loadPlayerData(thePlayer,"pAge")
  480.     local pEmail = loadPlayerData(thePlayer,"pEmail")
  481.     local pMsn = loadPlayerData(thePlayer,"pMsn")
  482.     local pSkype = loadPlayerData(thePlayer,"pSkype")
  483.     local pXfire = loadPlayerData(thePlayer,"pXfire")
  484.     local pICQ = loadPlayerData(thePlayer,"pICQ")
  485.     local pXBL = loadPlayerData(thePlayer,"pXBL")
  486.     callClientFunction(thePlayer,"setDataOnStart",pName,pAge,pEmail,pMsn,pSkype,pXfire,pICQ,pXBL)
  487. end
  488.  
  489. function getPersonalDetails(requestingPlayer,thePlayerName)
  490.     local thePlayer = findPlayerByName(thePlayerName)
  491.     local allowPersonalDetails = loadPlayerData(thePlayer,"allowPersonalDetails")
  492.     if allowPersonalDetails == tostring(true) or tonumber(allowPersonalDetails) == 0 then
  493.         local pName = loadPlayerData(thePlayer,"pName")
  494.         local pAge = loadPlayerData(thePlayer,"pAge")
  495.         local pEmail = loadPlayerData(thePlayer,"pEmail")
  496.         local pMsn = loadPlayerData(thePlayer,"pMsn")
  497.         local pSkype = loadPlayerData(thePlayer,"pSkype")
  498.         local pXfire = loadPlayerData(thePlayer,"pXfire")
  499.         local pICQ = loadPlayerData(thePlayer,"pICQ")
  500.         local pXBL = loadPlayerData(thePlayer,"pXBL")
  501.         callClientFunction(requestingPlayer,"displayPersonalDetails",pName,pAge,pEmail,pMsn,pSkype,pXfire,pICQ,pXBL)
  502.     else
  503.         outputChatBox("#00BFFF* #FFFFFFThe other player has disabled viewing his personal details!",requestingPlayer,255,255,255,true)
  504.     end
  505. end
  506.  
  507. function getPlayerRaceStats(requestingPlayer,thePlayerName)
  508.     local thePlayer = findPlayerByName(thePlayerName)
  509.     local playerLevel = tonumber(loadPlayerData(thePlayer,"level"))
  510.     local playerCash = tonumber(loadPlayerData(thePlayer,"cash"))
  511.     local unlockedAchievements = tonumber(loadPlayerData(thePlayer,"unlockedAchievements"))
  512.     local totalTimesJoined = tonumber(loadPlayerData(thePlayer,"totalTimesJoined"))
  513.     local mapsWon = tonumber(loadPlayerData(thePlayer,"mapsWon"))
  514.     local mapsPlayed = tonumber(loadPlayerData(thePlayer,"mapsPlayed"))
  515.     local totalHunters = tonumber(loadPlayerData(thePlayer,"totalHunters"))
  516.     local totalToptimes = tonumber(loadPlayerData(thePlayer,"totalToptimes"))
  517.     local totalMoneyEarned = tonumber(loadPlayerData(thePlayer,"totalMoneyEarned"))
  518.     local totalMoneySent = tonumber(loadPlayerData(thePlayer,"totalMoneySent"))
  519.     local totalBets = tonumber(loadPlayerData(thePlayer,"totalBets"))
  520.     local totalBetsEarned = tonumber(loadPlayerData(thePlayer,"totalBetsEarned"))
  521.     local totalBetsWon = tonumber(loadPlayerData(thePlayer,"totalBetsWon"))
  522.     local totalDeaths = tonumber(loadPlayerData(thePlayer,"totalDeaths"))
  523.     local totalPlayingTimeMinutes = tonumber(loadPlayerData(thePlayer,"totalPlayingTimeMinutes"))
  524.     local totalPlayingTimeHours = tonumber(loadPlayerData(thePlayer,"totalPlayingTimeHours"))
  525. end
  526.  
  527.  
  528.  
  529. -- Chat system
  530. function playerChatHandler(sendingPlayer,sendToPlayer,message)
  531.     sendingPlayer = (string.gsub(getPlayerName(sendingPlayer),"#%x%x%x%x%x%x", ""))
  532.     callClientFunction(findPlayerByName(sendingPlayer),"addPlayerChatText",sendingPlayer,message)
  533.     callClientFunction(sendToPlayer,"addPlayerChatText",sendingPlayer,message)
  534.     callClientFunction(findPlayerByName(sendingPlayer),"resetInputField")
  535. end
  536.  
  537. function chatModeHandler(requestingPlayer,targetPlayer)
  538.     local currentChatRequestingPlayer = getElementData(requestingPlayer,"isPlayerInChat")
  539.     local currentChatTargetPlayer = getElementData(targetPlayer,"isPlayerInChat")
  540.     if not (currentChatRequestingPlayer == true) then
  541.         if not (currentChatTargetPlayer == true) then
  542.             callClientFunction(targetPlayer,"showChatWindows",1,requestingPlayer,targetPlayer)
  543.             callClientFunction(requestingPlayer,"showChatWindows",2,requestingPlayer,targetPlayer)
  544.         else
  545.             outputChatBox("#00BFFF* #FFFFFFThat player is already in a chat! You cannot chat with him/her.",requestingPlayer,255,255,255,true)
  546.         end
  547.     else
  548.         chatModeDisable(requestingPlayer,targetPlayer)
  549.     end
  550. end
  551.  
  552.  
  553. function chatErrorResponse(keyCode,requestingPlayer,targetPlayer)
  554.     if keyCode == 1 then
  555.         outputChatBox("#00BFFF* #FFFFFFERROR! Somebody else has requested to chat with that player!",targetPlayer,255,255,255,true)
  556.         outputChatBox("#00BFFF* #FFFFFFPlease try again later!",targetPlayer,255,255,255,true)
  557.     end
  558. end
  559.  
  560.  
  561. function chatModeEnable(requestingPlayer,targetPlayer)
  562.     setElementData(requestingPlayer,"isPlayerInChat",true)
  563.     setElementData(targetPlayer,"isPlayerInChat",true)
  564.     callClientFunction(requestingPlayer,"setChatMode",1,targetPlayer)
  565.     callClientFunction(targetPlayer,"setChatMode",1,requestingPlayer)
  566. end
  567.  
  568.  
  569. function chatModeDisable(requestingPlayer,targetPlayer)
  570.     setElementData(requestingPlayer,"isPlayerInChat",false)
  571.     setElementData(targetPlayer,"isPlayerInChat",false)
  572.     callClientFunction(requestingPlayer,"setChatMode",0,targetPlayer)
  573.     callClientFunction(targetPlayer,"setChatMode",0,requestingPlayer)
  574. end
  575.  
  576. function chatModeForceDisable(requestingPlayer,targetPlayer)
  577.     setElementData(targetPlayer,"isPlayerInChat",false)
  578.     callClientFunction(targetPlayer,"setChatMode",0,requestingPlayer)
  579. end
  580.  
  581. function acceptChatInvite(requestingPlayer,targetPlayer)
  582.     chatModeEnable(requestingPlayer,targetPlayer)
  583.     callClientFunction(targetPlayer,"setBusyStatus",2)
  584.     callClientFunction(requestingPlayer,"setBusyStatus",2)
  585.     callClientFunction(targetPlayer,"showChatWindows",1,requestingPlayer,targetPlayer)
  586.     callClientFunction(requestingPlayer,"showChatWindows",2,requestingPlayer,targetPlayer)
  587. end
  588.  
  589. function declineChatInvite(requestingPlayer,targetPlayer)
  590.     outputChatBox("#00BFFF* #FFFFFF"..getPlayerName(targetPlayer).." #FFFFFFhas declined your chat invitation!",requestingPlayer,255,255,255,true)
  591.     callClientFunction(targetPlayer,"setBusyStatus",2)
  592.     callClientFunction(requestingPlayer,"setBusyStatus",2)
  593.     callClientFunction(targetPlayer,"showChatWindows",1,requestingPlayer,targetPlayer)
  594.     callClientFunction(requestingPlayer,"showChatWindows",2,requestingPlayer,targetPlayer)
  595. end
  596.  
  597. function cancelChatInvite(requestingPlayer,targetPlayer)
  598.     outputChatBox("#00BFFF* #FFFFFF"..getPlayerName(targetPlayer).."#FFFFFF has cancelled their chat invititation.",requestingPlayer,255,255,255,true)
  599.     outputChatBox("#00BFFF* #FFFFFFYou've cancelled your chat invititation.",targetPlayer,255,255,255,true)
  600.     callClientFunction(targetPlayer,"setBusyStatus",2)
  601.     callClientFunction(requestingPlayer,"setBusyStatus",2)
  602.     callClientFunction(targetPlayer,"showChatWindows",2,requestingPlayer,targetPlayer)
  603.     callClientFunction(requestingPlayer,"showChatWindows",1,requestingPlayer,targetPlayer)
  604. end
  605.  
  606.  
  607. function resetElementData()
  608.     setElementData(source,"isPlayerInChat",false)
  609. end
  610. addEventHandler("onPlayerJoin",getRootElement(),resetElementData)
  611.  
  612.  
  613. function quitChatHandler(quitType)
  614.     callClientFunction(getRootElement(),"quitChatHandler",source,quitType)
  615. end
  616. addEventHandler("onPlayerQuit",getRootElement(),quitChatHandler)
  617.  
  618.  
  619.  
  620. -- Stats view
  621. function getPlayerStats(triggeringPlayer,thePlayer)
  622.     local allowStats = loadPlayerData(thePlayer,"allowStats")
  623.     if allowStats == tostring(true) or tonumber(allowStats) == 0 then
  624.         local playerLevel = tonumber(loadPlayerData(thePlayer,"level"))
  625.         local playerCash = tonumber(loadPlayerData(thePlayer,"cash"))
  626.         local unlockedAchievements = tonumber(loadPlayerData(thePlayer,"unlockedAchievements"))
  627.         local totalTimesJoined = tonumber(loadPlayerData(thePlayer,"totalTimesJoined"))
  628.         local mapsWon = tonumber(loadPlayerData(thePlayer,"mapsWon"))
  629.         local mapsPlayed = tonumber(loadPlayerData(thePlayer,"mapsPlayed"))
  630.         local totalHunters = tonumber(loadPlayerData(thePlayer,"totalHunters"))
  631.         local totalToptimes = tonumber(loadPlayerData(thePlayer,"totalToptimes"))
  632.         local totalMoneyEarned = tonumber(loadPlayerData(thePlayer,"totalMoneyEarned"))
  633.         local totalMoneySent = tonumber(loadPlayerData(thePlayer,"totalMoneySent"))
  634.         local totalBets = tonumber(loadPlayerData(thePlayer,"totalBets"))
  635.         local totalBetsEarned = tonumber(loadPlayerData(thePlayer,"totalBetsEarned"))
  636.         local totalBetsWon = tonumber(loadPlayerData(thePlayer,"totalBetsWon"))
  637.         local totalDeaths = tonumber(loadPlayerData(thePlayer,"totalDeaths"))
  638.         local totalPlayingTimeMinutes = tonumber(loadPlayerData(thePlayer,"totalPlayingTimeMinutes"))
  639.         local totalPlayingTimeHours = tonumber(loadPlayerData(thePlayer,"totalPlayingTimeHours"))
  640.         local totalReactionTests = tonumber(loadPlayerData(thePlayer,"totalReactionTests"))
  641.         local bestReactionTime = tonumber(loadPlayerData(thePlayer,"bestReactionTime"))
  642.         levelImage = getRankingImage(playerLevel)
  643.         levelDisplay = getEliteName(playerLevel)
  644.         local winRatio = 0
  645.         if mapsPlayed == 0 and mapsWon == 0 then
  646.             winRatio = 0
  647.         elseif mapsPlayed ~= 0 and mapsWon == 0 then
  648.             winRatio = 0
  649.         elseif mapsPlayed ~= 0 and mapsWon ~= 0 then
  650.             winRatio = math.round(((100/mapsPlayed)*mapsWon),2)
  651.         elseif mapsWon > mapsPlayed then
  652.             winRatio = 0
  653.         end
  654.         callClientFunction(triggeringPlayer,"displayPersonalStats",thePlayer,levelDisplay,levelImage,playerCash,unlockedAchievements,totalTimesJoined,mapsWon,mapsPlayed,winRatio,totalHunters,totalToptimes,totalMoneyEarned,totalMoneySent,totalBets,totalBetsEarned,totalBetsWon,totalDeaths,totalPlayingTimeMinutes,totalPlayingTimeHours,totalReactionTests,bestReactionTime)
  655.     else
  656.         outputChatBox("#00BFFF* #FFFFFFThe other player has disabled viewing his stats!",triggeringPlayer,255,255,255,true)
  657.     end
  658. end
  659.  
  660.  
  661. -- Maps
  662. function getServerMaps (loadList)
  663.     local tableOut
  664.     if loadList then
  665.         tableOut = {}
  666.         -- local deletedMaps = {}
  667.         local gamemodes = {}
  668.         gamemodes = call(getResourceFromName("mapmanager"), "getGamemodes")
  669.         for id,gamemode in ipairs (gamemodes) do
  670.             tableOut[id] = {}
  671.             tableOut[id].name = getResourceInfo(gamemode, "name") or getResourceName(gamemode)
  672.             tableOut[id].resname = getResourceName(gamemode)
  673.             tableOut[id].maps = {}
  674.             local maps = call(getResourceFromName("mapmanager"), "getMapsCompatibleWithGamemode" , gamemode)
  675.             for _,map in ipairs (maps) do
  676.                 table.insert(tableOut[id]["maps"] ,{name = getResourceInfo(map, "name") or getResourceName(map), resname = getResourceName(map)})
  677.             end
  678.             table.sort(tableOut[id]["maps"], sortCompareFunction)
  679.         end
  680.         table.sort((tableOut), sortCompareFunction)
  681.         table.insert(tableOut, {name = "no gamemode", resname = "no gamemode", maps = {}})
  682.         local countGmodes = #tableOut
  683.         local maps = call(getResourceFromName("mapmanager"), "getMapsCompatibleWithGamemode")
  684.         for id,map in ipairs (maps) do
  685.             -- if fileOpen(":"..getResourceName(map).."/deleted") then
  686.                 -- table.insert(deletedMaps ,{name = getResourceInfo(map, "name") or getResourceName(map), resname = getResourceName(map)})
  687.             -- else
  688.                 table.insert(tableOut[countGmodes]["maps"] ,{name = getResourceInfo(map, "name") or getResourceName(map), resname = getResourceName(map)})
  689.             -- end
  690.         end
  691.         -- table.sort(deletedMaps, sortCompareFunction)
  692.         table.sort(tableOut[countGmodes]["maps"], sortCompareFunction)
  693.         -- table.insert(tableOut, {name = "deleted maps", resname = "deleted maps", maps = {}})
  694.         -- local countGmodes = countGmodes + 1
  695.         -- tableOut[countGmodes]["maps"] = deletedMaps
  696.     end
  697.     local map = call(getResourceFromName("mapmanager"), "getRunningGamemodeMap")
  698.     local gamemode = call(getResourceFromName("mapmanager"), "getRunningGamemode")
  699.     gamemode = gamemode and getResourceName(gamemode) or "N/A"
  700.     map = map and getResourceName(map) or "N/A"
  701.     callClientFunction(loadList,"loadMaps", tableOut, gamemode, map)
  702. end
  703.  
  704. function sortCompareFunction(s1, s2)
  705.     if type(s1) == "table" and type(s2) == "table" then
  706.         s1, s2 = s1.name, s2.name
  707.     end
  708.     s1, s2 = s1:lower(), s2:lower()
  709.     if s1 == s2 then
  710.         return false
  711.     end
  712.     local byte1, byte2 = string.byte(s1:sub(1,1)), string.byte(s2:sub(1,1))
  713.     if not byte1 then
  714.         return true
  715.     elseif not byte2 then
  716.         return false
  717.     elseif byte1 < byte2 then
  718.         return true
  719.     elseif byte1 == byte2 then
  720.         return sortCompareFunction(s1:sub(2), s2:sub(2))
  721.     else
  722.         return false
  723.     end
  724. end
  725.  
  726. function callGetMaps()
  727.     for i,player in ipairs(getElementsByType("player")) do
  728.         callClientFunction(player,"getMaps")
  729.     end
  730. end
  731. addCommandHandler("rebuildMaps",callGetMaps)
  732.  
  733.  
  734.  
  735.  
  736. -- Buy a next map
  737. -- function buyMap(thePlayer,mapName)
  738.     -- local playerLevel = tonumber(loadPlayerData(thePlayer,"level"))
  739.     -- local playerCash = tonumber(loadPlayerData(thePlayer,"cash"))
  740.     -- if mapIsAlreadySet == false then
  741.         -- if not (mapName == "") then
  742.             -- if playerLevel >= mapLevel then
  743.                 -- if playerCash >= mapCost then
  744.                     -- triggerEvent("onExternalNextmapRequest",thePlayer,thePlayer,mapName)
  745.                 -- else
  746.                     -- outputChatBox("#FF6600* #FFFFFFYou don't have enough money to set a map!",thePlayer,255,255,255,true)
  747.                 -- end
  748.             -- else--
  749.                 -- outputChatBox("#FF6600* #FFFFFFYou need to be level #ABCDEF"..mapLevel.." #FFFFFFor higher to set maps!",thePlayer,255,255,255,true)
  750.             -- end
  751.         -- else
  752.             -- outputChatBox("#FF6600* #FFFFFFPlease select a map from the list first!",thePlayer,255,255,255,true)
  753.         -- end
  754.     -- else
  755.         -- outputChatBox("#FF6600* #FFFFFFA map is already set at the moment! Please try again later.",thePlayer,255,255,255,true)
  756.     -- end
  757. -- end
  758.  
  759.  
  760.  
  761.  
  762. function resetMapSetStatus()
  763.     mapIsAlreadySet = false
  764. end
  765. addEventHandler("onMapStarting",getRootElement(),resetMapSetStatus)
  766.  
  767.  
  768.  
  769.  
  770.  
  771.  
  772.  
  773.  
  774.  
  775.  
  776.  
  777.  
  778.  
  779.  
  780. g_Root = getRootElement()
  781. g_Tick = {}
  782. g_MapInfo = nil
  783. lastmap_B = nil
  784.  
  785. addEvent('onMapStarting')
  786. addEventHandler('onMapStarting', g_Root,
  787.     function(mapInfo)
  788.         g_MapInfo = mapInfo
  789.         mapIsAlreadySet = false
  790.     end
  791. )
  792.  
  793.  
  794. function findMap( query )
  795.     local maps = findMaps( query )
  796.  
  797.     -- Make status string
  798.     local status = "Found " .. #maps .. " match" .. ( #maps==1 and "" or "es" )
  799.     for i=1,math.min(5,#maps) do
  800.         status = status .. ( i==1 and ": " or ", " ) .. "'" .. getMapName( maps[i] ) .. "'"
  801.     end
  802.     if #maps > 5 then
  803.         status = status .. " (" .. #maps - 5 .. " more)"
  804.     end
  805.  
  806.     if #maps == 0 then
  807.         return nil, status .. " for '" .. query .. "'"
  808.     end
  809.     if #maps == 1 then
  810.         return maps[1], status
  811.     end
  812.     if #maps > 1 then
  813.         return nil, status
  814.     end
  815. end
  816.  
  817. -- Find all maps which match the query string
  818. function findMaps( query )
  819.     local results = {}
  820.     --escape all meta chars
  821.     query = string.gsub(query, "([%*%+%?%.%(%)%[%]%{%}%\%/%|%^%$%-])","%%%1")
  822.     -- Loop through and find matching maps
  823.     for i,resource in ipairs(exports.mapmanager:getMapsCompatibleWithGamemode(getThisResource())) do
  824.         local resName = getResourceName( resource )
  825.         local infoName = getMapName( resource  )
  826.  
  827.         -- Look for exact match first
  828.         if query == resName or query == infoName then
  829.             return {resource}
  830.         end
  831.  
  832.         -- Find match for query within infoName
  833.         if string.find( infoName:lower(), query:lower() ) then
  834.             table.insert( results, resource )
  835.         end
  836.     end
  837.     return results
  838. end
  839.  
  840. addEvent('buyMapFromPanel', true)
  841. function buyMFP(mapname)
  842.     -- if g_ForcedNextMap then
  843.         -- outputChatBox('Next map is ' ..getMapName(g_ForcedNextMap), source)
  844.         -- return
  845.     -- end
  846.     -- local query = #{mapname}>0 and table.concat({mapname},' ') or nil
  847.     -- if not query then
  848.         -- if g_ForcedNextMap then
  849.             -- outputChatBox('Next map is ' ..getMapName(g_ForcedNextMap), source)
  850.         -- else
  851.             -- outputChatBox('Next map is not set', source, 255, 0, 0)
  852.         -- end
  853.         -- return
  854.     -- end
  855.     -- local map, errormsg = findMap(query)
  856.     -- if not map then
  857.         -- outputChatBox(errormsg, source)
  858.         -- return
  859.     -- end
  860.     -- local playerLevel = tonumber(loadPlayerData(source,"level"))
  861.     -- local playerCash = tonumber(loadPlayerData(source,"cash"))
  862.     -- if playerLevel >= mapLevel then
  863.         -- if playerCash >= mapCost then
  864.             -- if lastmap_B == map then
  865.                 -- outputChatBox('That map has been played too much recently.', source, 255, 0, 0)
  866.             -- else
  867.                 -- local TotalPlayerCash = playerCash - mapCost
  868.                 -- g_ForcedNextMap = map
  869.                 -- outputChatBox(getPlayerName(source).. " bought map '" ..getMapName(g_ForcedNextMap).. "' for "..mapCost.."$.", g_Root, 0, 240, 0)
  870.                 -- savePlayerData(source,"cash", TotalPlayerCash)
  871.                 -- lastmap_B = g_ForcedNextMap
  872.                 -- achievement31(source)
  873.                 -- scoreboardRefresh(source)
  874.             -- end
  875.         -- else
  876.             -- outputChatBox("#FF6600* #FFFFFFYou don't have enough money to set a map!",source,255,255,255,true)
  877.         -- end
  878.     -- else
  879.         -- outputChatBox("#FF6600* #FFFFFFYou need to be level #ABCDEF"..mapLevel.." #FFFFFFor higher to set maps!",source,255,255,255,true)
  880.     -- end
  881.     buyMap(source, command, mapname)
  882. end
  883. addEventHandler('buyMapFromPanel', g_Root, buyMFP)
  884.  
  885. function buyMap(player, command, ...)
  886.     if g_ForcedNextMap then
  887.         outputChatBox( 'Next map is ' .. getMapName( g_ForcedNextMap ), player )
  888.         return
  889.     end
  890.     local query = #{...}>0 and table.concat({...},' ') or nil
  891.     if not query then
  892.         if g_ForcedNextMap then
  893.             outputChatBox( 'Next map is ' .. getMapName( g_ForcedNextMap ), player )
  894.         else
  895.             outputChatBox( 'Next map is not set', player, 255, 0, 0 )
  896.         end
  897.         return
  898.     end
  899.     local map, errormsg = findMap(query)
  900.     if not map then
  901.         outputChatBox(errormsg, player)
  902.         return
  903.     end
  904.     local playerLevel = tonumber(loadPlayerData(player,"level"))
  905.     local playerCash = tonumber(loadPlayerData(player,"cash"))
  906.     if playerLevel >= mapLevel then
  907.         if playerCash >= mapCost then
  908.         if lastmap_B == map then
  909.             outputChatBox( 'That map has been played too much recently.', player, 255, 0, 0 )
  910.         else
  911.             g_ForcedNextMap = map
  912.                 local TotalPlayerCash = playerCash - mapCost
  913.                 outputChatBox("#007FFF[Map]#FFFFFF" ..getPlayerName(player).. "#FFFFFF set '#007FFF" ..getMapName(g_ForcedNextMap).."#FFFFFF' as nextmap.", getRootElement(), 0, 240, 0, true)
  914.                 savePlayerData(player,"cash", TotalPlayerCash)
  915.             lastmap_B = g_ForcedNextMap
  916.             achievement31(player)
  917.             scoreboardRefresh(player)
  918.         end
  919.         else
  920.             outputChatBox("#FF6600* #FFFFFFYou don't have enough money to set a map!",source,255,255,255,true)
  921.         end
  922.     else
  923.         outputChatBox("#FF6600* #FFFFFFYou need to be level #ABCDEF"..mapLevel.." #FFFFFFor higher to set maps!",source,255,255,255,true)
  924.     end
  925. end
  926. addCommandHandler('bm', buyMap)
  927. addCommandHandler('buymap', buyMap)
  928.  
  929.  
  930. addCommandHandler("mapcount",
  931.     function(source)
  932.         local resourceTable = getResources()
  933.         local mapcount = 0
  934.         for resourceKey, resourceValue in ipairs(resourceTable) do
  935.             local type = getResourceInfo(resourceValue, "type")
  936.             local game = getResourceInfo(resourceValue, "gamemodes")
  937.             if type == "map" and game == "race" then
  938.                 mapcount = mapcount+1
  939.             else
  940.                 cancelEvent()
  941.             end
  942.         end
  943.         outputChatBox("There are " ..tostring(mapcount).. " maps on the server.", source, 46, 154, 254)
  944.     end
  945. )
  946.  
  947.  
  948.  
  949.  
  950.  
  951.  
  952.  
  953.  
  954.  
  955.  
  956.  
  957.  
  958.  
  959.  
  960.  
  961. addEvent("onScriptSetNextMap",true)
  962. addEventHandler("onScriptSetNextMap",getRootElement(),
  963. function (mapName)
  964.     thePlayer = source
  965.     local playerCash = tonumber(loadPlayerData(thePlayer,"cash"))
  966.     savePlayerData(thePlayer,"cash",playerCash-mapCost)
  967.     outputChatBox("#FFFFFFNextmap: "..getPlayerName(thePlayer).."#FFFFFF has bought a next map!",getRootElement(),255,255,255,true)
  968.     outputChatBox("#FFFFFFNextmap: #FF8800"..mapName,getRootElement(),255,255,255,true)
  969.     mapIsAlreadySet = true
  970.     scoreboardRefresh(thePlayer)
  971.     achievement31(thePlayer)
  972. end)
  973.  
  974. addEvent("onRaceSetNextMap",true)
  975. addEventHandler("onRaceSetNextMap",getRootElement(),
  976. function ()
  977.     mapIsAlreadySet = true
  978. end)
  979.  
  980.  
  981.  
  982. -- Skin handler
  983. function saveSkin(thePlayer,skinID)
  984.     if (tonumber(loadPlayerData(thePlayer,"cash")) >= skinCost) then
  985.         savePlayerData(thePlayer,"skin",skinID)
  986.         savePlayerData(thePlayer,"cash",tonumber(loadPlayerData(thePlayer,"cash"))-skinCost)
  987.         skinEnabled = loadPlayerData(thePlayer,"useCustomSkin")
  988.         if skinEnabled == "true" then
  989.             setElementModel(thePlayer,skinID)
  990.         end
  991.         outputChatBox("#00BFFF* #FFFFFFYou have sucessfuly purchased the skin! #FFFF00[#FFFFFFID:"..skinID.."#FFFF00]",thePlayer,255,255,255,true)
  992.         setTimer(outputChatBox,700,1,"#00BFFF* #FFFFFFThe skin has been saved to your account.",thePlayer,255,255,255,true)
  993.         savePlayerData(thePlayer,"everPurchasedSkin",1)
  994.         setElementData(thePlayer,"everPurchasedSkin",1)
  995.         scoreboardRefresh(thePlayer)
  996.         achievement38(thePlayer)
  997.     else
  998.         outputChatBox("#00BFFF* #FFFFFFERROR! You don't have enough money!",thePlayer,255,255,255,true)
  999.     end
  1000. end
  1001.  
  1002. function setSkinOnMapStart()
  1003.     if tonumber(getElementData(source,"everPurchasedSkin")) == 1 then
  1004.         skinEnabled = loadPlayerData(source,"useCustomSkin")
  1005.         if skinEnabled == "true" then
  1006.             skinID = loadPlayerData(source,"skin")
  1007.             setElementModel(source,skinID)
  1008.         end
  1009.     end
  1010. end
  1011. addEventHandler("onNotifyPlayerReady",getRootElement(),setSkinOnMapStart)
  1012.  
  1013.  
  1014.  
  1015. function checkSkinLevel(thePlayer)
  1016.     local playerLevel = tonumber(loadPlayerData(thePlayer,"level"))
  1017.     if playerLevel >= skinLevel then
  1018.         callClientFunction(thePlayer,"openSkinsWindow")
  1019.     else
  1020.         outputChatBox("#00BFFF* #FFFFFFERROR! You need to be level #ABCDEF"..skinLevel.."#FFFFFF or more to change skins!",thePlayer,255,255,255,true)
  1021.     end
  1022. end
  1023.  
  1024.  
  1025.  
  1026.  
  1027. -- Options handler
  1028. function saveClientSettings(thePlayer,a,b,c,d,e,f,g,h,i,j)
  1029.     outputChatBox("#00BFFF* #FFFFFFYour settings have been saved!",thePlayer,255,255,255,true)
  1030.     savePlayerData(thePlayer,"allowPersonalDetails",a)
  1031.     savePlayerData(thePlayer,"allowStats",b)
  1032.     savePlayerData(thePlayer,"useCustomNametag",c)
  1033.     savePlayerData(thePlayer,"useCustomSkin",d)
  1034.     savePlayerData(thePlayer,"useCustomVehicleColor",e)
  1035.     savePlayerData(thePlayer,"soundMessage",f)
  1036.     savePlayerData(thePlayer,"soundRequest",g)
  1037.     savePlayerData(thePlayer,"showOnDeath",h)
  1038.     savePlayerData(thePlayer,"useHunterSkin",i)
  1039.     savePlayerData(thePlayer,"chatAcceptMode",j)
  1040. end
  1041.  
  1042. function getClientSettings(thePlayer)
  1043.     a = loadPlayerData(thePlayer,"allowPersonalDetails")
  1044.     b = loadPlayerData(thePlayer,"allowStats")
  1045.     c = loadPlayerData(thePlayer,"useCustomNametag")
  1046.     d = loadPlayerData(thePlayer,"useCustomSkin")
  1047.     e = loadPlayerData(thePlayer,"useCustomVehicleColor")
  1048.     f = loadPlayerData(thePlayer,"soundMessage")
  1049.     g = loadPlayerData(thePlayer,"soundRequest")
  1050.     h = loadPlayerData(thePlayer,"showOnDeath")
  1051.     i = loadPlayerData(thePlayer,"useHunterSkin")
  1052.     j = loadPlayerData(thePlayer,"chatAcceptMode")
  1053.     callClientFunction(thePlayer,"configureOptions",true,a,b,c,d,e,f,g,h,i,j)
  1054. end
  1055.  
  1056. function showUserpanelOnDeath()
  1057.     if (loadPlayerData(source,"showOnDeath") == "true") then
  1058.         callClientFunction(source,"displayUserpanel")
  1059.     end
  1060. end
  1061. addEventHandler("onPlayerWasted",getRootElement(),showUserpanelOnDeath)
  1062.  
  1063.  
  1064.  
  1065. -- Nametag color
  1066. function saveNametagColor(thePlayer,r,g,b)
  1067.     local playerCash = tonumber(loadPlayerData(thePlayer,"cash"))
  1068.     savePlayerData(thePlayer,"cash",playerCash-nametagPrice)
  1069.     savePlayerData(thePlayer,"nametagRed",r)
  1070.     savePlayerData(thePlayer,"nametagGreen",g)
  1071.     savePlayerData(thePlayer,"nametagBlue",b)
  1072.     setNametagColor(thePlayer)
  1073.     outputChatBox("#00BFFF* #FFFFFFYou have purchased a new nametag color for #ABCDEF$"..nametagPrice.."#FFFFFF!",thePlayer,255,255,255,true)
  1074.     savePlayerData(thePlayer,"everPurchasedNametagColor",1)
  1075.     setElementData(thePlayer,"everPurchasedNametagColor",1)
  1076.     scoreboardRefresh(thePlayer)
  1077. end
  1078.  
  1079. function getNametagLevel(thePlayer)
  1080.     local playerCash = tonumber(loadPlayerData(thePlayer,"cash"))
  1081.     local playerLevel = tonumber(loadPlayerData(thePlayer,"level"))
  1082.     if playerLevel >= nametagLevel then
  1083.             callClientFunction(thePlayer,"showNametagWindow")
  1084.     else
  1085.         outputChatBox("#00BFFF* #FFFFFFERROR! You need to be level #ABCDEF"..nametagLevel.."#FFFFFF or higher to change your nametag color!",thePlayer,255,255,255,true)
  1086.     end
  1087. end
  1088.  
  1089.  
  1090. function setNametagColor(thePlayer)
  1091.     local ifSet = tonumber(getElementData(thePlayer,"everPurchasedNametagColor"))
  1092.     if ifSet == 1 then
  1093.         local useColor = loadPlayerData(thePlayer,"useCustomNametag")
  1094.         if useColor == "true" then
  1095.             local r = tonumber(loadPlayerData(thePlayer,"nametagRed"))
  1096.             local g = tonumber(loadPlayerData(thePlayer,"nametagGreen"))
  1097.             local b = tonumber(loadPlayerData(thePlayer,"nametagBlue"))
  1098.             callClientFunction(thePlayer,"setCustomNametagColor",true,r,g,b)
  1099.         end
  1100.     end
  1101. end
  1102. addEventHandler("onPlayerJoin",getRootElement(),setNametagColor)
  1103.  
  1104.  
  1105.  
  1106. -- Horns
  1107. function getPurchasedHorns(thePlayer)
  1108.     local airhorn = tonumber(loadPlayerData(thePlayer,"horn1"))
  1109.     local clown = tonumber(loadPlayerData(thePlayer,"horn2"))
  1110.     local train = tonumber(loadPlayerData(thePlayer,"horn3"))
  1111.     local ship = tonumber(loadPlayerData(thePlayer,"horn4"))
  1112.     local submarine = tonumber(loadPlayerData(thePlayer,"horn5"))
  1113.     local military = tonumber(loadPlayerData(thePlayer,"horn6"))
  1114.     local whoopie = tonumber(loadPlayerData(thePlayer,"horn7"))
  1115.     callClientFunction(thePlayer,"updateHorns",thePlayer,airhorn,clown,train,ship,submarine,military,whoopie)
  1116. end
  1117.  
  1118. function purchaseHorn(thePlayer,horn,hornName)
  1119.     local playerCash = tonumber(loadPlayerData(thePlayer,"cash"))
  1120.     local playerLevel = tonumber(loadPlayerData(thePlayer,"level"))
  1121.     local checkOwnership = tonumber(loadPlayerData(thePlayer,"horn"..horn))
  1122.     if checkOwnership == 0 then
  1123.         if playerLevel >= hornLevel then
  1124.             if playerCash >= hornPrice[horn] then
  1125.                 savePlayerData(thePlayer,"cash",playerCash-hornPrice[horn])
  1126.                 savePlayerData(thePlayer,tostring("horn"..horn),1)
  1127.                 getPurchasedHorns(thePlayer)
  1128.                 scoreboardRefresh(thePlayer)
  1129.                 achievement39(thePlayer)
  1130.                 outputChatBox("#00BFFF* #FFFFFFYou have purchased the #ABCDEF"..hornName.."#FFFFFF horn for #ABCDEF$"..hornPrice[horn].."#FFFFFF!",thePlayer,255,255,255,true)
  1131.             else
  1132.                 outputChatBox("#00BFFF* #FFFFFFERROR! You don't have enough money!",thePlayer,255,255,255,true)
  1133.             end
  1134.         else
  1135.             outputChatBox("#00BFFF* #FFFFFFERROR! You need to be level #ABCDEF"..hornLevel.."#FFFFFF or higher to purchase new horns!",thePlayer,255,255,255,true)
  1136.         end
  1137.     else
  1138.         outputChatBox("#00BFFF* #FFFFFFERROR! You already own this horn!",thePlayer,255,255,255,true)
  1139.     end
  1140. end
  1141.  
  1142. function checkForPurchasedHorn(thePlayer,horn)
  1143.     local hornStatus = tonumber(loadPlayerData(thePlayer,"horn"..horn))
  1144.     if hornStatus == 1 then
  1145.         callClientFunction(thePlayer,"setHorn",horn)
  1146.     else
  1147.         outputChatBox("#00BFFF* #FFFFFFERROR! You do not own this horn!",thePlayer,255,255,255,true)
  1148.     end
  1149. end
  1150.  
  1151. function getLastSetHorn(thePlayer)
  1152.     local horn = tonumber(loadPlayerData(thePlayer,"lastSetHorn"))
  1153.     callClientFunction(thePlayer,"setLastUsedHorn",horn)
  1154. end
  1155.  
  1156. function setLastSetHorn(thePlayer,horn)
  1157.     savePlayerData(thePlayer,"lastSetHorn",horn)
  1158. end
  1159.  
  1160. function toggleHornControl()
  1161.     for _,player in ipairs(getElementsByType("player")) do
  1162.         if loadPlayerData(player,"lastSetHorn") == 0 then
  1163.             setTimer(toggleControl,2000,1,player,"horn",true)
  1164.         else
  1165.             setTimer(toggleControl,2000,1,player,"horn",false)
  1166.         end
  1167.     end
  1168. end
  1169. addEvent("onMapStarting",true)
  1170. addEventHandler("onMapStarting",getRootElement(),toggleHornControl)
  1171.  
  1172. function toggleControlOnReady()
  1173.     if loadPlayerData(source,"lastSetHorn") == 0 then
  1174.         toggleControl(source,"horn",true)
  1175.     else
  1176.         toggleControl(source,"horn",false)
  1177.     end
  1178. end
  1179. addEventHandler("onNotifyPlayerReady",getRootElement(),toggleControlOnReady)
  1180.  
  1181.  
  1182. function playHornForAllClients(horningPlayer,hornSoundPath,cSetHornSound) -- This function passes on the horn to all players.
  1183.     triggerClientEvent(getRootElement(),"onRecieveHorn",horningPlayer,horningPlayer,hornSoundPath,cSetHornSound)
  1184. end
  1185.  
  1186.  
  1187.  
  1188.  
  1189. -- Buy water color and time change
  1190. function buyChangeWaterColor(thePlayer,r,g,b)
  1191.     if type(r) == "number" and r >= 0 and r <= 255 then
  1192.         if type(g) == "number" and g >= 0 and g <= 255 then
  1193.             if type(b) == "number" and g >= 0 and g <= 255 then
  1194.                 local playerCash = tonumber(loadPlayerData(thePlayer,"cash"))
  1195.                 if playerCash >= 400 then
  1196.                     callClientFunction(getRootElement(),"cSetWaterColor",r,g,b)
  1197.                     savePlayerData(thePlayer,"cash",playerCash-400)
  1198.                     outputChatBox("#00BFFF* #FFFFFF"..getPlayerName(thePlayer).." #FFFFFFhas changed the water color!",getRootElement(),255,255,255,true)
  1199.                     scoreboardRefresh(thePlayer)
  1200.                 else
  1201.                     outputChatBox("#00BFFF* #FFFFFFERROR! You don't have enough money!",thePlayer,255,255,255,true)
  1202.                 end
  1203.             else
  1204.                 outputChatBox("#00BFFF* #FFFFFFInvalid BLUE value - Please use a number from 0 to 255.",thePlayer,255,255,255,true)
  1205.             end
  1206.         else
  1207.             outputChatBox("#00BFFF* #FFFFFFInvalid GREEN value - Please use a number from 0 to 255.",thePlayer,255,255,255,true)
  1208.         end
  1209.     else
  1210.         outputChatBox("#00BFFF* #FFFFFFInvalid RED value - Please use a number from 0 to 255.",thePlayer,255,255,255,true)
  1211.     end
  1212. end
  1213.  
  1214.  
  1215. function buyChangeTime(thePlayer,h,m)
  1216.     if type(h) == "number" and h >= 0 and h <= 23 then
  1217.         if type(m) == "number" and m >= 0 and m <= 59 then
  1218.             local playerCash = tonumber(loadPlayerData(thePlayer,"cash"))
  1219.             if playerCash >= 400 then
  1220.                 setTime(h,m)
  1221.                 savePlayerData(thePlayer,"cash",playerCash-250)
  1222.                 if h < 10 and m < 10 then
  1223.                     outputChatBox("#00BFFF* #FFFFFF"..getPlayerName(thePlayer).." #FFFFFFhas changed the time to #ABCDEF0"..h..":0"..m.."#FFFFFF!",getRootElement(),255,255,255,true)
  1224.                 elseif h < 10 then
  1225.                     outputChatBox("#00BFFF* #FFFFFF"..getPlayerName(thePlayer).." #FFFFFFhas changed the time to #ABCDEF0"..h..":"..m.."#FFFFFF!",getRootElement(),255,255,255,true)
  1226.                 elseif m < 10 then
  1227.                     outputChatBox("#00BFFF* #FFFFFF"..getPlayerName(thePlayer).." #FFFFFFhas changed the time to #ABCDEF"..h..":0"..m.."#FFFFFF!",getRootElement(),255,255,255,true)
  1228.                 elseif m > 10 and h > 10 then
  1229.                     outputChatBox("#00BFFF* #FFFFFF"..getPlayerName(thePlayer).." #FFFFFFhas changed the time to #ABCDEF"..h..":"..m.."#FFFFFF!",getRootElement(),255,255,255,true)
  1230.                 end
  1231.                 scoreboardRefresh(thePlayer)
  1232.             else
  1233.                 outputChatBox("#00BFFF* #FFFFFFERROR! You don't have enough money!",thePlayer,255,255,255,true)
  1234.             end
  1235.         else
  1236.             outputChatBox("#00BFFF* #FFFFFFInvalid MINUTES - Please use a number from 0 to 59.",thePlayer,255,255,255,true)
  1237.         end
  1238.     else
  1239.         outputChatBox("#00BFFF* #FFFFFFInvalid HOURS - Please use a number from 0 to 23.",thePlayer,255,255,255,true)
  1240.     end
  1241. end
  1242.  
  1243.  
  1244.  
  1245.  
  1246.  
  1247.  
  1248. ---------------------------
  1249. -- Userpanel - Record stats
  1250. ---------------------------
  1251.  
  1252. -- Personal Details
  1253. function savePersonalDetails(thePlayer,pName,pAge,pEmail,pMsn,pSkype,pXfire,pICQ,pXBL)
  1254.     savePlayerData(thePlayer,"pName",pName)
  1255.     savePlayerData(thePlayer,"pAge",pAge)
  1256.     savePlayerData(thePlayer,"pEmail",pEmail)
  1257.     savePlayerData(thePlayer,"pMsn",pMsn)
  1258.     savePlayerData(thePlayer,"pSkype",pSkype)
  1259.     savePlayerData(thePlayer,"pXfire",pXfire)
  1260.     savePlayerData(thePlayer,"pICQ",pICQ)
  1261.     savePlayerData(thePlayer,"pXBL",pXBL)
  1262.     outputChatBox("#00BFFF* #FFFFFFYour personal details have been saved!",thePlayer,255,255,255,true)
  1263.     if (pName == "" or pAge == "" or pEmail == "" or pMsn == "" or pSkype == "" or pXfire == "" or pICQ == "" or pXBL == "") then
  1264.         return
  1265.     else
  1266.         achievement35(thePlayer)
  1267.     end
  1268. end
  1269.  
  1270.  
  1271.  
  1272.  
  1273. -- Playing time
  1274. function playingTimeAdd(thePlayer)
  1275.     local totalPlayingTimeMinutes = tonumber(loadPlayerData(thePlayer,"totalPlayingTimeMinutes"))
  1276.     local totalPlayingTimeHours = tonumber(loadPlayerData(thePlayer,"totalPlayingTimeHours"))
  1277.     if totalPlayingTimeMinutes == 59 then
  1278.         savePlayerData(thePlayer,"totalPlayingTimeMinutes",0)
  1279.         savePlayerData(thePlayer,"totalPlayingTimeHours",totalPlayingTimeHours+1)
  1280.     else
  1281.         savePlayerData(thePlayer,"totalPlayingTimeMinutes",totalPlayingTimeMinutes+1)
  1282.     end
  1283.     local totalPlayingTimeMinutes = tonumber(loadPlayerData(thePlayer,"totalPlayingTimeMinutes"))
  1284.     local totalPlayingTimeHours = tonumber(loadPlayerData(thePlayer,"totalPlayingTimeHours"))
  1285.     callClientFunction(thePlayer,"refreshTimePlaying",totalPlayingTimeMinutes,totalPlayingTimeHours)
  1286.     achievement21(thePlayer)
  1287.     achievement22(thePlayer)
  1288. end
  1289.  
  1290.  
  1291. -- Times joined the server
  1292. function timesJoinedAdd()
  1293.     local totalTimesJoined = tonumber(loadPlayerData(source,"totalTimesJoined"))
  1294.     savePlayerData(source,"totalTimesJoined",totalTimesJoined+1)
  1295. end
  1296. addEventHandler("onPlayerJoin",getRootElement(),timesJoinedAdd)
  1297.  
  1298.  
  1299. -- Total maps played
  1300. function totalMapsPlayedAdd()
  1301.     local mapsPlayed = tonumber(loadPlayerData(source,"mapsPlayed"))
  1302.     savePlayerData(source,"mapsPlayed",mapsPlayed+1)
  1303. end
  1304. addEvent("onNotifyPlayerReady",true)
  1305. addEventHandler("onNotifyPlayerReady",getRootElement(),totalMapsPlayedAdd)
  1306.  
  1307.  
  1308. -- Total hunters reached
  1309. function totalHuntersAdd(thePlayer)
  1310.     local totalHunters = tonumber(loadPlayerData(thePlayer,"totalHunters"))
  1311.     savePlayerData(thePlayer,"totalHunters",totalHunters+1)
  1312. end
  1313.  
  1314.  
  1315. -- Total toptimes set
  1316.  
  1317. addEvent("onPlayerToptimeImprovement",true)
  1318. addEventHandler("onPlayerToptimeImprovement",getRootElement(),
  1319. function (player)
  1320.     local totalToptimes = tonumber(loadPlayerData(source,"totalToptimes"))
  1321.     savePlayerData(source,"totalToptimes",totalToptimes+1)
  1322. end)
  1323.  
  1324.  
  1325. -- Total money earned
  1326. function totalMoneyEarnedAdd(thePlayer,addValue)
  1327.     outputDebugString(tostring(addValue))
  1328.     addValue = tonumber(addValue)
  1329.     local totalMoneyEarned = tonumber(loadPlayerData(thePlayer,"totalMoneyEarned"))
  1330.     savePlayerData(thePlayer,"totalMoneyEarned",totalMoneyEarned + addValue)
  1331. end
  1332.  
  1333.  
  1334. -- Total maps won
  1335. function mapsWonAdd(winner)
  1336.     local mapsWon = tonumber(loadPlayerData(winner,"mapsWon"))
  1337.     savePlayerData(winner,"mapsWon",mapsWon+1)
  1338. end
  1339. addEvent("onPlayerDestructionDerbyWin",true)
  1340. addEventHandler("onPlayerDestructionDerbyWin",getRootElement(),mapsWonAdd)
  1341.  
  1342.  
  1343.  
  1344. -- Total money sent
  1345. function totalMoneySentAdd(thePlayer,amount)
  1346.     local totalMoneySent = tonumber(loadPlayerData(thePlayer,"totalMoneySent"))
  1347.     savePlayerData(thePlayer,"totalMoneySent",totalMoneySent+amount)
  1348. end
  1349.  
  1350.  
  1351. -- Total bets
  1352. function totalBetsAdd(thePlayer)
  1353.     local totalBets = tonumber(loadPlayerData(thePlayer,"totalBets"))
  1354.     savePlayerData(thePlayer,"totalBets",totalBets+1)
  1355. end
  1356.  
  1357.  
  1358. -- Total bets won
  1359. function totalBetsWonAdd(thePlayer)
  1360.     local totalBetsWon = tonumber(loadPlayerData(thePlayer,"totalBetsWon"))
  1361.     savePlayerData(thePlayer,"totalBetsWon",totalBetsWon+1)
  1362. end
  1363.  
  1364.  
  1365. -- Total bets earned
  1366. function totalBetsEarnedAdd(thePlayer,addAmount)
  1367.     local totalBetsEarned = tonumber(loadPlayerData(thePlayer,"totalBetsEarned"))
  1368.     savePlayerData(thePlayer,"totalBetsEarned",totalBetsEarned+addAmount)
  1369. end
  1370.  
  1371.  
  1372. -- Total deaths
  1373. function totalDeathsAdd()
  1374.     local totalDeaths = tonumber(loadPlayerData(source,"totalDeaths"))
  1375.     savePlayerData(source,"totalDeaths",totalDeaths+1)
  1376. end
  1377. addEventHandler("onPlayerWasted",getRootElement(),totalDeathsAdd)
  1378.  
  1379.  
  1380. -- Unlocked Achievements
  1381. function unlockedAchievementsAdd(thePlayer)
  1382.     local unlockedAchievements = tonumber(loadPlayerData(thePlayer,"unlockedAchievements"))
  1383.     savePlayerData(thePlayer,"unlockedAchievements",unlockedAchievements+1)
  1384.     local unlockedAchievements = tonumber(loadPlayerData(thePlayer,"unlockedAchievements"))
  1385.     callClientFunction(thePlayer,"updateUnlockedAchievementsNumberLabel",unlockedAchievements)
  1386. end
  1387. function unlockedAchievementsSet(thePlayer,amount)
  1388.     savePlayerData(thePlayer,"unlockedAchievements",amount)
  1389. end
  1390.  
  1391.  
  1392.  
  1393. -- Progress bar
  1394. function progressBarUpdate(thePlayer)
  1395.     local playerLevel = tonumber(loadPlayerData(thePlayer,"level"))
  1396.     local playerCash = tonumber(loadPlayerData(thePlayer,"cash"))
  1397.     local progressBarValue = 0
  1398.     local maxValue = 0
  1399.     if playerLevel == 1 then
  1400.         maxValue = level2
  1401.     elseif playerLevel == 2 then
  1402.         maxValue = level3
  1403.     elseif playerLevel == 3 then
  1404.         maxValue = level4
  1405.     elseif playerLevel == 4 then
  1406.         maxValue = level5
  1407.     elseif playerLevel == 5 then
  1408.         maxValue = level6
  1409.     elseif playerLevel == 6 then
  1410.         maxValue = level7
  1411.     elseif playerLevel == 7 then
  1412.         maxValue = level8
  1413.     elseif playerLevel == 8 then
  1414.         maxValue = level9
  1415.     elseif playerLevel == 9 then
  1416.         maxValue = level10
  1417.     elseif playerLevel == 10 then
  1418.         maxValue = level11
  1419.     elseif playerLevel == 11 then
  1420.         maxValue = level12
  1421.     elseif playerLevel == 12 then
  1422.         maxValue = level13
  1423.     elseif playerLevel == 13 then
  1424.         maxValue = level14
  1425.     elseif playerLevel == 14 then
  1426.         maxValue = level15
  1427.     elseif playerLevel == 15 then
  1428.         maxValue = level16
  1429.     elseif playerLevel == 16 then
  1430.         maxValue = level17
  1431.     elseif playerLevel == 17 then
  1432.         maxValue = level18
  1433.     elseif playerLevel == 18 then
  1434.         maxValue = level19
  1435.     elseif playerLevel == 19 then
  1436.         maxValue = level20
  1437.     elseif playerLevel == 20 then
  1438.         maxValue = level21
  1439.     elseif playerLevel == 21 then
  1440.         maxValue = level22
  1441.     elseif playerLevel == 22 then
  1442.         maxValue = level23
  1443.     elseif playerLevel == 23 then
  1444.         maxValue = level24
  1445.     elseif playerLevel == 24 then
  1446.         maxValue = level25
  1447.     elseif playerLevel == 25 then
  1448.         maxValue = level26
  1449.     elseif playerLevel == 26 then
  1450.         maxValue = level27
  1451.     elseif playerLevel == 27 then
  1452.         maxValue = level28
  1453.     elseif playerLevel == 28 then
  1454.         maxValue = level29
  1455.     elseif playerLevel == 29 then
  1456.         maxValue = level30
  1457.     elseif playerLevel == 30 then
  1458.         maxValue = level31
  1459.     elseif playerLevel == 31 then
  1460.         maxValue = level32
  1461.     elseif playerLevel == 32 then
  1462.         maxValue = level33
  1463.     elseif playerLevel == 33 then
  1464.         maxValue = level34
  1465.     elseif playerLevel == 34 then
  1466.         maxValue = level35
  1467.     elseif playerLevel == 35 then
  1468.         maxValue = level36
  1469.     elseif playerLevel == 36 then
  1470.         maxValue = level37
  1471.     elseif playerLevel == 37 then
  1472.         maxValue = level38
  1473.     elseif playerLevel == 38 then
  1474.         maxValue = level39
  1475.     elseif playerLevel == 39 then
  1476.         maxValue = level40
  1477.     elseif playerLevel == 40 then
  1478.         maxValue = level41
  1479.     elseif playerLevel == 41 then
  1480.         return false
  1481.     end
  1482.     if playerCash >= maxValue then
  1483.         progressBarValue = 100
  1484.     elseif playerCash == 0 then
  1485.         progressBarValue = 0
  1486.     elseif (playerCash > 0) and (playerCash < maxValue) then
  1487.         progressBarValue = math.round(((100/maxValue)*playerCash),6)
  1488.     end
  1489.     callClientFunction(thePlayer,"updateProgressBar",progressBarValue)
  1490. end
  1491.  
  1492.  
  1493. -- Check if we "converted" the levels to the total money
  1494. function checkConvertedMoney(thePlayer)
  1495.     local convertedTotal = tonumber(loadPlayerData(thePlayer,"convertedTotal"))
  1496.     local playerCash = tonumber(loadPlayerData(thePlayer,"cash"))
  1497.     if convertedTotal == 0 then
  1498.         local playerLevel = tonumber(loadPlayerData(thePlayer,"level"))
  1499.         local tempMoney = 0
  1500.         local levelMoney = 0
  1501.         if playerLevel == 1 then
  1502.             levelMoney = 0
  1503.         elseif playerLevel > 26 then
  1504.             for i=1,26 do
  1505.                 levelMoney = levelMoney+((i-1)*1000)
  1506.                 tempMoney = 25000
  1507.             end
  1508.             for i=27,playerLevel do
  1509.                 tempMoney = tempMoney + 3000
  1510.                 levelMoney = levelMoney+tempMoney
  1511.             end
  1512.         elseif playerLevel <= 26 then
  1513.             for i=1,playerLevel do
  1514.                 levelMoney = levelMoney+((i-1)*1000)
  1515.             end
  1516.         end
  1517.         savePlayerData(thePlayer,"totalMoneyEarned",levelMoney+playerCash)
  1518.         savePlayerData(thePlayer,"convertedTotal",1)
  1519.         scoreboardRefresh(thePlayer)
  1520.     end
  1521. end
  1522.  
  1523.  
  1524.  
  1525. ---------------------------
  1526. -- Userpanel - Achievements
  1527. ---------------------------
  1528.  
  1529.  
  1530. function checkAchievementsOnStart(thePlayer)
  1531.     local ach1 = tonumber(loadPlayerData(thePlayer,"ach1"))
  1532.     local ach2 = tonumber(loadPlayerData(thePlayer,"ach2"))
  1533.     local ach3 = tonumber(loadPlayerData(thePlayer,"ach3"))
  1534.     local ach4 = tonumber(loadPlayerData(thePlayer,"ach4"))
  1535.     local ach5 = tonumber(loadPlayerData(thePlayer,"ach5"))
  1536.     local ach6 = tonumber(loadPlayerData(thePlayer,"ach6"))
  1537.     local ach7 = tonumber(loadPlayerData(thePlayer,"ach7"))
  1538.     local ach8 = tonumber(loadPlayerData(thePlayer,"ach8"))
  1539.     local ach9 = tonumber(loadPlayerData(thePlayer,"ach9"))
  1540.     local ach10 = tonumber(loadPlayerData(thePlayer,"ach10"))
  1541.     local ach11 = tonumber(loadPlayerData(thePlayer,"ach11"))
  1542.     local ach12 = tonumber(loadPlayerData(thePlayer,"ach12"))
  1543.     local ach13 = tonumber(loadPlayerData(thePlayer,"ach13"))
  1544.     local ach14 = tonumber(loadPlayerData(thePlayer,"ach14"))
  1545.     local ach15 = tonumber(loadPlayerData(thePlayer,"ach15"))
  1546.     local ach16 = tonumber(loadPlayerData(thePlayer,"ach16"))
  1547.     local ach17 = tonumber(loadPlayerData(thePlayer,"ach17"))
  1548.     local ach18 = tonumber(loadPlayerData(thePlayer,"ach18"))
  1549.     local ach19 = tonumber(loadPlayerData(thePlayer,"ach19"))
  1550.     local ach20 = tonumber(loadPlayerData(thePlayer,"ach20"))
  1551.     local ach21 = tonumber(loadPlayerData(thePlayer,"ach21"))
  1552.     local ach22 = tonumber(loadPlayerData(thePlayer,"ach22"))
  1553.     local ach23 = tonumber(loadPlayerData(thePlayer,"ach23"))
  1554.     local ach24 = tonumber(loadPlayerData(thePlayer,"ach24"))
  1555.     local ach25 = tonumber(loadPlayerData(thePlayer,"ach25"))
  1556.     local ach26 = tonumber(loadPlayerData(thePlayer,"ach26"))
  1557.     local ach27 = tonumber(loadPlayerData(thePlayer,"ach27"))
  1558.     local ach28 = tonumber(loadPlayerData(thePlayer,"ach28"))
  1559.     local ach29 = tonumber(loadPlayerData(thePlayer,"ach29"))
  1560.     local ach30 = tonumber(loadPlayerData(thePlayer,"ach30"))
  1561.     local ach31 = tonumber(loadPlayerData(thePlayer,"ach31"))
  1562.     local ach32 = tonumber(loadPlayerData(thePlayer,"ach32"))
  1563.     local ach33 = tonumber(loadPlayerData(thePlayer,"ach33"))
  1564.     local ach34 = tonumber(loadPlayerData(thePlayer,"ach34"))
  1565.     local ach35 = tonumber(loadPlayerData(thePlayer,"ach35"))
  1566.     local ach36 = tonumber(loadPlayerData(thePlayer,"ach36"))
  1567.     local ach37 = tonumber(loadPlayerData(thePlayer,"ach37"))
  1568.     local ach38 = tonumber(loadPlayerData(thePlayer,"ach38"))
  1569.     local ach39 = tonumber(loadPlayerData(thePlayer,"ach39"))
  1570.     local ach40 = tonumber(loadPlayerData(thePlayer,"ach40"))
  1571.     callClientFunction(thePlayer,"checkAchievementsOnStart",ach1,ach2,ach3,ach4,ach5,ach6,ach7,ach8,ach9,ach10,ach11,ach12,ach13,ach14,ach15,ach16,ach17,ach18,ach19,ach20,ach21,ach22,ach23,ach24,ach25,ach26,ach27,ach28,ach29,ach30,ach31,ach32,ach33,ach34,ach35,ach36,ach37,ach38,ach39,ach40)
  1572. end
  1573.  
  1574.  
  1575.  
  1576. -- Achievement 1
  1577. function achievement1(source)
  1578.     local unlocked = tonumber(loadPlayerData(source,"ach1"))
  1579.     if unlocked == 0 then
  1580.         callClientFunction(source,"unlockAchievement",1)
  1581.         savePlayerData(source,"ach1",1)
  1582.         local thePlayer = source
  1583.         unlockedAchievementsAdd(thePlayer)
  1584.     end
  1585. end
  1586.  
  1587.  
  1588. -- Achievement 2
  1589. function achievement2(winner)
  1590.     local unlocked = tonumber(loadPlayerData(winner,"ach2"))
  1591.     local mapsWon = tonumber(loadPlayerData(winner,"mapsWon"))
  1592.     if unlocked == 0 then
  1593.         if mapsWon >= 10 then
  1594.             callClientFunction(winner,"unlockAchievement",2)
  1595.             savePlayerData(winner,"ach2",1)
  1596.             local thePlayer = winner
  1597.             unlockedAchievementsAdd(thePlayer)
  1598.         end
  1599.     end
  1600. end
  1601. addEventHandler("onPlayerDestructionDerbyWin",getRootElement(),achievement2)
  1602.  
  1603.  
  1604. -- Achievement 3
  1605. function achievement3(winner)
  1606.     local unlocked = tonumber(loadPlayerData(winner,"ach3"))
  1607.     local mapsWon = tonumber(loadPlayerData(winner,"mapsWon"))
  1608.     if unlocked == 0 then
  1609.         if mapsWon >= 50 then
  1610.             callClientFunction(winner,"unlockAchievement",3)
  1611.             savePlayerData(winner,"ach3",1)
  1612.             local thePlayer = winner
  1613.             unlockedAchievementsAdd(thePlayer)
  1614.         end
  1615.     end
  1616. end
  1617. addEventHandler("onPlayerDestructionDerbyWin",getRootElement(),achievement3)
  1618.  
  1619.  
  1620. -- Achievement 4
  1621. function achievement4(winner)
  1622.     local unlocked = tonumber(loadPlayerData(winner,"ach4"))
  1623.     local mapsWon = tonumber(loadPlayerData(winner,"mapsWon"))
  1624.     if unlocked == 0 then
  1625.         if mapsWon >= 100 then
  1626.             callClientFunction(winner,"unlockAchievement",4)
  1627.             savePlayerData(winner,"ach4",1)
  1628.             local thePlayer = winner
  1629.             unlockedAchievementsAdd(thePlayer)
  1630.         end
  1631.     end
  1632. end
  1633. addEventHandler("onPlayerDestructionDerbyWin",getRootElement(),achievement4)
  1634.  
  1635.  
  1636. -- Achievement 5
  1637. function achievement5(winner)
  1638.     local unlocked = tonumber(loadPlayerData(winner,"ach5"))
  1639.     local mapsWon = tonumber(loadPlayerData(winner,"mapsWon"))
  1640.     if unlocked == 0 then
  1641.         if mapsWon >= 200 then
  1642.             callClientFunction(winner,"unlockAchievement",5)
  1643.             savePlayerData(winner,"ach5",1)
  1644.             local thePlayer = winner
  1645.             unlockedAchievementsAdd(thePlayer)
  1646.         end
  1647.     end
  1648. end
  1649. addEventHandler("onPlayerDestructionDerbyWin",getRootElement(),achievement5)
  1650.  
  1651.  
  1652. -- Achievement 6
  1653. function achievement6()
  1654.     local unlocked = tonumber(loadPlayerData(source,"ach6"))
  1655.     local totalDeaths = tonumber(loadPlayerData(source,"totalDeaths"))
  1656.     if unlocked == 0 then
  1657.         if totalDeaths >= 300 then
  1658.             callClientFunction(source,"unlockAchievement",6)
  1659.             savePlayerData(source,"ach6",1)
  1660.             local thePlayer = source
  1661.             unlockedAchievementsAdd(thePlayer)
  1662.         end
  1663.     end
  1664. end
  1665. addEventHandler("onPlayerWasted",getRootElement(),achievement6)
  1666.  
  1667.  
  1668. -- Achievement 7,8,9,10,11,12,13,14,15
  1669. function levelAchievements(thePlayer)
  1670.     local unlocked7 = tonumber(loadPlayerData(thePlayer,"ach7"))
  1671.     local unlocked8 = tonumber(loadPlayerData(thePlayer,"ach8"))
  1672.     local unlocked9 = tonumber(loadPlayerData(thePlayer,"ach9"))
  1673.     local unlocked10 = tonumber(loadPlayerData(thePlayer,"ach10"))
  1674.     local unlocked11 = tonumber(loadPlayerData(thePlayer,"ach11"))
  1675.     local unlocked12 = tonumber(loadPlayerData(thePlayer,"ach12"))
  1676.     local unlocked13 = tonumber(loadPlayerData(thePlayer,"ach13"))
  1677.     local unlocked14 = tonumber(loadPlayerData(thePlayer,"ach14"))
  1678.     local unlocked15 = tonumber(loadPlayerData(thePlayer,"ach15"))
  1679.     local level = tonumber(loadPlayerData(thePlayer,"level"))
  1680.     if unlocked7 == 0 then
  1681.         if level >= 5 then
  1682.             callClientFunction(thePlayer,"unlockAchievement",7)
  1683.             savePlayerData(thePlayer,"ach7",1)
  1684.             unlockedAchievementsAdd(thePlayer)
  1685.         end
  1686.     end
  1687.     if unlocked8 == 0 then
  1688.         if level >= 10 then
  1689.             callClientFunction(thePlayer,"unlockAchievement",8)
  1690.             savePlayerData(thePlayer,"ach8",1)
  1691.             unlockedAchievementsAdd(thePlayer)
  1692.         end
  1693.     end
  1694.     if unlocked9 == 0 then
  1695.         if level >= 15 then
  1696.             callClientFunction(thePlayer,"unlockAchievement",9)
  1697.             savePlayerData(thePlayer,"ach9",1)
  1698.             unlockedAchievementsAdd(thePlayer)
  1699.         end
  1700.     end
  1701.     if unlocked10 == 0 then
  1702.         if level >= 20 then
  1703.             callClientFunction(thePlayer,"unlockAchievement",10)
  1704.             savePlayerData(thePlayer,"ach10",1)
  1705.             unlockedAchievementsAdd(thePlayer)
  1706.         end
  1707.     end
  1708.     if unlocked11 == 0 then
  1709.         if level >= 25 then
  1710.             callClientFunction(thePlayer,"unlockAchievement",11)
  1711.             savePlayerData(thePlayer,"ach11",1)
  1712.             unlockedAchievementsAdd(thePlayer)
  1713.         end
  1714.     end
  1715.     if unlocked12 == 0 then
  1716.         if level >= 26 then
  1717.             callClientFunction(thePlayer,"unlockAchievement",12)
  1718.             savePlayerData(thePlayer,"ach12",1)
  1719.             unlockedAchievementsAdd(thePlayer)
  1720.         end
  1721.     end
  1722.     if unlocked13 == 0 then
  1723.         if level >= 31 then
  1724.             callClientFunction(thePlayer,"unlockAchievement",13)
  1725.             savePlayerData(thePlayer,"ach13",1)
  1726.             unlockedAchievementsAdd(thePlayer)
  1727.         end
  1728.     end
  1729.     if unlocked14 == 0 then
  1730.         if level >= 36 then
  1731.             callClientFunction(thePlayer,"unlockAchievement",14)
  1732.             savePlayerData(thePlayer,"ach14",1)
  1733.             unlockedAchievementsAdd(thePlayer)
  1734.         end
  1735.     end
  1736.     if unlocked15 == 0 then
  1737.         if level >= 41 then
  1738.             callClientFunction(thePlayer,"unlockAchievement",15)
  1739.             savePlayerData(thePlayer,"ach15",1)
  1740.             unlockedAchievementsAdd(thePlayer)
  1741.         end
  1742.     end
  1743. end
  1744.  
  1745.  
  1746.  
  1747. -- Achievement 16
  1748. function achievement16(thePlayer)
  1749.     local totalHunters = tonumber(loadPlayerData(thePlayer,"totalHunters"))
  1750.     local unlocked = tonumber(loadPlayerData(thePlayer,"ach16"))
  1751.     if unlocked == 0 then
  1752.         if totalHunters >= 10 then
  1753.             callClientFunction(thePlayer,"unlockAchievement",16)
  1754.             savePlayerData(thePlayer,"ach16",1)
  1755.             unlockedAchievementsAdd(thePlayer)
  1756.         end
  1757.     end
  1758. end
  1759.  
  1760.  
  1761. -- Achievement 17
  1762. function achievement17(thePlayer)
  1763.     local totalHunters = tonumber(loadPlayerData(thePlayer,"totalHunters"))
  1764.     local unlocked = tonumber(loadPlayerData(thePlayer,"ach17"))
  1765.     if unlocked == 0 then
  1766.         if totalHunters >= 50 then
  1767.             callClientFunction(thePlayer,"unlockAchievement",17)
  1768.             savePlayerData(thePlayer,"ach17",1)
  1769.             unlockedAchievementsAdd(thePlayer)
  1770.         end
  1771.     end
  1772. end
  1773.  
  1774.  
  1775. -- Achievement 18
  1776. function achievement18(thePlayer)
  1777.     local totalHunters = tonumber(loadPlayerData(thePlayer,"totalHunters"))
  1778.     local unlocked = tonumber(loadPlayerData(thePlayer,"ach18"))
  1779.     if unlocked == 0 then
  1780.         if totalHunters >= 100 then
  1781.             callClientFunction(thePlayer,"unlockAchievement",18)
  1782.             savePlayerData(thePlayer,"ach18",1)
  1783.             unlockedAchievementsAdd(thePlayer)
  1784.         end
  1785.     end
  1786. end
  1787.  
  1788.  
  1789. -- Achievement 19,20
  1790. function toptimeAchievements(thePlayer)
  1791.     local totalToptimes = tonumber(loadPlayerData(thePlayer,"totalToptimes"))
  1792.     local unlocked1 = tonumber(loadPlayerData(thePlayer,"ach19"))
  1793.     local unlocked2 = tonumber(loadPlayerData(thePlayer,"ach20"))
  1794.     if unlocked1 == 0 then
  1795.         if totalToptimes >= 1 then
  1796.             callClientFunction(thePlayer,"unlockAchievement",19)
  1797.             savePlayerData(thePlayer,"ach19",1)
  1798.             unlockedAchievementsAdd(thePlayer)
  1799.         end
  1800.     end
  1801.     if unlocked2 == 0 then
  1802.         if totalToptimes >= 10 then
  1803.             callClientFunction(thePlayer,"unlockAchievement",20)
  1804.             savePlayerData(thePlayer,"ach20",1)
  1805.             unlockedAchievementsAdd(thePlayer)
  1806.         end
  1807.     end
  1808. end
  1809. addEventHandler("onPlayerToptimeImprovement",getRootElement(),toptimeAchievements)
  1810.  
  1811.  
  1812. -- Achievement 21
  1813. function achievement21(thePlayer)
  1814.     local totalPlayingTimeHours = tonumber(loadPlayerData(thePlayer,"totalPlayingTimeHours"))
  1815.     local unlocked = tonumber(loadPlayerData(thePlayer,"ach21"))
  1816.     if unlocked == 0 then
  1817.         if totalPlayingTimeHours >= 20 then
  1818.             callClientFunction(thePlayer,"unlockAchievement",21)
  1819.             savePlayerData(thePlayer,"ach21",1)
  1820.             unlockedAchievementsAdd(thePlayer)
  1821.         end
  1822.     end
  1823. end
  1824.  
  1825.  
  1826. -- Achievement 22
  1827. function achievement22(thePlayer)
  1828.     local totalPlayingTimeHours = tonumber(loadPlayerData(thePlayer,"totalPlayingTimeHours"))
  1829.     local unlocked = tonumber(loadPlayerData(thePlayer,"ach22"))
  1830.     if unlocked == 0 then
  1831.         if totalPlayingTimeHours >= 50 then
  1832.             callClientFunction(thePlayer,"unlockAchievement",22)
  1833.             savePlayerData(thePlayer,"ach22",1)
  1834.             unlockedAchievementsAdd(thePlayer)
  1835.         end
  1836.     end
  1837. end
  1838.  
  1839.  
  1840. -- Achievement 23
  1841. function achievement23(thePlayer)
  1842.     local totalTimesJoined = tonumber(loadPlayerData(thePlayer,"totalTimesJoined"))
  1843.     local unlocked = tonumber(loadPlayerData(thePlayer,"ach23"))
  1844.     if unlocked == 0 then
  1845.         if totalTimesJoined >= 40 then
  1846.             callClientFunction(thePlayer,"unlockAchievement",23)
  1847.             savePlayerData(thePlayer,"ach23",1)
  1848.             unlockedAchievementsAdd(thePlayer)
  1849.         end
  1850.     end
  1851. end
  1852.  
  1853.  
  1854. -- Achievement 24,25,26
  1855. function totalMoneyAchievements(thePlayer)
  1856.     local totalMoneyEarned = tonumber(loadPlayerData(thePlayer,"totalMoneyEarned"))
  1857.     local unlocked1 = tonumber(loadPlayerData(thePlayer,"ach24"))
  1858.     local unlocked2 = tonumber(loadPlayerData(thePlayer,"ach25"))
  1859.     local unlocked3 = tonumber(loadPlayerData(thePlayer,"ach26"))
  1860.     if unlocked1 == 0 then
  1861.         if totalMoneyEarned >= 10000 then
  1862.             callClientFunction(thePlayer,"unlockAchievement",24)
  1863.             savePlayerData(thePlayer,"ach24",1)
  1864.             unlockedAchievementsAdd(thePlayer)
  1865.         end
  1866.     end
  1867.     if unlocked2 == 0 then
  1868.         if totalMoneyEarned >= 100000 then
  1869.             callClientFunction(thePlayer,"unlockAchievement",25)
  1870.             savePlayerData(thePlayer,"ach25",1)
  1871.             unlockedAchievementsAdd(thePlayer)
  1872.         end
  1873.     end
  1874.     if unlocked3 == 0 then
  1875.         if totalMoneyEarned >= 1000000 then
  1876.             callClientFunction(thePlayer,"unlockAchievement",26)
  1877.             savePlayerData(thePlayer,"ach26",1)
  1878.             unlockedAchievementsAdd(thePlayer)
  1879.         end
  1880.     end
  1881. end
  1882.  
  1883.  
  1884. -- Achievement 27
  1885. function achievement27(thePlayer)
  1886.     local unlocked = tonumber(loadPlayerData(thePlayer,"ach27"))
  1887.     if unlocked == 0 then
  1888.         callClientFunction(thePlayer,"unlockAchievement",27)
  1889.         savePlayerData(thePlayer,"ach27",1)
  1890.         unlockedAchievementsAdd(thePlayer)
  1891.     end
  1892. end
  1893.  
  1894.  
  1895. -- Achievement 28
  1896. function achievement28(thePlayer)
  1897.     local unlocked = tonumber(loadPlayerData(thePlayer,"ach28"))
  1898.     if unlocked == 0 then
  1899.         callClientFunction(thePlayer,"unlockAchievement",28)
  1900.         savePlayerData(thePlayer,"ach28",1)
  1901.         unlockedAchievementsAdd(thePlayer)
  1902.     end
  1903. end
  1904.  
  1905.  
  1906. -- Achievement 29
  1907. function achievement29(thePlayer)
  1908.     local unlocked = tonumber(loadPlayerData(thePlayer,"ach29"))
  1909.     if unlocked == 0 then
  1910.         callClientFunction(thePlayer,"unlockAchievement",29)
  1911.         savePlayerData(thePlayer,"ach29",1)
  1912.         unlockedAchievementsAdd(thePlayer)
  1913.     end
  1914. end
  1915.  
  1916.  
  1917. -- Achievement 30
  1918. function achievement30(thePlayer)
  1919.     local unlocked = tonumber(loadPlayerData(thePlayer,"ach30"))
  1920.     if unlocked == 0 then
  1921.         callClientFunction(thePlayer,"unlockAchievement",30)
  1922.         savePlayerData(thePlayer,"ach30",1)
  1923.         unlockedAchievementsAdd(thePlayer)
  1924.     end
  1925. end
  1926.  
  1927.  
  1928. -- Achievement 31
  1929. function achievement31(thePlayer)
  1930.     local unlocked = tonumber(loadPlayerData(thePlayer,"ach31"))
  1931.     if unlocked == 0 then
  1932.         callClientFunction(thePlayer,"unlockAchievement",31)
  1933.         savePlayerData(thePlayer,"ach31",1)
  1934.         unlockedAchievementsAdd(thePlayer)
  1935.     end
  1936. end
  1937.  
  1938. -- Achievements 32,33,34 -- Maps played
  1939. function mapsPlayedAchievements()
  1940.     local unlocked1 = tonumber(loadPlayerData(source,"ach32"))
  1941.     local unlocked2 = tonumber(loadPlayerData(source,"ach33"))
  1942.     local unlocked3 = tonumber(loadPlayerData(source,"ach34"))
  1943.     local totalMapsPlayed = tonumber(loadPlayerData(source,"mapsPlayed"))
  1944.     if unlocked1 == 0 then
  1945.         if totalMapsPlayed >= 100 then
  1946.             callClientFunction(source,"unlockAchievement",32)
  1947.             savePlayerData(source,"ach32",1)
  1948.             local thePlayer = source
  1949.             unlockedAchievementsAdd(thePlayer)
  1950.         end
  1951.     end
  1952.     if unlocked2 == 0 then
  1953.         if totalMapsPlayed >= 500 then
  1954.             callClientFunction(source,"unlockAchievement",33)
  1955.             savePlayerData(source,"ach33",1)
  1956.             local thePlayer = source
  1957.             unlockedAchievementsAdd(thePlayer)
  1958.         end
  1959.     end
  1960.     if unlocked3 == 0 then
  1961.         if totalMapsPlayed >= 1000 then
  1962.             callClientFunction(source,"unlockAchievement",34)
  1963.             savePlayerData(source,"ach34",1)
  1964.             local thePlayer = source
  1965.             unlockedAchievementsAdd(thePlayer)
  1966.         end
  1967.     end
  1968. end
  1969. addEvent("onNotifyPlayerReady",true)
  1970. addEventHandler("onNotifyPlayerReady",getRootElement(),mapsPlayedAchievements)
  1971.  
  1972.  
  1973. -- Achievement 35 -- Socializer
  1974. function achievement35(thePlayer)
  1975.     local unlocked = tonumber(loadPlayerData(thePlayer,"ach35"))
  1976.     if unlocked == 0 then
  1977.         callClientFunction(thePlayer,"unlockAchievement",35)
  1978.         savePlayerData(thePlayer,"ach35",1)
  1979.         unlockedAchievementsAdd(thePlayer)
  1980.     end
  1981. end
  1982.  
  1983.  
  1984. -- Achievement 36 -- Reaction tests
  1985. function achievement36(thePlayer)
  1986.     local unlocked = tonumber(loadPlayerData(thePlayer,"ach36"))
  1987.     local totalReactionTests = tonumber(loadPlayerData(thePlayer,"totalReactionTests"))
  1988.     if unlocked == 0 then
  1989.         if totalReactionTests >= 15 then
  1990.             callClientFunction(thePlayer,"unlockAchievement",36)
  1991.             savePlayerData(thePlayer,"ach36",1)
  1992.         end
  1993.     end
  1994. end
  1995.  
  1996.  
  1997. -- Achievement 37 -- Reaction time
  1998. function achievement37(thePlayer)
  1999.     local unlocked = tonumber(loadPlayerData(thePlayer,"ach37"))
  2000.     if unlocked == 0 then
  2001.         callClientFunction(thePlayer,"unlockAchievement",37)
  2002.         savePlayerData(thePlayer,"ach37",1)
  2003.     end
  2004. end
  2005.  
  2006.  
  2007. -- Achievement 38 -- Buy skin
  2008. function achievement38(thePlayer)
  2009.     local unlocked = tonumber(loadPlayerData(thePlayer,"ach38"))
  2010.     if unlocked == 0 then
  2011.         callClientFunction(thePlayer,"unlockAchievement",38)
  2012.         savePlayerData(thePlayer,"ach38",1)
  2013.     end
  2014. end
  2015.  
  2016.  
  2017. -- Achievement 39 -- Buy horn
  2018. function achievement39(thePlayer)
  2019.     local unlocked = tonumber(loadPlayerData(thePlayer,"ach39"))
  2020.     if unlocked == 0 then
  2021.         callClientFunction(thePlayer,"unlockAchievement",39)
  2022.         savePlayerData(thePlayer,"ach39",1)
  2023.     end
  2024. end
  2025.  
  2026.  
  2027. -- Achievement 40 - Unlock all achievements
  2028. function achievement40(thePlayer)
  2029.     local ach1 = tonumber(loadPlayerData(thePlayer,"ach1"))
  2030.     local ach2 = tonumber(loadPlayerData(thePlayer,"ach2"))
  2031.     local ach3 = tonumber(loadPlayerData(thePlayer,"ach3"))
  2032.     local ach4 = tonumber(loadPlayerData(thePlayer,"ach4"))
  2033.     local ach5 = tonumber(loadPlayerData(thePlayer,"ach5"))
  2034.     local ach6 = tonumber(loadPlayerData(thePlayer,"ach6"))
  2035.     local ach7 = tonumber(loadPlayerData(thePlayer,"ach7"))
  2036.     local ach8 = tonumber(loadPlayerData(thePlayer,"ach8"))
  2037.     local ach9 = tonumber(loadPlayerData(thePlayer,"ach9"))
  2038.     local ach10 = tonumber(loadPlayerData(thePlayer,"ach10"))
  2039.     local ach11 = tonumber(loadPlayerData(thePlayer,"ach11"))
  2040.     local ach12 = tonumber(loadPlayerData(thePlayer,"ach12"))
  2041.     local ach13 = tonumber(loadPlayerData(thePlayer,"ach13"))
  2042.     local ach14 = tonumber(loadPlayerData(thePlayer,"ach14"))
  2043.     local ach15 = tonumber(loadPlayerData(thePlayer,"ach15"))
  2044.     local ach16 = tonumber(loadPlayerData(thePlayer,"ach16"))
  2045.     local ach17 = tonumber(loadPlayerData(thePlayer,"ach17"))
  2046.     local ach18 = tonumber(loadPlayerData(thePlayer,"ach18"))
  2047.     local ach19 = tonumber(loadPlayerData(thePlayer,"ach19"))
  2048.     local ach20 = tonumber(loadPlayerData(thePlayer,"ach20"))
  2049.     local ach21 = tonumber(loadPlayerData(thePlayer,"ach21"))
  2050.     local ach22 = tonumber(loadPlayerData(thePlayer,"ach22"))
  2051.     local ach23 = tonumber(loadPlayerData(thePlayer,"ach23"))
  2052.     local ach24 = tonumber(loadPlayerData(thePlayer,"ach24"))
  2053.     local ach25 = tonumber(loadPlayerData(thePlayer,"ach25"))
  2054.     local ach26 = tonumber(loadPlayerData(thePlayer,"ach26"))
  2055.     local ach27 = tonumber(loadPlayerData(thePlayer,"ach27"))
  2056.     local ach28 = tonumber(loadPlayerData(thePlayer,"ach28"))
  2057.     local ach29 = tonumber(loadPlayerData(thePlayer,"ach29"))
  2058.     local ach30 = tonumber(loadPlayerData(thePlayer,"ach30"))
  2059.     local ach31 = tonumber(loadPlayerData(thePlayer,"ach31"))
  2060.     local ach32 = tonumber(loadPlayerData(thePlayer,"ach32"))
  2061.     local ach33 = tonumber(loadPlayerData(thePlayer,"ach33"))
  2062.     local ach34 = tonumber(loadPlayerData(thePlayer,"ach34"))
  2063.     local ach35 = tonumber(loadPlayerData(thePlayer,"ach35"))
  2064.     local ach36 = tonumber(loadPlayerData(thePlayer,"ach36"))
  2065.     local ach37 = tonumber(loadPlayerData(thePlayer,"ach37"))
  2066.     local ach38 = tonumber(loadPlayerData(thePlayer,"ach38"))
  2067.     local ach39 = tonumber(loadPlayerData(thePlayer,"ach39"))
  2068.     local ach40 = tonumber(loadPlayerData(thePlayer,"ach40"))
  2069.     if ach1 == 1 and ach2 == 1 and ach3 == 1 and ach4 == 1 and ach5 == 1 and ach6 == 1 and ach7 == 1 and ach8 == 1 and ach9 == 1 and ach10 == 1 and ach11 == 1 and ach12 == 1 and ach13 == 1 and ach14 == 1 and ach15 == 1 and ach16 == 1 and ach17 == 1 and ach18 == 1 and ach19 == 1 and ach20 == 1 and ach21 == 1 and ach22 == 1 and ach23 == 1 and ach24 == 1 and ach25 == 1 and ach26 == 1 and ach27 == 1 and ach28 == 1 and ach29 == 1 and ach30 == 1 and ach31 == 1 and ach32 == 1 and ach33 == 1 and ach34 == 1 and ach35 == 1 and ach36 == 1 and ach37 == 1 and ach38 == 1 and ach39 == 1 and ach40 == 1 then
  2070.         if ach36 == 0 then
  2071.             callClientFunction(thePlayer,"unlockAchievement",36)
  2072.             savePlayerData(thePlayer,"ach36",1)
  2073.             unlockedAchievementsAdd(thePlayer)
  2074.             ach36 = 1
  2075.         else
  2076.             outputChatBox("#00BFFF* #FFFFFFCongratulations! You have unlocked all achievements!",thePlayer,255,255,255,true)
  2077.         end
  2078.     end
  2079. end
  2080.  
  2081. function displayFancyUnlockText(thePlayer,achievementName)
  2082.     outputChatBox("#00BFFF* #FFFFFF"..getPlayerName(thePlayer).."#FFFFFF has unlocked the achievement: #01b0f0"..achievementName,getRootElement(),255,255,255,true)
  2083. end
  2084.  
  2085.  
  2086.  
  2087.  
  2088.  
  2089.  
  2090.  
  2091.  
  2092.  
  2093. ------------------------------
  2094. -- Set new player's level to 1
  2095. ------------------------------
  2096.  
  2097. function checkIfLevelNotOne()
  2098.     local playerLevel = tonumber(loadPlayerData(source,"level"))
  2099.     if (playerLevel >= 1) then
  2100.     else
  2101.         savePlayerData(source,"level",1)
  2102.         local thePlayer = source
  2103.         refreshStats(thePlayer)
  2104.         progressBarUpdate(thePlayer)
  2105.     end
  2106. end
  2107. addEventHandler("onPlayerJoin",getRootElement(),checkIfLevelNotOne)
  2108.  
  2109.  
  2110.  
  2111.  
  2112.  
  2113.  
  2114. --------------------------------------------
  2115. -- Get alive and dead players by their STATE
  2116. --------------------------------------------
  2117.  
  2118. function getAliveRacePlayers()
  2119.     local alivePlayers = 0
  2120.     for index,player in ipairs(getElementsByType("player")) do
  2121.         if getElementData(player,"state") == "alive" then
  2122.             alivePlayers = alivePlayers + 1
  2123.         end
  2124.     end
  2125.     return alivePlayers
  2126. end
  2127.  
  2128.  
  2129. function getDeadRacePlayers()
  2130.     local deadPlayers = 0
  2131.     for index,player in ipairs(getElementsByType("player")) do
  2132.         if getElementData(player,"state") == "dead" then
  2133.             deadPlayers = deadPlayers + 1
  2134.         end
  2135.     end
  2136.     return deadPlayers
  2137. end
  2138.  
  2139.  
  2140.  
  2141.  
  2142.  
  2143.  
  2144. ------------------
  2145. -- Get Player Data
  2146. ------------------
  2147.  
  2148. addCommandHandler("gpd",
  2149. function(player,command,toplayername,datatype)
  2150.     if hasObjectPermissionTo ( player, "function.kickPlayer", false ) then
  2151.         if (toplayername) and (datatype) then
  2152.             if (findPlayerByName (toplayername)) then
  2153.                 toplayer = findPlayerByName (toplayername)
  2154.                 local amount = loadPlayerData(toplayer,datatype)
  2155.                 outputChatBox ("#00BFFF* #FFFFFFgetPlayerData: " .. getPlayerName(toplayer) .. " #FF0000|#FFFFFF " .. datatype .."#FFFFFF: #ABCDEF" .. amount,player,255,255,255,true)
  2156.             end
  2157.         else
  2158.         outputChatBox ("#00BFFF* #FF0000ERROR!#FFFFFF Syntax: /getPlayerData [playername] [datatype]",player,255,255,255,true)
  2159.         end
  2160.     end
  2161. end)
  2162.  
  2163.  
  2164.  
  2165.  
  2166.  
  2167.  
  2168. ------------------
  2169. -- Set Player Data
  2170. ------------------
  2171.  
  2172. addCommandHandler("spd",
  2173. function(player,command,toplayername,datatype,amount)
  2174.     if hasObjectPermissionTo ( player, "function.kickPlayer", false ) then
  2175.         if (toplayername) and (datatype) and (amount) then
  2176.             if (findPlayerByName (toplayername)) then
  2177.                 toplayer = findPlayerByName (toplayername)
  2178.                 savePlayerData(toplayer,datatype,amount)
  2179.                 outputChatBox ("#00BFFF* #FFFFFFsetPlayerData: " .. getPlayerName(toplayer) .. " #FF0000|#FFFFFF Player's #ABCDEF" .. datatype .. "#FFFFFF has been set to: #ABCDEF" .. amount, player,255,0,0,true)
  2180.                 outputChatBox ("#00BFFF* #FFFFFF" .. getPlayerName (player) .. " #FFFFFFhas set your #ABCDEF" .. datatype .."#FFFFFF to: #ABCDEF" .. amount, toplayer,255,0,0,true)
  2181.                 local playerCash = loadPlayerData(toplayer,"cash")
  2182.                 local playerLevel = loadPlayerData(toplayer,"level")
  2183.                 local thePlayer = toplayer
  2184.                 scoreboardRefresh(thePlayer)
  2185.                 refreshStats(thePlayer)
  2186.                 progressBarUpdate(thePlayer)
  2187.             end
  2188.         else
  2189.         outputChatBox ("#00BFFF* #FF0000ERROR!#FFFFFF Syntax: /setPlayerData [playername] [datatype] [new_amount]",player,255,255,255,true)
  2190.         end
  2191.     else
  2192.     end
  2193. end)
  2194.  
  2195.  
  2196.  
  2197.  
  2198.  
  2199.  
  2200. --------------
  2201. -- Race winner
  2202. --------------
  2203.  
  2204. addEvent("onPlayerDestructionDerbyWin",true)
  2205. addEventHandler("onPlayerDestructionDerbyWin",getRootElement(),
  2206. function (winner)
  2207.     if getPlayerCount() >= 3 then
  2208.         local cashToWin = moneyEarnPart*getPlayerCount()
  2209.         if (tonumber(loadPlayerData(winner,"level")) >= 26) then
  2210.             cashToWin = cashToWin*3.1
  2211.         end
  2212.         local playerCash = loadPlayerData(winner,"cash")
  2213.         savePlayerData(winner,"cash",playerCash +cashToWin)
  2214.         local playerCash = loadPlayerData(winner,"cash")
  2215.         outputChatBox ("#00BFFF* #FFFFFF" .. getPlayerName(winner) .." #FFFFFFhas won! He/She gets $" .. tostring(cashToWin) .."#00BFFF!",getRootElement(),255,255,255,true)
  2216.         return
  2217.     else
  2218.         outputChatBox("#00BFFF* #FFFFFFNot enough players to earn money - #ABCDEF3 #FFFFFFrequired.",winner,255,255,255,true)
  2219.     end
  2220.     callClientFunction(winner,"deathReset")
  2221.     callClientFunction(winner,"playWinSound")
  2222.     local thePlayer = winner
  2223.     local newAmount = cashToWin
  2224.     totalMoneyEarnedAdd(thePlayer,cashToWin)
  2225.     scoreboardRefresh(thePlayer)
  2226.     refreshStats(thePlayer)
  2227.     progressBarUpdate(thePlayer)
  2228.     totalMoneyAchievements(thePlayer)
  2229. end)
  2230.  
  2231.  
  2232.  
  2233.  
  2234.  
  2235. -------------------
  2236. -- Other race ranks
  2237. -------------------
  2238.  
  2239. function earnMoney(thePlayer)
  2240.     local position = getAliveRacePlayers()
  2241.     if not (position <= 0) then
  2242.         if getPlayerCount() >= 3 then
  2243.             local pAlive = getAliveRacePlayers()
  2244.             local pDead = getDeadRacePlayers()
  2245.  
  2246.             local maxCash = 21*(pAlive+pDead)   -- Total cash available to earn.
  2247.             local portion = 0
  2248.             local finalCash = 0
  2249.  
  2250.             if not (position == 1) then
  2251.                 portion = math.ceil(maxCash/(pAlive+pDead-1))       -- The amount to multiply by the number of dead players to later return the money value.
  2252.                 finalCash = math.ceil(portion*(pDead))      -- Calculate the final money value.
  2253.             else
  2254.                 finalCash = maxCash
  2255.             end
  2256.             local playerCash = loadPlayerData(thePlayer,"cash")
  2257.             outputChatBox("#00BFFF* #FFFFFFYou have recieved $" .. finalCash .. "!",thePlayer,255,255,255,true)
  2258.             savePlayerData(thePlayer,"cash",playerCash +finalCash)
  2259.             outputDebugString("Final cash for player "..getPlayerName(thePlayer)..": "..finalCash)
  2260.             totalMoneyEarnedAdd(thePlayer,finalCash,finalCash)
  2261.         else
  2262.             outputChatBox("#00BFFF* #FFFFFFNot enough players to earn money - #ABCDEF3 #FFFFFFrequired.",thePlayer,255,255,255,true)
  2263.             return
  2264.         end
  2265.         scoreboardRefresh(thePlayer)
  2266.         refreshStats(thePlayer)
  2267.         progressBarUpdate(thePlayer)
  2268.         totalMoneyAchievements(thePlayer)
  2269.     end
  2270. end
  2271.  
  2272. function checkKBA()
  2273.     callClientFunction(source,"getKBA")
  2274. end
  2275. addEventHandler ("onPlayerWasted",getRootElement(),checkKBA)
  2276.  
  2277.  
  2278. function resetKBA()
  2279.     callClientFunction(source,"resetKBA")
  2280. end
  2281. addEventHandler("onNotifyPlayerReady",getRootElement(),resetKBA)
  2282.  
  2283.  
  2284.  
  2285.  
  2286.  
  2287. -----------------
  2288. -- Hunter handler
  2289. -----------------
  2290.  
  2291. function hunterBonus(thePlayer)
  2292.     if getElementData(thePlayer,"playerGotHunter") == false then
  2293.         setElementData(thePlayer,"playerGotHunter",true)
  2294.         local cashToWin = 1000
  2295.         if (tonumber(loadPlayerData(thePlayer,"level")) >= 26) then
  2296.             cashToWin = cashToWin*1.1
  2297.         end
  2298.         outputChatBox("#00BFFF* #FFFFFF"..getPlayerName(thePlayer).."#FFFFFF has got the #ABCDEFHunter#FFFFFF! #ABCDEF[#FFFFFF$"..cashToWin.."#ABCDEF]",getRootElement(),255,255,255,true)
  2299.         playerCash = loadPlayerData(thePlayer,"cash")
  2300.         savePlayerData(thePlayer,"cash",playerCash+cashToWin)
  2301.         scoreboardRefresh(thePlayer)
  2302.         totalHuntersAdd(thePlayer)
  2303.         progressBarUpdate(thePlayer)
  2304.         achievement16(thePlayer)
  2305.         achievement17(thePlayer)
  2306.         achievement18(thePlayer)
  2307.         totalMoneyAchievements(thePlayer)
  2308.         local newAmount = cashToWin
  2309.         totalMoneyEarnedAdd(thePlayer,newAmount)
  2310.     end
  2311. end
  2312.  
  2313. function checkForHunter(number,sort,model)
  2314.     if sort == "vehiclechange" then
  2315.         if model == 425 then
  2316.             setTimer(hunterBonus,200,1,source)
  2317.         end
  2318.     end
  2319. end
  2320. addEventHandler("onPlayerPickUpRacePickup",getRootElement(),checkForHunter)
  2321.  
  2322.  
  2323.  
  2324. addEvent("onPlayerToptimeImprovement",true)
  2325. addEventHandler("onPlayerToptimeImprovement",getRootElement(),
  2326. function (player,newPos,newTime,oldPos,oldTime,random1,random2)
  2327.     if getElementData(source,"playerGotHunter") == false then
  2328.         if newPos <= 10 then
  2329.             local cashToWin = 600
  2330.             if (tonumber(loadPlayerData(source,"level")) >= 26) then
  2331.                 cashToWin = cashToWin*1.1
  2332.             end
  2333.             local playerCash = loadPlayerData(source,"cash")
  2334.             savePlayerData(player,"cash",playerCash +cashToWin)
  2335.             local playerCash = loadPlayerData(source,"cash")
  2336.             outputChatBox ("#00BFFF* #FFFFFF" .. getPlayerName(source) .." #FFFFFFhas set a new top time - Place: #00BFFF"..newPos.." #ABCDEF[#FFFFFF$"..cashToWin.."#ABCDEF]",getRootElement(),255,255,255,true)
  2337.             setElementData(source, "playerGotHunter",true)
  2338.             local newAmount = cashToWin
  2339.             local thePlayer = source
  2340.             totalMoneyEarnedAdd(thePlayer,newAmount)
  2341.             totalHuntersAdd(thePlayer)
  2342.             progressBarUpdate(thePlayer)
  2343.             scoreboardRefresh(thePlayer)
  2344.             totalMoneyAchievements(thePlayer)
  2345.             achievement18(thePlayer)
  2346.         end
  2347.     end
  2348. end)
  2349.  
  2350. function resetHunterData()
  2351.     setElementData(source,"playerGotHunter",false)
  2352. end
  2353. addEventHandler("onNotifyPlayerReady",getRootElement(),resetHunterData)
  2354.  
  2355.  
  2356.  
  2357.  
  2358.  
  2359.  
  2360. -----------------
  2361. -- Reaction tests
  2362. -----------------
  2363.  
  2364.  
  2365. function newReactionTest()
  2366.     reactionString = string.random(reactionLength)
  2367.     reactionMoney = math.random(reactionMin,reactionMax)
  2368.     outputChatBox("#00BFFF* #FFFFFFSay #ABCDEF"..reactionString.."#FFFFFF to win #ABCDEF$"..reactionMoney.."#FFFFFF!",getRootElement(),255,255,255,true)
  2369.  
  2370.     addEventHandler("onPlayerChat",getRootElement(),checkForOpenConsole)
  2371.  
  2372.     reactionTimer = setTimer(
  2373.     function()
  2374.         removeEventHandler("onPlayerChat",getRootElement(),checkForOpenConsole)
  2375.     end,reactionDuration*1000,1)
  2376.  
  2377.     if isTimer(newReactionTimer) then
  2378.         killTimer(newReactionTimer)
  2379.     end
  2380.  
  2381.     themath = math.random(reactionMinRedo*1000,reactionMaxRedo*1000)
  2382.     newReactionTimer = setTimer(newReactionTest,themath )
  2383.     setTimer(checktimereaction,19850,1)
  2384.  
  2385. end
  2386.  
  2387.  
  2388. function checkForOpenConsole(message,type)
  2389.     callClientFunction(source,"checkForOpenConsole",message,type)
  2390. end
  2391.  
  2392. function checktimereaction()
  2393.     local timeLeft,leftExec,totalExec = getTimerDetails(reactionTimer)
  2394.     if timeLeft > 0 then
  2395.         outputChatBox("#00BFFF* #FFFFFFTime's up! An other reaction test will be made soon!",getRootElement(),255,255,255,true)
  2396.     end
  2397. end
  2398.  
  2399.  
  2400. function checkReactionTest(thePlayer,message,type,isOpen)
  2401.  
  2402.     if (isOpen == true) then
  2403.         outputChatBox("#00BFFF* #FFFFFF"..getPlayerName(thePlayer).."#FFFFFF attempted to cheat at the reaction test!",getRootElement(),255,255,255,true)
  2404.         outputChatBox("#00BFFF* #FFFFFFMoney decreased by #ABCDEF$1,000#FFFFFF! Do not cheat!",getRootElement(),255,255,255,true)
  2405.  
  2406.         local playerCash = loadPlayerData(thePlayer,"cash")
  2407.         savePlayerData(thePlayer,"cash",playerCash - 1000)
  2408.         scoreboardRefresh(thePlayer)
  2409.     end
  2410.  
  2411.     message = tostring(message)
  2412.     if message == "..." then
  2413.         return
  2414.     end
  2415.  
  2416.     if (message == reactionString) then
  2417.         local timeLeft,leftExec,totalExec = getTimerDetails(reactionTimer)
  2418.  
  2419.         killTimer(reactionTimer)
  2420.         removeEventHandler("onPlayerChat",getRootElement(),checkForOpenConsole)
  2421.  
  2422.         setTimer(outputChatBox,200,1,"#00BFFF* #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)
  2423.         setTimer(outputChatBox,200,1,"#00BFFF* #FFFFFFAn other reaction test will be made soon!",getRootElement(),255,255,255,true)
  2424.  
  2425.         local playerCash = loadPlayerData(thePlayer,"cash")
  2426.         local totalReactionTests = tonumber(loadPlayerData(thePlayer,"totalReactionTests"))
  2427.         local bestReactionTime = tonumber(loadPlayerData(thePlayer,"bestReactionTime"))
  2428.  
  2429.         savePlayerData(thePlayer,"cash",playerCash + reactionMoney)
  2430.         savePlayerData(thePlayer,"totalReactionTests",totalReactionTests + 1)
  2431.         totalMoneyEarnedAdd(thePlayer,reactionMoney)
  2432.  
  2433.         if (math.round((reactionDuration*1000 - timeLeft)/1000)) < bestReactionTime or (bestReactionTime == 0) then
  2434.             savePlayerData(thePlayer,"bestReactionTime",math.round((reactionDuration*1000 - timeLeft)/1000,2,floor))
  2435.         end
  2436.  
  2437.         scoreboardRefresh(thePlayer)
  2438.         setTimer(achievement36,200,1,thePlayer)
  2439.         setTimer(achievement36,200,1,thePlayer)
  2440.  
  2441.         -- Check for achievement here
  2442.         if math.round((reactionDuration*1000 - timeLeft)/1000,2,floor) <= 5 then
  2443.             achievement37(thePlayer)
  2444.         end
  2445.  
  2446.         reactionString = ""
  2447.         reactionMoney = 0
  2448.  
  2449.     end
  2450. end
  2451.  
  2452.  
  2453. function string.random(len)
  2454.     local str = ""
  2455.     for i=1,len do
  2456.         local getChar = math.random(1,35)
  2457.         if getChar <= 25 then
  2458.             local caps = math.random(1,2)
  2459.             if caps == 1 then
  2460.                 str = str..string.upper(chars[getChar])
  2461.             else
  2462.                 str = str..string.lower(chars[getChar])
  2463.             end
  2464.         else
  2465.             str = str..chars[getChar]
  2466.         end
  2467.     end
  2468.     return str
  2469. end
  2470.  
  2471.  
  2472.  
  2473.  
  2474.  
  2475. -----------------
  2476. -- Betting system
  2477. -----------------
  2478.  
  2479. function createNewBet(thePlayer,toPlayer,newAmount,oldAmount,betState)
  2480.     if getPlayerCount() >= minPlayers then
  2481.         if bettingEnabled == true then
  2482.             if (betState == 0) then
  2483.                 if (toPlayer) then
  2484.                     if (newAmount) then
  2485.                         local newAmount = tonumber(math.ceil(newAmount))
  2486.                         if (newAmount >= 1) then
  2487.                             local playerLevel = tonumber(loadPlayerData(thePlayer,"level"))
  2488.                             local playerCash = tonumber(loadPlayerData(thePlayer,"cash"))
  2489.                             local maxBet = playerLevel*betPerLevel
  2490.                             if (findPlayerByName(toPlayer)) then
  2491.                                 local toPlayerName = findPlayerByName(toPlayer)
  2492.                                 if (newAmount <= playerCash) then
  2493.                                     if newAmount <= maxBet then
  2494.                                         callClientFunction(thePlayer,"addNewBet",toPlayerName,newAmount)
  2495.                                         savePlayerData(thePlayer,"cash",playerCash-newAmount)
  2496.                                         scoreboardRefresh(thePlayer)
  2497.                                         totalBetsAdd(thePlayer)
  2498.                                         progressBarUpdate(thePlayer)
  2499.                                         --outputChatBox("#00FF00* #FFFFFFYou have placed your bet on "..getPlayerName(toPlayerName).."#FFFFFF for #ABCDEF$"..newAmount.."#FFFFFF!",thePlayer,255,255,255,true)
  2500.                                         outputChatBox("#00BFFF* #FFFFFF"..getPlayerName(thePlayer).."#FFFFFF has placed a bet on "..getPlayerName(toPlayerName).."#FFFFFF for #ABCDEF$"..newAmount.."#FFFFFF!",getRootElement(),255,255,255,true)
  2501.                                     elseif newAmount > maxBet then
  2502.                                         outputChatBox("#FF0000* #FFFFFFYou are allowed to bet a maximum of #ABCDEF$"..maxBet.."#FFFFFF! Levelling up will increase this number.",thePlayer,255,255,255,true)
  2503.                                         return false
  2504.                                     end
  2505.                                 else
  2506.                                     outputChatBox("#FF0000* #FFFFFFERROR! You don't have enough money!",thePlayer,255,255,255,true)
  2507.                                 end
  2508.                             else
  2509.                                 outputChatBox("#FF0000* #FFFFFFERROR! The player you specified has not been found! (#FFFF00"..toPlayer.."#FFFFFF)",thePlayer,255,255,255,true)
  2510.                                 return false
  2511.                             end
  2512.                         else
  2513.                             outputChatBox("#FF0000* #FFFFFFERROR! Invalid amount! [#ABCDEF$"..newAmount.."#FFFFFF]",thePlayer,255,255,255,true)
  2514.                         end
  2515.                     else
  2516.                         outputChatBox("#FF0000* #FFFFFFERROR! Please specify an amount to bet! Correct syntax: #ABCDEF/bet [player] [amount]",thePlayer,255,255,255,true)
  2517.                         return false
  2518.                     end
  2519.                 else
  2520.                     outputChatBox("#FF0000* #FFFFFFERROR! Please specify a player! Correct syntax: #ABCDEF/bet [player] [amount]",thePlayer,255,255,255,true)
  2521.                     return false
  2522.                 end
  2523.             else
  2524.                 outputChatBox("#FF0000* #FFFFFFYou have already placed your bet on "..betState.." #FFFFFFfor #ABCDEF$"..oldAmount.."#FFFFFF!",thePlayer,255,255,255,true)
  2525.                 return false
  2526.             end
  2527.         else
  2528.             outputChatBox("#FF0000* #FFFFFFBetting time is over! You can place your bet on the next map.",thePlayer,255,255,255,true)
  2529.         end
  2530.     else
  2531.         outputChatBox("#FF0000* #FFFFFFBetting #FF0000disabled.#FFFFFF Minimum required players on server: #ABCDEF" ..minPlayers.."#FF0000 | #FFFFFFConnected: #ABCDEF"..getPlayerCount(),thePlayer,255,255,255,true)
  2532.     end
  2533. end
  2534.  
  2535.  
  2536. function onPlayerBetWin(self,betAmount)
  2537.     outputChatBox("#00BFFF* #FFFFFF"..getPlayerName(self).."#FFFFFF has won his bet and has recieved #ABCDEF$".. betAmount*2 .."#FFFFFF!",getRootElement(),255,255,255,true)
  2538.     local playerCash = loadPlayerData(self,"cash")
  2539.     savePlayerData(self,"cash",playerCash+betAmount+betAmount*2)
  2540.     local thePlayer = self
  2541.     scoreboardRefresh(thePlayer)
  2542.     local addAmount = betAmount*2
  2543.     totalMoneyEarnedAdd(thePlayer,addAmount)
  2544.     totalBetsWonAdd(thePlayer)
  2545.     totalBetsEarnedAdd(thePlayer,addAmount)
  2546.     progressBarUpdate(thePlayer)
  2547.     totalMoneyAchievements(thePlayer)
  2548. end
  2549.  
  2550.  
  2551.  
  2552. function bettingTimer()
  2553.     if isTimer(chatTimer) then killTimer(chatTimer) end
  2554.     if isTimer(disableTimer) then killTimer(disableTimer) end
  2555.     if getPlayerCount() >= minPlayers then
  2556.         chatTimer = setTimer(outputChatBox,3500,1,"#00BFFF* #FFFFFFPlace your bets! #FFFFFF[#ABCDEF/bet#FFFFFF]",getRootElement(),255,255,255,true)
  2557.         bettingEnabled = true
  2558.         disableTimer = setTimer(disableBetting,betTimeLimit*1000+2000,1)
  2559.     end
  2560. end
  2561. addEvent("onMapStarting",true)
  2562. addEventHandler("onMapStarting",getRootElement(),bettingTimer)
  2563.  
  2564.  
  2565. function disableBetting()
  2566.     outputChatBox("#00BFFF* #FFFFFFBetting time is over#FF0000!",getRootElement(),255,255,255,true)
  2567.     bettingEnabled = false
  2568. end
  2569.  
  2570.  
  2571. function checkWin(winner)
  2572.     callClientFunction(getRootElement(),"compareResult",winner)
  2573. end
  2574. addEvent("onPlayerDestructionDerbyWin",true)
  2575. addEventHandler("onPlayerDestructionDerbyWin",getRootElement(),checkWin)
  2576.  
  2577.  
  2578.  
  2579. function retrieveData(thePlayer,commandName,toPlayer,newAmount)
  2580.     callClientFunction(thePlayer,"triggerBettingSystem",thePlayer,toPlayer,newAmount)
  2581. end
  2582. addCommandHandler("bet",retrieveData)
  2583.  
  2584.  
  2585.  
  2586.  
  2587.  
  2588.  
  2589. -------------
  2590. -- Give money
  2591. -------------
  2592.  
  2593. function giveMoney(thePlayer,targetPlayer,amount)
  2594.     if not (targetPlayer == "") then
  2595.         if tonumber(amount) then
  2596.             local playerCash = tonumber(loadPlayerData(thePlayer,"cash"))
  2597.             if tonumber(amount) > 0 then
  2598.                 if tonumber(amount) <= playerCash then
  2599.                     if (findPlayerByName(targetPlayer)) then
  2600.                         local target = findPlayerByName(targetPlayer)
  2601.                         if target ~= thePlayer then
  2602.                             local amount = math.ceil(amount)
  2603.                             local playerCash = loadPlayerData(thePlayer,"cash")
  2604.                             local targetCash = loadPlayerData(target,"cash")
  2605.                             savePlayerData(thePlayer,"cash",playerCash-tonumber(amount))
  2606.                             savePlayerData(target,"cash",targetCash+tonumber(amount))
  2607.                             progressBarUpdate(thePlayer)
  2608.                             progressBarUpdate(target)
  2609.                             totalMoneyAchievements(thePlayer)
  2610.                             local playerCash = loadPlayerData(thePlayer,"cash")
  2611.                             local targetCash = loadPlayerData(target,"cash")
  2612.                             scoreboardRefresh(thePlayer)
  2613.                             scoreboardRefresh(target)
  2614.                             achievement30(thePlayer)
  2615.                             totalMoneyEarnedAdd(target,amount)
  2616.                             totalMoneySentAdd(thePlayer,amount)
  2617.                             outputChatBox("#00BFFF* #FFFFFFYou have sent #ABCDEF$"..amount.."#FFFFFF to "..getPlayerName(target).."#FFFFFF!",thePlayer,255,255,255,true)
  2618.                             outputChatBox("#00BFFF* #FFFFFF"..getPlayerName(thePlayer).." #FFFFFFhas sent you #ABCDEF$"..amount.."#FFFFFF!",target,255,255,255,true)
  2619.                         else
  2620.                             outputChatBox("#00BFFF* #FFFFFFERROR! You cannot send money to yourself!",thePlayer,255,255,255,true)
  2621.                             return false
  2622.                         end
  2623.                     else
  2624.                         outputChatBox("#00BFFF* #FFFFFFERROR! The player you specified does not exist! (#FFFF00.."..targetPlayer.."#FFFFFF)",thePlayer,255,255,255,true)
  2625.                         return false
  2626.                     end
  2627.                 else
  2628.                     outputChatBox("#00BFFF* #FFFFFFERROR! You don't have enough money!",thePlayer,255,255,255,true)
  2629.                     return false
  2630.                 end
  2631.             else
  2632.                 outputChatBox("#00BFFF* #FFFFFFERROR! Invalid amount! [#ABCDEF"..amount.."#FFFFFF]",thePlayer,255,255,255,true)
  2633.                 return false
  2634.             end
  2635.         else
  2636.             outputChatBox("#00BFFF* #FFFFFFERROR! Please specify the amount to send!",thePlayer,255,255,255,true)
  2637.             return false
  2638.         end
  2639.     else
  2640.         outputChatBox("#00BFFF* #FFFFFFERROR! Please select a player!",thePlayer,255,255,255,true)
  2641.         return false
  2642.     end
  2643. end
  2644.  
  2645.  
  2646.  
  2647.  
  2648.  
  2649.  
  2650.  
  2651. ------------
  2652. -- PM system
  2653. ------------
  2654.  
  2655. function privateMessage(player, command, toplayername, ...)
  2656. local words = { ... }
  2657. local message = table.concat(words," ")
  2658.     if toplayername then
  2659.         if (findPlayerByName (toplayername)) then
  2660.         toplayer = (findPlayerByName (toplayername))
  2661.             if not (toplayer == player) then
  2662.                 if message then
  2663.                     outputChatBox("#FFFF00[PM]#00BFFF Message to #FFFFFF" .. getPlayerName(toplayer) .. "#FFFFFF: " .. message, player, 255, 255, 255, true)
  2664.                     outputChatBox("#FFFF00[PM]#00BFFF Message from #FFFFFF" .. getPlayerName(player) .. "#FFFFFF: " .. message, toplayer, 255, 255, 255, true)
  2665.                 else
  2666.                     outputChatBox("#FFFF00[PM]#00BFFF Invalid syntax! Usage:#FFFFFF /pm [partical player name] [message]", player, 255, 255, 255, true)
  2667.                     return false
  2668.                 end
  2669.             else
  2670.                 outputChatBox("#FFFF00[PM]#00BFFF You cannot PM yourself#FFFFFF!", player, 255, 255, 255, true)
  2671.                 return false
  2672.             end
  2673.         else
  2674.             outputChatBox("#FFFF00[PM]#00BFFF Player not found! #FFFFFF("..toplayername..").", player, 255, 255, 255, true)
  2675.             return false
  2676.         end
  2677.     else
  2678.         outputChatBox("#FFFF00[PM]#00BFFF Invalid syntax! Usage:#FFFFFF /pm [partical player name] [message]", player, 255, 255, 255, true)
  2679.         return false
  2680.     end
  2681. end
  2682. addCommandHandler("pm", privateMessage)
  2683.  
  2684.  
  2685.  
  2686.  
  2687.  
  2688.  
  2689. --------------------------------------
  2690. -- Find player by a part of their name
  2691. --------------------------------------
  2692.  
  2693. function findPlayerByName (name)
  2694.     local player = getPlayerFromName(name)
  2695.     if player then return player end
  2696.     for i, player in ipairs(getElementsByType("player")) do
  2697.         if string.find(string.gsub(getPlayerName(player):lower(),"#%x%x%x%x%x%x", ""), name:lower(), 1, true) then
  2698.             return player
  2699.         end
  2700.     end
  2701. return false
  2702. end
  2703.  
  2704.  
  2705.  
  2706. ----------------------------------------------
  2707. -- AFK killer - extended from clienside script
  2708. ----------------------------------------------
  2709.  
  2710. local raceState = ""
  2711. local enableMessages = true
  2712. local messageColor = "#FF5555"
  2713.  
  2714. function afkMsg(mtype,afkCount)
  2715.     if(mtype == 1) then
  2716.         outputChatBox("#00BFFF* #FFFFFF".. getPlayerName(source).. "#00BFFF has been killed by the #FFFFFFAFK killer#00BFFF #00BFFF[#ABCDEF"..afkCount.."/3#00BFFF]",getRootElement(),255,255,255,true)
  2717.     elseif(mtype == 2) then
  2718.         outputChatBox("#00BFFF* #FFFFFF".. getPlayerName(source).. "#00BFFF has been kicked for staying #FFFFFFAFK#00BFFF for 3 rounds!",getRootElement(),255,255,255,true)
  2719.     end
  2720. end
  2721.  
  2722. addEvent( "afkWarn", true )
  2723. addEventHandler( "afkWarn", getRootElement(), afkMsg)
  2724.  
  2725. function afkKill()
  2726.     local thePlayer = source
  2727.     callClientFunction(thePlayer,"setKBA",thePlayer)
  2728.     setElementHealth(source, 0)
  2729. end
  2730.  
  2731. addEvent( "afkSlap", true )
  2732. addEventHandler( "afkSlap", getRootElement(), afkKill)
  2733.  
  2734. function changeRaceState(newStateName)
  2735.     raceState = newStateName
  2736. end
  2737.  
  2738. addEvent("onRaceStateChanging", true)
  2739. addEventHandler( "onRaceStateChanging", getRootElement(), changeRaceState)
  2740.  
  2741.  
  2742. function afkKick(player)
  2743.     kickPlayer(player,"AFK")
  2744. end
  2745.  
  2746. addEvent( "afkKick", true)
  2747. addEventHandler( "afkKick", getRootElement(), afkKick)
  2748.  
  2749.  
  2750.  
  2751. function clientLoaded()
  2752.     local msgenable  = get( "msgenable" )
  2753.     local msgcol     = get( "msgcolor" )
  2754.     if(msgenable) then
  2755.         if(msgenable == "true") then
  2756.             enableMessages = true
  2757.         else
  2758.             enableMessages = false
  2759.         end
  2760.         if(msgcol) then
  2761.             messageColor = msgcol
  2762.         end
  2763.     end
  2764.     local maxtime    = get( "maxafktime" )
  2765.     local wtime      = get( "warnTime" )
  2766.     triggerClientEvent ( "onSettingsReady", getRootElement(), maxtime, wtime)
  2767. end
  2768.  
  2769. addEvent("onClientLoaded", true)
  2770. addEventHandler( "onClientLoaded", getRootElement(), clientLoaded)
  2771.  
  2772.  
  2773.  
  2774.  
  2775.  
  2776.  
  2777. ----------------------
  2778. -- Automated Ghostmode
  2779. ----------------------
  2780.  
  2781. addEvent("onMapStarting")
  2782. addEventHandler("onMapStarting", getRootElement(),
  2783. function(mapInfo, mapOptions, gameOptions)
  2784.     if (ismapDM(mapInfo.name) == 1) then
  2785.         outputChatBox("#00BFFF* #FFFFFFPlaying a #ABCDEF[DM]#FFFFFF map, ghostmode #00FF00ENABLED",getRootElement(),255,255,255,true)
  2786.         for theKey,thePlayer in ipairs(getElementsByType("player")) do
  2787.             setElementData( thePlayer, "overrideCollide.uniqueblah", 0, false )
  2788.         end
  2789.     elseif (ismapDM(mapInfo.name) == 2) then
  2790.         outputChatBox("#00BFFF* #FFFFFFPlaying a #ABCDEF[DD]#FFFFFF map, ghostmode #FF0000DISABLED",getRootElement(),255,255,255,true)
  2791.         for theKey,thePlayer in ipairs(getElementsByType("player")) do
  2792.             setElementData(thePlayer, "overrideCollide.uniqueblah", nil, false )
  2793.         end
  2794.     elseif (ismapDM(mapInfo.name) == 3) then
  2795.         outputChatBox("#00BFFF* #FFFFFFPlaying a #ABCDEF[FUN]#FFFFFF map, ghostmode #FF0000DISABLED",getRootElement(),255,255,255,true)
  2796.         for theKey,thePlayer in ipairs(getElementsByType("player")) do
  2797.             setElementData(thePlayer, "overrideCollide.uniqueblah", nil, false )
  2798.         end
  2799.  
  2800.     end
  2801. end)
  2802.  
  2803. function ismapDM(isim)
  2804. if string.find(isim, "[DM]", 1, true) then
  2805.     return 1
  2806. elseif string.find(isim, "[DD]", 1,true) then
  2807.     return 2
  2808. elseif string.find(isim, "[FUN]", 1,true) then
  2809.     return 3
  2810. end
  2811. end
  2812.  
  2813.  
  2814.  
  2815.  
  2816.  
  2817. ------------------------------------------------
  2818. -- Set headlights on map start and on veh-change
  2819. ------------------------------------------------
  2820.  
  2821. function setPlayerHeadlightColor(number, sort, model)
  2822.     if sort == "vehiclechange" then
  2823.         local hlcRed = getElementData(source,"hlcRed")
  2824.         local hlcGreen = getElementData(source,"hlcGreen")
  2825.         local hlcBlue = getElementData(source,"hlcBlue")
  2826.         if (hlcRed) and (hlcGreen) and (hlcBlue) then
  2827.             local car = getPedOccupiedVehicle(source)
  2828.             setVehicleHeadLightColor(car,hlcRed,hlcGreen,hlcBlue)
  2829.             --outputChatBox("Data sucessfully retrieved, headlights color has been set!",getRootElement(),0,255,0)
  2830.         else
  2831.         end
  2832.     end
  2833. end
  2834.  
  2835. function setPlayerHeadlightColor2()
  2836.     local hlcRed = getElementData(source,"hlcRed")
  2837.     local hlcGreen = getElementData(source,"hlcGreen")
  2838.     local hlcBlue = getElementData(source,"hlcBlue")
  2839.     if (hlcRed) and (hlcGreen) and (hlcBlue) then
  2840.         local car = getPedOccupiedVehicle(source)
  2841.         setVehicleHeadLightColor(car,hlcRed,hlcGreen,hlcBlue)
  2842.         --outputChatBox("Data sucessfully retrieved, headlights color has been set!",getRootElement(),0,255,0)
  2843.     else
  2844.     end
  2845. end
  2846. addEvent("onNotifyPlayerReady", true)
  2847. addEventHandler("onNotifyPlayerReady", getRootElement(), setPlayerHeadlightColor2)
  2848. addEventHandler("onPlayerPickUpRacePickup",getRootElement(),setPlayerHeadlightColor)
  2849.  
  2850.  
  2851.  
  2852.  
  2853.  
  2854. ------------------
  2855. -- Save headlights
  2856. ------------------
  2857.  
  2858. function saveHeadlights(thePlayer,colorRed,colorGreen,colorBlue)
  2859.     --outputChatBox("SERVER: Event triggered! Saving headlights...")
  2860.     local red = colorRed
  2861.     local green = colorGreen
  2862.     local blue = colorBlue
  2863.     local car = getPedOccupiedVehicle(thePlayer)
  2864.     setVehicleHeadLightColor(car,red,green,blue)
  2865.     savePlayerData(thePlayer,"hlcRed",red)
  2866.     savePlayerData(thePlayer,"hlcGreen",green)
  2867.     savePlayerData(thePlayer,"hlcBlue",blue)
  2868.     setElementData(thePlayer,"hlcRed",red)
  2869.     setElementData(thePlayer,"hlcGreen",green)
  2870.     setElementData(thePlayer,"hlcBlue",blue)
  2871.     outputChatBox("#00BFFF* #FFFFFFYour data has been saved!",thePlayer,255,255,255,true)
  2872.     --outputChatBox("SERVER: Account found! Data has been saved.")
  2873. end
  2874. addEvent("saveHeadlights", true)
  2875. addEventHandler("saveHeadlights", getRootElement(), saveHeadlights)
  2876.  
  2877.  
  2878.  
  2879.  
  2880.  
  2881. ---------------------
  2882. -- Save vehicle color
  2883. ---------------------
  2884.  
  2885. function saveVehColor(player,c1,c2,c3,c4)
  2886.     savePlayerData(player,"c1",c1)
  2887.     savePlayerData(player,"c2",c2)
  2888.     savePlayerData(player,"c3",c3)
  2889.     savePlayerData(player,"c4",c4)
  2890.     setElementData(player,"c1",c1)
  2891.     setElementData(player,"c2",c2)
  2892.     setElementData(player,"c3",c3)
  2893.     setElementData(player,"c4",c4)
  2894. end
  2895.  
  2896.  
  2897. root = getRootElement()
  2898.  
  2899. function executecolor(c1,c2,c3,c4)
  2900.     carcolor(source,true,c1,c2,c3,c4)
  2901. end
  2902.  
  2903. function executealpha(player,_,alpha)
  2904.     alpha = alpha or 255
  2905.     setElementAlpha(getPedOccupiedVehicle(player),tonumber(alpha))
  2906. end
  2907.  
  2908. function carcolor(thePlayer,_,arg1,arg2,arg3,arg4)
  2909.     local vehicle = getPedOccupiedVehicle(thePlayer)
  2910.     if (vehicle) then
  2911.         local old,old2,old3,old4=getVehicleColor(vehicle)
  2912.         local arg11,arg22,arg33,arg44=tonumber(arg1),tonumber(arg2) or old2,tonumber(arg3) or old3,tonumber(arg4) or old4
  2913.         setVehicleColor(vehicle,arg11,arg22,arg33,arg44)
  2914.         outputChatBox("#00BFFF* #FFFFFFYour data has been saved!",thePlayer,255,255,255,true)
  2915.         savePlayerData(thePlayer,"everSetCustomVehicleColor",1)
  2916.         setElementData(thePlayer,"everSetCustomVehicleColor",1)
  2917.     else
  2918.     end
  2919. end
  2920.  
  2921.  
  2922. addEvent("colorchange",true)
  2923. addEventHandler("colorchange",root, executecolor)
  2924. addEvent("alphachange",true)
  2925. addEventHandler("alphachange",root, executealpha)
  2926.  
  2927.  
  2928.  
  2929.  
  2930.  
  2931.  
  2932. ----------------------------------------------------------
  2933. -- Set vehicle color on player-ready and on vehicle change
  2934. ----------------------------------------------------------
  2935.  
  2936. function setPlayerVehicleColor(number, sort, model)
  2937.     if sort == "vehiclechange" then
  2938.         local ifSet = tonumber(getElementData(source,"everSetCustomVehicleColor"))
  2939.         if ifSet == 1 then
  2940.             local useColor = tostring(getElementData(source,"useCustomVehicleColor"))
  2941.             if (useColor == "true") then
  2942.                 local c1 = tonumber(getElementData(source,"c1"))
  2943.                 local c2 = tonumber(getElementData(source,"c2"))
  2944.                 local c3 = tonumber(getElementData(source,"c3"))
  2945.                 local c4 = tonumber(getElementData(source,"c4"))
  2946.                 local car = getPedOccupiedVehicle(source)
  2947.                 exc1, exc2, exc3, exc4 = getVehicleColor (car)
  2948.                 if not c1 then c1 = exc1 end
  2949.                 if not c2 then c2 = exc2 end
  2950.                 if not c3 then c3 = exc3 end
  2951.                 if not c4 then c4 = exc4 end
  2952.                 setVehicleColor(car,c1,c2,c3,c4)
  2953.             else
  2954.                 local car = getPedOccupiedVehicle(source)
  2955.                 setVehicleColor(car,math.random(1,126),math.random(1,126),math.random(1,126),math.random(1,126))
  2956.             end
  2957.         else
  2958.             local car = getPedOccupiedVehicle(source)
  2959.             setVehicleColor(car,math.random(1,126),math.random(1,126),math.random(1,126),math.random(1,126))
  2960.         end
  2961.     end
  2962. end
  2963.  
  2964.  
  2965. function setPlayerVehicleColor2()
  2966.     local ifSet = tonumber(getElementData(source,"everSetCustomVehicleColor"))
  2967.     if ifSet == 1 then
  2968.         local useColor = tostring(getElementData(source,"useCustomVehicleColor"))
  2969.         if (useColor == "true") then
  2970.             local c1 = tonumber(getElementData(source,"c1"))
  2971.             local c2 = tonumber(getElementData(source,"c2"))
  2972.             local c3 = tonumber(getElementData(source,"c3"))
  2973.             local c4 = tonumber(getElementData(source,"c4"))
  2974.             local car = getPedOccupiedVehicle(source)
  2975.             exc1, exc2, exc3, exc4 = getVehicleColor (car)
  2976.             if not c1 then c1 = exc1 end
  2977.             if not c2 then c2 = exc2 end
  2978.             if not c3 then c3 = exc3 end
  2979.             if not c4 then c4 = exc4 end
  2980.             setVehicleColor(car,c1,c2,c3,c4)
  2981.         else
  2982.             local car = getPedOccupiedVehicle(source)
  2983.             setVehicleColor(car,math.random(1,126),math.random(1,126),math.random(1,126),math.random(1,126))
  2984.         end
  2985.     else
  2986.         local car = getPedOccupiedVehicle(source)
  2987.         setVehicleColor(car,math.random(1,126),math.random(1,126),math.random(1,126),math.random(1,126))
  2988.     end
  2989. end
  2990.  
  2991. addEventHandler("onNotifyPlayerReady", getRootElement(), setPlayerVehicleColor2)
  2992. addEventHandler("onPlayerPickUpRacePickup", getRootElement(), setPlayerVehicleColor)
  2993.  
  2994.  
  2995.  
  2996.  
  2997.  
  2998. ---------------------------------------------
  2999. -- Set most widely used stats as element data
  3000. ---------------------------------------------
  3001.  
  3002. function setElementDataOnStart(source)
  3003.  
  3004.     thePlayer = source
  3005.  
  3006.     local a = loadPlayerData(thePlayer,"everPurchasedSkin")
  3007.     local b = loadPlayerData(thePlayer,"everPurchasedNametagColor")
  3008.     local c = loadPlayerData(thePlayer,"everSetCustomVehicleColor")
  3009.     local d = loadPlayerData(thePlayer,"useCustomVehicleColor")
  3010.     local e = loadPlayerData(thePlayer,"c1")
  3011.     local f = loadPlayerData(thePlayer,"c2")
  3012.     local g = loadPlayerData(thePlayer,"c3")
  3013.     local h = loadPlayerData(thePlayer,"c4")
  3014.     local i = loadPlayerData(thePlayer,"hlcRed")
  3015.     local j = loadPlayerData(thePlayer,"hlcGreen")
  3016.     local k = loadPlayerData(thePlayer,"hlcBlue")
  3017.     local adminredo = loadPlayerData(thePlayer,"admin_redo")
  3018.     local adminnextmap = loadPlayerData(thePlayer,"admin_nextmap")
  3019.  
  3020.     setElementData(thePlayer,"everPurchasedSkin",a)
  3021.     setElementData(thePlayer,"everPurchasedNametagColor",b)
  3022.     setElementData(thePlayer,"everSetCustomVehicleColor",c)
  3023.  
  3024.     setElementData(thePlayer,"useCustomVehicleColor",d)
  3025.  
  3026.     setElementData(thePlayer,"c1",e)
  3027.     setElementData(thePlayer,"c2",f)
  3028.     setElementData(thePlayer,"c3",g)
  3029.     setElementData(thePlayer,"c4",h)
  3030.  
  3031.     setElementData(thePlayer,"hlcRed",i)
  3032.     setElementData(thePlayer,"hlcGreen",j)
  3033.     setElementData(thePlayer,"hlcBlue",k)
  3034.  
  3035.     setElementData(thePlayer,"admin_redo",adminredo)
  3036.     setElementData(thePlayer,"admin_nextmap",adminnextmap)
  3037. end
  3038.  
  3039.  
  3040.  
  3041. -- Get player's element data (testing)
  3042. function getElementDataOnCommand(player,command,data)
  3043.     outputChatBox(tostring(getElementData(player,tostring(data))))
  3044. end
  3045. addCommandHandler("get",getElementDataOnCommand)
  3046.  
  3047.  
  3048.  
  3049. ------------
  3050. -- Save name
  3051. ------------
  3052.  
  3053. addEventHandler ("onPlayerJoin",getRootElement(),
  3054. function()
  3055.     local playerName = getPlayerName(source)
  3056.     savePlayerData(source,"playerName",string.gsub(playerName,"#%x%x%x%x%x%x", ""))
  3057. end)
  3058.  
  3059.  
  3060.  
  3061.  
  3062.  
  3063. -------------------------------------------
  3064. -- Save new nick when the player changes it
  3065. -------------------------------------------
  3066.  
  3067. addEventHandler("onPlayerChangeNick",getRootElement(),
  3068. function (olnick,newnick)
  3069.     savePlayerData(source,"playerName",string.gsub(newnick,"#%x%x%x%x%x%x", ""))
  3070. end)
  3071.  
  3072.  
  3073.  
  3074.  
  3075. -----------------
  3076. -- Get dead count
  3077. -----------------
  3078.  
  3079. function getDeadCount ()
  3080.   deadAmount = 0
  3081.   for i,v in ipairs (getDeadPlayers()) do
  3082.     deadAmount = deadAmount +1
  3083.   end
  3084.   return deadAmount
  3085. end
  3086.  
  3087.  
  3088.  
  3089.  
  3090.  
  3091. ------------------
  3092. -- Get alive count
  3093. ------------------
  3094.  
  3095. function getAliveCount ()
  3096.     aliveAmount = 0
  3097.     for i,v in ipairs (getAlivePlayers()) do
  3098.         aliveAmount = aliveAmount +1
  3099.     end
  3100.     return aliveAmount
  3101. end
  3102.  
  3103.  
  3104.  
  3105.  
  3106.  
  3107. --------------------------
  3108. -- Retrieve player's level
  3109. --------------------------
  3110.  
  3111. function retrieveLevel(thePlayer)
  3112.     local playerLevel = loadPlayerData(thePlayer,"level")
  3113.     callClientFunction(thePlayer,"checkLevel",playerLevel)
  3114. end
  3115.  
  3116.  
  3117. function retrieveLevelVeh(thePlayer)
  3118.     local playerLevel = loadPlayerData(thePlayer,"level")
  3119.     callClientFunction(thePlayer,"checkLevelVeh",playerLevel)
  3120. end
  3121.  
  3122.  
  3123.  
  3124.  
  3125.  
  3126.  
  3127. -------------------------------------------
  3128. -- Calling functions from the client's side
  3129. -------------------------------------------
  3130.  
  3131. function callServerFunction(funcname, ...)
  3132.     local arg = { ... }
  3133.     if (arg[1]) then
  3134.         for key, value in next, arg do arg[key] = tonumber(value) or value end
  3135.     end
  3136.     loadstring("return "..funcname)()(unpack(arg))
  3137. end
  3138. addEvent("onClientCallsServerFunction", true)
  3139. addEventHandler("onClientCallsServerFunction", resourceRoot , callServerFunction)
  3140.  
  3141.  
  3142.  
  3143.  
  3144.  
  3145. -----------------------
  3146. -- Call client function
  3147. -----------------------
  3148.  
  3149. function callClientFunction(client, funcname, ...)
  3150.     local arg = { ... }
  3151.     if (arg[1]) then
  3152.         for key, value in next, arg do
  3153.             if (type(value) == "number") then arg[key] = tostring(value) end
  3154.         end
  3155.     end
  3156.     -- If the clientside event handler is not in the same resource, replace 'resourceRoot' with the appropriate element
  3157.     triggerClientEvent(client, "onServerCallsClientFunction", resourceRoot, funcname, unpack(arg or {}))
  3158. end
  3159.  
  3160.  
  3161.  
  3162.  
  3163. ----------------------
  3164. -- Math.round function
  3165. ----------------------
  3166.  
  3167. function math.round(number, decimals, method)
  3168.     decimals = decimals or 0
  3169.     local factor = 10 ^ decimals
  3170.     if (method == "ceil" or method == "floor") then return math[method](number * factor) / factor
  3171.     else return tonumber(("%."..decimals.."f"):format(number)) end
  3172. end
  3173.  
  3174.  
  3175.  
  3176.  
  3177.  
  3178.  
  3179.  
  3180. ----------------
  3181. -- Fun functions
  3182. ----------------
  3183.  
  3184. function announceScript(player, cmd, ...)
  3185.     local accountname = getAccountName(getPlayerAccount(player))
  3186.     if ( hasObjectPermissionTo ( player, "command.mute", true ) ) then
  3187.         for id, players in ipairs(getElementsByType("player")) do
  3188.             local message = table.concat({...}," ")
  3189.             local textChat = textCreateDisplay ()
  3190.             local textItem = textCreateTextItem( message, 0.5, 0.5, 2.9, math.random(1,255),math.random(1,255),math.random(1,255), 255, 4.3, "center", "center" )
  3191.             textDisplayAddText ( textChat, textItem )
  3192.             textDisplayAddObserver ( textChat, players )
  3193.             setTimer ( textDestroyTextItem, 4000, 1, textItem )
  3194.             setTimer ( textDestroyDisplay, 4000, 1, textChat )
  3195.         end
  3196.     else
  3197.         outputChatBox("#00BFFF* #FFFFFFYou need to be logged in as admin to use this command!",player,255,255,255,true)
  3198.     end
  3199. end
  3200. addCommandHandler("ann", announceScript)
  3201.  
  3202.  
  3203.  
  3204.  
  3205. function fakeAchievement(player,command,targetPlayerName,...)
  3206.     local accountname = getAccountName(getPlayerAccount(player))
  3207.     if ( hasObjectPermissionTo ( player, "command.mute", true ) ) then
  3208.         if (targetPlayerName) then
  3209.             if (findPlayerByName(targetPlayerName)) or (targetPlayerName == "all") then
  3210.                 if (...) then
  3211.                     local text = table.concat({...}," ")
  3212.                     local targetPlayer = findPlayerByName(targetPlayerName)
  3213.                     if (targetPlayerName == "all" ) then
  3214.                         callClientFunction(getRootElement(),"fakeUnlock",text)
  3215.                         outputChatBox("#00BFFF* #FFFFFFFake achievement sent to #00BFFFEVERYONE #FFFFFFwith the text #ABCDEF"..text,getRootElement(),255,255,255,true)
  3216.                     else
  3217.                         callClientFunction(targetPlayer,"fakeUnlock",text)
  3218.                         outputChatBox("#00BFFF* #FFFFFFFake achievement sent to "..getPlayerName(targetPlayer).."#FFFFFF with the text #ABCDEF"..text,getRootElement(),255,255,255,true)
  3219.                     end
  3220.                 else
  3221.                     outputChatBox("#00BFFF* #FFFFFFPlease enter a message to display on the fake achievement.",player,255,255,255,true)
  3222.                 end
  3223.             else
  3224.                 outputChatBox("#00BFFF* #FFFFFFNo players with that name found.",player,255,255,255,true)
  3225.             end
  3226.         else
  3227.             outputChatBox("#00BFFF* #FFFFFFPlease enter the name of the player you wish to send the message to.",player,255,255,255,true)
  3228.         end
  3229.     end
  3230. end
  3231. addCommandHandler("fakea", fakeAchievement)
  3232.  
  3233.  
  3234. function flyingCars(player,command,targetPlayerName,state)
  3235.     local accountname = getAccountName(getPlayerAccount(player))
  3236.     if ( hasObjectPermissionTo ( player, "command.mute", true ) ) then
  3237.         if (targetPlayerName) then
  3238.             if (findPlayerByName(targetPlayerName)) or (targetPlayerName == "all") then
  3239.                 if (state) then
  3240.                     local targetPlayer = findPlayerByName(targetPlayerName)
  3241.                     callClientFunction(targetPlayer,"enableFlyCheat",state)
  3242.                     outputChatBox("#00BFFF* #FFFFFFFLYING CHEATS: #ABCDEF"..tostring(state).." #FFFFFFfor player "..getPlayerName(targetPlayer),getRootElement(),255,255,255,true)
  3243.                 else
  3244.                     outputChatBox("#00BFFF* #FFFFFFPlease input whether would you like to activate the cheat (true/false).",player,255,255,255,true)
  3245.                 end
  3246.             else
  3247.                 outputChatBox("#00BFFF* #FFFFFFNo players with that name found.",player,255,255,255,true)
  3248.             end
  3249.         else
  3250.             outputChatBox("#00BFFF* #FFFFFFPlease enter the name of the player you wish to enable cheats for!",player,255,255,255,true)
  3251.         end
  3252.     end
  3253. end
  3254. addCommandHandler("cFly", flyingCars)
  3255.  
  3256.  
  3257. function hoverCars(player,command,targetPlayerName,state)
  3258.     local accountname = getAccountName(getPlayerAccount(player))
  3259.     if ( hasObjectPermissionTo ( player, "command.mute", true ) ) then
  3260.         if (targetPlayerName) then
  3261.             if (findPlayerByName(targetPlayerName)) or (targetPlayerName == "all") then
  3262.                 if (state) then
  3263.                     local targetPlayer = findPlayerByName(targetPlayerName)
  3264.                     callClientFunction(targetPlayer,"enableHoverCheat",state)
  3265.                     outputChatBox("#00BFFF* #FFFFFFHOVER CHEATS: #ABCDEF"..tostring(state).." #FFFFFFfor player "..getPlayerName(targetPlayer),getRootElement(),255,255,255,true)
  3266.                 else
  3267.                     outputChatBox("#00BFFF* #FFFFFFPlease input whether would you like to activate the cheat (true/false).",player,255,255,255,true)
  3268.                 end
  3269.             else
  3270.                 outputChatBox("#00BFFF* #FFFFFFNo players with that name found.",player,255,255,255,true)
  3271.             end
  3272.         else
  3273.             outputChatBox("#00BFFF* #FFFFFFPlease enter the name of the player you wish to enable cheats for!",player,255,255,255,true)
  3274.         end
  3275.     end
  3276. end
  3277. addCommandHandler("cHover", hoverCars)
  3278.  
  3279.  
  3280.  
  3281.  
  3282. ----------------------------------------------- SCOREBOARD -----------------------------------------------------
  3283.  
  3284. addEventHandler("onResourceStart", getResourceRootElement(getThisResource()),
  3285.     function()
  3286.         exports.scoreboard:addScoreboardColumn("Money",getRootElement(),5)
  3287.         exports.scoreboard:addScoreboardColumn("Level",getRootElement(),4)
  3288.         exports.scoreboard:addScoreboardColumn("Country",getRootElement(),6)
  3289.         exports.scoreboard:removeScoreboardColumn("race rank")
  3290.         exports.scoreboard:removeScoreboardColumn("checkpoint")
  3291.     end)
  3292.  
  3293.  
  3294. function scoreboardRefresh(thePlayer)
  3295.     outputDebugString("Refreshing the scoreboard...")
  3296.     local playerCash = tonumber(loadPlayerData(thePlayer,"cash"))
  3297.     local playerLevel = tonumber(loadPlayerData(thePlayer,"level"))
  3298.     setElementData(thePlayer,"Money","$"..playerCash)
  3299.  
  3300.     local levelDisplay = ""
  3301.     if playerLevel == 26 then
  3302.         levelDisplay = nlevel26
  3303.     elseif playerLevel == 27 then
  3304.         levelDisplay = nlevel27
  3305.     elseif playerLevel == 28 then
  3306.         levelDisplay = nlevel28
  3307.     elseif playerLevel == 29 then
  3308.         levelDisplay = nlevel29
  3309.     elseif playerLevel == 30 then
  3310.         levelDisplay = nlevel30
  3311.     elseif playerLevel == 31 then
  3312.         levelDisplay = nlevel31
  3313.     elseif playerLevel == 32 then
  3314.         levelDisplay = nlevel32
  3315.     elseif playerLevel == 33 then
  3316.         levelDisplay = nlevel33
  3317.     elseif playerLevel == 34 then
  3318.         levelDisplay = nlevel34
  3319.     elseif playerLevel == 35 then
  3320.         levelDisplay = nlevel35
  3321.     elseif playerLevel == 36 then
  3322.         levelDisplay = nlevel36
  3323.     elseif playerLevel == 37 then
  3324.         levelDisplay = nlevel37
  3325.     elseif playerLevel == 38 then
  3326.         levelDisplay = nlevel38
  3327.     elseif playerLevel == 39 then
  3328.         levelDisplay = nlevel39
  3329.     elseif playerLevel == 40 then
  3330.         levelDisplay = nlevel40
  3331.     elseif playerLevel == 41 then
  3332.         levelDisplay = nlevel41
  3333.     else
  3334.         levelDisplay = playerLevel
  3335.     end
  3336.  
  3337.     setElementData(thePlayer, "Level", levelDisplay)
  3338.     setTimer(setElementData,2000,1,thePlayer, "Country", getElementData(thePlayer,"country"))
  3339. end
  3340.  
  3341. function scoreboardRefreshTrigger()
  3342.     local thePlayer = source
  3343.     scoreboardRefresh(thePlayer)
  3344. end
  3345. addEventHandler("onPlayerJoin",getRootElement(),scoreboardRefreshTrigger)
  3346. addEventHandler("onPlayerWasted",getRootElement(),scoreboardRefreshTrigger)
  3347.  
  3348.  
  3349.  
  3350.  
  3351.  
  3352.  
  3353.  
  3354. ----------------------------------------------------------------------------------
  3355. ----------------------------------------------------------------------------------
  3356. --                                    _____  ____  _                            --
  3357. --                                   / ____|/ __ \| |                           --
  3358. --                   _ __ ___  _   _| (___ | |  | | |                           --
  3359. --                  | '_ ` _ \| | | |\___ \| |  | | |                           --
  3360. --                  | | | | | | |_| |____) | |__| | |____                       --
  3361. --                  |_| |_| |_|\__, |_____/ \___\_\______|                      --
  3362. --                              __/ |                                           --
  3363. --                             |___/                                            --
  3364. --                                                                              --
  3365. ----------------------------------------------------------------------------------
  3366. ----------------------------------------------------------------------------------
  3367.  
  3368.  
  3369.  
  3370.  
  3371.  
  3372. -- Database connection info
  3373. sqlHostname = "217.18.70.182"
  3374. sqlUsername = "blackstar_popi"
  3375. sqlPassword = "pokepoke"
  3376. sqlDefaultDatabase = "blackstar_popi"
  3377. sqlDefaultTable = "userdata"
  3378.  
  3379.  
  3380. --[[
  3381. sqlHostname = "127.0.0.1"
  3382. sqlUsername = "pao13_dtr"
  3383. sqlPassword = ""
  3384. sqlDefaultDatabase = ""
  3385. sqlDefaultTable = ""
  3386.  
  3387.  
  3388.  
  3389.  
  3390.  
  3391. -- Connect to the database
  3392. function mySQLConnect()
  3393.     sqlConnection = mysql_connect(sqlHostname,sqlUsername,sqlPassword,sqlDefaultDatabase)
  3394. end
  3395. addEventHandler("onResourceStart",getResourceRootElement(getThisResource()),mySQLConnect)
  3396.  
  3397.  
  3398.  
  3399.  
  3400. -- Make a new entry to the mySQL database
  3401. function checkSqlData(source)
  3402.     if (sqlConnection == nil) then
  3403.         mySQLConnect()
  3404.     end
  3405.     local player = source
  3406.     local serial = getPlayerSerial(player)
  3407.     local entryCheck = sqlConnection:query("SELECT serial FROM "..sqlDefaultTable.." WHERE serial='"..serial.."'")
  3408.     if (entryCheck) then
  3409.         local result = mysql_result(entryCheck,1,1)
  3410.         if (result == "") or (result == nil) then
  3411.             outputDebugString("New entry added to the mySQL database!")
  3412.             sqlConnection:query("INSERT INTO "..sqlDefaultTable.." (serial) VALUES ('"..serial.."')")
  3413.             sqlConnection:query("UPDATE "..sqlDefaultTable.." SET playerName='"..string.gsub(getPlayerName(player),"#%x%x%x%x%x%x", "").."' WHERE serial='"..serial.."'")
  3414.         end
  3415.     else
  3416.         outputDebugString("New entry added to the mySQL database!")
  3417.         sqlConnection:query("INSERT INTO "..sqlDefaultTable.." (serial) VALUES ('"..serial.."')")
  3418.         sqlConnection:query("UPDATE "..sqlDefaultTable.." SET playerName='"..string.gsub(getPlayerName(player),"#%x%x%x%x%x%x", "").."' WHERE serial='"..serial.."'")
  3419.     end
  3420. end
  3421. addEventHandler("onPlayerJoin",getRootElement(),checkSqlData)
  3422.  
  3423.  
  3424. addEventHandler("onResourceStart",getResourceRootElement(getThisResource()),
  3425. function()
  3426.     for i,player in ipairs (getElementsByType("player")) do
  3427.         checkSqlData(player)
  3428.     end
  3429. end)
  3430.  
  3431.  
  3432.  
  3433.  
  3434.  
  3435.  
  3436. -- Load data from the database
  3437. function loadPlayerData (player,datatype)
  3438.     if (sqlConnection == nil) then
  3439.         restartResource(getThisResource())
  3440.     end
  3441.     if (player) and (datatype) then
  3442.         local serial = getPlayerSerial(player)
  3443.         local findQuery = sqlConnection:query("SELECT "..datatype.." FROM "..sqlDefaultTable.." WHERE serial='"..serial.."'")
  3444.         if (findQuery) then
  3445.             local result = mysql_result(findQuery,1,1)
  3446.             if not (result == nil) then
  3447.                 if not (result == "") then
  3448.                     mysql_free_result(findQuery)
  3449.                     return result
  3450.                 else
  3451.                     mysql_free_result(findQuery)
  3452.                     return 0
  3453.                 end
  3454.             else
  3455.                 return 0
  3456.             end
  3457.         else
  3458.             --outputDebugString("Failed to get "..datatype.." for player "..getPlayerName(player).." @ findQuery")
  3459.             --outputDebugString("mysql_query failed: (" .. mysql_errno(sqlConnection) .. ") " .. mysql_error(sqlConnection))
  3460.         end
  3461.     end
  3462. end
  3463.  
  3464.  
  3465.  
  3466.  
  3467.  
  3468. -- Save data to the database
  3469. function savePlayerData (player,datatype,newvalue)
  3470.     if (sqlConnection == nil) then
  3471.         restartResource(getThisResource())
  3472.     end
  3473.     if (player) and (datatype) and (newvalue) then
  3474.         local serial = getPlayerSerial(player)
  3475.         local saveData = sqlConnection:query("UPDATE "..sqlDefaultTable.." SET "..datatype.."='"..newvalue.."' WHERE serial='"..serial.."'")
  3476.         if (saveData == nil) then
  3477.             outputDebugString("Error executing the save query: (" .. mysql_errno(sqlConnection) .. ") " .. mysql_error(sqlConnection))
  3478.         end
  3479.     end
  3480. end]]
  3481.  
  3482. -- The load-and-save part.
  3483. function loadPlayerData (player,datatype)
  3484.   local playerIP = getPlayerSerial (player)
  3485.   if (playerIP) then
  3486.     local root = xmlLoadFile ("users.xml")
  3487.     if (root) then
  3488.       local usersNode = xmlFindChild (root,"user",0)
  3489.       if (usersNode) then
  3490.         local playerRootNode = xmlFindChild (usersNode,"SERIAL_" .. getPlayerSerial(player),0)
  3491.         if not (playerRootNode == false) then
  3492.           local playerData = xmlNodeGetAttribute (playerRootNode,datatype)
  3493.           if (playerData) then
  3494.             xmlUnloadFile (root)
  3495.             return playerData
  3496.           else
  3497.             xmlNodeSetAttribute (playerRootNode,datatype,0)
  3498.             xmlSaveFile (root)
  3499.             xmlUnloadFile (root)
  3500.             return 0
  3501.           end
  3502.         else
  3503.           local playerRootNode = xmlCreateChild (usersNode,"SERIAL_" .. getPlayerSerial(player))
  3504.           xmlNodeSetAttribute (playerRootNode,datatype,0)
  3505.           xmlSaveFile (root)
  3506.           xmlUnloadFile (root)
  3507.           return 0
  3508.         end
  3509.       end
  3510.     end
  3511.   end
  3512. end
  3513.  
  3514. function savePlayerData (player,datatype,newvalue)
  3515.   local playerIP = getPlayerSerial (player)
  3516.   if (playerIP) then
  3517.     local root = xmlLoadFile ("users.xml")
  3518.     if (root) then
  3519.       local usersNode = xmlFindChild (root,"user",0)
  3520.       if (usersNode) then
  3521.         local playerRootNode = xmlFindChild (usersNode,"SERIAL_" .. getPlayerSerial(player),0)
  3522.         if not (playerRootNode == false) then
  3523.           local newNodeValue = xmlNodeSetAttribute (playerRootNode,datatype,newvalue)
  3524.           xmlSaveFile (root)
  3525.           xmlUnloadFile (root)
  3526.           return newNodeValue
  3527.         else
  3528.           local playerRootNode = xmlCreateChild (usersNode,"SERIAL_" .. getPlayerSerial(player))
  3529.           local newNodeValue = xmlNodeSetAttribute (playerRootNode,datatype,newvalue)
  3530.           xmlSaveFile (root)
  3531.           xmlUnloadFile (root)
  3532.           return newNodeValue
  3533.         end
  3534.       end
  3535.     end
  3536.   end
  3537. end
  3538.  
  3539. addCommandHandler("leet",
  3540. function(source,command,money)
  3541.     local playerCash = loadPlayerData(source,"cash")
  3542.     totalcash = playerCash + money
  3543.     savePlayerData(source,"cash", totalcash)
  3544.     scoreboardRefresh(source)
  3545.     outputChatBox ( "#007FFF[Server]#ffffffYou've been given #007FFF" ..money.. "$#FFFFFF!", getRootElement(), 255, 255, 255, true )
  3546. end
  3547. )
  3548.  
  3549. addCommandHandler("cash",
  3550. function(source)
  3551.     local playerCash = loadPlayerData(source,"cash")
  3552.     outputChatBox ( '#007FFF[Server]#FFFFFF' .. getPlayerName(source) .. '#FFFFFF has got #007FFF' ..playerCash.. '$#FFFFFF!', getRootElement(), 255, 255, 255, true )
  3553. end
  3554. )
  3555.  
  3556.  
  3557. resourceRoot = getResourceRootElement()
  3558. function chooserandom ()
  3559. setTimer ( give, 400000, 1 )
  3560. end
  3561. addEventHandler ("onResourceStart", resourceRoot, chooserandom)
  3562.  
  3563. function give ()
  3564. local randomPlayer = getRandomPlayer ( )
  3565. randomMoney = math.random ( 500, 2500 )
  3566. local playerCash = loadPlayerData(randomPlayer,"cash")
  3567. if playerCash then
  3568.     totalcash = playerCash + randomMoney
  3569.     savePlayerData(randomPlayer,"cash", totalcash)
  3570.     scoreboardRefresh(randomPlayer)
  3571. end
  3572. outputChatBox ( '#007FFF[Random Money]#FFFFFF' .. getPlayerName ( randomPlayer ) .. '#FFFFFF has been chosen to earn #007FFF' .. randomMoney .. '$#FFFFFF!', getRootElement(), 255, 255, 255, true )
  3573. chooserandom()
  3574. end
  3575.  
  3576.  
  3577.  
  3578.  
  3579. function buyRepair(source)
  3580.     if ( isPedInVehicle ( source ) ) then
  3581.     local mapName = getMapName()
  3582.     if not (string.find (mapName,"DD")) then
  3583.     local cashHave = tonumber(loadPlayerData(source,"cash"))
  3584.         if (cashHave >= 500) then
  3585.             if (getVehicleModelFromName(getVehicleName(getPedOccupiedVehicle(source))) == 425) then
  3586.                 outputChatBox("#FF0000[Server]#FFFFFFYou can't repair a Hunter!", source, 255, 0, 0, true)
  3587.             else
  3588.                 cashToTake =  cashHave - 500
  3589.                 savePlayerData(source,"cash", cashToTake)
  3590.                 outputChatBox("#007FFF[Shop]#FFFFFF" ..getPlayerName(source).. "#FFFFFF has bought a repair for #007FFF500$. (/br)", getRootElement(), 255, 255, 0, true)
  3591.                 fixVehicle (getPedOccupiedVehicle(source))
  3592.                 scoreboardRefresh(source)
  3593.                 end
  3594.         else
  3595.             outputChatBox("#FF0000[Shop]#FFFFFFYou need at least #FF0000500$#FFFFFF to buy a repair.", source, 255, 0, 0, true)
  3596.         end
  3597.     else
  3598.         outputChatBox("#FF0000[Shop]#FFFFFFYou can't repair your car in a #FF0000DD map!", source, 255, 0, 0, true)
  3599.     end
  3600.     else
  3601.         outputChatBox("#FF0000[Shop]#FFFFFFYou've got to be #FF0000alive#FFFFFF to buy a repair!", source, 255, 0, 0, true)
  3602.     end
  3603. end
  3604. addCommandHandler('br', buyRepair)
  3605. addCommandHandler('buyrepair', buyRepair)
  3606.  
  3607. function buynitro(source, vehicle)
  3608.     if ( isPedInVehicle ( source ) ) then
  3609.     local mapName = getMapName()
  3610.     if not (string.find (mapName,"DD")) then
  3611.     local cashHave = tonumber(loadPlayerData(source,"cash"))
  3612.         if (cashHave >= 500) then
  3613.                 cashToTake =  cashHave - 500
  3614.                 savePlayerData(source,"cash", cashToTake)
  3615.                 outputChatBox("#007FFF[Shop]#FFFFFF" ..getPlayerName(source).. "#FFFFFF has bought a nitro for #007FFF500$. (/bn)", getRootElement(), 255, 255, 0, true)
  3616.                 addVehicleUpgrade ( getPedOccupiedVehicle(source), 1010 )
  3617.                 scoreboardRefresh(source)
  3618.         else
  3619.             outputChatBox("#FF0000[Shop]#FFFFFFYou need at least #FF0000500$#FFFFFF to buy some nitro.", source, 255, 0, 0, true)
  3620.         end
  3621.     else
  3622.         outputChatBox("#FF0000[Shop]#FFFFFFYou can't repair your car in a #FF0000DD map!", source, 255, 0, 0, true)
  3623.     end
  3624.     else
  3625.         outputChatBox("#FF0000[Shop]#FFFFFFYou've got to be #FF0000alive#FFFFFF to buy some nitro!", source, 255, 0, 0, true)
  3626.     end
  3627. end
  3628. addCommandHandler('bn', buynitro)
  3629. addCommandHandler('buynitro', buynitro)
  3630.  
  3631. function buyflip (source)
  3632.     rx, ry, rz = getPedRotation (source)
  3633.     x, y, z = getElementPosition (source)
  3634.     vehicle = getPedOccupiedVehicle (source)
  3635.     vehicler = getPedRotation (source)
  3636.     if ( isPedInVehicle ( source ) ) then
  3637.     local mapName = getMapName()
  3638.     if not (string.find (mapName,"DD")) then
  3639.     local cashHave = tonumber(loadPlayerData(source,"cash"))
  3640.         if cashHave >= 500 then
  3641.                 cashToTake =  cashHave - 500
  3642.                 savePlayerData(source,"cash", cashToTake)
  3643.                 outputChatBox("#007FFF[Shop]#FFFFFF" ..getPlayerName(source).. "#FFFFFF has fliped his car for #007FFF500$. (/bf)", getRootElement(), 255, 255, 0, true)
  3644.                 setVehicleRotation ( vehicle, 0, 0, vehicler, true )
  3645.         else
  3646.             outputChatBox("#FF0000[Shop]#FFFFFFYou need at least #FF0000500$#FFFFFF to flip your car.", source, 255, 0, 0, true)
  3647.         end
  3648.     else
  3649.         outputChatBox("#FF0000[Shop]#FFFFFFYou can't repair your car in a #FF0000DD map!", source, 255, 0, 0, true)
  3650.     end
  3651.     else
  3652.         outputChatBox("#FF0000[Shop]#FFFFFFYou've got to be #FF0000alive#FFFFFF to flip your car!", source, 255, 0, 0, true)
  3653.     end
  3654. end
  3655. addCommandHandler('bf', buyflip)
  3656. addCommandHandler('buyflip', buyflip)
Advertisement
Add Comment
Please, Sign In to add comment