Advertisement
Guest User

Untitled

a guest
May 22nd, 2018
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 62.94 KB | None | 0 0
  1. local mysql = exports.mysql
  2. local scriptVer = exports.global:getScriptVersion()
  3. local salt = "vgrpkeyscotland"
  4.  
  5. -- Gay beta code
  6. local hasBeta = { }
  7.  
  8. function UserAccountLoggedOut()
  9.     exports['anticheat-system']:changeProtectedElementDataEx(client, "gameaccountloggedin", 0, true)
  10. end
  11. addEvent("account:loggedout", true)
  12. addEventHandler("account:loggedout", getRootElement(), UserAccountLoggedOut)
  13.  
  14. function UserLoggedOut()
  15.     exports['anticheat-system']:changeProtectedElementDataEx(source, "loggedin", 0, true)
  16. end
  17. addEvent("player:loggedout", true)
  18. addEventHandler("player:loggedout", getRootElement(), UserLoggedOut)
  19.  
  20. function UserLoggedOutAll()
  21.     exports['anticheat-system']:changeProtectedElementDataEx(client, "loggedin", 0, true)
  22.     exports['anticheat-system']:changeProtectedElementDataEx(client, "gameaccountloggedin", 0, true)
  23. end
  24. addEvent("accountplayer:loggedout", true)
  25. addEventHandler("accountplayer:loggedout", getRootElement(), UserLoggedOutAll)
  26.  
  27. function informServerHasBeta()
  28.     hasBeta[client] = true
  29. end
  30. addEvent("hasBeta", true)
  31. addEventHandler("hasBeta", getRootElement(), informServerHasBeta)
  32.  
  33. function beta(thePlayer)
  34.     if ( exports.global:isPlayerAdmin(thePlayer)) then
  35.         local count = 0
  36.         for k,v in pairs(hasBeta) do
  37.             count = count + 1
  38.         end
  39.         exports.global:sendMessageToAdmins("> " .. count .. " people are running Sapphire Beta.")
  40.     end
  41. end
  42. addCommandHandler("beta", beta)
  43.  
  44. function playerQuit()
  45.     hasBeta[source] = nil
  46. end
  47. addEventHandler("onPlayerQuit", getRootElement(), playerQuit)
  48.  
  49. function acceptBeta()
  50.     redirectPlayer(client, "server.mta.vg", getServerPort(), getServerPassword())
  51. end
  52. addEvent("acceptBeta", true)
  53. addEventHandler("acceptBeta", getRootElement(), acceptBeta)
  54. -- end gay beta code
  55.  
  56. function sendSalt()
  57.     triggerClientEvent(client, "sendSalt", source, salt, getPlayerIP(source), getElementData(getRootElement(), "account:motd"))
  58. end
  59. addEvent("getSalt", true)
  60. addEventHandler("getSalt", getRootElement(), sendSalt)
  61.  
  62. function encrypt(str)
  63.     local hash = 0
  64.     for i = 1, string.len(str) do
  65.         hash = hash + tonumber(string.byte(str, i, i))
  66.     end
  67.    
  68.     if (hash==0) then
  69.         return 0
  70.     end
  71.     hash = hash + 100000000
  72.     return hash
  73. end
  74.  
  75. function encryptSerial(str)
  76.     local hash = md5(str)
  77.     local rhash = "VGRP" .. string.sub(hash, 17, 20) .. string.sub(hash, 1, 2) .. string.sub(hash, 25, 26) .. string.sub(hash, 21, 2)
  78.     return rhash
  79. end
  80.  
  81. function resourceStart(resource)
  82.     setGameType(scriptVer)
  83.     setMapName("Zero City")
  84.     setRuleValue("Script Version", tostring(scriptVer))
  85.     setRuleValue("Author", "Zero Team")
  86.    
  87.     local motdresult = mysql:query_fetch_assoc("SELECT value FROM settings WHERE name='motd' LIMIT 1")
  88.     exports['anticheat-system']:changeProtectedElementDataEx(getRootElement(), "account:motd", motdresult["value" ], false )
  89.     local amotdresult = mysql:query_fetch_assoc("SELECT value FROM settings WHERE name='amotd' LIMIT 1")
  90.     exports['anticheat-system']:changeProtectedElementDataEx(getRootElement(), "account:amotd", amotdresult["value" ], false )
  91.  
  92.     for key, value in ipairs(exports.pool:getPoolElementsByType("player")) do
  93.         triggerEvent("playerJoinResourceStart", value, resource)
  94.     end
  95. end
  96. addEventHandler("onResourceStart", getResourceRootElement(getThisResource()), resourceStart)
  97.    
  98. function onJoin()
  99.     -- Set the user as not logged in, so they can't see chat or use commands
  100.     exports['anticheat-system']:changeProtectedElementDataEx(source, "loggedin", 0)
  101.     exports['anticheat-system']:changeProtectedElementDataEx(source, "gameaccountloggedin", 0, false)
  102.     exports['anticheat-system']:changeProtectedElementDataEx(source, "gameaccountusername", "")
  103.     exports['anticheat-system']:changeProtectedElementDataEx(source, "gameaccountid", "")
  104.     exports['anticheat-system']:changeProtectedElementDataEx(source, "dbid", false)
  105.     exports['anticheat-system']:changeProtectedElementDataEx(source, "adminlevel", 0)
  106.     exports['anticheat-system']:changeProtectedElementDataEx(source, "hiddenadmin", 0)
  107.     exports['anticheat-system']:changeProtectedElementDataEx(source, "globalooc", 1, false)
  108.     exports['anticheat-system']:changeProtectedElementDataEx(source, "muted", 0)
  109.     exports['anticheat-system']:changeProtectedElementDataEx(source, "loginattempts", 0, false)
  110.     exports['anticheat-system']:changeProtectedElementDataEx(source, "timeinserver", 0, false)
  111.     setElementDimension(source, 9999)
  112.     setElementInterior(source, 0)
  113.     clearChatBox(source)
  114.     exports.global:updateNametagColor(source)
  115. end
  116. addEventHandler("onPlayerJoin", getRootElement(), onJoin)
  117. addEvent("playerJoinResourceStart", false)
  118. addEventHandler("playerJoinResourceStart", getRootElement(), onJoin)
  119.  
  120. addEvent("restoreJob", false)
  121. function spawnCharacter(charname, version)
  122.     exports.global:takeAllWeapons(client)
  123.     exports.global:takeAllWeapons(source)
  124.     takeAllWeapons(source)
  125.     takeAllWeapons(client)
  126.     source = client
  127.    
  128.     local id = getElementData(client, "gameaccountid")
  129.     charname = string.gsub(tostring(charname), " ", "_")
  130.    
  131.     local safecharname = mysql:escape_string(charname)
  132.    
  133.     local data = mysql:query_fetch_assoc("SELECT * FROM characters WHERE charactername='" .. safecharname .. "' AND account='" .. mysql:escape_string(id) .. "' AND cked = 0")
  134.    
  135.     if (data) then
  136.         local id = tonumber(data["id"])
  137.         local currentid = getElementData(source, "dbid")
  138.         if hasBeta[source] then
  139.             if id == currentid then
  140.                 return
  141.             elseif currentid then
  142.                 triggerEvent("savePlayer", source, "Change Character", source)
  143.             end
  144.         end
  145.        
  146.         for key, value in ipairs(getElementsByType("player")) do
  147.             if ( getElementData(value, "loggedin") == 1 and value ~= source and hasBeta[value] ) then
  148.                 triggerClientEvent(value, "onPlayerCharacterChange", source, charname)
  149.             end
  150.         end
  151.        
  152.         local x = tonumber(data["x"])
  153.         local y = tonumber(data["y"])
  154.         local z = tonumber(data["z"])
  155.        
  156.         local rot = tonumber(data["rotation"])
  157.         local interior = tonumber(data["interior_id"])
  158.         local dimension = tonumber(data["dimension_id"])
  159.         local health = tonumber(data["health"])
  160.         local armor = tonumber(data["armor"])
  161.         local skin = tonumber(data["skin"])
  162.         setPedSkin(source, skin)
  163.        
  164.         local money = tonumber(data["money"])
  165.         local factionID = tonumber(data["faction_id"])
  166.         local cuffed = tonumber(data["cuffed"])
  167.         local radiochannel = tonumber(data["radiochannel"])
  168.         local masked = tonumber(data["masked"])
  169.         local duty = tonumber(data["duty"])
  170.         local cellnumber = tonumber(data["cellnumber"])
  171.         local fightstyle = tonumber(data["fightstyle"])
  172.         local pdjail = tonumber(data["pdjail"])
  173.         local pdjail_time = tonumber(data["pdjail_time"])
  174.         local pdjail_station = tonumber(data["pdjail_station"])
  175.         local job = tonumber(data["job"])
  176.         local casualskin = tonumber(data["casualskin"])
  177.         local weapons = tostring(data["weapons"])
  178.         local ammo = tostring(data["ammo"])
  179.         local carlicense = tonumber(data["car_license"])
  180.         local gunlicense = tonumber(data["gun_license"])
  181.         local bankmoney = tonumber(data["bankmoney"])
  182.         local fingerprint = tostring(data["fingerprint"])
  183.         local tag = tonumber(data["tag"])
  184.         local hoursplayed = tonumber(data["hoursplayed"])
  185.         local timeinserver = tonumber(data["timeinserver"])
  186.         local restrainedobj = tonumber(data["restrainedobj"])
  187.         local restrainedby = tonumber(data["restrainedby"])
  188.         local factionrank = tonumber(data["faction_rank"])
  189.         local dutyskin = tonumber(data["dutyskin"])
  190.         local phoneoff = tonumber(data["phoneoff"])
  191.         local blindfold = tonumber(data["blindfold"])
  192.         local gender = tonumber(data["gender"])
  193.         local cellphonesecret = tonumber(data["cellphonesecret"])
  194.         local photos = tonumber(data["photos"])
  195.        
  196.         local age = data["age"]
  197.         local race = tonumber(data["skincolor"])
  198.         local weight = data["weight"]
  199.         local height = data["height"]
  200.         local desc = data["description"]
  201.         local maxvehicles = tonumber(data["maxvehicles"])
  202.         local factionleader = tonumber(data["faction_leader"])
  203.         local d_addiction = tostring(data["d_addiction"])
  204.        
  205.         exports['anticheat-system']:changeProtectedElementDataEx(source, "chardescription", desc)
  206.         exports['anticheat-system']:changeProtectedElementDataEx(source, "age", age)
  207.         exports['anticheat-system']:changeProtectedElementDataEx(source, "weight", weight)
  208.         exports['anticheat-system']:changeProtectedElementDataEx(source, "height", height)
  209.         exports['anticheat-system']:changeProtectedElementDataEx(source, "race", race)
  210.         exports['anticheat-system']:changeProtectedElementDataEx(source, "maxvehicles", maxvehicles)
  211.        
  212.         -- LANGUAGES
  213.         local lang1 = tonumber(data["lang1"])
  214.         local lang1skill = tonumber(data["lang1skill"])
  215.         local lang2 = tonumber(data["lang2"])
  216.         local lang2skill = tonumber(data["lang2skill"])
  217.         local lang3 = tonumber(data["lang3"])
  218.         local lang3skill = tonumber(data["lang3skill"])
  219.         local currentLanguage = tonumber(data["currlang"])
  220.         exports['anticheat-system']:changeProtectedElementDataEx(source, "languages.current", currentLanguage, false)
  221.                
  222.         if lang1 == 0 then
  223.             lang1skill = 0
  224.         end
  225.        
  226.         if lang2 == 0 then
  227.             lang2skill = 0
  228.         end
  229.        
  230.         if lang3 == 0 then
  231.             lang3skill = 0
  232.         end
  233.        
  234.         exports['anticheat-system']:changeProtectedElementDataEx(source, "languages.lang1", lang1, false)
  235.         exports['anticheat-system']:changeProtectedElementDataEx(source, "languages.lang1skill", lang1skill, false)
  236.        
  237.         exports['anticheat-system']:changeProtectedElementDataEx(source, "languages.lang2", lang2, false)
  238.         exports['anticheat-system']:changeProtectedElementDataEx(source, "languages.lang2skill", lang2skill, false)
  239.        
  240.         exports['anticheat-system']:changeProtectedElementDataEx(source, "languages.lang3", lang3, false)
  241.         exports['anticheat-system']:changeProtectedElementDataEx(source, "languages.lang3skill", lang3skill, false)
  242.         -- END OF LANGUAGES
  243.        
  244.         exports['anticheat-system']:changeProtectedElementDataEx(source, "timeinserver", timeinserver, false)
  245.        
  246.         exports['anticheat-system']:changeProtectedElementDataEx(source, "dbid", tonumber(id))
  247.         exports['item-system']:loadItems( source, true )
  248.        
  249.         exports['anticheat-system']:changeProtectedElementDataEx(source, "loggedin", 1)
  250.        
  251.         -- Check his name isn't in use by a squatter
  252.         local playerWithNick = getPlayerFromName(tostring(charname))
  253.         if isElement(playerWithNick) and (playerWithNick~=source) then
  254.             kickPlayer(playerWithNick, getRootElement(), "Duplicate Session.")
  255.         end
  256.        
  257.         -- casual skin
  258.         exports['anticheat-system']:changeProtectedElementDataEx(source, "casualskin", casualskin, false)
  259.        
  260.         -- bleeding
  261.         exports['anticheat-system']:changeProtectedElementDataEx(source, "bleeding", 0, false)
  262.        
  263.         -- Set their name to the characters
  264.         exports['anticheat-system']:changeProtectedElementDataEx(source, "legitnamechange", 1)
  265.         setPlayerName(source, tostring(charname))
  266.         local pid = getElementData(source, "playerid")
  267.         local fixedName = string.gsub(tostring(charname), "_", " ")
  268.  
  269.         setPlayerNametagText(source, tostring(fixedName))
  270.         exports['anticheat-system']:changeProtectedElementDataEx(source, "legitnamechange", 0)
  271.        
  272.         -- If their an admin change their nametag colour
  273.         local adminlevel = getElementData(source, "adminlevel")
  274.         local hiddenAdmin = getElementData(source, "hiddenadmin")
  275.         local adminduty = getElementData(source, "adminduty")
  276.         local muted = getElementData(source, "muted")
  277.         local donator = getElementData(source, "donator")
  278.        
  279.         -- remove all custom badges
  280.         exports['anticheat-system']:changeProtectedElementDataEx(source, "PDbadge")
  281.         exports['anticheat-system']:changeProtectedElementDataEx(source, "ESbadge")
  282.         exports['anticheat-system']:changeProtectedElementDataEx(source, "GOVbadge")
  283.         exports['anticheat-system']:changeProtectedElementDataEx(source, "SANbadge")
  284.        
  285.         exports.global:updateNametagColor(source)
  286.         setPlayerNametagShowing(source, false)
  287.        
  288.         -- Server message
  289.         clearChatBox(source)
  290.         outputChatBox("* " .. charname .. " karaktere sikeresen betöltve.", source, 0, 255, 0)
  291.  
  292.         outputChatBox("(( Segítségre van szükséged? Használd a '/helpme' parancsot! ))", source, 255, 194, 14)
  293.         outputChatBox("(( Ha itt se találtad meg a választ, használd az interaktív menünket -> /? ))", source, 255, 194, 14)
  294.         triggerClientEvent (source, "LoginZeneStop")
  295.  
  296.         setPedGravity ( source,0.008 )
  297.         setElementData(source, "superman:flying", false)
  298.         setPedAnimation(source, false)
  299.         setElementVelocity(source, 0, 0, 0)
  300.        
  301.         -- freeze the player, will be unfrozen client-side when on ground/after 2 secs
  302.         triggerClientEvent(source, "usedElevator", source)
  303.         setElementFrozen(source, false)
  304.        
  305.         -- Load the character info
  306.         spawnPlayer(source, x, y, z, rot, skin)
  307.         setElementHealth(source, health)
  308.         setPedArmor(source, armor)
  309.        
  310.        
  311.         setElementDimension(source, dimension)
  312.         setElementInterior(source, interior, x, y, z)
  313.         setCameraInterior(source, interior)
  314.        
  315. --      local motd = getElementData(getRootElement(), "account:motd")
  316. --      outputChatBox("MOTD: " .. motd, source, 255, 255, 0)
  317.        
  318. --      if ((getElementData(source, "adminlevel") or 0) > 0) then
  319.     --      local amotd = getElementData(getRootElement(), "account:amotd")
  320.         --  outputChatBox("Admin MOTD: " .. amotd, source, 135, 206, 250)
  321.         --end
  322.        
  323.         local timer = getElementData(source, "pd.jailtimer")
  324.         if isTimer(timer) then
  325.             killTimer(timer)
  326.         end
  327.        
  328.         exports['anticheat-system']:changeProtectedElementDataEx(source, "pd.jailserved")
  329.         exports['anticheat-system']:changeProtectedElementDataEx(source, "pd.jailtime")
  330.         exports['anticheat-system']:changeProtectedElementDataEx(source, "pd.jailtimer")
  331.         exports['anticheat-system']:changeProtectedElementDataEx(source, "pd.jailstation")
  332.        
  333.         -- ADMIN JAIL
  334.         local jailed = getElementData(source, "adminjailed")
  335.         local jailed_time = getElementData(source, "jailtime")
  336.         local jailed_by = getElementData(source, "jailadmin")
  337.         local jailed_reason = getElementData(source, "jailreason")
  338.        
  339.         if jailed then
  340.             outputChatBox("You still have " .. jailed_time .. " minute(s) to serve of your admin jail sentance.", source, 255, 0, 0)
  341.             outputChatBox(" ", source)
  342.             outputChatBox("You were jailed by: " .. jailed_by .. ".", source, 255, 0, 0)
  343.             outputChatBox("Reason: " .. jailed_reason, source, 255, 0, 0)
  344.                
  345.             local incVal = getElementData(source, "playerid")
  346.                
  347.             setElementDimension(source, 65400+incVal)
  348.             setElementInterior(source, 6)
  349.             setCameraInterior(source, 6)
  350.             setElementPosition(source, 263.821807, 77.848365, 1001.0390625)
  351.             setPedRotation(source, 267.438446)
  352.            
  353.             if jailed_time ~= 999 then
  354.                 local theTimer = setTimer(timerUnjailPlayer, 60000, 1, source)
  355.                 exports['anticheat-system']:changeProtectedElementDataEx(source, "jailtime", jailed_time, false)
  356.                 exports['anticheat-system']:changeProtectedElementDataEx(source, "jailtimer", theTimer)
  357.             else
  358.                 exports['anticheat-system']:changeProtectedElementDataEx(source, "jailtime", "Unlimited", false)
  359.                 exports['anticheat-system']:changeProtectedElementDataEx(source, "jailtimer", true, false)
  360.             end
  361.             exports['anticheat-system']:changeProtectedElementDataEx(source, "jailserved", 0, false)
  362.             exports['anticheat-system']:changeProtectedElementDataEx(source, "adminjailed", true)
  363.             exports['anticheat-system']:changeProtectedElementDataEx(source, "jailreason", jailed_reason, false)
  364.             exports['anticheat-system']:changeProtectedElementDataEx(source, "jailadmin", jailed_by, false)
  365.            
  366.             setElementInterior(source, 6)
  367.             setCameraInterior(source, 6)
  368.         elseif pdjail == 1 then -- PD JAIL
  369.             outputChatBox("You still have " .. pdjail_time .. " minute(s) to serve of your state jail sentance.", source, 255, 0, 0)
  370.            
  371.             local theTimer = setTimer(timerPDUnjailPlayer, 60000, 1, source)
  372.             exports['anticheat-system']:changeProtectedElementDataEx(source, "pd.jailserved", 0, false)
  373.             exports['anticheat-system']:changeProtectedElementDataEx(source, "pd.jailtime", pdjail_time, false)
  374.             exports['anticheat-system']:changeProtectedElementDataEx(source, "pd.jailtimer", theTimer, false)
  375.             exports['anticheat-system']:changeProtectedElementDataEx(source, "pd.jailstation", pdjail_station, false)
  376.         end
  377.        
  378.         -- FACTIONS
  379.         local factionName = nil
  380.         if (factionID~=-1) then
  381.             local fresult = mysql:query("SELECT name FROM factions WHERE id='" .. mysql:escape_string(factionID) .. "'")
  382.             if (mysql:num_rows(fresult)>0) then
  383.                 local row = mysql:fetch_assoc(fresult)
  384.                 factionName = row["name"]
  385.             else
  386.                 factionName = "Citizen"
  387.                 factionID = -1
  388.                 outputChatBox("Your faction has been deleted, and you have been set factionless.", source, 255, 0, 0)
  389.                 mysql:query_free("UPDATE characters SET faction_id='-1', faction_rank='1' WHERE id='" .. mysql:escape_string(id) .. "' LIMIT 1")
  390.             end
  391.            
  392.             if (fresult) then
  393.                 mysql:free_result(fresult)
  394.             end
  395.         else
  396.             factionName = "Citizen"
  397.         end
  398.        
  399.         local theTeam = getTeamFromName(tostring(factionName))
  400.         setPlayerTeam(source, theTeam)
  401.         exports['anticheat-system']:changeProtectedElementDataEx(source, "factionrank", factionrank)
  402.         exports['anticheat-system']:changeProtectedElementDataEx(source, "factionleader", factionleader, false)
  403.        
  404.         if factionID == 1 then
  405.             exports.global:givePlayerAchievement(source, 2)
  406.         elseif factionID == 2 then
  407.             exports.global:givePlayerAchievement(source, 5)
  408.         elseif factionID == 3 then
  409.             exports.global:givePlayerAchievement(source, 6)
  410.         end
  411.         -- END FACTIONS
  412.        
  413.         -- number of friends etc
  414.         local playercount = getPlayerCount()
  415.         local maxplayers = getMaxPlayers()
  416.         local percent = math.ceil((playercount/maxplayers)*100)
  417.        
  418.         local friends = mysql:query("SELECT friend FROM friends WHERE id = " .. mysql:escape_string(getElementData( source, "gameaccountid" )) )
  419.         if friends then
  420.             local ids = {}
  421.             while true do
  422.                 local row = mysql:fetch_assoc(friends)
  423.                 if not row then break end
  424.                 ids[ tonumber( row["friend"] ) ] = true
  425.             end
  426.            
  427.             exports['anticheat-system']:changeProtectedElementDataEx(source, "friends", ids, false)
  428.         end
  429.         mysql:free_result( friends )
  430.  
  431.         -- LAST LOGIN
  432.         mysql:query_free("UPDATE characters SET lastlogin=NOW() WHERE id='" .. mysql:escape_string(id) .. "'")
  433.            
  434.         -- Player is cuffed
  435.         if (cuffed==1) then
  436.             toggleControl(source, "sprint", false)
  437.             toggleControl(source, "fire", false)
  438.             toggleControl(source, "jump", false)
  439.             toggleControl(source, "next_weapon", false)
  440.             toggleControl(source, "previous_weapon", false)
  441.             toggleControl(source, "accelerate", false)
  442.             toggleControl(source, "brake_reverse", false)
  443.         end
  444.            
  445.         exports['anticheat-system']:changeProtectedElementDataEx(source, "adminlevel", tonumber(adminlevel))
  446.         exports['anticheat-system']:changeProtectedElementDataEx(source, "loggedin", 1)
  447.         exports['anticheat-system']:changeProtectedElementDataEx(source, "businessprofit", 0, false)
  448.         exports['anticheat-system']:changeProtectedElementDataEx(source, "hiddenadmin", tonumber(hiddenAdmin))
  449.         exports['anticheat-system']:changeProtectedElementDataEx(source, "legitnamechange", 0)
  450.         exports['anticheat-system']:changeProtectedElementDataEx(source, "muted", tonumber(muted))
  451.         exports['anticheat-system']:changeProtectedElementDataEx(source, "hoursplayed", hoursplayed)
  452.         exports.global:setMoney(source, money)
  453.         exports.global:checkMoneyHacks(source)
  454.        
  455.         exports['anticheat-system']:changeProtectedElementDataEx(source, "faction", factionID)
  456.         exports['anticheat-system']:changeProtectedElementDataEx(source, "factionMenu", 0)
  457.         exports['anticheat-system']:changeProtectedElementDataEx(source, "restrain", cuffed)
  458.         exports['anticheat-system']:changeProtectedElementDataEx(source, "tazed", 0, false)
  459.         exports['anticheat-system']:changeProtectedElementDataEx(source, "cellnumber", cellnumber, false)
  460.         exports['anticheat-system']:changeProtectedElementDataEx(source, "cellphone.secret", cellphonesecret, false)
  461.         exports['anticheat-system']:changeProtectedElementDataEx(source, "calling", nil, false)
  462.         exports['anticheat-system']:changeProtectedElementDataEx(source, "calltimer", nil, false)
  463.         exports['anticheat-system']:changeProtectedElementDataEx(source, "phonestate", 0, false)
  464.         exports['anticheat-system']:changeProtectedElementDataEx(source, "realinvehicle", 0, false)
  465.         exports['anticheat-system']:changeProtectedElementDataEx(source, "duty", duty)
  466.         exports['anticheat-system']:changeProtectedElementDataEx(source, "job", job)
  467.         exports['anticheat-system']:changeProtectedElementDataEx(source, "license.car", carlicense)
  468.         exports['anticheat-system']:changeProtectedElementDataEx(source, "license.gun", gunlicense)
  469.         exports['anticheat-system']:changeProtectedElementDataEx(source, "bankmoney", bankmoney)
  470.         exports['anticheat-system']:changeProtectedElementDataEx(source, "fingerprint", fingerprint, false)
  471.         exports['anticheat-system']:changeProtectedElementDataEx(source, "tag", tag)
  472.         exports['anticheat-system']:changeProtectedElementDataEx(source, "dutyskin", dutyskin, false)
  473.         exports['anticheat-system']:changeProtectedElementDataEx(source, "phoneoff", phoneoff, false)
  474.         exports['anticheat-system']:changeProtectedElementDataEx(source, "blindfold", blindfold, false)
  475.         exports['anticheat-system']:changeProtectedElementDataEx(source, "gender", gender)
  476.        
  477.         if (restrainedobj>0) then
  478.             exports['anticheat-system']:changeProtectedElementDataEx(source, "restrainedObj", restrainedobj, false)
  479.         end
  480.        
  481.         if (restrainedby>0) then
  482.             exports['anticheat-system']:changeProtectedElementDataEx(source, "restrainedBy", restrainedby, false)
  483.         end
  484.        
  485.         if job == 1 then
  486.             triggerClientEvent(source,"restoreTruckerJob",source)
  487.         end
  488.         triggerEvent("restoreJob", source)
  489.         triggerClientEvent(source, "updateCollectionValue", source, photos)
  490.        
  491.         -- Let's give them their weapons
  492.         --triggerEvent("syncWeapons", source, weapons, ammo)
  493.         if (tostring(weapons)~=tostring(mysql_null())) and (tostring(ammo)~=tostring(mysql_null())) then -- if player has weapons saved
  494.             for i=0, 12 do
  495.                 local tokenweapon = gettok(weapons, i+1, 59)
  496.                 local tokenammo = gettok(ammo, i+1, 59)
  497.                
  498.                 if (not tokenweapon) or (not tokenammo) then
  499.                     break
  500.                 else
  501.                     exports.global:giveWeapon(source, tonumber(tokenweapon), tonumber(tokenammo), false)
  502.                 end
  503.             end
  504.         end
  505.        
  506.         -- Let's stick some blips on the properties they own
  507.         local interiors = { }
  508.         for key, value in ipairs(getElementsByType("pickup", getResourceRootElement(getResourceFromName("interior-system")))) do
  509.             if isElement(value) and getElementDimension(value) == 0 then
  510.                 if getElementData(value, "name") then
  511.                     local inttype = getElementData(value, "inttype")
  512.                     local owner = tonumber(getElementData(value, "owner"))
  513.  
  514.                     if owner == tonumber(id) then
  515.                         local x, y = getElementPosition(value)
  516.                         if (inttype ~= 2) then
  517.                             if inttype == 3 then inttype = 0 end
  518.                             interiors[#interiors+1] = { inttype, x, y }
  519.                         end
  520.                     end
  521.                 end
  522.             end
  523.         end
  524.        
  525.         triggerClientEvent(source, "createBlipsFromTable", source, interiors)
  526.        
  527.         -- Fight style
  528.         setPedFightingStyle(source, tonumber(fightstyle))
  529.        
  530.         -- Achievement
  531.         if not (exports.global:doesPlayerHaveAchievement(source, 38)) then
  532.             exports.global:givePlayerAchievement(source, 38) -- Welcome to Los Santos
  533.             triggerClientEvent(source, "showCityGuide", source)
  534.         end
  535.        
  536.         -- Weapon stats
  537.         setPedStat(source, 70, 999)
  538.         setPedStat(source, 71, 999)
  539.         setPedStat(source, 72, 999)
  540.         setPedStat(source, 74, 999)
  541.         setPedStat(source, 76, 999)
  542.         setPedStat(source, 77, 999)
  543.         setPedStat(source, 78, 999)
  544.         setPedStat(source, 79, 999)
  545.        
  546.         toggleAllControls(source, true, true, true)
  547.         setElementFrozen(source, false)
  548.        
  549.         -- blindfolds
  550.         if (blindfold==1) then
  551.             exports['anticheat-system']:changeProtectedElementDataEx(source, "blindfold", 1)
  552.             outputChatBox("Your character is blindfolded. If this was an OOC action, please contact an administrator via F2.", source, 255, 194, 15)
  553.             --fadeCamera(player, false)
  554.         else
  555.             fadeCamera(source, true, 2)
  556.             setTimer(blindfoldFix, 5000, 1, source)
  557.         end
  558.        
  559.         -- impounded cars
  560.         if exports.global:hasItem(source, 2) then -- phone
  561.             local impounded = mysql:query_fetch_assoc("SELECT COUNT(*) as 'numbr'  FROM `vehicles` WHERE `owner` = " .. mysql:escape_string(id) .. " and `Impounded` > 0")
  562.             if impounded then
  563.                 local amount = tonumber(impounded["numbr"]) or 0
  564.                 if amount > 0 then
  565.                     outputChatBox("((Los Santos Towing & Recovery)) #999 [SMS]: " .. amount .. " of your vehicles are impounded. Head over to the Impound to release them.", source, 120, 255, 80)
  566.                 end
  567.             end
  568.         end
  569.        
  570.         -- drug addictions
  571.         if (tostring(d_addiction)~=tostring(mysql_null())) then
  572.             local getdrug = split(d_addiction, string.byte(';'))
  573.             for k, v in ipairs(getdrug) do
  574.                 exports['anticheat-system']:changeProtectedElementDataEx(source, "drug." ..k, tonumber(v))
  575.             end
  576.         end
  577.        
  578.         --if (version) and (version < getVersion().mta) then
  579.         --  outputChatBox("You are using an Old Version of MTA! (V" .. version .. ").", source, 255, 0, 0)
  580.         --  outputChatBox("We recommend you upgrade to V" .. getVersion().mta .. " to ensure full script compatability and improve your experience.", source, 255, 0, 0)
  581.         --end
  582.        
  583.         if ( hasBeta[source] ) then
  584.             outputChatBox("You can visit the Home Menu again by pressing Home.", source, 255, 194, 15)
  585.         end
  586.        
  587.         triggerEvent("onCharacterLogin", source, charname, factionID)
  588.        
  589.  
  590.         triggerClientEvent(source, "updateHudClock", source)
  591.     else
  592.         outputDebugString( "Spawning Char failed: ")
  593.     end
  594. end
  595. addEvent("onCharacterLogin", false)
  596. addEvent("spawnCharacter", true)
  597. addEventHandler("spawnCharacter", getRootElement(), spawnCharacter)
  598.  
  599. function blindfoldFix(player)
  600.     fadeCamera(player, true, 2)
  601. end
  602.  
  603. function timerUnjailPlayer(jailedPlayer)
  604.     if(isElement(jailedPlayer)) then
  605.         local timeServed = getElementData(jailedPlayer, "jailserved")
  606.         local timeLeft = getElementData(jailedPlayer, "jailtime")
  607.         local accountID = getElementData(jailedPlayer, "gameaccountid")
  608.        
  609.         if (timeServed) and (timeLeft) then
  610.             exports['anticheat-system']:changeProtectedElementDataEx(jailedPlayer, "jailserved", timeServed+1)
  611.             local timeLeft = timeLeft - 1
  612.             exports['anticheat-system']:changeProtectedElementDataEx(jailedPlayer, "jailtime", timeLeft)
  613.             local result
  614.             if (timeLeft<=0) then
  615.                 mysql:query_free("UPDATE accounts SET adminjail_time='0', adminjail='0' WHERE id='" .. mysql:escape_string(accountID) .. "'")
  616.                 exports['anticheat-system']:changeProtectedElementDataEx(jailedPlayer, "jailtimer")
  617.                 exports['anticheat-system']:changeProtectedElementDataEx(jailedPlayer, "adminjailed")
  618.                 exports['anticheat-system']:changeProtectedElementDataEx(jailedPlayer, "jailreason")
  619.                 exports['anticheat-system']:changeProtectedElementDataEx(jailedPlayer, "jailtime")
  620.                 exports['anticheat-system']:changeProtectedElementDataEx(jailedPlayer, "jailadmin")
  621.                 setElementPosition(jailedPlayer, 1519.7177734375, -1697.8154296875, 13.546875)
  622.                 setPedRotation(jailedPlayer, 269.92446899414)
  623.                 setElementDimension(jailedPlayer, 0)
  624.                 setElementInterior(jailedPlayer, 0)
  625.                 setCameraInterior(jailedPlayer, 0)
  626.                 toggleControl(jailedPlayer,'next_weapon',true)
  627.                 toggleControl(jailedPlayer,'previous_weapon',true)
  628.                 toggleControl(jailedPlayer,'fire',true)
  629.                 toggleControl(jailedPlayer,'aim_weapon',true)
  630.                
  631.                 local theTimer = getElementData(jailedPlayer, "jailtimer")
  632.                 killTimer(theTimer)
  633.                
  634.                 outputChatBox("Your time has been served, Behave next time!", jailedPlayer, 0, 255, 0)
  635.                 exports.global:sendMessageToAdmins("AdmJail: " .. getPlayerName(jailedPlayer) .. " has served his jail time.")
  636.             else
  637.                 mysql:query_free("UPDATE accounts SET adminjail_time='" .. mysql:escape_string(timeLeft) .. "' WHERE id='" .. mysql:escape_string(accountID) .. "'")
  638.             end
  639.         else
  640.             if (isElement(jailedPlayer)) then
  641.                 local theTimer = getElementData(jailedPlayer, "jailtimer")
  642.            
  643.                 if (theTimer) then
  644.                     killTimer(theTimer)
  645.                 end
  646.             end
  647.         end
  648.     end
  649. end
  650.  
  651. function calculateAutoLoginHash(username)
  652.     local hash = md5(salt .. username .. math.random(1,1000000) .. salt .. "b" .. math.random(10,99) .."ring-fuckyoudaniels")
  653.     local hash2 = md5( math.random(1,1000000)..  math.random(1,1000000)..  math.random(1,1000000)..  math.random(1,1000000)..  math.random(1,1000000).. "vG")
  654.     local finalhash = hash .. hash2
  655.     mysql:query_free("UPDATE `accounts` SET `loginhash`='".. finalhash .."' WHERE `username`='".. mysql:escape_string(username) .."'")
  656.     return finalhash
  657. end
  658.  
  659. function loginPlayer(username, password, operatingsystem, hashPlease)
  660.     local autologin = false
  661.     local loginErrorCode = 1
  662.     if (string.len(password)~=64) then
  663.         password = md5(salt .. password)
  664.     else
  665.         autologin = true
  666.         loginErrorCode = 6
  667.     end
  668.  
  669.    
  670.     local safeusername = mysql:escape_string(username)
  671.     local safepassword = mysql:escape_string(password)
  672.    
  673.     local query
  674.     if (autologin) then
  675.          query = "SELECT * FROM `accounts` WHERE `username`='" .. safeusername .. "' AND `loginhash`='" .. safepassword .. "'"
  676.     else
  677.          query = "SELECT * FROM `accounts` WHERE `username`='" .. safeusername .. "' AND `password`='" .. safepassword .. "'"
  678.     end
  679.    
  680.     local result = mysql:query(query)
  681.     source = client
  682.     if (mysql:num_rows(result)>0) then
  683.         local data = mysql:fetch_assoc(result)
  684.         triggerEvent("onPlayerLogin", source, username, password)
  685.         for key, value in ipairs(getElementsByType("player")) do
  686.             if ( getElementData(value, "loggedin") == 1 and value ~= source and hasBeta[value] ) then
  687.                 triggerClientEvent(value, "onPlayerAccountLogin", source, username)
  688.             end
  689.         end
  690.        
  691.         local id = tonumber(data["id"])
  692.        
  693.         local newhash = calculateAutoLoginHash(safeusername) -- make the autologin hash expire
  694.         if (hashPlease) then -- send their new hash
  695.             triggerClientEvent(source, "account:onAutoLoginHashReceive", source, newhash)
  696.         end
  697.        
  698.         -- Check the account isn't already logged in
  699.         local found = false
  700.         for key, value in ipairs(exports.pool:getPoolElementsByType("player")) do
  701.             local accid = tonumber(getElementData(value, "gameaccountid"))
  702.             if (accid) then
  703.                 if (accid==id) and (value~=source) then
  704.                     found = true
  705.                     break
  706.                 end
  707.             end
  708.         end
  709.        
  710.         if not (found) then
  711.             outputChatBox("Adatok betöltése folyamatban...",source,255,0,0)
  712.             triggerClientEvent(source, "ToggleLoginGomb", source, false)
  713.             local admin = tonumber(data["admin"])
  714.             local hiddenadmin = tonumber(data["hiddenadmin"])
  715.             local adminduty = tonumber(data["adminduty"])
  716.             local donator = tonumber(data["donator"])
  717.             local adminjail = tonumber(data["adminjail"])
  718.             local adminjail_time = tonumber(data["adminjail_time"])
  719.             local adminjail_by = tostring(data["adminjail_by"])
  720.             local adminjail_reason = data["adminjail_reason"]
  721.             local banned = tonumber(data["banned"])
  722.             local banned_by = data["banned_by"]
  723.             local banned_reason = data["banned_reason"]
  724.             local muted = tonumber(data["muted"])
  725.             local donatorchat = tonumber(data["donatorchat"])
  726.             local globalooc = tonumber(data["globalooc"])
  727.             local blur = tonumber(data["blur"])
  728.             local adminreports = tonumber(data["adminreports"])
  729.             local pmblocked = tonumber(data["pmblocked"])
  730.             local adblocked = tonumber(data["adblocked"])
  731.             local newsblocked = tonumber(data["newsblocked"])
  732.             local warns = tonumber(data["warns"])
  733.             local chatbubbles = tonumber(data["chatbubbles"])
  734.             local appstate = tonumber(data["appstate"])
  735.             local liveusername = data["liveusername"]
  736.             local steamusername = data["steamusername"]
  737.            
  738.             if ( admin <= 0 and hasBeta[client] and not exports.global:isPlayerScripter( username ) and donator <= 0 ) then -- non admin with beta? ban
  739.                 exports.global:sendMessageToAdmins("[AdmWarn] " .. getPlayerName(client) .. " was banned for running a hacked Sapphire Beta.")
  740.                 local ban = banPlayer(client, true, false, false, getRootElement(), "Hacked Beta.", 0)
  741.                 mysql:query_free("UPDATE accounts SET banned='1', banned_reason='Hacked Beta.', banned_by='Script' WHERE id='" .. mysql:escape_string(id) .. "'")
  742.             end
  743.            
  744.             local country = tostring(exports.global:getPlayerCountry(source))
  745.             if username == "Daniels" then
  746.                 country = "SC"
  747.             end
  748.             exports['anticheat-system']:changeProtectedElementDataEx(source, "country", country)
  749.            
  750.             if tonumber(admin) == 0 then
  751.                 adminduty = 0
  752.                 hiddenadmin = 0
  753.             end
  754.            
  755.             if ( liveusername ~= mysql_null() and hasBeta[source] ) then
  756.                 callRemote("http://valhallagaming.net/mtaucp/mta/lookup_live.php", xboxReturnExisting, tostring(liveusername), source)
  757.             end
  758.            
  759.             if ( steamusername ~= mysql_null() and hasBeta[source] ) then
  760.                 callRemote("http://valhallagaming.net/mtaucp/mta/lookup_steam.php", steamReturnExisting, tostring(steamusername), source)
  761.             end
  762.            
  763.             if donator > 0 then -- check if they're a donator
  764.                 exports['anticheat-system']:changeProtectedElementDataEx(source, "pmblocked", pmblocked, false)
  765.                 exports['anticheat-system']:changeProtectedElementDataEx(source, "tognews", newsblocked, false)
  766.                 exports['anticheat-system']:changeProtectedElementDataEx(source, "disableAds", adblocked == 1, false)
  767.             else -- no donator, set default things
  768.                 exports['anticheat-system']:changeProtectedElementDataEx(source, "pmblocked", 0, false)
  769.                 exports['anticheat-system']:changeProtectedElementDataEx(source, "disableAds", false, false)
  770.                 exports['anticheat-system']:changeProtectedElementDataEx(source, "tognews", 0, false)
  771.             end
  772.        
  773.            
  774.             exports['anticheat-system']:changeProtectedElementDataEx(source, "donatorlevel", tonumber(donator))
  775.             exports['anticheat-system']:changeProtectedElementDataEx(source, "adminlevel", tonumber(admin))
  776.             exports['anticheat-system']:changeProtectedElementDataEx(source, "hiddenadmin", tonumber(hiddenadmin))
  777.             exports['anticheat-system']:changeProtectedElementDataEx(source, "donator", tonumber(donator))
  778.            
  779.             exports['anticheat-system']:changeProtectedElementDataEx(source, "blur", blur)
  780.             setPlayerBlurLevel(source, blur == 0 and 0 or 38)
  781.            
  782.             if (banned==1) then
  783.                 triggerClientEvent(source, "loginFail", source, 3)
  784.             else
  785.                 exports['anticheat-system']:changeProtectedElementDataEx(source, "gameaccountloggedin", 1, false)
  786.                 exports['anticheat-system']:changeProtectedElementDataEx(source, "gameaccountusername", username)
  787.                 exports['anticheat-system']:changeProtectedElementDataEx(source, "gameaccountid", tonumber(id))
  788.                 exports['anticheat-system']:changeProtectedElementDataEx(source, "adminduty", tonumber(adminduty))
  789.                 exports['anticheat-system']:changeProtectedElementDataEx(source, "adminjailed", adminjail == 1, false)
  790.                 exports['anticheat-system']:changeProtectedElementDataEx(source, "jailtime", tonumber(adminjail_time), false)
  791.                 exports['anticheat-system']:changeProtectedElementDataEx(source, "jailadmin", tostring(adminjail_by), false)
  792.                 exports['anticheat-system']:changeProtectedElementDataEx(source, "jailreason", tostring(adminjail_reason), false)
  793.                 exports['anticheat-system']:changeProtectedElementDataEx(source, "globalooc", tonumber(globalooc), false)
  794.                 exports['anticheat-system']:changeProtectedElementDataEx(source, "donatorchat", tonumber(donatorchat), false)
  795.                 exports['anticheat-system']:changeProtectedElementDataEx(source, "muted", tonumber(muted))
  796.                 exports['anticheat-system']:changeProtectedElementDataEx(source, "adminreports", adminreports, false)
  797.                 exports['anticheat-system']:changeProtectedElementDataEx(source, "warns", warns, false)
  798.                 exports['anticheat-system']:changeProtectedElementDataEx(source, "chatbubbles", chatbubbles, false)
  799.                
  800.                 triggerClientEvent(source, "hideUI", source)
  801.                 local playerid = getElementData(source, "playerid")
  802.  
  803.                 spawnPlayer(source, 258.43417358398, -41.489139556885, 1002.0234375, 268.19247436523, 0, 14, 65000+playerid)
  804.                 fadeCamera(source, true)
  805.                
  806.                 sendAccounts(source, id)
  807.  
  808.                 --setTimer(sendAccounts, 15000, 1, source, id)
  809.                
  810.                 -- Get login time & date
  811.                 local time = getRealTime()
  812.                 local days = time.monthday
  813.                 local months = (time.month+1)
  814.                 local years = (1900+time.year)
  815.                
  816.                 local yearday = time.yearday
  817.                 local logindate = days .. "/" .. months .. "/" .. years
  818.                
  819.                 local ip = getPlayerIP(source)
  820.                
  821.                 mysql:query("UPDATE accounts SET lastlogin=NOW(), ip='" .. mysql:escape_string(ip) .. "', country='" .. mysql:escape_string(country) .. "', mtaserial='" .. mysql:escape_string(getPlayerSerial(source)) .. "' WHERE id='" .. mysql:escape_string(id) .. "'")
  822.             end
  823.         else
  824.             triggerClientEvent(source, "loginFail", source, 2)
  825.         end
  826.     else
  827.         local attempts = tonumber(getElementData(source, "loginattempts"))
  828.         attempts = attempts + 1
  829.         exports['anticheat-system']:changeProtectedElementDataEx(source, "loginattempts", attempts, false)
  830.        
  831.         if (attempts>=3) then
  832.             kickPlayer(source, "Rendszer","Túl sok bejelentkezési próbálkozás")
  833.         else
  834.             triggerClientEvent(source, "loginFail", source, loginErrorCode)
  835.         end
  836.     end
  837.    
  838.     if (result) then
  839.         mysql:free_result(result)
  840.     end
  841. end
  842. addEvent("onPlayerLogin", false)
  843. addEvent("attemptLogin", true)
  844. addEventHandler("attemptLogin", getRootElement(), loginPlayer)
  845. function userregister(username, password, operatingsystem, hashPlease)
  846.     local safeusername = mysql:escape_string(username)
  847.     local safepassword = mysql:escape_string(password)
  848.  
  849.     local autologin = false
  850.     local loginErrorCode = 1
  851.     if (string.len(password)~=64) then
  852.         password = md5(salt .. password)
  853.     else
  854.         autologin = true
  855.         loginErrorCode = 6
  856.     end
  857.     local result = mysql:query("SELECT username FROM accounts WHERE username='" .. safeusername .. "'")
  858.     if (mysql:num_rows(result)>0) then -- Name is already taken
  859.         outputChatBox("Ez a név már regisztrálva van.",source,255,0,0)
  860.         return
  861.     end
  862.     outputChatBox("A felhasználó sikeresen regisztrálva! Most már bejelentkezhetsz.",source,0,255,0)
  863.     triggerClientEvent(source,"loginChange",source)
  864.     triggerClientEvent(source,"inforeg",source)
  865.    
  866.     local safeusername = mysql:escape_string(username)
  867.     local safepassword = mysql:escape_string(password)
  868.     local id = mysql:query_insert_free("INSERT INTO accounts SET username='" .. safeusername .. "', loginhash='" .. safepassword .. "',password='".. safepassword.."'")
  869.                
  870. end
  871. addEvent("attemptRegister", true)
  872. addEventHandler("attemptRegister", getRootElement(), userregister)
  873.  
  874. pendingResult = { }
  875. function displayRetrieveDetailsResult(result, player)
  876.     if (player) and (pendingResult[player] ~= nil) then
  877.         pendingResult[player] = nil
  878.         if ( result == 0 ) then
  879.             outputChatBox("Information on how to retrieve your username and password has been sent to your email address.", player, 0, 255, 0)
  880.         else
  881.             outputChatBox("This service is currently unavailable.", player, 255, 0, 0)
  882.         end
  883.     end
  884. end
  885.  
  886. function checkTimeout(player)
  887.     if ( pendingResult[player] ) then
  888.         pendingResult[player] = nil
  889.         outputChatBox("[TIMEOUT] This service is currently unavailable.", player, 255, 0, 0)
  890.     end
  891. end
  892.  
  893. function retrieveDetails(email)
  894.     local safeEmail = mysql:escape_string(tostring(email))
  895.    
  896.     local result = mysql:query("SELECT id FROM accounts WHERE email='" .. safeEmail .. "'")
  897.    
  898.     if (mysql:num_rows(result)>0) then
  899.         local row = mysql:fetch_assoc(result)
  900.         local id = tonumber(row["id"])
  901.         callRemote("http://www.valhallagaming.net/mtaucp/sendfpmail.php", displayRetrieveDetailsResult, id)
  902.         outputChatBox("Contacting account server... Please wait...", source, 255, 194, 15)
  903.        
  904.         pendingResult[source] = true
  905.         setTimer(checkTimeout, 10000, 1, source)
  906.     else
  907.         outputChatBox("Invalid Email.", source, 255, 0, 0)
  908.     end
  909.     mysql:free_result(result)
  910. end
  911. addEvent("retrieveDetails", true)
  912. addEventHandler("retrieveDetails", getRootElement(), retrieveDetails)
  913.  
  914. function sendAccounts(thePlayer, id, isChangeChar)
  915.     exports['anticheat-system']:changeProtectedElementDataEx(thePlayer,"loggedin",0)
  916.     exports.global:updateNametagColor(thePlayer)
  917.     exports.global:takeAllWeapons(thePlayer)
  918.     local accounts = { }
  919.  
  920.     local result = mysql:query("SELECT id, charactername, cked, lastarea, age, gender, faction_id, faction_rank, skin, DATEDIFF(NOW(), lastlogin) as llastlogin FROM characters WHERE account='" .. mysql:escape_string(id) .. "'  ORDER BY cked ASC, lastlogin DESC")
  921.     if (mysql:num_rows(result)>0) then
  922.         if (isChangeChar) then
  923.             triggerEvent("savePlayer", source, "Change Character", source)
  924.            
  925.         end
  926.        
  927.         local i = 1
  928.  
  929.         while true do
  930.             local row = mysql:fetch_assoc(result)
  931.             if not row then break end
  932.             accounts[i] = { }
  933.             accounts[i][1] = tonumber(row["id"])
  934.             accounts[i][2] = row["charactername"]
  935.            
  936.             if (tonumber(row["cked"]) or 0) > 0 then
  937.                 accounts[i][3] = 1
  938.             end
  939.            
  940.             accounts[i][4] = row["lastarea"]
  941.             accounts[i][5] = tonumber(row["age"])
  942.             accounts[i][6] = tonumber(row["gender"])
  943.            
  944.             local factionID = tonumber(row["faction_id"])
  945.             local factionRank = tonumber(row["faction_rank"])
  946.            
  947.             if (factionID<1) or not (factionID) then
  948.                 accounts[i][7] = nil
  949.                 accounts[i][8] = nil
  950.             else
  951.                 factionResult = mysql:query_fetch_assoc("SELECT name, rank_" .. mysql:escape_string(factionRank) .. " as rankname FROM factions WHERE id='" .. mysql:escape_string(tonumber(factionID)) .. "'")
  952.  
  953.                 if (factionResult) then
  954.                     accounts[i][7] = factionResult["name"]
  955.                     accounts[i][8] = factionResult["rankname"]
  956.                    
  957.                     if (string.len(accounts[i][7])>53) then
  958.                         accounts[i][7] = string.sub(accounts[i][7], 1, 32) .. "..."
  959.                     end
  960.                 else
  961.                     accounts[i][7] = nil
  962.                     accounts[i][8] = nil
  963.                 end
  964.             end
  965.             accounts[i][9] = tonumber(row["skin"])
  966.             accounts[i][10] = tonumber(row["llastlogin"])
  967.             i = i + 1
  968.         end
  969.        
  970.     end
  971.    
  972.     if (result) then
  973.         mysql:free_result(result)
  974.     end
  975.    
  976.     local playerid = getElementData(thePlayer, "playerid")
  977.  
  978.     if ( hasBeta[thePlayer] ) then
  979.         spawnPlayer(thePlayer, 1409.9384765625, -808.51953125, 91.859375, 172.96313476563, 0, 0, 65000+playerid)
  980.         toggleAllControls(source, false, true, true)
  981.         setElementFrozen(source, true)
  982.     else
  983.         local playerid = getElementData(thePlayer, "playerid")
  984.         spawnPlayer(thePlayer, 258.43417358398, -41.489139556885, 1002.0234375, 268.19247436523, 0, 14, 65000+playerid)
  985.     end
  986.    
  987.     local emailresult = mysql:query_fetch_assoc("SELECT email FROM accounts WHERE id = '" .. mysql:escape_string(id) .. "'")
  988.    
  989.     if ( emailresult) then
  990.         local hasEmail = emailresult["email"]
  991.        
  992.         if ( hasEmail == mysql_null() ) then
  993.             triggerClientEvent(thePlayer, "showCharacterSelection", thePlayer, accounts, false, true)
  994.         else
  995.             triggerClientEvent(thePlayer, "showCharacterSelection", thePlayer, accounts)
  996.         end
  997.     else
  998.         triggerClientEvent(thePlayer, "showCharacterSelection", thePlayer, accounts)
  999.     end
  1000.    
  1001.     if ( hasBeta[thePlayer] ) then
  1002.         requestAchievements(thePlayer)
  1003.     end
  1004. end
  1005. addEvent("sendAccounts", true)
  1006. addEventHandler("sendAccounts", getRootElement(), sendAccounts)
  1007.  
  1008. function storeEmail(email)
  1009.     local accountid = getElementData(client, "gameaccountid")
  1010.     local safeemail = mysql:escape_string(email)
  1011.     mysql:query_free("UPDATE accounts SET email = '" .. safeemail .. "' WHERE id = '" .. mysql:escape_string(accountid) .. "'")
  1012. end
  1013. addEvent("storeEmail", true)
  1014. addEventHandler("storeEmail", getRootElement(), storeEmail)
  1015.  
  1016. function requestFriends(player)
  1017.     local accid = getElementData(player, "gameaccountid")
  1018.     local result = mysql:query("SELECT f.friend as friend, a.username as username, a.friendsmessage as friendsmessage, a.country as country FROM friends f LEFT JOIN accounts a ON f.friend = a.id WHERE f.id = " .. mysql:escape_string(accid) .. " ORDER BY a.lastlogin DESC" )
  1019.     if result then
  1020.         local friends = { }
  1021.         while true do
  1022.             local row = mysql:fetch_assoc(result)
  1023.             if not row then break end
  1024.            
  1025.             local id = tonumber( row["friend"] )
  1026.             local account = row["username"]
  1027.            
  1028.             if account == mysql_null( ) then --
  1029.                 mysql:query_free("DELETE FROM friends WHERE id = " .. mysql:escape_string(id) .. " OR friend = " .. mysql:escape_string(id) )
  1030.             else
  1031.                 table.insert( friends, { id, account, row["friendsmessage"], row["country"] } )
  1032.             end
  1033.         end
  1034.        
  1035.         mysql:free_result( result )
  1036.        
  1037.         local friendsmessage = ""
  1038.         local result = mysql:query_fetch_assoc("SELECT friendsmessage FROM accounts WHERE id = " .. mysql:escape_string(accid) )
  1039.         if result then
  1040.             friendsmessage = result["friendsmessage"]
  1041.             if friendsmessage == mysql_null( ) then
  1042.                 friendsmessage = ""
  1043.             end
  1044.         else
  1045.             outputDebugString( "Friendmessage load failed: ")
  1046.         end
  1047.         triggerClientEvent( player, "returnFriends", player, friends, friendsmessage )
  1048.     else
  1049.         outputDebugString( "Friends load failed: " )
  1050.         outputChatBox("Error 600000 - Could not retrieve friends list.", player, 255, 0, 0)
  1051.     end
  1052.     requestAccount(player)
  1053. end
  1054.  
  1055. function requestAccount(player)
  1056.     local accid = getElementData(player, "gameaccountid")
  1057.     local result = mysql:query_fetch_assoc("SELECT mtausername FROM accounts WHERE id = " .. mysql:escape_string(tonumber(accid)))
  1058.    
  1059.     if ( result ) then
  1060.         local mtausername = result["mtausername"]
  1061.        
  1062.         if ( mtausername == mysql_null() ) then
  1063.             triggerClientEvent(player, "storeAccountInformation", player)
  1064.         else
  1065.             triggerClientEvent(player, "storeAccountInformation", player, tostring(mtausername))
  1066.         end
  1067.     else
  1068.         outputDebugString( "Account Information load failed: " )
  1069.         outputChatBox("Error 600001 - Could not retrieve account information.", source, 255, 0, 0)
  1070.     end
  1071. end
  1072.  
  1073. function requestAchievements(player)
  1074.     -- Get achievements
  1075.     local gameAccountID = getElementData(player, "gameaccountid")
  1076.     local aresult = mysql:query("SELECT achievementid, date FROM achievements WHERE account='" .. mysql:escape_string(gameAccountID) .. "'")
  1077.    
  1078.     local achievements = { }
  1079.    
  1080.     if aresult then
  1081.         while true do
  1082.             local row = mysql:fetch_assoc(aresult)
  1083.             if not row then break end
  1084.            
  1085.             achievements[#achievements+1] = { tonumber( row["achievementid"] ), row["date"] }
  1086.         end
  1087.  
  1088.     end
  1089.     mysql:free_result(aresult)
  1090.     triggerClientEvent(player, "returnAchievements", player, achievements)
  1091.    
  1092.     if ( hasBeta[player] ) then
  1093.         requestFriends(player)
  1094.     end
  1095. end
  1096.  
  1097. function getAchievements()
  1098.     requestAchievements(client)
  1099. end
  1100. addEvent("requestAchievements", true)
  1101. addEventHandler("requestAchievements", getRootElement(), getAchievements)
  1102.  
  1103. function deleteCharacterByName(charname)
  1104.    
  1105.     local fixedName = mysql:escape_string(string.gsub(tostring(charname), " ", "_"))
  1106.  
  1107.     local accountID = getElementData(client, "gameaccountid")
  1108.     local result = mysql:query_fetch_assoc("SELECT id FROM characters WHERE charactername='" .. fixedName .. "' AND account='" .. mysql:escape_string(accountID) .. "' LIMIT 1")
  1109.     local charid = tonumber(result["id"])
  1110.    
  1111.     if charid then -- not ck'ed
  1112.         -- delete all in-game vehicles
  1113.         for key, value in pairs( getElementsByType( "vehicle" ) ) do
  1114.             if isElement( value ) then
  1115.                 if getElementData( value, "owner" ) == charid then
  1116.                     call( getResourceFromName( "item-system" ), "deleteAll", 3, getElementData( value, "dbid" ) )
  1117.                     destroyElement( value )
  1118.                 end
  1119.             end
  1120.         end
  1121.         mysql:query_free("DELETE FROM vehicles WHERE owner = " .. mysql:escape_string(charid) )
  1122.  
  1123.         -- logs the deletion of the characters
  1124.         local accountUsername = getElementData(client, "gameaccountusername")
  1125.         exports.logs:logMessage("[DELETE CHARACTER] #" .. accountID .. "-" .. accountUsername .. " has deleted character #" .. charid .. "-" .. charname .. ".", 31)
  1126.  
  1127.         -- un-rent all interiors
  1128.         local old = getElementData( client, "dbid" )
  1129.         exports['anticheat-system']:changeProtectedElementDataEx( client, "dbid", charid )
  1130.         local result = mysql:query("SELECT id FROM interiors WHERE owner = " .. mysql:escape_string(charid) .. " AND type != 2" )
  1131.         if result then
  1132.             while true do
  1133.                 local row = mysql:fetch_assoc()
  1134.                 if not row then break end
  1135.                
  1136.                 local id = tonumber(row["id"])
  1137.                 call( getResourceFromName( "interior-system" ), "publicSellProperty", client, id, false, false )
  1138.             end
  1139.         end
  1140.         exports['anticheat-system']:changeProtectedElementDataEx( client, "dbid", old )
  1141.        
  1142.         -- get rid of all items
  1143.         mysql:query_free("DELETE FROM items WHERE type = 1 AND owner = " .. mysql:escape_string(charid) )
  1144.        
  1145.         -- finally delete the character
  1146.         mysql:query_free("DELETE FROM characters WHERE id='" .. mysql:escape_string(charid) .. "' AND account='" .. mysql:escape_string(accountID) .. "' LIMIT 1")
  1147.     end
  1148.     --sendAccounts(client, accountID)
  1149.     --showChat(client, true)
  1150. end
  1151. addEvent("deleteCharacter", true)
  1152. addEventHandler("deleteCharacter", getRootElement(), deleteCharacterByName)
  1153.  
  1154.  
  1155. function clearChatBox(thePlayer)
  1156.     outputChatBox(" ", thePlayer)
  1157.     outputChatBox(" ", thePlayer)
  1158.     outputChatBox(" ", thePlayer)
  1159.     outputChatBox(" ", thePlayer)
  1160.     outputChatBox(" ", thePlayer)
  1161.     outputChatBox(" ", thePlayer)
  1162.     outputChatBox(" ", thePlayer)
  1163.     outputChatBox(" ", thePlayer)
  1164.     outputChatBox(" ", thePlayer)
  1165.     outputChatBox(" ", thePlayer)
  1166.     outputChatBox(" ", thePlayer)
  1167.     outputChatBox(" ", thePlayer)
  1168.     outputChatBox(" ", thePlayer)
  1169.     outputChatBox(" ", thePlayer)
  1170.     outputChatBox(" ", thePlayer)
  1171.     outputChatBox(" ", thePlayer)
  1172.     outputChatBox(" ", thePlayer)
  1173.     outputChatBox(" ", thePlayer)
  1174.     outputChatBox(" ", thePlayer)
  1175.     outputChatBox(" ", thePlayer)
  1176.     outputChatBox(" ", thePlayer)
  1177. end
  1178. addCommandHandler("clearchat", clearChatBox) -- Users can now clear their chat if they wish
  1179.  
  1180. function declineTOS()
  1181.     kickPlayer(client, getRootElement(), "Declined TOS")
  1182. end
  1183. addEvent("declineTOS", true)
  1184. addEventHandler("declineTOS", getRootElement(), declineTOS)
  1185.  
  1186. function doesCharacterExist(charname)
  1187.     charname = string.gsub(tostring(charname), " ", "_")
  1188.     local safecharname = mysql:escape_string( charname)
  1189.    
  1190.     local result = mysql:query("SELECT charactername FROM characters WHERE charactername='" .. safecharname .. "'")
  1191.    
  1192.     if (mysql:num_rows(result)>0) then
  1193.         triggerClientEvent(client, "characterNextStep", source, true)
  1194.     else
  1195.         triggerClientEvent(client, "characterNextStep", source, false)
  1196.     end
  1197.    
  1198.     mysql:free_result(result)
  1199. end
  1200. addEvent("doesCharacterExist", true)
  1201. addEventHandler("doesCharacterExist", getRootElement(), doesCharacterExist)
  1202.  
  1203. function resetNick(oldNick, newNick)
  1204.     exports['anticheat-system']:changeProtectedElementDataEx(client, "legitnamechange", 1)
  1205.     setPlayerName(client, oldNick)
  1206.     exports['anticheat-system']:changeProtectedElementDataEx(client, "legitnamechange", 0)
  1207.     exports.global:sendMessageToAdmins("AdmWrn: " .. tostring(oldNick) .. " tried to change name to " .. tostring(newNick) .. ".")
  1208. end
  1209.  
  1210. addEvent("resetName", true )
  1211. addEventHandler("resetName", getRootElement(), resetNick)
  1212.  
  1213. function createCharacter(name, gender, skincolour, weight, height, fatness, muscles, transport, description, age, skin, language)
  1214.     source = client
  1215.     local charname = string.gsub(tostring(name), " ", "_")
  1216.     local safecharname = mysql:escape_string(charname)
  1217.     description = string.gsub(tostring(description), "'", "")
  1218.    
  1219.     local result = mysql:query("SELECT charactername FROM characters WHERE charactername='" .. safecharname .. "'")
  1220.  
  1221.     local accountID = getElementData(source, "gameaccountid")
  1222.     local accountUsername = getElementData(source, "gameaccountusername")
  1223.  
  1224.     local npid = nil
  1225.     if (mysql:num_rows(result)>0) then -- Name is already taken
  1226.         triggerEvent("onPlayerCreateCharacter", source, charname, gender, skincolour, weight, height, fatness, muscles, transport, description, age, skin, language, false)
  1227.         if (hasBeta[client]) then
  1228.             triggerClientEvent(client, "charCreateFail", client)
  1229.         end
  1230.         return
  1231.     else
  1232.        
  1233.         -- /////////////////////////////////////
  1234.         -- TRANSPORT
  1235.         -- /////////////////////////////////////
  1236.         local x, y, z, r, lastarea = 0, 0, 0, 0, "Unknown"
  1237.        
  1238.         if (transport==1) then
  1239.             x, y, z = 1742.1884765625, -1861.3564453125, 13.577615737915
  1240.             r = 0.98605346679688
  1241.             lastarea = "Unity Bus Station"
  1242.         else
  1243.             x, y, z = 1685.583984375, -2329.4443359375, 13.546875
  1244.             r = 0.79379272460938
  1245.             lastarea = "Los Santos International"
  1246.         end
  1247.        
  1248.         local salt = "fingerprintscotland"
  1249.         local fingerprint = md5(salt .. safecharname)
  1250.        
  1251.         local id = mysql:query_insert_free("INSERT INTO characters SET charactername='" .. safecharname .. "', x='" .. mysql:escape_string(x) .. "', y='" .. mysql:escape_string(y) .. "', z='" .. mysql:escape_string(z) .. "', rotation='" .. mysql:escape_string(r) .. "', faction_id='-1', transport='" .. mysql:escape_string(transport) .. "', gender='" .. mysql:escape_string(gender) .. "', skincolor='" .. mysql:escape_string(skincolour) .. "', weight='" .. mysql:escape_string(weight) .. "', height='" .. mysql:escape_string(height) .. "', muscles='" .. mysql:escape_string(muscles) .. "', fat='" .. mysql:escape_string(fatness) .. "', description='" .. mysql:escape_string(description) .. "', account='" .. mysql:escape_string(accountID) .. "', skin='" .. mysql:escape_string(skin) .. "', lastarea='" .. mysql:escape_string(lastarea) .. "', age='" .. mysql:escape_string(age) .. "', fingerprint='" .. mysql:escape_string(fingerprint) .. "', lang1=" .. mysql:escape_string(language) .. ", lang1skill=100, currLang=1" )
  1252.        
  1253.         if (id) then
  1254.             exports['anticheat-system']:changeProtectedElementDataEx(source, "dbid", id, false)
  1255.             exports.global:giveItem( source, 16, skin )
  1256.             exports.global:giveItem( source, 17, 1 )
  1257.             exports.global:giveItem( source, 18, 1 )
  1258.             exports['anticheat-system']:changeProtectedElementDataEx(source, "dbid")
  1259.  
  1260.             -- CELL PHONE
  1261.             local cellnumber = id+15000
  1262.             local update = mysql:query_free("UPDATE characters SET cellnumber='" .. mysql:escape_string(cellnumber) .. "' WHERE charactername='" .. safecharname .. "'")
  1263.            
  1264.             if (update) then
  1265.                 triggerEvent("onPlayerCreateCharacter", source, charname, gender, skincolour, weight, height, fatness, muscles, transport, description, age, skin, language, true)
  1266.             else
  1267.                 outputChatBox("Error 100003 - Report on forums.", source, 255, 0, 0)
  1268.             end
  1269.             npid = tonumber(id)
  1270.             if (hasBeta[client]) then
  1271.                 triggerClientEvent(client, "charCreateSuccess", client, npid)
  1272.             end
  1273.         else
  1274.             triggerEvent("onPlayerCreateCharacter", source, charname, gender, skincolour, weight, height, fatness, muscles, transport, description, age, skin, language, false)
  1275.         end
  1276.     end
  1277.     exports.logs:logMessage("[CREATE CHARACTER] #" .. accountID .. "-" .. accountUsername .. " has created a character by the name " .. charname:gsub("_"," ") .. "-#" .. npid, 31)
  1278.     sendAccounts(source, accountID)
  1279.    
  1280.     mysql:free_result(result)
  1281. end
  1282. addEvent("onPlayerCreateCharacter", false)
  1283. addEvent("createCharacter", true)
  1284. addEventHandler("createCharacter", getRootElement(), createCharacter)
  1285.  
  1286. function serverToggleBlur(enabled)
  1287.     if (enabled) then
  1288.         exports['anticheat-system']:changeProtectedElementDataEx(client, "blur", 1)
  1289.         setPlayerBlurLevel(client, 38)
  1290.     else
  1291.         exports['anticheat-system']:changeProtectedElementDataEx(client, "blur", 0)
  1292.         setPlayerBlurLevel(client, 0)
  1293.     end
  1294.     mysql:query_free("UPDATE accounts SET blur=" .. mysql:escape_string(getElementData( client, "blur" )) .. " WHERE id = " .. mysql:escape_string(getElementData( client, "gameaccountid" )) )
  1295. end
  1296. addEvent("updateBlurLevel", true)
  1297. addEventHandler("updateBlurLevel", getRootElement(), serverToggleBlur)
  1298.  
  1299. function cmdToggleBlur(thePlayer, commandName)
  1300.     local blur = getElementData(thePlayer, "blur")
  1301.    
  1302.     if (blur==0) then
  1303.         outputChatBox("Vehicle blur enabled.", thePlayer, 255, 194, 14)
  1304.         exports['anticheat-system']:changeProtectedElementDataEx(thePlayer, "blur", 1)
  1305.         setPlayerBlurLevel(thePlayer, 38)
  1306.     elseif (blur==1) then
  1307.         outputChatBox("Vehicle blur disabled.", thePlayer, 255, 194, 14)
  1308.         exports['anticheat-system']:changeProtectedElementDataEx(thePlayer, "blur", 0)
  1309.         setPlayerBlurLevel(thePlayer, 0)
  1310.     end
  1311.     mysql:query_free("UPDATE accounts SET blur=" .. mysql:escape_string(( 1 - blur )) .. " WHERE id = " .. mysql:escape_string(getElementData( thePlayer, "gameaccountid" )) )
  1312. end
  1313. addCommandHandler("toggleblur", cmdToggleBlur)
  1314.  
  1315. function cguiSetNewPassword(oldPassword, newPassword)
  1316.    
  1317.     local gameaccountID = getElementData(client, "gameaccountid")
  1318.    
  1319.     local safeoldpassword = mysql:escape_string(oldPassword)
  1320.     local safenewpassword = mysql:escape_string(newPassword)
  1321.    
  1322.     local query = mysql:query("SELECT username FROM accounts WHERE id='" .. mysql:escape_string(gameaccountID) .. "' AND password=MD5('" .. salt .. safeoldpassword .. "')")
  1323.    
  1324.     if not (query) or (mysql:num_rows(query)==0) then
  1325.         outputChatBox("Your current password you entered was wrong.", client, 255, 0, 0)
  1326.     else
  1327.         local update = mysql:query_free("UPDATE accounts SET password=MD5('" .. salt .. safenewpassword .. "') WHERE id='" .. mysql:escape_string(gameaccountID) .. "'")
  1328.  
  1329.         if (update) then
  1330.             outputChatBox("You changed your password to '" .. newPassword .. "'", client, 0, 255, 0)
  1331.         else
  1332.             outputChatBox("Error 100004 - Report on forums.", client, 255, 0, 0)
  1333.         end
  1334.     end
  1335.     mysql:free_result(query)
  1336. end
  1337. addEvent("cguiSavePassword", true)
  1338. addEventHandler("cguiSavePassword", getRootElement(), cguiSetNewPassword)
  1339.  
  1340. function timerPDUnjailPlayer(jailedPlayer)
  1341.     if(isElement(jailedPlayer)) then
  1342.         local timeServed = getElementData(jailedPlayer, "pd.jailserved", false) or 0
  1343.         local timeLeft = getElementData(jailedPlayer, "pd.jailtime", false) or 0
  1344.         local username = getPlayerName(jailedPlayer)
  1345.         if not username then
  1346.             local theTimer = getElementData(jailedPlayer, "pd.jailtimer")
  1347.             if isTimer(theTimer) then
  1348.                 killTimer(theTimer)
  1349.             end
  1350.             exports['anticheat-system']:changeProtectedElementDataEx(jailedPlayer, "pd.jailtimer")
  1351.             return
  1352.         end
  1353.         exports['anticheat-system']:changeProtectedElementDataEx(jailedPlayer, "pd.jailserved", timeServed+1, false)
  1354.         local timeLeft = timeLeft - 1
  1355.         exports['anticheat-system']:changeProtectedElementDataEx(jailedPlayer, "pd.jailtime", timeLeft, false)
  1356.  
  1357.         if (timeLeft<=0) then
  1358.             fadeCamera(jailedPlayer, false)
  1359.             mysql:query_free("UPDATE characters SET pdjail_time='0', pdjail='0', pdjail_station='0' WHERE charactername='" .. mysql:escape_string(username) .. "'")
  1360.             local station = getElementData(jailedPlayer, "pd.jailstation") or 1
  1361.             setElementDimension(jailedPlayer, station <= 4 and 1 or 10583)
  1362.             setElementInterior(jailedPlayer, 10)
  1363.             setCameraInterior(jailedPlayer, 10)
  1364.            
  1365.            
  1366.             setElementPosition(jailedPlayer, 241.3583984375, 115.232421875, 1003.2257080078)
  1367.             setPedRotation(jailedPlayer, 270)
  1368.                
  1369.             local theTimer = getElementData(jailedPlayer, "pd.jailtimer")
  1370.             if (theTimer) then
  1371.                 killTimer(theTimer)
  1372.             end
  1373.                
  1374.             exports['anticheat-system']:changeProtectedElementDataEx(jailedPlayer, "pd.jailserved", 0, false)
  1375.             exports['anticheat-system']:changeProtectedElementDataEx(jailedPlayer, "pd.jailtime", 0, false)
  1376.             exports['anticheat-system']:changeProtectedElementDataEx(jailedPlayer, "pd.jailtimer")
  1377.             exports['anticheat-system']:changeProtectedElementDataEx(jailedPlayer, "pd.jailstation")
  1378.             fadeCamera(jailedPlayer, true)
  1379.             outputChatBox("Your time has been served.", jailedPlayer, 0, 255, 0)
  1380.         else
  1381.             mysql:query_free("UPDATE characters SET pdjail_time='" .. mysql:escape_string(timeLeft) .. "' WHERE charactername='" .. mysql:escape_string(username) .. "'")
  1382.         end
  1383.     end
  1384. end
  1385.  
  1386. function sendEditingInformation(charname)
  1387.     local result = mysql:query_fetch_assoc("SELECT description, age, weight, height, gender FROM characters WHERE charactername='" .. mysql:escape_string(charname:gsub(" ", "_")) .. "'")
  1388.     local description = tostring(result["description"])
  1389.     local age = tostring(result["age"])
  1390.     local weight = tostring(result["weight"])
  1391.     local height = tostring(result["height"])
  1392.     local gender = tonumber(result["gender"])
  1393.    
  1394.     triggerClientEvent(client, "sendEditingInformation", client, height, weight, age, description, gender)
  1395. end
  1396. addEvent("requestEditCharInformation", true)
  1397. addEventHandler("requestEditCharInformation", getRootElement(), sendEditingInformation)
  1398.  
  1399. function updateEditedCharacter(charname, height, weight, age, description)
  1400.     mysql:query_free("UPDATE characters SET description='" .. mysql:escape_string(description) .. "', height=" .. mysql:escape_string(height) .. ", weight=" .. mysql:escape_string(weight) .. ", age=" .. mysql:escape_string(age) .. " WHERE charactername='" .. mysql:escape_string(charname:gsub(" ", "_")) .. "'")
  1401. end
  1402. addEvent("updateEditedCharacter", true)
  1403. addEventHandler("updateEditedCharacter", getRootElement(), updateEditedCharacter)
  1404.  
  1405.  
  1406. ---------------------------------
  1407. -- XBOX LIVE LOOKUPS
  1408. ---------------------------------
  1409. function xboxReturn(result, player, gamertag, status, activity, lastgame, level )
  1410.     local result = tonumber(result)
  1411.     if ( result == 0 ) then
  1412.         if ( isElement(player) ) then
  1413.             triggerClientEvent(player, "CxboxFail", player)
  1414.         end
  1415.     else
  1416.         if ( isElement(player) ) then
  1417.             -- sql update
  1418.             mysql:query_free("UPDATE accounts SET liveusername='" .. mysql:escape_string(gamertag) .. "' WHERE username='" .. getElementData(player, "gameaccountusername") .. "' LIMIT 1")
  1419.             triggerClientEvent(player, "CxboxSuccess", player, gamertag, status, activity, lastgame, level)
  1420.         end
  1421.     end
  1422. end
  1423.  
  1424. function xboxReturnExisting(result, player, gamertag, status, activity, lastgame, level )
  1425.     local result = tonumber(result)
  1426.  
  1427.     if ( result == 0 ) then
  1428.         if ( isElement(player) ) then
  1429.             mysql:query_free("UPDATE accounts SET liveusername=NULL WHERE username='" .. getElementData(player, "gameaccountusername") .. "' LIMIT 1")
  1430.         end
  1431.     else
  1432.         if ( isElement(player) ) then
  1433.             triggerClientEvent(player, "CxboxSuccess", player, gamertag, status, activity, lastgame, level)
  1434.         end
  1435.     end
  1436. end
  1437.  
  1438. function updateAccountXbox(username)
  1439.     callRemote("http://valhallagaming.net/mtaucp/mta/lookup_live.php", xboxReturn, username, client)
  1440. end
  1441. addEvent("SupdateXbox", true)
  1442. addEventHandler("SupdateXbox", getRootElement(), updateAccountXbox)
  1443.  
  1444.  
  1445. ---------------------------------
  1446. -- STEAM LOOKUPS
  1447. ---------------------------------
  1448. -- STATES:
  1449. -- 0 = Service Unavailable
  1450. -- 1 = Invalid Username
  1451. -- 2 = OK, but profile is private
  1452. -- 3 = OK
  1453. function steamReturn(result, player, name, nickname, online, state, game, timeplayed)
  1454.     local result = tonumber(result)
  1455.     if ( result == 0 ) then
  1456.         if ( isElement(player) ) then
  1457.             triggerClientEvent(player, "CsteamDown", player)
  1458.         end
  1459.     elseif ( result == 1 ) then
  1460.         if ( isElement(player) ) then
  1461.             triggerClientEvent(player, "CsteamFail", player)
  1462.         end
  1463.     else
  1464.         if ( isElement(player) ) then
  1465.             -- sql update
  1466.             mysql:query_free("UPDATE accounts SET steamusername='" .. mysql:escape_string(name) .. "' WHERE username='" .. getElementData(player, "gameaccountusername") .. "' LIMIT 1")
  1467.            
  1468.             if ( result == 3 ) then
  1469.                 triggerClientEvent(player, "CsteamSuccess", player, name, nickname, online, state, game, timeplayed)
  1470.             else
  1471.                 triggerClientEvent(player, "CsteamSuccess", player, name, nickname, online)
  1472.             end
  1473.         end
  1474.     end
  1475. end
  1476.  
  1477. function steamReturnExisting(result, player, name, nickname, online, state, game, timeplayed)
  1478.     local result = tonumber(result)
  1479.     if ( result == 0 ) then
  1480.         if ( isElement(player) ) then
  1481.             triggerClientEvent(player, "CsteamDown", player)
  1482.         end
  1483.     elseif ( result == 1 ) then
  1484.         if ( isElement(player) ) then
  1485.             mysql:query_free("UPDATE accounts SET steamusername=NULL WHERE username='" .. getElementData(player, "gameaccountusername") .. "' LIMIT 1")
  1486.         end
  1487.     else
  1488.         if ( isElement(player) ) then
  1489.             if ( result == 3 ) then
  1490.                 triggerClientEvent(player, "CsteamSuccess", player, name, nickname, online, state, game, timeplayed)
  1491.             else
  1492.                 triggerClientEvent(player, "CsteamSuccess", player, name, nickname, online)
  1493.             end
  1494.         end
  1495.     end
  1496. end
  1497.  
  1498. function updateAccountSteam(username)
  1499.     callRemote("http://valhallagaming.net/mtaucp/mta/lookup_steam.php", steamReturn, username, client)
  1500. end
  1501. addEvent("SupdateSteam", true)
  1502. addEventHandler("SupdateSteam", getRootElement(), updateAccountSteam)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement