Castillo

Untitled

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