Advertisement
Guest User

Untitled

a guest
Dec 29th, 2012
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 43.61 KB | None | 0 0
  1. gRoot = getRootElement()
  2.  
  3. AchievementsName = {
  4. "First Win!", -- 1sze zwyciestwo
  5. "First Hunter!", -- 1szy hunter
  6. "Top Winner!", -- 300 wins
  7. "Awesome Winner!", -- 1000 wins
  8. "Top Gamer!", -- 2000 map
  9. "Long Time Player!", -- 7 dni
  10. "Hunter Owner!", -- hunter 50 razy
  11. "Beat my TT kid!", -- pobij swoj TT
  12. "5 Maps In a Row LOL!", -- 5x
  13. "Triple Deathmatch!", -- 3x dm pod rzad
  14. "Triple Dest. Derby!", -- 3x DD
  15. "Hunter Power", -- hunterfight z 3 graczami
  16. "Map Buyer", -- 10 razy kupic mape
  17. "Top Times collector!", -- 50 toptimow
  18. "Rich player!", -- 1 mln
  19. }
  20. LastWinnersDD={"","","","",""}
  21. LastWinnersDM={"","","","",""}
  22. LastWinners={"","","","",""}
  23. HunterCount = 0
  24. ------------------------------------------
  25. -- Settings
  26. ------------------------------------------
  27. mapCost = 5000
  28. RepairCost = 4000
  29.  
  30. local activePlayers = {}
  31.  
  32. function startResource ()
  33. exports.scoreboard:removeScoreboardColumn("race rank")
  34. exports.scoreboard:removeScoreboardColumn("checkpoint")
  35. exports.scoreboard:addScoreboardColumn("Money",gRoot,5,100)
  36. mapIsAlreadySet = false
  37. repairset = true
  38. txBMaps = {}
  39. for i,pla in ipairs(getElementsByType("player")) do
  40. scoreboardRefresh(pla)
  41. end
  42. end
  43. addEventHandler ( "onResourceStart", getResourceRootElement(getThisResource()), startResource )
  44.  
  45. ------------------------------------------
  46. -- Load All Stats on Join
  47. ------------------------------------------
  48. function scoreboardRefresh(thePlayer)
  49. local playerCash = loadPlayerData(thePlayer,"cash")
  50. setElementData(thePlayer,"Money","$"..playerCash)
  51. callClientFunction(thePlayer, "refreshCash", playerCash)
  52. end
  53.  
  54. function playerJoinHandler ( )
  55. outputChatBox("#00AAFF# #FFFFFFPress '#00AAFFF7#FFFFFF' to open your User Panel!",source,255,255,255,true)
  56. scoreboardRefresh(source)
  57. end
  58. addEventHandler ( "onPlayerJoin", gRoot, playerJoinHandler )
  59.  
  60. ------------------------------------------
  61. -- DD/DM/FUN checking
  62. ------------------------------------------
  63. addEvent("onMapStarting")
  64. addEventHandler("onMapStarting", getRootElement(),
  65. function(mapInfo, mapOptions, gameOptions)
  66. CurrentMap = nil
  67. HunterCount = 0
  68. MaxI = 0
  69. for i,thePlayer in ipairs(getElementsByType("player")) do
  70. MaxI = i
  71. end
  72. if MaxI >=3 then
  73. if (checkMapType(mapInfo.name) == 1) then
  74. CurrentMap = 1
  75. for i,thePlayer in ipairs(getElementsByType("player")) do
  76. local mapsPlayedDM = tonumber(loadPlayerData(thePlayer,"mapsPlayedDM"))
  77. savePlayerData(thePlayer,"mapsPlayedDM", mapsPlayedDM+1)
  78. CheckAchievement(thePlayer,5)
  79. end
  80. elseif (checkMapType(mapInfo.name) == 2) then
  81. CurrentMap = 2
  82. for i,thePlayer in ipairs(getElementsByType("player")) do
  83. local mapsPlayedDD = tonumber(loadPlayerData(thePlayer,"mapsPlayedDD"))
  84. savePlayerData(thePlayer,"mapsPlayedDD", mapsPlayedDD+1)
  85. CheckAchievement(thePlayer,5)
  86. end
  87. end
  88. else
  89. outputChatBox("#00AAFF# #FFFFFF Min. 3 players to get stats and cash!",gRoot,255,255,255,true)
  90. end
  91. end)
  92.  
  93. function checkMapType(mapname)
  94. if string.find(mapname, "[DM]", 1, true) then
  95. return 1
  96. elseif string.find(mapname, "[DD]", 1,true) then
  97. return 2
  98. elseif string.find(mapname, "[FUN]", 1,true) then
  99. return 3
  100. elseif string.find(mapname, "[HUNTER]", 1,true) then
  101. return 4
  102. elseif string.find(mapname, "[SHOOTER]", 1,true) then
  103. return 5
  104. end
  105. end
  106.  
  107.  
  108. function getRaceAlivePlayers()
  109. local result = {}
  110. local _getAlivePlayers = getElementsByType("player")
  111. for i,v in ipairs(_getAlivePlayers) do
  112. if getElementData(v,"state") == "alive" then
  113. table.insert(result,v)
  114. end
  115. end
  116. return result
  117. end
  118.  
  119.  
  120. ------------------------------------------
  121. -- Wins Stats
  122. ------------------------------------------
  123. function onPlayerDeadInRace()
  124. local thePlayer = source
  125. local dPlayers = getDeadRacePlayers()
  126. local aPlayers = getAliveRacePlayers()
  127. local Position = aPlayers + 1
  128. if dPlayers + aPlayers >= 3 then
  129. local cashForPlayer = math.floor((200/Position)*(dPlayers + aPlayers))
  130. local playerCash = loadPlayerData(thePlayer,"cash")
  131. savePlayerData(thePlayer,"cash",playerCash+cashForPlayer)
  132. CheckAchievement(thePlayer,15)
  133. scoreboardRefresh(thePlayer)
  134. if Position == 1 then
  135. outputChatBox("#00AAFF# "..getPlayerName(thePlayer).." #FFFFFFhas won the map +$#00AAFF" .. cashForPlayer.. "#FFFFFF!",gRoot,255,255,255,true)
  136. --triggerClientEvent ( "showWinMessage", getRootElement(), thePlayer, cashForPlayer)
  137.  
  138. if LastWinners[1] == "" then
  139. if LastWinners[2] == "" then
  140. if LastWinners[3] == "" then
  141. if LastWinners[4] == "" then
  142. if LastWinners[5] == "" then
  143. LastWinners[5] = thePlayer
  144. else
  145. LastWinners[4] = thePlayer
  146. end
  147. else
  148. LastWinners[3] = thePlayer
  149. end
  150. else
  151. LastWinners[2] = thePlayer
  152. end
  153. else
  154. LastWinners[1] = thePlayer
  155. end
  156. else
  157. LastWinners[5] = LastWinners[4]
  158. LastWinners[4] = LastWinners[3]
  159. LastWinners[3] = LastWinners[2]
  160. LastWinners[2] = LastWinners[1]
  161. LastWinners[1] = thePlayer
  162. CheckAchievement(thePlayer,9)
  163. end
  164.  
  165.  
  166.  
  167. if CurrentMap and CurrentMap == 1 then
  168. local mapsWonDM = tonumber(loadPlayerData(thePlayer,"mapsWonDM"))
  169. savePlayerData(thePlayer,"mapsWonDM", mapsWonDM+1)
  170. CheckAchievement(thePlayer,1)
  171. CheckAchievement(thePlayer,3)
  172. CheckAchievement(thePlayer,4)
  173. if LastWinnersDM[1] == ""then
  174. if LastWinnersDM[2] == "" then
  175. if LastWinnersDM[3] == "" then
  176. LastWinnersDM[3] = thePlayer
  177. else
  178. LastWinnersDM[2] = thePlayer
  179. end
  180. else
  181. LastWinnersDM[1] = thePlayer
  182. end
  183. else
  184. LastWinnersDM[3] = LastWinnersDM[2]
  185. LastWinnersDM[2] = LastWinnersDM[1]
  186. LastWinnersDM[1] = thePlayer
  187. CheckAchievement(thePlayer,10)
  188. end
  189. if HunterCount >= 3 then
  190. unlockedAC(thePlayer,12)
  191. end
  192. elseif CurrentMap and CurrentMap == 2 then
  193. local mapsWonDD = tonumber(loadPlayerData(thePlayer,"mapsWonDD"))
  194. savePlayerData(thePlayer,"mapsWonDD", mapsWonDD+1)
  195. CheckAchievement(thePlayer,1)
  196. CheckAchievement(thePlayer,3)
  197. CheckAchievement(thePlayer,4)
  198. if LastWinnersDD[1] == "" then
  199. if LastWinnersDD[2] == "" then
  200. if LastWinnersDD[3] == "" then
  201. LastWinnersDD[3] = thePlayer
  202. else
  203. LastWinnersDD[2] = thePlayer
  204. end
  205. else
  206. LastWinnersDD[1] = thePlayer
  207. end
  208. else
  209. LastWinnersDD[3] = LastWinnersDD[2]
  210. LastWinnersDD[2] = LastWinnersDD[1]
  211. LastWinnersDD[1] = thePlayer
  212. CheckAchievement(thePlayer,11)
  213. end
  214. end
  215. else
  216. outputChatBox("#00AAFF# #FFFFFFYou have recieved $#00AAFF" .. cashForPlayer .. "#FFFFFF!",thePlayer,255,255,255,true)
  217. end
  218. else
  219. outputChatBox("#00AAFF# #FFFFFF Min. 3 players to get stats and cash!",thePlayer,255,255,255,true)
  220. end
  221. end
  222. addEvent("onPlayerWasted", true)
  223. addEventHandler("onPlayerWasted", gRoot , onPlayerDeadInRace)
  224.  
  225. ------------------------------------------
  226. -- Statystyki
  227. ------------------------------------------
  228. function showStats(thePlayer,CMD,targetPlayer)
  229. if targetPlayer then
  230. if (findPlayerByName(targetPlayer)) then
  231. local targetPlayer = findPlayerByName(targetPlayer)
  232. local c,ddw,ddp,ddr,dmw,dmp,dmr,pt,h,mb,ac,tt = loadPlayerStats(targetPlayer)
  233. outputChatBox("#00AAFF# #FFFFFF"..getPlayerName(targetPlayer).."#FFFFFF's stats:",thePlayer,255,255,255,true)
  234. outputChatBox("#00AAFF# [DM] #FFFFFFPlayed: "..dmp.." | Wins: "..dmw.." | Ratio: "..dmr.."%",thePlayer,255,255,255,true)
  235. outputChatBox("#00AAFF# [DD] #FFFFFFPlayed: "..ddp.." | Wins: "..ddw.." | Ratio: "..ddr.."%",thePlayer,255,255,255,true)
  236. outputChatBox("#00AAFF# #FFFFFFCash: $"..c.." | Hunters: "..h.." | Map Buys: "..mb,thePlayer,255,255,255,true)
  237. outputChatBox("#00AAFF# #FFFFFFPlayed Time: "..convertTime(pt),thePlayer,255,255,255,true)
  238. ACCOUNT = 0
  239. for i=1,#ac do
  240. if ac[i] == 1 then
  241. ACCOUNT = ACCOUNT+1
  242. end
  243. end
  244. outputChatBox("#00AAFF# #FFFFFFAchievements: "..ACCOUNT.."/15 | TopTimes: "..tt,thePlayer,255,255,255,true)
  245. else
  246. outputChatBox("#00AAFF# #FFFFFFERROR! The player you specified does not exist!",thePlayer,255,255,255,true)
  247. end
  248. else
  249. local c,ddw,ddp,ddr,dmw,dmp,dmr,pt,h,mb,ac,tt = loadPlayerStats(thePlayer)
  250. outputChatBox("#00AAFF# #FFFFFF"..getPlayerName(thePlayer).."#FFFFFF's stats:",thePlayer,255,255,255,true)
  251. outputChatBox("#00AAFF# [DM] #FFFFFFPlayed: "..dmp.." | Wins: "..dmw.." | Ratio: "..dmr.."%",thePlayer,255,255,255,true)
  252. outputChatBox("#00AAFF# [DD] #FFFFFFPlayed: "..ddp.." | Wins: "..ddw.." | Ratio: "..ddr.."%",thePlayer,255,255,255,true)
  253. outputChatBox("#00AAFF# #FFFFFFCash: $"..c.." | Hunters: "..h.." | Map Buys: "..mb,thePlayer,255,255,255,true)
  254. outputChatBox("#00AAFF# #FFFFFFPlayed Time: "..convertTime(pt),thePlayer,255,255,255,true)
  255. ACCOUNT = 0
  256. for i=1,#ac do
  257. if ac[i] == 1 then
  258. ACCOUNT = ACCOUNT+1
  259. end
  260. end
  261. outputChatBox("#00AAFF# #FFFFFFAchievements: "..ACCOUNT.."/15 | TopTimes: "..tt,thePlayer,255,255,255,true)
  262. end
  263. end
  264. addCommandHandler("stats", showStats)
  265. addCommandHandler("st", showStats)
  266.  
  267. ------------------------------------------
  268. -- Shaders
  269. ------------------------------------------
  270.  
  271. function ShadersUpdate(Who,Shader,Data)
  272. savePlayerData(Who,"Shader"..Shader,Data)
  273. end
  274. function ClientStarted ( who )
  275. for i=1,2 do
  276. local data = loadPlayerData(who,"Shader"..i)
  277. if i == 1 then callClientFunction(who,"CarShaderToggle",who,data)
  278. elseif i == 2 then callClientFunction(who,"WaterShaderToggle",who,data)
  279. end
  280. end
  281. end
  282.  
  283. ------------------------------------------
  284. -- SPD GPD
  285. ------------------------------------------
  286. addCommandHandler("spd",
  287. function(player,command,toplayername,datatype,amount)
  288. if hasObjectPermissionTo ( player, "function.kickPlayer", false ) then
  289. if (toplayername) and (datatype) and (amount) then
  290. if datatype == "cash" or datatype == "mapsWonDD" or datatype == "mapsPlayedDD" or datatype == "mapsWonDM" or datatype == "mapsPlayedDM" or datatype == "playedTime" or datatype == "hunters" or datatype == "mapBuys" then
  291. if (findPlayerByName (toplayername)) then
  292. toplayer = findPlayerByName (toplayername)
  293. savePlayerData(toplayer,datatype,amount)
  294. outputChatBox ("#00AAFF# #FFFFFFsetPlayerData: " .. getPlayerName(toplayer) .. " #FF0000|#FFFFFF Player's #00AAFF" .. datatype .. "#FFFFFF has been set to: #00AAFF" .. amount, player,255,0,0,true)
  295. outputChatBox ("#00AAFF# #FFFFFF" .. getPlayerName (player) .. " #FFFFFFhas set your #ABCDEF" .. datatype .."#FFFFFF to: #00AAFF" .. amount, toplayer,255,0,0,true)
  296. local playerCash = loadPlayerData(toplayer,"cash")
  297. local playerLevel = loadPlayerData(toplayer,"level")
  298. local thePlayer = toplayer
  299. scoreboardRefresh(thePlayer)
  300. end
  301. else
  302. outputChatBox ("#00AAFF# #FF0000ERROR! #FFFFFFDatatype: cash/mapsWonDD/mapsPlayedDD/mapsWonDM/mapsPlayedDM/playedTime/hunters/mapBuys",player,255,255,255,true)
  303. end
  304. else
  305. outputChatBox ("#00AAFF# #FF0000ERROR!#FFFFFF Syntax: /setPlayerData [playername] [datatype] [new_amount]",player,255,255,255,true)
  306. end
  307. else
  308. end
  309. end)
  310.  
  311. addCommandHandler("gpd",
  312. function(player,command,toplayername,datatype)
  313. if hasObjectPermissionTo ( player, "function.kickPlayer", false ) then
  314. if (toplayername) and (datatype) then
  315. if datatype == "cash" or datatype == "mapsWonDD" or datatype == "mapsPlayedDD" or datatype == "mapsWonDM" or datatype == "mapsPlayedDM" or datatype == "playedTime" or datatype == "hunters" or datatype == "mapBuys" then
  316. if (findPlayerByName (toplayername)) then
  317. toplayer = findPlayerByName (toplayername)
  318. local amount = loadPlayerData(toplayer,datatype)
  319. outputChatBox ("#00AAFF# #FFFFFFgetPlayerData: " .. getPlayerName(toplayer) .. " #FF0000|#FFFFFF " .. datatype .."#FFFFFF: #00AAFF" .. amount,player,255,255,255,true)
  320. end
  321. else
  322. outputChatBox ("#00AAFF# #FF0000ERROR! #FFFFFFDatatype: cash/mapsWonDD/mapsPlayedDD/mapsWonDM/mapsPlayedDM/playedTime/hunters/mapBuys",player,255,255,255,true)
  323. end
  324. else
  325. outputChatBox ("#00AAFF# #FF0000ERROR!#FFFFFF Syntax: /getPlayerData [playername] [datatype]",player,255,255,255,true)
  326. end
  327. end
  328. end)
  329.  
  330.  
  331. ------------------------------------------
  332. -- loadStats
  333. ------------------------------------------
  334. function loadStats(thePlayer,whoask)
  335. local playerCash = tonumber(loadPlayerData(thePlayer,"cash"))
  336. setElementData(thePlayer,"Money","$"..playerCash)
  337. local mapsWonDD = tonumber(loadPlayerData(thePlayer,"mapsWonDD"))
  338. local mapsPlayedDD = tonumber(loadPlayerData(thePlayer,"mapsPlayedDD"))
  339. local mapsWonDM = tonumber(loadPlayerData(thePlayer,"mapsWonDM"))
  340. local mapsPlayedDM = tonumber(loadPlayerData(thePlayer,"mapsPlayedDM"))
  341. ------ playedTime
  342. local PlayerCheckTime = getTickCount ()
  343. local PlayerTodayTime = math.floor((PlayerCheckTime - getElementData(thePlayer,"joinTime"))/1000)
  344. local PlayerOldTime = loadPlayerData(thePlayer,"playedTime")
  345. savePlayerData(thePlayer,"playedTime", PlayerOldTime + PlayerTodayTime)
  346. CheckAchievement(thePlayer,6)
  347. setElementData(thePlayer,"joinTime", PlayerCheckTime)
  348. ------
  349. local playedTime = PlayerOldTime + PlayerTodayTime
  350. local hunters = tonumber(loadPlayerData(thePlayer,"hunters"))
  351. local mapBuys = tonumber(loadPlayerData(thePlayer,"mapBuys"))
  352. AC = {}
  353. for i=1,15 do
  354. AC[i] = tonumber(loadPlayerData(thePlayer,"ac"..i))
  355. end
  356. local toptimes = tonumber(loadPlayerData(thePlayer,"TopTimes"))
  357. --[[UData = {}
  358. for j=1,20 do
  359. UData[j] = loadPlayerData(thePlayer,"ud"..j)
  360. end]]--
  361.  
  362.  
  363. local winRatioDD = 0
  364. local winRatioDM = 0
  365. if mapsPlayedDD == 0 and mapsWonDD == 0 then
  366. winRatioDD = 0
  367. elseif mapsPlayedDD ~= 0 and mapsWonDD == 0 then
  368. winRatioDD = 0
  369. elseif mapsPlayedDD ~= 0 and mapsWonDD ~= 0 then
  370. winRatioDD = math.round(((100/mapsPlayedDD)*mapsWonDD),2)
  371. elseif mapsWonDD > mapsPlayedDD then
  372. winRatioDD = 0
  373. end
  374. if mapsPlayedDM == 0 and mapsWonDM == 0 then
  375. winRatioDM = 0
  376. elseif mapsPlayedDM ~= 0 and mapsWonDM == 0 then
  377. winRatioDM = 0
  378. elseif mapsPlayedDM ~= 0 and mapsWonDM ~= 0 then
  379. winRatioDM = math.round(((100/mapsPlayedDM)*mapsWonDM),2)
  380. elseif mapsWonDM > mapsPlayedDM then
  381. winRatioDM = 0
  382. end
  383. callClientFunction(whoask, "refreshPanelData", thePlayer ,playerCash, mapsWonDD, mapsPlayedDD, winRatioDD, mapsWonDM, mapsPlayedDM, winRatioDM, playedTime, hunters, mapBuys, AC,toptimes)
  384. end
  385.  
  386. function loadPlayerStats(thePlayer)
  387. local playerCash = tonumber(loadPlayerData(thePlayer,"cash"))
  388. setElementData(thePlayer,"Money","$"..playerCash)
  389. local mapsWonDD = tonumber(loadPlayerData(thePlayer,"mapsWonDD"))
  390. local mapsPlayedDD = tonumber(loadPlayerData(thePlayer,"mapsPlayedDD"))
  391. local mapsWonDM = tonumber(loadPlayerData(thePlayer,"mapsWonDM"))
  392. local mapsPlayedDM = tonumber(loadPlayerData(thePlayer,"mapsPlayedDM"))
  393. local playedTime = tonumber(loadPlayerData(thePlayer,"playedTime"))
  394. local hunters = tonumber(loadPlayerData(thePlayer,"hunters"))
  395. local mapBuys = tonumber(loadPlayerData(thePlayer,"mapBuys"))
  396. AC = {}
  397. for i=1,15 do
  398. local name = "ac"..i
  399. AC[i] = tonumber(loadPlayerData(thePlayer,name))
  400. end
  401. local toptimes = tonumber(loadPlayerData(thePlayer,"TopTimes"))
  402.  
  403. local winRatioDD = 0
  404. local winRatioDM = 0
  405. if mapsPlayedDD == 0 and mapsWonDD == 0 then
  406. winRatioDD = 0
  407. elseif mapsPlayedDD ~= 0 and mapsWonDD == 0 then
  408. winRatioDD = 0
  409. elseif mapsPlayedDD ~= 0 and mapsWonDD ~= 0 then
  410. winRatioDD = math.round(((100/mapsPlayedDD)*mapsWonDD),2)
  411. elseif mapsWonDD > mapsPlayedDD then
  412. winRatioDD = 0
  413. end
  414. if mapsPlayedDM == 0 and mapsWonDM == 0 then
  415. winRatioDM = 0
  416. elseif mapsPlayedDM ~= 0 and mapsWonDM == 0 then
  417. winRatioDM = 0
  418. elseif mapsPlayedDM ~= 0 and mapsWonDM ~= 0 then
  419. winRatioDM = math.round(((100/mapsPlayedDM)*mapsWonDM),2)
  420. elseif mapsWonDM > mapsPlayedDM then
  421. winRatioDM = 0
  422. end
  423. return playerCash, mapsWonDD, mapsPlayedDD, winRatioDD, mapsWonDM, mapsPlayedDM, winRatioDM, playedTime, hunters, mapBuys, AC, toptimes
  424. end
  425.  
  426. --[[function NewUserDataFromPanel(ud,thePlayer)
  427. for i=1,20 do
  428. savePlayerData (thePlayer,"ud"..i,ud[i])
  429. end
  430. end
  431.  
  432. function getUserStats(whoask,who)
  433. UData = {}
  434. for j=1,20 do
  435. UData[j] = loadPlayerData(who,"ud"..j)
  436. end
  437. callClientFunction(whoask,"UserStats",UData)
  438. end]]--
  439. ------------------------------------------
  440. -- Load & Save Data
  441. ------------------------------------------
  442. function loadPlayerData (player,datatype)
  443. local playerSerial = getPlayerSerial (player)
  444. if (playerSerial) then
  445. local root = xmlLoadFile ("DataBase.xml")
  446. if (root) then
  447. local usersNode = xmlFindChild (root,"user",0)
  448. if (usersNode) then
  449. local playerRootNode = xmlFindChild (usersNode,"SERIAL_" .. playerSerial,0)
  450. if not (playerRootNode == false) then
  451. local playerData = xmlNodeGetAttribute (playerRootNode,datatype)
  452. if (playerData) then
  453. xmlUnloadFile (root)
  454. --outputDebugString("---- LoadD: "..getPlayerName(player).." , "..datatype.." , "..playerData)
  455. return playerData
  456. else
  457. xmlNodeSetAttribute (playerRootNode,datatype,0)
  458. xmlSaveFile (root)
  459. xmlUnloadFile (root)
  460. --outputDebugString("---- LoadD: "..getPlayerName(player).." , "..datatype.." , 0")
  461. return 0
  462. end
  463. else
  464. local playerRootNode = xmlCreateChild (usersNode,"SERIAL_" .. playerSerial)
  465. xmlNodeSetAttribute (playerRootNode,datatype,0)
  466. xmlSaveFile (root)
  467. xmlUnloadFile (root)
  468. --outputDebugString("---- LoadD: "..getPlayerName(player).." , "..datatype.." , 0")
  469. return 0
  470. end
  471. end
  472. end
  473. end
  474. end
  475.  
  476. function savePlayerData (player,datatype,newvalue)
  477. local playerSerial = getPlayerSerial (player)
  478. if (playerSerial) then
  479. local root = xmlLoadFile ("DataBase.xml")
  480. if (root) then
  481. local usersNode = xmlFindChild (root,"user",0)
  482. if (usersNode) then
  483. local playerRootNode = xmlFindChild (usersNode,"SERIAL_" .. playerSerial,0)
  484. if not (playerRootNode == false) then
  485. local newNodeValue = xmlNodeSetAttribute (playerRootNode,datatype,newvalue)
  486. xmlSaveFile (root)
  487. xmlUnloadFile (root)
  488. --outputDebugString("---- SaveD: "..getPlayerName(player).." , "..datatype.." , "..newvalue)
  489. return newNodeValue
  490. else
  491. local playerRootNode = xmlCreateChild (usersNode,"SERIAL_" .. playerSerial)
  492. local newNodeValue = xmlNodeSetAttribute (playerRootNode,datatype,newvalue)
  493. xmlSaveFile (root)
  494. xmlUnloadFile (root)
  495. --outputDebugString("---- SaveD: "..getPlayerName(player).." , "..datatype.." , "..newvalue)
  496. return newNodeValue
  497. end
  498. end
  499. end
  500. end
  501. end
  502. ------------------------------------------
  503. -- Achievementy
  504. ------------------------------------------
  505.  
  506.  
  507. function CheckAchievement(thePlayer,achiev)
  508. local name = "ac"..achiev
  509. local LockedUnlocked = tonumber(loadPlayerData(thePlayer,name))
  510. if LockedUnlocked == 0 then
  511. if achiev == 1 then -- 1st win
  512. local mapsWonDD = tonumber(loadPlayerData(thePlayer,"mapsWonDD"))
  513. local mapsWonDM = tonumber(loadPlayerData(thePlayer,"mapsWonDM"))
  514. if mapsWonDD > 0 or mapsWonDM > 0 then
  515. unlockedAC(thePlayer,achiev)
  516. end
  517. elseif achiev == 2 then -- 1st hunter
  518. local hunters = tonumber(loadPlayerData(thePlayer,"hunters"))
  519. if hunters > 0 then
  520. unlockedAC(thePlayer,achiev)
  521. end
  522. elseif achiev == 3 then -- 300+ wins
  523. local mapsWonDD = tonumber(loadPlayerData(thePlayer,"mapsWonDD"))
  524. local mapsWonDM = tonumber(loadPlayerData(thePlayer,"mapsWonDM"))
  525. if mapsWonDD + mapsWonDM >= 300 then
  526. unlockedAC(thePlayer,achiev)
  527. end
  528. elseif achiev == 4 then -- 1000+wins
  529. local mapsWonDD = tonumber(loadPlayerData(thePlayer,"mapsWonDD"))
  530. local mapsWonDM = tonumber(loadPlayerData(thePlayer,"mapsWonDM"))
  531. if mapsWonDD + mapsWonDM >= 1000 then
  532. unlockedAC(thePlayer,achiev)
  533. end
  534. elseif achiev == 5 then -- 2000 played
  535. local mapsPlayedDD = tonumber(loadPlayerData(thePlayer,"mapsPlayedDD"))
  536. local mapsPlayedDM = tonumber(loadPlayerData(thePlayer,"mapsPlayedDM"))
  537. if mapsPlayedDD + mapsPlayedDM >= 2000 then
  538. unlockedAC(thePlayer,achiev)
  539. end
  540. elseif achiev == 6 then -- 7days
  541. local playedTime = tonumber(loadPlayerData(thePlayer,"playedTime"))
  542. if playedTime >= 604800 then
  543. unlockedAC(thePlayer,achiev)
  544. end
  545. elseif achiev == 7 then -- 50+ hunters
  546. local hunters = tonumber(loadPlayerData(thePlayer,"hunters"))
  547. if hunters >= 50 then
  548. unlockedAC(thePlayer,achiev)
  549. end
  550. elseif achiev == 8 then--beat TT
  551. local toptimes = tonumber(loadPlayerData(thePlayer,"TopTimes"))
  552. if toptimes > 0 then
  553. unlockedAC(thePlayer,achiev)
  554. end
  555. elseif achiev == 9 then-- 5x in a row
  556. if LastWinners[1] == thePlayer and LastWinners[2] == thePlayer and LastWinners[3] == thePlayer and LastWinners[4] == thePlayer and LastWinners[5] == thePlayer then
  557. unlockedAC(thePlayer,achiev)
  558. end
  559. elseif achiev == 10 then --3x DM
  560. if LastWinnersDM[1] == thePlayer and LastWinnersDM[2] == thePlayer and LastWinnersDM[3] == thePlayer then
  561. unlockedAC(thePlayer,achiev)
  562. end
  563. elseif achiev == 11 then --3x DD
  564. if LastWinnersDD[1] == thePlayer and LastWinnersDD[2] == thePlayer and LastWinnersDD[3] == thePlayer then
  565. unlockedAC(thePlayer,achiev)
  566. end
  567. elseif achiev == 13 then --10x mapbuy
  568. local mapBuys = tonumber(loadPlayerData(thePlayer,"mapBuys"))
  569. if mapBuys >= 10 then
  570. unlockedAC(thePlayer,achiev)
  571. end
  572. elseif achiev == 14 then --50 toptimow
  573. local toptimes = tonumber(loadPlayerData(thePlayer,"TopTimes"))
  574. if toptimes >= 50 then
  575. unlockedAC(thePlayer,achiev)
  576. end
  577. elseif achiev == 15 then --1mln
  578. local playerCash = tonumber(loadPlayerData(thePlayer,"cash"))
  579. if playerCash >= 1000000 then
  580. unlockedAC(thePlayer,achiev)
  581. end
  582. end
  583. else
  584. if achiev == 15 then
  585. local playerCash = tonumber(loadPlayerData(thePlayer,"cash"))
  586. if playerCash < 1000000 then
  587. savePlayerData(thePlayer,"ac"..achiev,0)
  588. end
  589. elseif achiev == 13 then
  590. local mapBuys = tonumber(loadPlayerData(thePlayer,"mapBuys"))
  591. if mapBuys <= 10 then
  592. unlockedAC(thePlayer,achiev)
  593. end
  594. end
  595. end
  596. end
  597.  
  598. function unlockedAC(thePlayer,achiev)
  599. callClientFunction(thePlayer,"unlockAChievement", achiev)
  600. outputChatBox("#FFFFFFAC: #00AAFF"..getPlayerName(thePlayer).."#FFFFFF has unlocked an achievement!",getRootElement(),255,255,255,true)
  601. outputChatBox("#FFFFFFAC: #00AAFF"..AchievementsName[achiev],getRootElement(),255,255,255,true)
  602. savePlayerData(thePlayer,"ac"..achiev,1)
  603. end
  604.  
  605. addEvent("onPlayerToptimeImprovement",true)
  606. addEventHandler("onPlayerToptimeImprovement",getRootElement(),
  607. function (player)
  608. local totalToptimes = tonumber(loadPlayerData(source,"TopTimes"))
  609. savePlayerData(source,"TopTimes",totalToptimes+1)
  610. CheckAchievement(source,8)
  611. CheckAchievement(source,14)
  612. end)
  613. ------------------------------------------
  614. -- Join - PlayedTime
  615. ------------------------------------------
  616. function PlayedTimeJoin()
  617. local thePlayer = source
  618. local PlayerJoinTime = getTickCount ()
  619. setElementData(thePlayer,"joinTime", PlayerJoinTime)
  620. end
  621. addEventHandler ("onPlayerJoin",getRootElement(), PlayedTimeJoin)
  622.  
  623. function PlayedTimeQuit()
  624. local thePlayer = source
  625. local PlayerQuitTime = getTickCount ()
  626. local PlayerTodayTime = math.floor((PlayerQuitTime - getElementData(thePlayer,"joinTime"))/1000)
  627. local PlayerOldTime = loadPlayerData(thePlayer,"playedTime")
  628. savePlayerData(thePlayer,"playedTime", PlayerOldTime + PlayerTodayTime)
  629. end
  630. addEventHandler ("onPlayerQuit",getRootElement(), PlayedTimeQuit)
  631.  
  632. function convertTime(timeinseconds)
  633. Days = math.floor(timeinseconds/86400)
  634. timeinseconds = timeinseconds - Days*86400
  635. Hours = math.floor(timeinseconds/3600)
  636. timeinseconds = timeinseconds - Hours*3600
  637. Minutes = math.floor(timeinseconds/60)
  638. timeinseconds = timeinseconds - Minutes*60
  639. Seconds = timeinseconds
  640. if Days > 0 then
  641. Time = Days.." days "..Hours.."h "..Minutes.."m "..Seconds.."s"
  642. elseif Hours > 0 then
  643. Time = Hours.."h "..Minutes.."m "..Seconds.."s"
  644. elseif Minutes > 0 then
  645. Time = Minutes.."m "..Seconds.."s"
  646. else
  647. Time = Seconds.."s"
  648. end
  649. return Time
  650. end
  651.  
  652. ------------------------------------------
  653. -- Hunters
  654. ------------------------------------------
  655. function checkForHunter(number,sort,model)
  656. thePlayer = source
  657. if sort == "vehiclechange" then
  658. if model == 425 then
  659. if getElementData(thePlayer,"playerGotHunter") == false then
  660. setElementData(thePlayer,"playerGotHunter",true)
  661. local oldhunters = loadPlayerData(thePlayer,"hunters")
  662. savePlayerData(thePlayer,"hunters", oldhunters + 1)
  663. CheckAchievement(thePlayer,2)
  664. CheckAchievement(thePlayer,7)
  665. HunterCount = HunterCount + 1
  666. end
  667. end
  668. end
  669. end
  670. addEventHandler("onPlayerPickUpRacePickup",getRootElement(),checkForHunter)
  671.  
  672. ------------------------------------------
  673. -- Mapy
  674. ------------------------------------------executeCommandHandler("nextmap", thePlayer, mapName)
  675. function buyMap(thePlayer,mapName)
  676. if mapIsAlreadySet == false then
  677. if not (mapName == "") then
  678. local playerCash = tonumber(loadPlayerData(thePlayer,"cash"))
  679. local theTime = getMsFromMin(5);
  680. if playerCash >= mapCost then
  681. if (not txBMaps[mapName]) then
  682. txBMaps[mapName] = true
  683. executeCommandHandler("pnfnsdhasd3w7432jhdsbw3ersdncsdir",thePlayer,mapName)
  684. savePlayerData(thePlayer,"cash",playerCash-mapCost)
  685. outputChatBox("#FFFFFFNextmap: "..getPlayerName(thePlayer).."#FFFFFF has bought a next map!",getRootElement(),255,255,255,true)
  686. outputChatBox("#FFFFFFNextmap: #00AAFF"..mapName,getRootElement(),255,255,255,true)
  687. mapIsAlreadySet = thePlayer
  688. local oldmapbuys = loadPlayerData(thePlayer,"mapBuys")
  689. savePlayerData(thePlayer,"mapBuys", oldmapbuys + 1)
  690. CheckAchievement(thePlayer,13)
  691. scoreboardRefresh(thePlayer)
  692. setTimer(removeMapFromList,theTime.ms,1,mapName)
  693. else
  694. outputChatBox("#"..mapName.." will be available for 5 minutes",player,254,12,26,true);
  695. end
  696.  
  697. else
  698. outputChatBox("#00AAFF# #FFFFFFYou don't have enough money to set a map!",thePlayer,255,255,255,true)
  699. end
  700. else
  701. outputChatBox("#00AAFF# #FFFFFFPlease select a map from the list first!",thePlayer,255,255,255,true)
  702. end
  703. else
  704. outputChatBox("#00AAFF# #FFFFFFA map is already set at the moment! Please try again later.",thePlayer,255,255,255,true)
  705. end
  706. end
  707.  
  708. function removeMapFromList(mapName)
  709. outputChatBox("* #abcdef"..mapName.." #ffffff - #ffffffis now #abcdefavailable #ffffffat the #abcdefMap Shop!",getRootElement(),255,255,255,true);
  710. txBMaps[mapName] = nil
  711. end
  712.  
  713. function getMsFromMin(pMin)
  714. local mSeconds = 60 * pMin * 1000;
  715. return { ms = mSeconds };
  716. end
  717.  
  718. function resetMapSetStatus()
  719. mapIsAlreadySet = false
  720. repairset = true
  721. end
  722. addEventHandler("onMapStarting",getRootElement(),resetMapSetStatus)
  723.  
  724. function buyRepair ( thePlayer )
  725. if repairset == true and isPedInVehicle ( thePlayer ) then
  726. local playerCash = tonumber ( loadPlayerData ( thePlayer, "cash" ) )
  727. local v = getPedOccupiedVehicle ( thePlayer )
  728. if playerCash >= RepairCost then
  729. outputChatBox ( getPlayerName ( thePlayer ).." Has bought a Repair for 4000$", root, 0, 255, 0, true)
  730. fixVehicle ( v )
  731. repairset = false
  732. savePlayerData ( thePlayer, "cash", playerCash - RepairCost )
  733. scoreboardRefresh ( thePlayer )
  734. else
  735. outputChatBox ( "You don't have enought money!", thePlayer, 255, 0, 0, true )
  736. end
  737. else
  738. --outputChatBox ( "You need to be in vehicle!", thePlayer, 255, 0, 0, true )
  739. end
  740. outputChatBox("You most be wait a nextmap for buy another repair!", p, 255, 3, 19)
  741. end
  742.  
  743.  
  744. addCommandHandler ( "br", buyRepair )
  745. addCommandHandler ( "buyrepair", buyRepair )
  746.  
  747.  
  748. function getServerMaps (loadList,s)
  749. local tableOut
  750. if loadList then
  751.  
  752. tableOut = {}
  753. -- local deletedMaps = {}
  754. local gamemodes = {}
  755. gamemodes = call(getResourceFromName("mapmanager"), "getGamemodes")
  756. for id,gamemode in ipairs (gamemodes) do
  757. tableOut[id] = {}
  758. tableOut[id].name = getResourceInfo(gamemode, "name") or getResourceName(gamemode)
  759. tableOut[id].resname = getResourceName(gamemode)
  760. tableOut[id].maps = {}
  761. local maps = call(getResourceFromName("mapmanager"), "getMapsCompatibleWithGamemode" , gamemode)
  762. for _,map in ipairs (maps) do
  763. table.insert(tableOut[id]["maps"] ,{name = getResourceInfo(map, "name") or getResourceName(map), resname = getResourceName(map)})
  764. end
  765. table.sort(tableOut[id]["maps"], sortCompareFunction)
  766. end
  767. table.sort((tableOut), sortCompareFunction)
  768. table.insert(tableOut, {name = "no gamemode", resname = "no gamemode", maps = {}})
  769. local countGmodes = #tableOut
  770. local maps = call(getResourceFromName("mapmanager"), "getMapsCompatibleWithGamemode")
  771. for id,map in ipairs (maps) do
  772. -- if fileOpen(":"..getResourceName(map).."/deleted") then
  773. -- table.insert(deletedMaps ,{name = getResourceInfo(map, "name") or getResourceName(map), resname = getResourceName(map)})
  774. -- else
  775. table.insert(tableOut[countGmodes]["maps"] ,{name = getResourceInfo(map, "name") or getResourceName(map), resname = getResourceName(map)})
  776. -- end
  777. end
  778. -- table.sort(deletedMaps, sortCompareFunction)
  779. table.sort(tableOut[countGmodes]["maps"], sortCompareFunction)
  780. -- table.insert(tableOut, {name = "deleted maps", resname = "deleted maps", maps = {}})
  781. -- local countGmodes = countGmodes + 1
  782. -- tableOut[countGmodes]["maps"] = deletedMaps
  783. end
  784.  
  785. local map = call(getResourceFromName("mapmanager"), "getRunningGamemodeMap")
  786. local gamemode = call(getResourceFromName("mapmanager"), "getRunningGamemode")
  787. gamemode = gamemode and getResourceName(gamemode) or "N/A"
  788. map = map and getResourceName(map) or "N/A"
  789. callClientFunction(loadList,"loadMaps", tableOut, gamemode, map, s)
  790. end
  791.  
  792. function sortCompareFunction(s1, s2)
  793. if type(s1) == "table" and type(s2) == "table" then
  794. s1, s2 = s1.name, s2.name
  795. end
  796. s1, s2 = s1:lower(), s2:lower()
  797. if s1 == s2 then
  798. return false
  799. end
  800. local byte1, byte2 = string.byte(s1:sub(1,1)), string.byte(s2:sub(1,1))
  801. if not byte1 then
  802. return true
  803. elseif not byte2 then
  804. return false
  805. elseif byte1 < byte2 then
  806. return true
  807. elseif byte1 == byte2 then
  808. return sortCompareFunction(s1:sub(2), s2:sub(2))
  809. else
  810. return false
  811. end
  812. end
  813.  
  814. ------------------------------------------
  815. -- giveMoney
  816. ------------------------------------------
  817. function giveMoney(thePlayer,CMD,targetPlayer,amount)
  818. if not (targetPlayer == "") then
  819. if tonumber(amount) then
  820. local playerCash = tonumber(loadPlayerData(thePlayer,"cash"))
  821. if tonumber(amount) > 0 then
  822. if tonumber(amount) <= playerCash then
  823. if (findPlayerByName(targetPlayer)) then
  824. local target = findPlayerByName(targetPlayer)
  825. if target ~= thePlayer then
  826. local amount = math.ceil(amount)
  827. local playerCash = loadPlayerData(thePlayer,"cash")
  828. local targetCash = loadPlayerData(target,"cash")
  829. savePlayerData(thePlayer,"cash",playerCash-tonumber(amount))
  830. CheckAchievement(thePlayer,15)
  831. savePlayerData(target,"cash",targetCash+tonumber(amount))
  832. CheckAchievement(target,15)
  833. local playerCash = loadPlayerData(thePlayer,"cash")
  834. local targetCash = loadPlayerData(target,"cash")
  835. scoreboardRefresh(thePlayer)
  836. scoreboardRefresh(target)
  837. outputChatBox("#00AAFF# #FFFFFFYou have sent #00AAFF$"..amount.."#FFFFFF to "..getPlayerName(target).."#FFFFFF!",thePlayer,255,255,255,true)
  838. outputChatBox("#00AAFF# #FFFFFF"..getPlayerName(thePlayer).." #FFFFFFhas sent you #00AAFF$"..amount.."#FFFFFF!",target,255,255,255,true)
  839. else
  840. outputChatBox("#00AAFF# #FFFFFFERROR! You cannot send money to yourself!",thePlayer,255,255,255,true)
  841. return false
  842. end
  843. else
  844. outputChatBox("#00AAFF# #FFFFFFERROR! The player you specified does not exist!",thePlayer,255,255,255,true)
  845. return false
  846. end
  847. else
  848. outputChatBox("#00AAFF# #FFFFFFERROR! You don't have enough money!",thePlayer,255,255,255,true)
  849. return false
  850. end
  851. else
  852. outputChatBox("#00AAFF# #FFFFFFERROR! Invalid amount! [#00AAFF"..amount.."#FFFFFF]",thePlayer,255,255,255,true)
  853. return false
  854. end
  855. else
  856. outputChatBox("#00AAFF# #FFFFFFERROR! Please specify the amount to send!",thePlayer,255,255,255,true)
  857. return false
  858. end
  859. else
  860. outputChatBox("#00AAFF# #FFFFFFERROR! Please select a player!",thePlayer,255,255,255,true)
  861. return false
  862. end
  863. end
  864. addCommandHandler("givecash", giveMoney)
  865. ------------------------------------------
  866. -- Tops
  867. ------------------------------------------
  868. function getDataFromServerAndSendToClient ( thePlayer , argument)
  869. if ( thePlayer ) then
  870. if argument then
  871. if string.lower(argument) == "cash" then
  872. local tablica = loadAllData ("cash")
  873. callClientFunction(thePlayer,"SortTops","Top Cash!",tablica,thePlayer,"$","")
  874. elseif string.lower(argument) == "achievements" or string.lower(argument) == "ac" then
  875. local tablica = loadAllData ("achievements")
  876. callClientFunction(thePlayer,"SortTops","Top Achievements!",tablica,thePlayer,"","")
  877. elseif string.lower(argument) == "ddwins" then
  878. local tablica = loadAllData ("mapsWonDD")
  879. callClientFunction(thePlayer,"SortTops","Top DD wins!",tablica,thePlayer,"","")
  880. elseif string.lower(argument) == "dmwins" then
  881. local tablica = loadAllData ("mapsWonDM")
  882. callClientFunction(thePlayer,"SortTops","Top DM wins!",tablica,thePlayer,"","")
  883. elseif string.lower(argument) == "dds" then
  884. local tablica = loadAllData ("mapsPlayedDD")
  885. callClientFunction(thePlayer,"SortTops","Top Played DDs!",tablica,thePlayer,"","")
  886. elseif string.lower(argument) == "dms" then
  887. local tablica = loadAllData ("mapsPlayedDM")
  888. callClientFunction(thePlayer,"SortTops","Top Played DMs!",tablica,thePlayer,"","")
  889. elseif string.lower(argument) == "playedtime" or string.lower(argument) == "pt" then
  890. local tablica = loadAllData ("playedTime")
  891. callClientFunction(thePlayer,"SortTops","Top Played Time!",tablica,thePlayer," "," ")
  892. elseif string.lower(argument) == "hunters" then
  893. local tablica = loadAllData ("hunters")
  894. callClientFunction(thePlayer,"SortTops","Top Hunters!",tablica,thePlayer,"","")
  895. elseif string.lower(argument) == "mapbuys" or string.lower(argument) == "mb" then
  896. local tablica = loadAllData ("mapBuys")
  897. callClientFunction(thePlayer,"SortTops","Top Map Buys!",tablica,thePlayer,"","")
  898. elseif string.lower(argument) == "toptimes" or string.lower(argument) == "tt" then
  899. local tablica = loadAllData ("TopTimes")
  900. callClientFunction(thePlayer,"SortTops","Top TopTimes!",tablica,thePlayer,"","")
  901. elseif string.lower(argument) == "ddratio" then
  902. local tablica = loadAllData ("ddratio")
  903. callClientFunction(thePlayer,"SortTops","Top DD Ratio!",tablica,thePlayer,"","%")
  904. elseif string.lower(argument) == "dmratio" then
  905. local tablica = loadAllData ("dmratio")
  906. callClientFunction(thePlayer,"SortTops","Top DM Ratio!",tablica,thePlayer,"","%")
  907. elseif string.lower(argument) == "ddmap" then
  908. local allMaps = call(getResourceFromName("mapmanager"), "getMapsCompatibleWithGamemode" , getResourceFromName("race"))
  909. tablicaMap = {}
  910. for i,map in ipairs(allMaps) do
  911. if checkMapType(getResourceInfo(map, "name")) == 2 then
  912. local mapinfo = getMapInfo(map)
  913. table.insert(tablicaMap,{pName = getResourceInfo(map, "name") or "???",dType = tonumber(mapinfo.playedCount) or 0})
  914. end
  915. end
  916. callClientFunction(thePlayer,"SortTopsMaps","Top DD Map!",tablicaMap,thePlayer,"","")
  917. elseif string.lower(argument) == "dmmap" then
  918. local allMaps = call(getResourceFromName("mapmanager"), "getMapsCompatibleWithGamemode" , getResourceFromName("race"))
  919. tablicaMap = {}
  920. for i,map in ipairs(allMaps) do
  921. if checkMapType(getResourceInfo(map, "name")) == 1 then
  922. local mapinfo = getMapInfo(map)
  923. table.insert(tablicaMap,{pName = getResourceInfo(map, "name") or "???",dType = tonumber(mapinfo.playedCount) or 0})
  924. end
  925. end
  926. callClientFunction(thePlayer,"SortTopsMaps","Top DM Map!",tablicaMap,thePlayer,"","")
  927. else
  928. outputChatBox("#00AAFF# #FFFFFFERROR! Invalid argument!",thePlayer,255,255,255,true)
  929. outputChatBox("[cash,achievements,ddwins,dmwins,dds,dms,playedtime]",thePlayer,255,255,255,true)
  930. outputChatBox("[hunters,mapbuys,toptimes,ddratio,dmratio,ddmap,dmmap]",thePlayer,255,255,255,true)
  931. end
  932. else
  933. outputChatBox ("#00AAFF# #FF0000ERROR!#FFFFFF Syntax: /top [datatype]",thePlayer,255,255,255,true)
  934. end
  935. end
  936. end
  937.  
  938. function loadMapInfoAll()
  939. local rows = executeSQLQuery( 'SELECT * FROM ' .. getTableName() )
  940. g_MapInfoList = {}
  941. for i,row in ipairs(rows) do
  942. local map = getResourceFromName( row.resName )
  943. if map then
  944. local mapInfo = getMapInfo( map )
  945. mapInfo.playedCount = row.playedCount
  946. mapInfo.lastTimePlayed = row.lastTimePlayed
  947. end
  948. end
  949. end
  950. function getTableName(value)
  951. return sqlString( 'race_mapmanager_maps' )
  952. end
  953. function sqlString(value)
  954. value = tostring(value) or ''
  955. return "'" .. value:gsub( "(['])", "''" ) .. "'"
  956. end
  957. function getMapInfo( map )
  958. if not g_MapInfoList then
  959. loadMapInfoAll()
  960. end
  961. if not g_MapInfoList[map] then
  962. g_MapInfoList[map] = {}
  963. end
  964. local mapInfo = g_MapInfoList[map]
  965. if mapInfo.loadTime ~= getResourceLoadTime(map) then
  966. -- Reset or clear data that may change between loads
  967. mapInfo.loadTime = getResourceLoadTime( map )
  968. mapInfo.spawnPointCount = false
  969. end
  970. return mapInfo
  971. end
  972.  
  973. function loadAllData (datatype)
  974. local root = xmlLoadFile ("DataBase.xml")
  975. if (root) then
  976. local usersNode = xmlFindChild (root,"user",0)
  977. if (usersNode) then
  978. local allPlayers = xmlNodeGetChildren(usersNode)
  979. allPlayersData = {}
  980. nrDD = 0
  981. nrDM = 0
  982. for i,data in ipairs(allPlayers) do
  983. if datatype == "achievements" then
  984. AchCount = 0
  985. for j=1,#AchievementsName do
  986. local ac = tonumber(xmlNodeGetAttribute (data,"ac"..j..""))
  987. if ac == 1 then
  988. AchCount = AchCount + 1
  989. end
  990. end
  991. local playerName = xmlNodeGetAttribute (data,"playerName")
  992. allPlayersData[i] = {pName = playerName or "???",dType = AchCount or 0}
  993. elseif datatype == "ddratio" then
  994. local played = tonumber(xmlNodeGetAttribute (data,"mapsPlayedDD")) or 0
  995. local wins = tonumber(xmlNodeGetAttribute (data,"mapsWonDD")) or 0
  996. local ratio = 0
  997. if played == 0 and wins == 0 then
  998. ratio = 0
  999. elseif played ~= 0 and wins == 0 then
  1000. ratio = 0
  1001. elseif played ~= 0 and wins ~= 0 then
  1002. ratio = (100/played)*wins
  1003. elseif wins > played then
  1004. ratio = 0
  1005. end
  1006. if played >= 100 then
  1007. nrDD = nrDD + 1
  1008. local playerName = xmlNodeGetAttribute (data,"playerName")
  1009. allPlayersData[nrDD] = {pName = playerName or "???",dType = ratio or 0}
  1010. end
  1011. elseif datatype == "dmratio" then
  1012. local played = tonumber(xmlNodeGetAttribute (data,"mapsPlayedDM")) or 0
  1013. local wins = tonumber(xmlNodeGetAttribute (data,"mapsWonDM")) or 0
  1014. local ratio = 0
  1015. if played == 0 and wins == 0 then
  1016. ratio = 0
  1017. elseif played ~= 0 and wins == 0 then
  1018. ratio = 0
  1019. elseif played ~= 0 and wins ~= 0 then
  1020. ratio = (100/played)*wins
  1021. elseif wins > played then
  1022. ratio = 0
  1023. end
  1024. if played >= 100 then
  1025. nrDM = nrDM + 1
  1026. local playerName = xmlNodeGetAttribute (data,"playerName")
  1027. allPlayersData[nrDM] = {pName = playerName or "???",dType = ratio or 0}
  1028. end
  1029. else
  1030. local playerData = tonumber(xmlNodeGetAttribute (data,datatype))
  1031. local playerName = xmlNodeGetAttribute (data,"playerName")
  1032. allPlayersData[i] = {pName = playerName or "???",dType = playerData or 0}
  1033. end
  1034. end
  1035. xmlUnloadFile (root)
  1036. return allPlayersData
  1037. end
  1038. end
  1039. end
  1040.  
  1041. ------------------------------------------
  1042. -- Kick All
  1043. ------------------------------------------
  1044. function kickAllPlayers ( sourcePlayer, commandname )
  1045. if ( hasObjectPermissionTo ( sourcePlayer, "function.kickPlayer" ) ) then
  1046. outputChatBox("#00AAFF# #FFFFFFScript restarting... Auto-Reconnecting in 5 seconds!", gRoot, 255,255,255,true)
  1047. setTimer(function()
  1048. for i,pla in ipairs(getElementsByType("player")) do
  1049. redirectPlayer ( pla, "213.189.52.40",22069)
  1050. end
  1051. end, 5000,1)
  1052. end
  1053. end
  1054. addCommandHandler ( "kickAllPlayers", kickAllPlayers )
  1055. ------------------------------------------
  1056. -- Triggering
  1057. ------------------------------------------
  1058. function callClientFunction(client, funcname, ...)
  1059. local arg = { ... }
  1060. if (arg[1]) then
  1061. for key, value in next, arg do
  1062. if (type(value) == "number") then arg[key] = tostring(value) end
  1063. end
  1064. end
  1065. triggerClientEvent(client, "onServerCallsClientFunction", getResourceRootElement(getThisResource()), funcname, unpack(arg or {}))
  1066. end
  1067. function callServerFunction(funcname, ...)
  1068. local arg = { ... }
  1069. if (arg[1]) then
  1070. for key, value in next, arg do arg[key] = tonumber(value) or value end
  1071. end
  1072. loadstring("return "..funcname)()(unpack(arg))
  1073. end
  1074. addEvent("onClientCallsServerFunction", true)
  1075. addEventHandler("onClientCallsServerFunction", getResourceRootElement(getThisResource()) , callServerFunction)
  1076.  
  1077. function math.round(number, decimals, method)
  1078. decimals = decimals or 0
  1079. local factor = 10 ^ decimals
  1080. if (method == "ceil" or method == "floor") then return math[method](number * factor) / factor
  1081. else return tonumber(("%."..decimals.."f"):format(number)) end
  1082. end
  1083.  
  1084. --------------------------------------------
  1085. -- Get alive and dead players by their STATE
  1086. --------------------------------------------
  1087. function getAliveRacePlayers()
  1088. local alivePlayers = 0
  1089. for index,player in ipairs(getElementsByType("player")) do
  1090. if getElementData(player,"state") == "alive" then
  1091. alivePlayers = alivePlayers + 1
  1092. end
  1093. end
  1094. return alivePlayers
  1095. end
  1096.  
  1097.  
  1098. function getDeadRacePlayers()
  1099. local deadPlayers = 0
  1100. for index,player in ipairs(getElementsByType("player")) do
  1101. if getElementData(player,"state") == "dead" then
  1102. deadPlayers = deadPlayers + 1
  1103. end
  1104. end
  1105. return deadPlayers
  1106. end
  1107.  
  1108. ------------------------------------------
  1109. -- Nick
  1110. ------------------------------------------
  1111. addEventHandler ("onPlayerJoin",getRootElement(),
  1112. function()
  1113. local playerName = getPlayerName(source)
  1114. savePlayerData(source,"playerName",string.gsub(playerName,"#%x%x%x%x%x%x", ""))
  1115. end)
  1116. addEventHandler("onPlayerChangeNick",getRootElement(),
  1117. function (olnick,newnick)
  1118.  
  1119. savePlayerData(source,"playerName",string.gsub(newnick,"#%x%x%x%x%x%x", ""))
  1120. end)
  1121.  
  1122. ------------------------------------------
  1123. -- PlayerNameFunctions
  1124. ------------------------------------------
  1125. function getPlayerNameWithoutColorCode (who)
  1126. local name = getPlayerName(who)
  1127. local name = string.gsub(name,'#%x%x%x%x%x%x',"")
  1128. return name
  1129. end
  1130.  
  1131. function getPlayerFromNameWithoutColorCode (name)
  1132. for i,pla in ipairs(getElementsByType("player")) do
  1133. if getPlayerNameWithoutColorCode (pla) == name then
  1134. return pla
  1135. end
  1136. end
  1137. end
  1138.  
  1139. function findPlayerByName (name)
  1140. local player = getPlayerFromName(name)
  1141. if player then return player end
  1142. for i, player in ipairs(getElementsByType("player")) do
  1143. if string.find(string.gsub(getPlayerName(player):lower(),"#%x%x%x%x%x%x", ""), name:lower(), 1, true) then
  1144. return player
  1145. end
  1146. end
  1147. return false
  1148. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement