Advertisement
Guest User

Untitled

a guest
Mar 1st, 2013
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 11.45 KB | None | 0 0
  1. function playerLogin (thePreviousAccount, theCurrentAccount, autoLogin)
  2.   if  not (isGuestAccount (getPlayerAccount (source))) then
  3.     local accountData = getAccountData (theCurrentAccount, "funmodev2-money")
  4.     if (accountData) then
  5.       local playerMoney = getAccountData (theCurrentAccount, "funmodev2-money")
  6.       local playerSkin = getAccountData (theCurrentAccount, "funmodev2-skin")
  7.       local playerHealth = getAccountData (theCurrentAccount, "funmodev2-health")
  8.       local playerArmor = getAccountData (theCurrentAccount, "funmodev2-armor")
  9.       local playerX = getAccountData (theCurrentAccount, "funmodev2-x")
  10.       local playerY = getAccountData (theCurrentAccount, "funmodev2-y")
  11.       local playerZ = getAccountData (theCurrentAccount, "funmodev2-z")
  12.       local playerInt = getAccountData (theCurrentAccount, "funmodev2-int")
  13.       local playerDim = getAccountData (theCurrentAccount, "funmodev2-dim")
  14.       local playerWanted = getAccountData (theCurrentAccount, "funmodev2-wantedlevel")
  15.      local playerTeam = getAccountData (theCurrentAccount, "funmodev2-Team")
  16.       local playerWeaponID0 = getAccountData (theCurrentAccount, "funmodev2-weaponID0")
  17.       local playerWeaponID1 = getAccountData (theCurrentAccount, "funmodev2-weaponID1")
  18.       local playerWeaponID2 = getAccountData (theCurrentAccount, "funmodev2-weaponID2")
  19.       local playerWeaponID3 = getAccountData (theCurrentAccount, "funmodev2-weaponID3")
  20.       local playerWeaponID4 = getAccountData (theCurrentAccount, "funmodev2-weaponID4")
  21.       local playerWeaponID5 = getAccountData (theCurrentAccount, "funmodev2-weaponID5")
  22.       local playerWeaponID6 = getAccountData (theCurrentAccount, "funmodev2-weaponID6")
  23.       local playerWeaponID7 = getAccountData (theCurrentAccount, "funmodev2-weaponID7")
  24.       local playerWeaponID8 = getAccountData (theCurrentAccount, "funmodev2-weaponID8")
  25.       local playerWeaponID9 = getAccountData (theCurrentAccount, "funmodev2-weaponID9")
  26.       local playerWeaponID10 = getAccountData (theCurrentAccount, "funmodev2-weaponID10")
  27.       local playerWeaponID11 = getAccountData (theCurrentAccount, "funmodev2-weaponID11")
  28.       local playerWeaponID12 = getAccountData (theCurrentAccount, "funmodev2-weaponID12")
  29.       local playerWeaponAmmo0 = getAccountData (theCurrentAccount, "funmodev2-weaponAmmo0")
  30.       local playerWeaponAmmo1 = getAccountData (theCurrentAccount, "funmodev2-weaponAmmo1")
  31.       local playerWeaponAmmo2 = getAccountData (theCurrentAccount, "funmodev2-weaponAmmo2")
  32.       local playerWeaponAmmo3 = getAccountData (theCurrentAccount, "funmodev2-weaponAmmo3")
  33.       local playerWeaponAmmo4 = getAccountData (theCurrentAccount, "funmodev2-weaponAmmo4")
  34.       local playerWeaponAmmo5 = getAccountData (theCurrentAccount, "funmodev2-weaponAmmo5")
  35.       local playerWeaponAmmo6 = getAccountData (theCurrentAccount, "funmodev2-weaponAmmo6")
  36.       local playerWeaponAmmo7 = getAccountData (theCurrentAccount, "funmodev2-weaponAmmo7")
  37.       local playerWeaponAmmo8 = getAccountData (theCurrentAccount, "funmodev2-weaponAmmo8")
  38.       local playerWeaponAmmo9 = getAccountData (theCurrentAccount, "funmodev2-weaponAmmo9")
  39.       local playerWeaponAmmo10 = getAccountData (theCurrentAccount, "funmodev2-weaponAmmo10")
  40.       local playerWeaponAmmo11 = getAccountData (theCurrentAccount, "funmodev2-weaponAmmo11")
  41.       local playerWeaponAmmo12 = getAccountData (theCurrentAccount, "funmodev2-weaponAmmo12")
  42.       spawnPlayer (source, playerX, playerY, playerZ +1, 0, playerSkin, playerInt, playerDim)
  43.       setPlayerMoney (source, playerMoney)
  44.       setTimer (setElementHealth, 50, 1, source, playerHealth)
  45.       setTimer (setPedArmor, 50, 1, source, playerArmor)
  46.       setTimer (setPlayerWantedLevel, 50, 1, source, playerWanted)
  47.       giveWeapon(source, playerWeaponID0, playerWeaponAmmo0, true)
  48.       giveWeapon(source, playerWeaponID1, playerWeaponAmmo1, false)
  49.       giveWeapon(source, playerWeaponID2, playerWeaponAmmo2, false)
  50.       giveWeapon(source, playerWeaponID3, playerWeaponAmmo3, false)
  51.       giveWeapon(source, playerWeaponID4, playerWeaponAmmo4, false)
  52.       giveWeapon(source, playerWeaponID5, playerWeaponAmmo5, false)
  53.       giveWeapon(source, playerWeaponID6, playerWeaponAmmo6, false)
  54.       giveWeapon(source, playerWeaponID7, playerWeaponAmmo7, false)
  55.       giveWeapon(source, playerWeaponID8, playerWeaponAmmo8, false)
  56.       giveWeapon(source, playerWeaponID9, playerWeaponAmmo9, false)
  57.       giveWeapon(source, playerWeaponID10, playerWeaponAmmo10, false)
  58.       giveWeapon(source, playerWeaponID11, playerWeaponAmmo11, false)
  59.       giveWeapon(source, playerWeaponID12, playerWeaponAmmo12, false)
  60.       setCameraTarget (source, source)
  61.       fadeCamera(source, true, 2.0)
  62.     end  
  63.   end
  64. end
  65. addEventHandler ("onPlayerLogin", getRootElement(), playerLogin)
  66.  
  67. function onLogout ()
  68.     kickPlayer (source, nil, "Logging out is disallowed.")
  69. end
  70. addEventHandler ("onPlayerLogout", getRootElement(), onLogout)
  71.  
  72. function onQuit (quitType, reason, responsibleElement)
  73.   if not (isGuestAccount (getPlayerAccount (source))) then
  74.     account = getPlayerAccount (source)
  75.     if (account) then
  76.       local x,y,z = getElementPosition (source)
  77.       setAccountData (account, "funmodev2-money", tostring (getPlayerMoney (source)))
  78.       setAccountData (account, "funmodev2-skin", tostring (getPedSkin (source)))
  79.       setAccountData (account, "funmodev2-health", tostring (getElementHealth (source)))
  80.       setAccountData (account, "funmodev2-armor", tostring (getPedArmor (source)))
  81.       setAccountData (account, "funmodev2-R", r)
  82.       setAccountData (account, "funmodev2-G", g)
  83.       setAccountData (account, "funmodev2-B", b)
  84.       setAccountData (account, "funmodev2-x", x)
  85.       setAccountData (account, "funmodev2-y", y)
  86.       setAccountData (account, "funmodev2-z", z)
  87.       setAccountData (account, "funmodev2-int", getElementInterior (source))
  88.       setAccountData (account, "funmodev2-dim", getElementDimension (source))
  89.       setAccountData (account, "funmodev2-wantedlevel", getPlayerWantedLevel (source))
  90.       setAccountData (account, "funmodev2-weaponID0", getPedWeapon (source, 0))
  91.       setAccountData (account, "funmodev2-weaponID1", getPedWeapon (source, 1))
  92.       setAccountData (account, "funmodev2-weaponID2", getPedWeapon (source, 2))
  93.       setAccountData (account, "funmodev2-weaponID3", getPedWeapon (source, 3))
  94.       setAccountData (account, "funmodev2-weaponID4", getPedWeapon (source, 4))
  95.       setAccountData (account, "funmodev2-weaponID5", getPedWeapon (source, 5))
  96.       setAccountData (account, "funmodev2-weaponID6", getPedWeapon (source, 6))
  97.       setAccountData (account, "funmodev2-weaponID7", getPedWeapon (source, 7))
  98.       setAccountData (account, "funmodev2-weaponID8", getPedWeapon (source, <!-- s8) --><img src=\"{SMILIES_PATH}/icon_cool.gif\" alt=\"8)\" title=\"Cool\" /><!-- s8) -->)
  99.       setAccountData (account, "funmodev2-weaponID9", getPedWeapon (source, 9))
  100.       setAccountData (account, "funmodev2-weaponID10", getPedWeapon (source, 10))
  101.       setAccountData (account, "funmodev2-weaponID11", getPedWeapon (source, 11))
  102.       setAccountData (account, "funmodev2-weaponID12", getPedWeapon (source, 12))
  103.       setAccountData (account, "funmodev2-weaponAmmo0", getPedTotalAmmo (source, 0))
  104.       setAccountData (account, "funmodev2-weaponAmmo1", getPedTotalAmmo (source, 1))
  105.       setAccountData (account, "funmodev2-weaponAmmo2", getPedTotalAmmo (source, 2))
  106.       setAccountData (account, "funmodev2-weaponAmmo3", getPedTotalAmmo (source, 3))
  107.       setAccountData (account, "funmodev2-weaponAmmo4", getPedTotalAmmo (source, 4))
  108.       setAccountData (account, "funmodev2-weaponAmmo5", getPedTotalAmmo (source, 5))
  109.       setAccountData (account, "funmodev2-weaponAmmo6", getPedTotalAmmo (source, 6))
  110.       setAccountData (account, "funmodev2-weaponAmmo7", getPedTotalAmmo (source, 7))
  111.       setAccountData (account, "funmodev2-weaponAmmo8", getPedTotalAmmo (source, <!-- s8) --><img src=\"{SMILIES_PATH}/icon_cool.gif\" alt=\"8)\" title=\"Cool\" /><!-- s8) -->)
  112.       setAccountData (account, "funmodev2-weaponAmmo9", getPedTotalAmmo (source, 9))
  113.       setAccountData (account, "funmodev2-weaponAmmo10", getPedTotalAmmo (source, 10))
  114.       setAccountData (account, "funmodev2-weaponAmmo11", getPedTotalAmmo (source, 11))
  115.       setAccountData (account, "funmodev2-weaponAmmo12", getPedTotalAmmo (source, 12))
  116.     end
  117.   end
  118. end
  119. addEventHandler ("onPlayerQuit", getRootElement(), onQuit)
  120.  
  121. ---
  122.  
  123. function setTeam()
  124.     local account = getPlayerAccount(source)
  125.     local team = getAccountData (account, "team")
  126.         if team and getTeamFromName(team) then
  127.               setPlayerTeam(source, getTeamFromName(team))
  128.     end
  129. end
  130. addEventHandler("onPlayerLogin",getRootElement(),setTeam)
  131.  
  132. function saveTeam()
  133.     local team = getPlayerTeam(source)
  134.     local account = getPlayerAccount(source)
  135.        if (team) and not isGuestAccount(account) then
  136.           setAccountData(account, "team", getTeamName(team))
  137.     end
  138. end
  139. addEventHandler("onPlayerQuit",getRootElement(),saveTeam)
  140.  
  141. function convertWeaponsToJSON(player)
  142.     local weaponSlots = 12
  143.     local weaponsTable = {}
  144.     for slot=1, weaponSlots do
  145.         local weapon = getPedWeapon( source, slot )
  146.         local ammo = getPedTotalAmmo( source, slot )
  147.         if (weapon > 0 and ammo > 0) then
  148.             weaponsTable[weapon] = ammo
  149.         end
  150.     end
  151.     return toJSON(weaponsTable)
  152. end
  153.  
  154. addEventHandler("onPlayerWasted", root,
  155.     function()
  156.         local weapons = convertWeaponsToJSON(source)
  157.         setElementData(source,"tempWeapons",weapons)
  158.         takeAllWeapons ( source )
  159.     end
  160. )
  161.  
  162. function giveWeaponsFromJSON(player, weapons)
  163.     if (weapons and weapons ~= "") then
  164.         for weapon, ammo in pairs(fromJSON(weapons)) do
  165.             if (weapon and ammo) then
  166.                 giveWeapon(player, tonumber(weapon), tonumber(ammo))
  167.             end
  168.         end
  169.     end
  170. end
  171. addEventHandler("onPlayerSpawn", root,
  172.     function ()
  173.         local weapons = getElementData(source,"tempWeapons")
  174.         if (weapons) then
  175.             giveWeaponsFromJSON(source, weapons)
  176.             removeElementData ( source, "tempWeapons" )
  177.         end
  178.     end
  179. )
  180.  
  181. function saveWeaponStats(player)
  182.     if (not player or not isElement(player)) then return end
  183.     local account = getPlayerAccount(player)
  184.     if (account and not isGuestAccount(account)) then
  185.         local stats = ""
  186.         for stat=69, 81 do
  187.             local value = getPedStat(player, stat)
  188.             stats = stats ..",".. stat ..";".. value
  189.         end
  190.         setAccountData(account, "weaponStats", stats)
  191.     end
  192. end
  193. addEventHandler("onPlayerQuit",root,function () saveWeaponStats(source) end)
  194.  
  195. function loadWeaponStats(player)
  196.     if (not player or not isElement(player)) then return end
  197.     local account = getPlayerAccount(player)
  198.     if (account and not isGuestAccount(account)) then
  199.         local statsData = getAccountData(account,"weaponStats")
  200.         local stats = split(statsData, ",")
  201.         for k, v in ipairs(stats) do
  202.             local stat = split(v, ";")
  203.             setPedStat(player, tonumber(stat[1]), tonumber(stat[2]))
  204.         end
  205.     end
  206. end
  207. addEventHandler("onPlayerLogin",root,function () loadWeaponStats(source) end)
  208.  
  209. function something()
  210. if (not getPlayerTeam(source)) then return end
  211. local r, g, b = getTeamColor(getPlayerTeam(source))
  212. setPlayerNametagColor(source, r, g, b)
  213. end
  214. addEventHandler("onPlayerLogin", root, something)
  215. addEventHandler("onPlayerJoin", root, something)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement