Guest User

Problem in Stats

a guest
Mar 27th, 2012
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 17.07 KB | None | 0 0
  1. addEventHandler("onPlayerChat")
  2. function(message,type) ,getRootElement(),
  3.   if (string.find(message,"!points")) and not (string.find(message," !points")) then
  4.     local playerPoints = loadPlayerData (source,"points")
  5.     setTimer(outputChatBox,50,1,getPlayerName (source) .. " #FF0000has " .. tostring(playerPoints) .. " points!",getRootElement(),255,0,0,true)
  6.   elseif (string.find(message,"!cash")) and not (string.find(message," !cash")) then
  7.     local playerCash = loadPlayerData (source,"cash")
  8.     setTimer(outputChatBox,50,1,getPlayerName (source) .. " #FF0000has " .. tostring(playerCash) .. "$!",getRootElement(),255,0,0,true)
  9.   elseif (string.find(message,"!inforollpl")) and not (string.find(message," !inforollpl")) then
  10.     setTimer(outputChatBox,50,1,"blahblahblah",source,255,0,0,false)
  11.     setTimer(outputChatBox,50,1,"Anyone can translate the english part o_o",source,255,0,0,false)
  12.     setTimer(outputChatBox,50,1,"and blah blah blah...",source,255,0,0,false)
  13.     setTimer(outputChatBox,50,1,"Wesseb maybe o.o",source,255,0,0,false)
  14.     setTimer(outputChatBox,50,1,"Or pat:<",source,255,0,0,false)
  15.     setTimer(outputChatBox,50,1,"Maybe eminem o_o",source,255,0,0,false)
  16.     setTimer(outputChatBox,50,1,"I can't speak polish :< sorry people:'(",source,255,0,0,false)
  17.   elseif (string.find(message,"!inforoll")) and not (string.find(message," !inforoll")) then
  18.     setTimer(outputChatBox,50,1,"Type !roll for start roll (cost 100$)!",source,255,0,0,false)
  19.     setTimer(outputChatBox,50,1,"First is generated if you will win money. ",source,255,0,0,false)
  20.     setTimer(outputChatBox,50,1," 1/4 - You win points and generated cash",source,255,0,0,false)
  21.     setTimer(outputChatBox,50,1," 1/4 - You win cash",source,255,0,0,false)
  22.     setTimer(outputChatBox,50,1," 2/4 - You lose cash",source,255,0,0,false)
  23.     setTimer(outputChatBox,50,1,"You can win 1000$ max!",source,255,0,0,false)
  24.     setTimer(outputChatBox,50,1,"You can lose 1000$ max!",source,255,0,0,false)
  25.   elseif (string.find(message,"!roll")) and not (string.find(message," !roll")) then
  26.     local playerCash = loadPlayerData (source,"cash")
  27.     if (tonumber(playerCash) > 100) then
  28.       if not (rollLimitCheckPlayerIsIn (source)) then
  29.         savePlayerData (source,"cash",loadPlayerData (source,"cash") -100)
  30.         local firstRollNumber = math.random (1,4)
  31.         local secondRollNumber = math.random (0,1000)
  32.         local thirdRollNumber = math.random (0,10)
  33.         rollLimitAddPlayer (source)
  34.         if (firstRollNumber == 1) then
  35.           setTimer(outputChatBox,50,1,"You win points AND cash! Calculating ...",source,255,0,0,false)
  36.           setTimer(outputChatBox,500,1,"You've won " .. tostring (secondRollNumber) .. "$ and " .. tostring (thirdRollNumber) .. " points!",source,255,0,0,false)
  37.           setTimer(savePlayerData,500,1,source,"cash",loadPlayerData(source,"cash") +secondRollNumber)
  38.           setTimer(savePlayerData,500,1,source,"points",loadPlayerData(source,"points") +thirdRollNumber)
  39.         elseif (firstRollNumber == 2) then
  40.           setTimer(outputChatBox,50,1,"You win cash! Calculating ...",source,255,0,0,false)
  41.           setTimer(outputChatBox,500,1,"You've won " .. tostring (secondRollNumber) .. "$!",source,255,0,0,false)
  42.           setTimer(savePlayerData,500,1,source,"cash",loadPlayerData(source,"cash") +secondRollNumber)
  43.         elseif (firstRollNumber == 3) then
  44.           setTimer(outputChatBox,50,1,"You lose cash! Calculating ...",source,255,0,0,false)
  45.           setTimer(outputChatBox,500,1,"You've lost " .. tostring (secondRollNumber) .. "$!",source,255,0,0,false)
  46.           setTimer(savePlayerData,500,1,source,"cash",loadPlayerData(source,"cash") -secondRollNumber)
  47.         elseif (firstRollNumber == 4) then
  48.           setTimer(outputChatBox,50,1,"You lose cash! Calculating ...",source,255,0,0,false)
  49.           setTimer(outputChatBox,500,1,"You've lost " .. tostring (secondRollNumber) .. "$!",source,255,0,0,false)
  50.           setTimer(savePlayerData,500,1,source,"cash",loadPlayerData(source,"cash") -secondRollNumber)
  51.         end
  52.       else
  53.         outputChatBox ("You only can use !roll once a minute!",source,255,0,0,false)
  54.         cancelEvent()
  55.       end
  56.     else
  57.       setTimer(outputChatBox,50,1,"You don't have got 100$, you need that before rolling!",source,255,0,0,false)
  58.     end
  59.   elseif (string.find(message,"!lang")) and not (string.find(message," !lang")) then
  60.     setTimer(outputChatBox,50,1,"Enabled languages: Polish, English, (and Dutch)",getRootElement(),255,0,0,false)
  61.   elseif (string.find(message,"!commands")) and not (string.find(message," !commands")) then
  62.     setTimer(outputChatBox,50,1," Commands",source,255,0,0,false)
  63.     setTimer(outputChatBox,50,1,"!cash - see your cash!",source,255,0,0,false)
  64.     setTimer(outputChatBox,50,1,"!points - see your points!",source,255,0,0,false)
  65.     setTimer(outputChatBox,50,1,"!roll - win or lose points and money! (100$)",source,255,0,0,false)
  66.     setTimer(outputChatBox,50,1,"!inforollpl - More info about !roll (polish)",source,255,0,0,false)
  67.     setTimer(outputChatBox,50,1,"!inforoll - More info about !roll (english)",source,255,0,0,false)
  68.     setTimer(outputChatBox,50,1,"!lang - Let see the enabled languages!",source,255,0,0,false)
  69.     setTimer(outputChatBox,2550,1,"[CENSORED] /buykick /buyfreeze :<",source,255,0,0,false)
  70.     if hasObjectPermissionTo ( source, "function.kickPlayer", false ) then
  71.       setTimer(outputChatBox,2550,1," Admin commands (only admins see this)",source,255,0,0,false)
  72.       setTimer(outputChatBox,2550,1,"/setPlayerData [player] [datatype] [amount] - Set players data",source,255,0,0,false)
  73.       setTimer(outputChatBox,2550,1,"/getPlayerData [player] [datatype] - Get players data",source,255,0,0,false)
  74.       setTimer(outputChatBox,2550,1,"/addvip [player] - Make a player VIP!",source,255,0,0,false)
  75.       setTimer(outputChatBox,2550,1,"/removevip [player] - Remove a players VIP!",source,255,0,0,false)
  76.     end
  77.     if (loadPlayerData (source,"teamrank") == "vipt") then
  78.       setTimer(outputChatBox,2550,1," VIP functions",source,255,0,0,false)
  79.       setTimer(outputChatBox,2550,1,"/enterteam - Enter the Vip Test Members !",source,255,0,0,false)
  80.     end
  81.   end
  82. end)
  83.  
  84. addEventHandler ("onResourceStart",getResourceRootElement(getThisResource()),
  85. function()
  86.   outputChatBox ("#ffff00Points #ffffffand #ffff00cash #ffffffsystem loaded",getRootElement(),255,255,255,true)
  87. end)
  88.  
  89. addCommandHandler("getPlayerData",
  90. function(player,command,toplayername,datatype)
  91.   if hasObjectPermissionTo ( player, "function.kickPlayer", false ) then
  92.     if (toplayername) and (datatype) then
  93.       if (findPlayerByName (toplayername)) then
  94.         toplayer = findPlayerByName (toplayername)
  95.         local amount = loadPlayerData (toplayer,datatype)
  96.         outputChatBox ("Succesfully data get - From: " .. getPlayerName(toplayer) .. " #FF0000- Datatype: " .. datatype .. " - amount: " .. amount .. ".",player,255,0,0,true)
  97.       end
  98.     else
  99.       outputChatBox ("WRONG! Syntax: /getPlayerData [playername (partical)] [datatype]",player,255,0,0,false)
  100.     end
  101.   else
  102.     outputChatBox ("Sorry, only admins can use this!",player,255,0,0,false)
  103.   end
  104. end)
  105.  
  106. addCommandHandler("setPlayerData",
  107. function(player,command,toplayername,datatype,amount)
  108.   if hasObjectPermissionTo ( player, "function.kickPlayer", false ) then
  109.     if (toplayername) and (datatype) and (amount) then
  110.       if (findPlayerByName (toplayername)) then
  111.         toplayer = findPlayerByName (toplayername)
  112.         savePlayerData (toplayer,datatype,amount)
  113.         outputChatBox ("Succesfully data set - To: " .. getPlayerName(toplayer) .. " #FF0000- Datatype: " .. datatype .. " - amount: " .. amount, player,255,0,0,true)
  114.         outputChatBox (getPlayerName (player) .. " #FF0000have set new data for you! - Datatype: " .. datatype .. " - amount: " .. amount, toplayer,255,0,0,true)
  115.       end
  116.     else
  117.       outputChatBox ("WRONG! Syntax: /setPlayerData [playername (partical)] [datatype] [amount]",player,255,0,0,false)
  118.     end
  119.   else
  120.     outputChatBox ("Sorry, only admins can use this!",player,255,0,0,false)
  121.   end
  122. end)
  123.  
  124. addCommandHandler("addvip",
  125. function(player,command,toplayername)
  126.   if hasObjectPermissionTo ( player, "function.kickPlayer", false ) then
  127.     if (toplayername) then
  128.       if (findPlayerByName (toplayername)) then
  129.         toplayer = findPlayerByName (toplayername)
  130.         savePlayerData (toplayer,"teamrank","vipt")
  131.         outputChatBox ("Succesfully vipt added to: " .. getPlayerName(toplayer) .. ".", player,255,0,0,true)
  132.         outputChatBox (getPlayerName (player) .. " #FF0000has made you VIPt! Fast do !commands for your new commands!", toplayer,255,0,0,true)
  133.       else
  134.         outputChatBox ("WRONG! Unknown username!",player,255,0,0,false)
  135.       end
  136.     else
  137.       outputChatBox ("WRONG! Syntax: /addvipt [playername (partical)]",player,255,0,0,false)
  138.     end
  139.   else
  140.     outputChatBox ("Sorry, only admins can use this!",player,255,0,0,false)
  141.   end
  142. end)
  143.  
  144. addCommandHandler("removevip",
  145. function(player,command,toplayername)
  146.   if hasObjectPermissionTo ( player, "function.kickPlayer", false ) then
  147.     if (toplayername) then
  148.       if (findPlayerByName (toplayername)) then
  149.         toplayer = findPlayerByName (toplayername)
  150.         savePlayerData (toplayer,"teamrank","none")
  151.         outputChatBox ("Succesfully VIP removed from: " .. getPlayerName(toplayer) .. ".", player,255,0,0,true)
  152.         outputChatBox (getPlayerName (player) .. " #FF0000has removed your VIPt :<", toplayer,255,0,0,true)
  153.       else
  154.         outputChatBox ("WRONG! Unknown username!",player,255,0,0,false)
  155.       end
  156.     else
  157.       outputChatBox ("WRONG! Syntax: /removevipt [playername (partical)]",player,255,0,0,false)
  158.     end
  159.   else
  160.     outputChatBox ("Sorry, only admins can use this!",player,255,0,0,false)
  161.   end
  162. end)
  163.  
  164. addCommandHandler("enterteam",
  165. function(player,command)
  166.   if (loadPlayerData (player,"teamrank") == "vipt") then
  167.     if (vipteam) then
  168.       setPlayerTeam (player,viptteam)
  169.     else
  170.       viptteam = createTeam ("Vip Members",0,255,127)
  171.       setPlayerTeam (player,viptteam)
  172.     end
  173.   end
  174. end)
  175.  
  176. function checkVIPTplayers ()
  177.   if (viptteam) then
  178.     local teamPlayerCount = countPlayersInTeam (viptteam)
  179.     if (teamPlayerCount == 0) then
  180.       destroyElement (viptteam)
  181.     end
  182.   end
  183. end
  184. addEventHandler ("onPlayerQuit",getRootElement(),checkVIPTplayers)
  185. addEventHandler ("onPlayerJoin",getRootElement(),checkVIPTplayers)
  186.  
  187.  
  188. --[[ddCommandHandler ("buykick",
  189. function(player,command,kickPlayerName)
  190.   local playerCash = loadPlayerData (player,"cash")
  191.   if (tonumber(playerCash) > 19999) then
  192.     if (findPlayerByName (kickPlayerName)) then
  193.       local playerToKick = findPlayerByName (kickPlayerName)
  194.       setTimer(kickPlayer,2500,1,playerToKick,getPlayerName(player) .. " have buykicked you!")
  195.       outputChatBox (getPlayerName(playerToKick) .. " #FF0000is buykicked by " .. getPlayerName(player) .. "#FF0000.",getRootElement(),255,0,0,true)
  196.       savePlayerData (player,"cash",loadPlayerData(player,"cash") -20000)
  197.     else
  198.       outputChatBox ("The nickname seems to be wrong.",player,255,0,0,false)
  199.     end
  200.   else
  201.     outputChatBox ("You can't kick anyone, you need 20,000$ first!",player,255,0,0,false)
  202.   end
  203. end)
  204.  
  205. addCommandHandler ("buyfreeze",
  206. function(player,command,kickPlayerName)
  207.   local playerCash = loadPlayerData (player,"cash")
  208.   if (tonumber(playerCash) > 6999) then
  209.     if (findPlayerByName (kickPlayerName)) then
  210.      local playerToKick = findPlayerByName (kickPlayerName)
  211.       setElementFrozen (getPedOccupiedVehicle(playerToKick),true)
  212.       setTimer (setElementFrozen,30000,1,getPedOccupiedVehicle(playerToKick),false)
  213.       setTimer (outputChatBox,30000,1,getPlayerName(playerToKick) .. " #FF0000is defrozen. Have a nice day :D",getRootElement(),255,0,0,true)
  214.       outputChatBox (getPlayerName(playerToKick) .. " #FF0000is buyfreezed by " .. getPlayerName(player) .. "#FF0000 (30 seconds).",getRootElement(),255,0,0,true)
  215.       savePlayerData (player,"cash",loadPlayerData(player,"cash") -7000)
  216.     else
  217.       outputChatBox ("The nickname seems to be wrong.",player,255,0,0,false)
  218.     end
  219.   else
  220.     outputChatBox ("You can't freeze anyone, you need 7,000$ first!",player,255,0,0,false)
  221.   end
  222. end)]]--
  223.  
  224.  
  225. -- extra roll functions
  226. rollusers = {}
  227. function rollLimitCheckPlayerIsIn (player)
  228.   for i,v in ipairs (rollusers) do
  229.     if (v == player) then
  230.       return true
  231.     end
  232.   end
  233. end
  234.  
  235. function rollLimitAddPlayer (player)
  236.   table.insert (rollusers,player)
  237. end
  238.  
  239. function rollLimitCleanUp2 ()
  240.   for i,v in ipairs (rollusers) do
  241.     table.remove (rollusers,i)
  242.   end
  243. end
  244.  
  245. --[[addEventHandler("onResourceStart",getResourceRootElement(getThisResource()),
  246. function()
  247.   if (rollLimitTimer2) then
  248.     outputChatBox ("Roll limit timer found, Delete and create new one.")
  249.     killTimer (rollLimitTimer2)
  250.     rollLimitTimer2 = setTimer (rollLimitCleanUp2,60000,0)
  251.   else
  252.     outputChatBox ("Roll limit timer not found, create new one.")
  253.     rollLimitTimer2 = setTimer (rollLimitCleanUp2,60000,0)
  254.   end
  255. end)]]--
  256.  
  257. -- stop extra roll functions
  258.  
  259.  
  260. addEventHandler ("onPlayerRaceWasted",getRootElement(),
  261. function()
  262.   killPed (source)
  263.   setElementHealth (source,0)
  264.   if (isPedInVehicle(source)) then
  265.     blowVehicle (getPedOccupiedVehicle(source))
  266.   end
  267. end)
  268.  
  269. addEventHandler ("onPlayerJoin",getRootElement(),
  270. function()
  271.   setElementHealth (source,0)
  272.   setTimer (setElementHealth,1500,1,0)
  273.   savePlayerData (source,"lastPlayerName",getPlayerName(source))
  274. end)
  275.  
  276. addEventHandler ("onPlayerChangeNick",getRootElement(),
  277. function(olnick,newnick)
  278.   savePlayerData (source,"lastPlayerName",newnick)
  279. end)
  280.  
  281. function checkWinAndIfWinGiveWinCash (totalAmmo,killer,killerWeapon,bodypart,stealth)
  282.   local rank = getAliveCount()
  283.   if (rank == 1) then
  284.     local allAlivePlayers = getAlivePlayers()
  285.     local player = allAlivePlayers[1]
  286.     local playerCount = getPlayerCount()
  287.     local pointsToWin = playerCount *13
  288.     local cashToWin = playerCount *53
  289.     savePlayerData (player,"points",loadPlayerData(player,"points") + pointsToWin)
  290.     savePlayerData (player,"cash",loadPlayerData(player,"cash") +cashToWin)
  291.     outputChatBox (getPlayerName(player) .." #FF0000is first! He wins ".. tostring(pointsToWin).." points and "..tostring(cashToWin).."$!",getRootElement(),255,0,0,true)
  292.   end
  293. end
  294. addEventHandler ("onPlayerWasted",getRootElement(),checkWinAndIfWinGiveWinCash)
  295. addEventHandler ("onPlayerQuit",getRootElement(),checkWinAndIfWinGiveWinCash)
  296.  
  297. function findPlayerByName (playerPart)
  298.   for i,v in ipairs (getElementsByType ("player")) do
  299.     if (string.find(getPlayerName(v),playerPart)) then
  300.       return v
  301.     end
  302.   end
  303. end
  304.  
  305. function getDeadCount ()
  306.   deadAmount = 0
  307.   for i,v in ipairs (getDeadPlayers()) do
  308.     deadAmount = deadAmount +1
  309.   end
  310.   return deadAmount
  311. end
  312.  
  313. function getSpawnedCount ()
  314.   spawnedAmount = 0
  315.   for i,v in ipairs (getAlivePlayers()) do
  316.     if (isPedInVehicle (v)) then
  317.       spawnedAmount = spawnedAmount +1
  318.     end
  319.   end
  320.   return spawnedAmount
  321. end
  322.  
  323. function getAliveCount ()
  324.   aliveAmount = 0
  325.   for i,v in ipairs (getAlivePlayers()) do
  326.     aliveAmount = aliveAmount +1
  327.   end
  328.   return aliveAmount
  329. end
  330.  
  331. -- The load-and-save part.
  332. function loadPlayerData (player,datatype)
  333.   local playerIP = getPlayerSerial (player)
  334.   if (playerIP) then
  335.     local root = xmlLoadFile ("users.xml")
  336.     if (root) then
  337.       local usersNode = xmlFindChild (root,"user",0)
  338.       if (usersNode) then
  339.         local playerRootNode = xmlFindChild (usersNode,"SERIAL_" .. getPlayerSerial(player),0)
  340.         if not (playerRootNode == false) then
  341.           local playerData = xmlNodeGetAttribute (playerRootNode,datatype)
  342.           if (playerData) then
  343.             xmlUnloadFile (root)
  344.             return playerData
  345.           else
  346.             xmlNodeSetAttribute (playerRootNode,datatype,0)
  347.             xmlSaveFile (root)
  348.             xmlUnloadFile (root)
  349.             return 0
  350.           end
  351.         else
  352.           local playerRootNode = xmlCreateChild (usersNode,"SERIAL_" .. getPlayerSerial(player))
  353.           xmlNodeSetAttribute (playerRootNode,datatype,0)
  354.           xmlSaveFile (root)
  355.           xmlUnloadFile (root)
  356.           return 0
  357.         end
  358.       end
  359.     end
  360.   end
  361. end
  362.  
  363. function savePlayerData (player,datatype,newvalue)
  364.   local playerIP = getPlayerSerial (player)
  365.   if (playerIP) then
  366.     local root = xmlLoadFile ("users.xml")
  367.     if (root) then
  368.       local usersNode = xmlFindChild (root,"user",0)
  369.       if (usersNode) then
  370.         local playerRootNode = xmlFindChild (usersNode,"SERIAL_" .. getPlayerSerial(player),0)
  371.         if not (playerRootNode == false) then
  372.           local newNodeValue = xmlNodeSetAttribute (playerRootNode,datatype,newvalue)
  373.           xmlSaveFile (root)
  374.           xmlUnloadFile (root)
  375.           return newNodeValue
  376.         else
  377.           local playerRootNode = xmlCreateChild (usersNode,"SERIAL_" .. getPlayerSerial(player))
  378.           local newNodeValue = xmlNodeSetAttribute (playerRootNode,datatype,newvalue)
  379.           xmlSaveFile (root)
  380.           xmlUnloadFile (root)
  381.           return newNodeValue
  382.         end
  383.       end
  384.     end
  385.   end
  386. end
Advertisement
Add Comment
Please, Sign In to add comment