Advertisement
Guest User

Untitled

a guest
May 1st, 2012
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 71.58 KB | None | 0 0
  1.     if not getKeyState("lctrl") and not getKeyState("rctrl") then return end
  2.  
  3.     -- если окно уже показано, то просто скрыть его
  4.     if guiGetVisible(tGUI_Window[1]) then
  5.         guiSetVisible( tGUI_Window[1], false )
  6.         showCursor(false)
  7.         return
  8.     end
  9.  
  10.     if not fIsGUIActionsAllowed() then return end
  11.  
  12.  
  13.     local uVehicle = getPedOccupiedVehicle(localPlayer)
  14.     if not uVehicle then return end
  15.  
  16.     local tHandling = getVehicleHandling(uVehicle)
  17.     if not uVehicle then return end
  18.  
  19.     fUpdateGUIFromHandlingTable( tHandling, getElementModel(uVehicle) )
  20.  
  21.     guiSetVisible( tGUI_Window[1], true )
  22.     showCursor(true)
  23. end
  24. bindKey( "h", "down", fOpenHandlingGUI )[/code]
  25. y bueno quisiera saber si podrian poner que ese comando ( que se abra con dos teclas ) en mi panel de admin
  26. este es el panel me ayudan
  27. [code=text] 
  28. _root = getRootElement()
  29. _types = { "player", "team", "vehicle", "resource", "bans", "server", "admin" }
  30. _settings = nil
  31.  
  32. aPlayers = {}
  33. aLogMessages = {}
  34. aInteriors = {}
  35. aStats = {}
  36. aReports = {}
  37. aWeathers = {}
  38. aNickChangeTime = {}
  39.  
  40. function notifyPlayerLoggedIn(player)
  41.     outputChatBox ( "Press 'p' to open your admin panel", player )
  42.     local unread = 0
  43.     for _, msg in ipairs ( aReports ) do
  44.         unread = unread + ( msg.read and 0 or 1 )
  45.     end
  46.     if unread > 0 then
  47.         outputChatBox( unread .. " unread Admin message" .. ( unread==1 and "" or "s" ), player, 255, 0, 0 )
  48.     end
  49. end
  50.  
  51. addEventHandler ( "onResourceStart", _root, function ( resource )
  52.     if ( resource ~= getThisResource() ) then
  53.         for id, player in ipairs(getElementsByType("player")) do
  54.             if ( hasObjectPermissionTo ( player, "general.tab_resources" ) ) then
  55.                 triggerClientEvent ( player, "aClientResourceStart", _root, getResourceName ( resource ) )
  56.             end
  57.         end
  58.         return
  59.     end
  60.     _settings = xmlLoadFile ( "conf\\settings.xml" )
  61.     if ( not _settings ) then
  62.         _settings = xmlCreateFile ( "conf\\settings.xml", "main" )
  63.         xmlSaveFile ( _settings )
  64.     end
  65.     aSetupACL()
  66.     aSetupCommands()
  67.     for id, player in ipairs ( getElementsByType ( "player" ) ) do
  68.         aPlayerInitialize ( player )
  69.         if ( hasObjectPermissionTo ( player, "general.adminpanel" ) ) then
  70.             notifyPlayerLoggedIn(player)
  71.         end
  72.     end
  73.     local node = xmlLoadFile ( "conf\\interiors.xml" )
  74.     if ( node ) then
  75.         local interiors = 0
  76.         while ( xmlFindChild ( node, "interior", interiors ) ) do
  77.             local interior = xmlFindChild ( node, "interior", interiors )
  78.             interiors = interiors + 1
  79.             aInteriors[interiors] = {}
  80.             aInteriors[interiors]["world"] = tonumber ( xmlNodeGetAttribute ( interior, "world" ) )
  81.             aInteriors[interiors]["id"] = xmlNodeGetAttribute ( interior, "id" )
  82.             aInteriors[interiors]["x"] = xmlNodeGetAttribute ( interior, "posX" )
  83.             aInteriors[interiors]["y"] = xmlNodeGetAttribute ( interior, "posY" )
  84.             aInteriors[interiors]["z"] = xmlNodeGetAttribute ( interior, "posZ" )
  85.             aInteriors[interiors]["r"] = xmlNodeGetAttribute ( interior, "rot" )
  86.         end
  87.         xmlUnloadFile ( node )
  88.     end
  89.     local node = xmlLoadFile ( "conf\\stats.xml" )
  90.     if ( node ) then
  91.         local stats = 0
  92.         while ( xmlFindChild ( node, "stat", stats ) ) do
  93.             local stat = xmlFindChild ( node, "stat", stats )
  94.             local id = tonumber ( xmlNodeGetAttribute ( stat, "id" ) )
  95.             local name = xmlNodeGetAttribute ( stat, "name" )
  96.             aStats[id] = name
  97.             stats = stats + 1
  98.         end
  99.         xmlUnloadFile ( node )
  100.     end
  101.     local node = xmlLoadFile ( "conf\\weathers.xml" )
  102.     if ( node ) then
  103.         local weathers = 0
  104.         while ( xmlFindChild ( node, "weather", weathers ) ~= false ) do
  105.         local weather = xmlFindChild ( node, "weather", weathers )
  106.             local id = tonumber ( xmlNodeGetAttribute ( weather, "id" ) )
  107.             local name = xmlNodeGetAttribute ( weather, "name" )
  108.             aWeathers[id] = name
  109.             weathers = weathers + 1
  110.         end
  111.         xmlUnloadFile ( node )
  112.     end
  113.     local node = xmlLoadFile ( "conf\\reports.xml" )
  114.     if ( node ) then
  115.         local messages = 0
  116.         while ( xmlFindChild ( node, "message", messages ) ) do
  117.             subnode = xmlFindChild ( node, "message", messages )
  118.             local author = xmlFindChild ( subnode, "author", 0 )
  119.             local subject = xmlFindChild ( subnode, "subject", 0 )
  120.             local category = xmlFindChild ( subnode, "category", 0 )
  121.             local text = xmlFindChild ( subnode, "text", 0 )
  122.             local time = xmlFindChild ( subnode, "time", 0 )
  123.             local read = ( xmlFindChild ( subnode, "read", 0 ) ~= false )
  124.             local id = #aReports + 1
  125.             aReports[id] = {}
  126.             if ( author ) then aReports[id].author = xmlNodeGetValue ( author )
  127.             else aReports[id].author = "" end
  128.             if ( category ) then aReports[id].category = xmlNodeGetValue ( category )
  129.             else aReports[id].category = "" end
  130.             if ( subject ) then aReports[id].subject = xmlNodeGetValue ( subject )
  131.             else aReports[id].subject = "" end
  132.             if ( text ) then aReports[id].text = xmlNodeGetValue ( text )
  133.             else aReports[id].text = "" end
  134.             if ( time ) then aReports[id].time = xmlNodeGetValue ( time )
  135.             else aReports[id].time = "" end
  136.             aReports[id].read = read
  137.             messages = messages + 1
  138.         end
  139.         -- Remove duplicates
  140.         local a = 1
  141.         while a <= #aReports do
  142.             local b = a + 1
  143.             while b <= #aReports do
  144.                 if table.cmp( aReports[a], aReports[b] ) then
  145.                     table.remove( aReports, b )
  146.                     b = b - 1
  147.                 end
  148.                 b = b + 1
  149.             end
  150.             a = a + 1
  151.         end
  152.         -- Upgrade time from '4/9 5:9' to '2009-09-04 05:09'
  153.         for id, rep in ipairs ( aReports ) do
  154.             if string.find( rep.time, "/" ) then
  155.                 local monthday, month, hour, minute = string.match( rep.time, "^(.-)/(.-) (.-):(.-)$" )
  156.                 rep.time = string.format( '%04d-%02d-%02d %02d:%02d', 2009, month + 1, monthday, hour, minute )
  157.             end
  158.         end
  159.         -- Sort messages by time
  160.         table.sort(aReports, function(a,b) return(a.time < b.time) end)
  161.         -- Limit number of messages
  162.         while #aReports > g_Prefs.maxmsgs do
  163.             table.remove( aReports, 1 )
  164.         end
  165.         xmlUnloadFile ( node )
  166.     end
  167.     local node = xmlLoadFile ( "conf\\messages.xml" )
  168.     if ( node ) then
  169.         for id, type in ipairs ( _types ) do
  170.             local subnode = xmlFindChild ( node, type, 0 )
  171.             if ( subnode ) then
  172.                 aLogMessages[type] = {}
  173.                 local groups = 0
  174.                 while ( xmlFindChild ( subnode, "group", groups ) ) do
  175.                     local group = xmlFindChild ( subnode, "group", groups )
  176.                     local action = xmlNodeGetAttribute ( group, "action" )
  177.                     local r = tonumber ( xmlNodeGetAttribute ( group, "r" ) )
  178.                     local g = tonumber ( xmlNodeGetAttribute ( group, "g" ) )
  179.                     local b = tonumber ( xmlNodeGetAttribute ( group, "b" ) )
  180.                     aLogMessages[type][action] = {}
  181.                     aLogMessages[type][action]["r"] = r or 0
  182.                     aLogMessages[type][action]["g"] = g or 255
  183.                     aLogMessages[type][action]["b"] = b or 0
  184.                     if ( xmlFindChild ( group, "all", 0 ) ) then aLogMessages[type][action]["all"] = xmlNodeGetValue ( xmlFindChild ( group, "all", 0 ) ) end
  185.                     if ( xmlFindChild ( group, "admin", 0 ) ) then aLogMessages[type][action]["admin"] = xmlNodeGetValue ( xmlFindChild ( group, "admin", 0 ) ) end
  186.                     if ( xmlFindChild ( group, "player", 0 ) ) then aLogMessages[type][action]["player"] = xmlNodeGetValue ( xmlFindChild ( group, "player", 0 ) ) end
  187.                     if ( xmlFindChild ( group, "log", 0 ) ) then aLogMessages[type][action]["log"] = xmlNodeGetValue ( xmlFindChild ( group, "log", 0 ) ) end
  188.                     groups = groups + 1
  189.                 end
  190.             end
  191.         end
  192.         xmlUnloadFile ( node )
  193.     end
  194. end )
  195.  
  196. addEventHandler ( "onResourceStop", _root, function ( resource )
  197.     -- Incase the resource being stopped has been deleted
  198.     local stillExists = false
  199.     for i, res in ipairs(getResources()) do
  200.         if res == resource then
  201.             stillExists = true
  202.             break
  203.         end
  204.     end
  205.     if not stillExists then return end
  206.    
  207.     if ( resource ~= getThisResource() ) then
  208.         for id, player in ipairs(getElementsByType("player")) do
  209.             if ( hasObjectPermissionTo ( player, "general.tab_resources" ) ) then
  210.                 triggerClientEvent ( player, "aClientResourceStop", _root, getResourceName ( resource ) )
  211.             end
  212.         end
  213.     else
  214.         local node = xmlLoadFile ( "conf\\reports.xml" )
  215.         if ( node ) then
  216.             while ( xmlFindChild ( node, "message", 0 ) ~= false ) do
  217.                 local subnode = xmlFindChild ( node, "message", 0 )
  218.                 xmlDestroyNode ( subnode )
  219.             end
  220.         else
  221.             node = xmlCreateFile ( "conf\\reports.xml", "messages" )
  222.         end
  223.         for id, message in ipairs ( aReports ) do
  224.             local subnode = xmlCreateChild ( node, "message" )
  225.             for key, value in pairs ( message ) do
  226.                 if ( value ) then
  227.                     xmlNodeSetValue ( xmlCreateChild ( subnode, key ), tostring ( value ) )
  228.                 end
  229.             end
  230.         end
  231.         xmlSaveFile ( node )
  232.         xmlUnloadFile ( node )
  233.     end
  234.     aclSave ()
  235. end )
  236.  
  237. function aGetSetting ( setting )
  238.     local result = xmlFindChild ( _settings, tostring ( setting ), 0 )
  239.     if ( result ) then
  240.         result = xmlNodeGetValue ( result )
  241.         if ( result == "true" ) then return true
  242.         elseif ( result == "false" ) then return false
  243.         else return result end
  244.     end
  245.     return false
  246. end
  247.  
  248. function aSetSetting ( setting, value )
  249.     local node = xmlFindChild ( _settings, tostring ( setting ), 0 )
  250.     if ( not node ) then
  251.         node = xmlCreateChild ( _settings, tostring ( setting ) )
  252.     end
  253.     xmlNodeSetValue ( node, tostring ( value ) )
  254.     xmlSaveFile ( _settings )
  255. end
  256.  
  257. function aRemoveSetting ( setting )
  258.     local node = xmlFindChild ( _settings, tostring ( setting ), 0 )
  259.     if ( node ) then
  260.         xmlDestroyNode ( node )
  261.     end
  262.     xmlSaveFile ( _settings )
  263. end
  264.  
  265. function iif ( cond, arg1, arg2 )
  266.     if ( cond ) then
  267.         return arg1
  268.     end
  269.     return arg2
  270. end
  271.  
  272. function getVehicleOccupants ( vehicle )
  273.     local tableOut = {}
  274.     local seats = getVehicleMaxPassengers ( vehicle ) + 1
  275.     for i = 0, seats do
  276.         local passenger = getVehicleOccupant ( vehicle, i )
  277.         if ( passenger ) then table.insert ( tableOut, passenger ) end
  278.     end
  279.     return tableOut
  280. end
  281.  
  282. function isValidSerial ( serial )
  283.     -- Did you know gmatch returns an iterator function?
  284.     return string.gmatch ( serial, "%w%w%w%w-%w%w%w%w-%w%w%w%w-%w%w%w%w" )
  285. end
  286.  
  287. function getWeatherNameFromID ( weather )
  288.     return iif ( aWeathers[weather], aWeathers[weather], "Unknown" )
  289. end
  290.  
  291. function getPlayerAccountName( player )
  292.     local account = getPlayerAccount ( player )
  293.     return account and getAccountName ( account )
  294. end
  295.  
  296. addEvent ( "onPlayerMute", false )
  297. function aSetPlayerMuted ( player, state, length )
  298.     if ( setPlayerMuted ( player, state ) ) then
  299.         if not state then
  300.             aRemoveUnmuteTimer( player )
  301.         elseif state and length and length > 0 then
  302.             aAddUnmuteTimer( player, length )
  303.         end
  304.         triggerEvent ( "onPlayerMute", player, state )
  305.         return true
  306.     end
  307.     return false
  308. end
  309.  
  310. addEventHandler ( "onPlayerJoin", _root, function ()
  311.     local player = source
  312.     if aHasUnmuteTimer( player ) then
  313.         if not isPlayerMuted(player) then
  314.             triggerEvent ( "aPlayer", getElementByIndex("console", 0), player, "mute" )
  315.         end
  316.     end
  317. end )
  318.  
  319. -- Allows for timed mutes across reconnects
  320. local aUnmuteTimerList = {}
  321. function aAddUnmuteTimer( player, length )
  322.     aRemoveUnmuteTimer( player )
  323.     local serial = getPlayerSerial( player )
  324.     aUnmuteTimerList[serial] = setTimer(
  325.                                 function()
  326.                                     aUnmuteTimerList[serial] = nil
  327.                                     for _,player in ipairs(getElementsByType('player')) do
  328.                                         if getPlayerSerial(player) == serial then
  329.                                             if isPlayerMuted(player) then
  330.                                                 triggerEvent ( "aPlayer", getElementByIndex("console", 0), player, "mute" )
  331.                                             end
  332.                                         end
  333.                                     end
  334.                                 end,
  335.                                 length*1000, 1 )
  336. end
  337.  
  338. function aRemoveUnmuteTimer( player )
  339.     local serial = getPlayerSerial( player )
  340.     if aUnmuteTimerList[serial] then
  341.         killTimer( aUnmuteTimerList[serial] )
  342.         aUnmuteTimerList[serial] = nil
  343.     end
  344. end
  345.  
  346. function aHasUnmuteTimer( player )
  347.     local serial = getPlayerSerial( player )
  348.     if aUnmuteTimerList[serial] then
  349.         return true
  350.     end
  351. end
  352.  
  353.  
  354. addEvent ( "onPlayerFreeze", false )
  355. function aSetPlayerFrozen ( player, state )
  356.     if ( toggleAllControls ( player, not state, true, false ) ) then
  357.         aPlayers[player]["freeze"] = state
  358.         triggerEvent ( "onPlayerFreeze", player, state )
  359.         local vehicle = getPedOccupiedVehicle( player )
  360.         if vehicle then
  361.             setElementFrozen ( vehicle, state )
  362.         end
  363.         return true
  364.     end
  365.     return false
  366. end
  367.  
  368. function isPlayerFrozen ( player )
  369.     if ( aPlayers[player]["freeze"] == nil ) then aPlayers[player]["freeze"] = false end
  370.     return aPlayers[player]["freeze"]
  371. end
  372.  
  373. addEventHandler ( "onPlayerJoin", _root, function ()
  374.     if ( aGetSetting ( "welcome" ) ) then
  375.         outputChatBox ( aGetSetting ( "welcome" ), source, 255, 100, 100 )
  376.     end
  377.     aPlayerInitialize ( source )
  378.     for id, player in ipairs(getElementsByType("player")) do
  379.         if ( hasObjectPermissionTo ( player, "general.adminpanel" ) ) then
  380.             triggerClientEvent ( player, "aClientPlayerJoin", source, getPlayerIP ( source ), getPlayerUserName ( source ), getPlayerAccountName ( source ), getPlayerSerial ( source ), hasObjectPermissionTo ( source, "general.adminpanel" ), aPlayers[source]["country"] )
  381.         end
  382.     end
  383.     setPedGravity ( source, getGravity() )
  384. end )
  385.  
  386. function aPlayerInitialize ( player )
  387.     local serial = getPlayerSerial ( player )
  388.     if ( not isValidSerial ( serial ) ) then
  389.         outputChatBox ( "ERROR: "..getPlayerName ( player ).." - Invalid Serial." )
  390.         kickPlayer ( player, "Invalid Serial" )
  391.     else
  392.         bindKey ( player, "p", "down", "admin" )
  393.         callRemote ( "http://community.mtasa.com/mta/verify.php", aPlayerSerialCheck, player, getPlayerUserName ( player ), getPlayerSerial ( player ) )
  394.         aPlayers[player] = {}
  395.         aPlayers[player]["country"] = getPlayerCountry ( player )
  396.         aPlayers[player]["money"] = getPlayerMoney ( player )
  397.     end
  398. end
  399.  
  400. addEventHandler ( "onPlayerQuit", root, function ()
  401.     aPlayers[source] = nil
  402.     aNickChangeTime[source] = nil
  403. end )
  404.  
  405. addEvent ( "aPlayerVersion", true )
  406. addEventHandler ( "aPlayerVersion", _root, function ( version )
  407.     if checkClient( false, source, 'aPlayerVersion' ) then return end
  408.     local bIsPre = false
  409.     -- If not Release, mark as 'pre'
  410.     if version.type:lower() ~= "release" then
  411.         bIsPre = true
  412.     else
  413.         -- Extract rc version if there
  414.         local _,_,rc = string.find( version.tag or "", "(%d)$" )
  415.         rc = tonumber(rc) or 0
  416.         -- If release, but before final rc, mark as 'pre'
  417.         if version.mta == "1.0.2" and rc > 0 and rc < 13 then
  418.             bIsPre = true
  419.         elseif version.mta == "1.0.3" and rc < 9 then
  420.             bIsPre = true
  421.         end
  422.         -- If version does not have a built in version check, maybe show a message box advising an upgrade
  423.         if version.number < 259 or ( version.mta == "1.0.3" and rc < 3 ) then
  424.             triggerClientEvent ( source, "aClientShowUpgradeMessage", source ) 
  425.         end
  426.     end
  427.  
  428.     -- Try to get new player version
  429.     local playerVersion
  430.     if getPlayerVersion then
  431.         playerVersion = getPlayerVersion(client)
  432.     else
  433.         playerVersion = version.mta .. "-" .. ( bIsPre and "7" or "9" ) .. ".00000.0"
  434.     end
  435.  
  436.     -- Format it all prettyful
  437.     local _,_,ver,type,build = string.find ( playerVersion, "(.*)-([0-9])\.(.*)" )
  438.     if aPlayers[source] then
  439.         aPlayers[source]["version"] = ver .. ( type < '9' and " pre  " or "  " ) .. "(" .. type .. "." .. build .. ")"
  440.     end
  441. end )
  442.  
  443. function aPlayerSerialCheck ( player, result )
  444.     if ( result == 0 ) then kickPlayer ( player, "Invalid serial" ) end
  445. end
  446.  
  447. addEventHandler ( "onPlayerLogin", _root, function ( previous, account, auto )
  448.     if ( hasObjectPermissionTo ( source, "general.adminpanel" ) ) then
  449.         triggerEvent ( "aPermissions", source )
  450.         notifyPlayerLoggedIn( source )
  451.     end
  452. end )
  453.  
  454. addCommandHandler ( "register", function ( player, command, arg1, arg2 )
  455.     local username = getPlayerName ( player )
  456.     local password = arg1
  457.     if ( arg2 ) then
  458.         username = arg1
  459.         password = arg2
  460.     end
  461.     if ( password ~= nil ) then
  462.         if ( string.len ( password ) < 4 ) then
  463.             outputChatBox ( "register: - Password should be at least 4 characters long", player, 255, 100, 70 )
  464.         elseif ( addAccount ( username, password ) ) then
  465.             outputChatBox ( "You have successfully registered! Username: '"..username.."', Password: '"..password.."'(Remember it)", player, 255, 100, 70 )
  466.             outputServerLog ( "ADMIN: "..getPlayerName ( player ).." registered account '"..username.."' (IP: "..getPlayerIP(player).."  Serial: "..getPlayerSerial(player)..")" )
  467.         elseif ( getAccount ( username ) ) then
  468.             outputChatBox ( "register: - Account with this name already exists.", player, 255, 100, 70 )
  469.         else
  470.             outputChatBox ( "Unknown Error", player, 255, 100, 70 )
  471.         end
  472.     else
  473.         outputChatBox ( "register: - Syntax is 'register [<nick>] <password>'", player, 255, 100, 70 )
  474.     end
  475. end )
  476.  
  477. -- This requires "function.removeAccount" permission for both the admin resource and the player
  478. addCommandHandler ( "unregister", function ( player, command, arg1, arg2 )
  479.     local username = arg1 or ""
  480.     local result = "failed - No permission"
  481.     if ( hasObjectPermissionTo ( player, "function.removeAccount" ) ) then
  482.         local account = getAccount ( username )
  483.         if not account then
  484.             result = "failed - Does not exist"
  485.         elseif #aclGetAccountGroups ( account ) > 1 then
  486.             result = "failed - Account in more than one ACL group"
  487.         elseif removeAccount( account ) then
  488.             result = "succeeded"
  489.         else
  490.             result = "failed - Check resource has permission"
  491.         end
  492.     end
  493.     outputChatBox ( "Unregistering account '"..username.."' "..result, player, 255, 100, 70 )
  494.     outputServerLog ( "ADMIN: "..getAdminNameForLog ( player ).." unregistering account '"..username.."' "..result.." (IP: "..getPlayerIP(player).."  Serial: "..getPlayerSerial(player)..")" ) 
  495. end )
  496.  
  497. -- Returns "name" or "name(accountname)" if they differ
  498. function getAdminNameForLog(player)
  499.     local name = getPlayerName( player )
  500.     if not isGuestAccount( getPlayerAccount( player ) ) then
  501.         local accountName = getAccountName( getPlayerAccount( player ) )
  502.         if name ~= accountName then
  503.             return name.."("..accountName..")"
  504.         end
  505.     end
  506.     return name
  507. end
  508.  
  509. function aAdminMenu ( player, command )
  510.     if ( hasObjectPermissionTo ( player, "general.adminpanel" ) ) then
  511.         triggerClientEvent ( player, "aClientAdminMenu", _root )
  512.         aPlayers[player]["chat"] = true
  513.     end
  514. end
  515. addCommandHandler ( "admin", aAdminMenu )
  516.  
  517. function aAction ( type, action, admin, player, data, more )
  518.     if ( aLogMessages[type] ) then
  519.         function aStripString ( string )
  520.             string = tostring ( string )
  521.             string = string.gsub ( string, "$admin", getPlayerName ( admin ) )
  522.             string = string.gsub ( string, "$by_admin_4all", isAnonAdmin4All( admin )    and "" or " by " .. getPlayerName ( admin ) )
  523.             string = string.gsub ( string, "$by_admin_4plr", isAnonAdmin4Victim( admin ) and "" or " by " .. getPlayerName ( admin ) )
  524.             string = string.gsub ( string, "$data2", more or "" )
  525.             if ( player ) then string = string.gsub ( string, "$player", getPlayerName ( player ) ) end
  526.             return tostring ( string.gsub ( string, "$data", data or "" ) )
  527.         end
  528.         local node = aLogMessages[type][action]
  529.         if ( node ) then
  530.             local r, g, b = node["r"], node["g"], node["b"]
  531.             if ( node["all"] ) then outputChatBox ( aStripString ( node["all"] ), _root, r, g, b ) end
  532.             if ( node["admin"] ) and ( admin ~= player ) then outputChatBox ( aStripString ( node["admin"] ), admin, r, g, b ) end
  533.             if ( node["player"] ) then outputChatBox ( aStripString ( node["player"] ), player, r, g, b ) end
  534.             if ( node["log"] ) then outputServerLog ( aStripString ( node["log"] ) ) end
  535.         end
  536.     end
  537. end
  538.  
  539. -- Should admin name be hidden from public chatbox message?
  540. function isAnonAdmin4All ( admin )
  541.     return getElementData( admin, "AnonAdmin" ) == true
  542. end
  543.  
  544. -- Should admin name be hidden from private chatbox message?
  545. function isAnonAdmin4Victim ( admin )
  546.     return false
  547. end
  548.  
  549. addEvent ( "aTeam", true )
  550. addEventHandler ( "aTeam", _root, function ( action, name, r, g, b )
  551.     if checkClient( "command."..action, source, 'aTeam', action ) then return end
  552.     if ( hasObjectPermissionTo ( source, "command."..action ) ) then
  553.         mdata = tostring ( data )
  554.         mdata = ""
  555.         if ( action == "createteam" ) then
  556.             local success = false
  557.             if ( tonumber ( r ) ) and ( tonumber ( g ) ) and ( tonumber ( b ) ) then
  558.                 success = createTeam ( name, tonumber ( r ), tonumber ( g ), tonumber ( b ) )
  559.             else
  560.                 success = createTeam ( name )
  561.             end
  562.             if ( not success ) then
  563.                 action = nil
  564.                 outputChatBox ( "Team \""..name.."\" could not be created.", source, 255, 0, 0 )
  565.             end
  566.         elseif ( action == "destroyteam" ) then
  567.             local team = getTeamFromName ( name )
  568.             if ( getTeamFromName ( name ) ) then
  569.                 destroyElement ( team )
  570.             else
  571.                 action = nil
  572.             end
  573.         else
  574.             action = nil
  575.         end
  576.         if ( action ~= nil ) then aAction ( "server", action, source, false, mdata, mdata2 ) end
  577.         return true
  578.     end
  579.     outputChatBox ( "Access denied for '"..tostring ( action ).."'", source, 255, 168, 0 )
  580.     return false
  581. end )
  582.  
  583. addEvent ( "aAdmin", true )
  584. addEventHandler ( "aAdmin", _root, function ( action, ... )
  585.     if checkClient( true, source, 'aAdmin', action ) then return end
  586.     local mdata = ""
  587.     local mdata2 = ""
  588.     if ( action == "password" ) then
  589.         action = nil
  590.         if ( not arg[1] ) then outputChatBox ( "Error - Password missing.", source, 255, 0, 0 )
  591.         elseif ( not arg[2] ) then outputChatBox ( "Error - New password missing.", source, 255, 0, 0 )
  592.         elseif ( not arg[3] ) then outputChatBox ( "Error - Confirm password.", source, 255, 0, 0 )
  593.         elseif ( tostring ( arg[2] ) ~= tostring ( arg[3] ) ) then outputChatBox ( "Error - Passwords do not match.", source, 255, 0, 0 )
  594.         else
  595.             local account = getAccount ( getPlayerAccountName ( source ), tostring ( arg[1] ) )
  596.             if ( account ) then
  597.                 action = "password"
  598.                 setAccountPassword ( account, arg[2] )
  599.                 mdata = arg[2]
  600.             else
  601.                 outputChatBox ( "Error - Invalid password.", source, 255, 0, 0 )
  602.             end
  603.         end
  604.     elseif ( action == "autologin" ) then
  605.  
  606.     elseif ( action == "settings" ) then
  607.         local cmd = arg[1]
  608.         local resName = arg[2]
  609.         local tableOut = {}
  610.         if ( cmd == "change" ) then
  611.             local name = arg[3]
  612.             local value = arg[4]
  613.             -- Get previous value
  614.             local settings = aGetResourceSettings( resName )
  615.             local oldvalue = settings[name].current
  616.             -- Match type
  617.             local changed = false
  618.             if type(oldvalue) == 'boolean' then value = value=='true'   end
  619.             if type(oldvalue) == 'number'  then value = tonumber(value) end
  620.             if type(oldvalue) == "table" then
  621.                 value = fromJSON("[["..value.."]]")
  622.                 changed = not table.compare(value, oldvalue)
  623.             else
  624.                 changed = value ~= oldvalue
  625.             end
  626.             if changed then
  627.                 if aSetResourceSetting( resName, name, value ) then
  628.                     -- Tell the resource one of its settings has changed
  629.                     local res = getResourceFromName(resName)
  630.                     local resRoot = getResourceRootElement(res)
  631.                     if resRoot then
  632.                         if getVersion().mta < "1.1" then
  633.                             triggerEvent('onSettingChange', resRoot, name, oldvalue, value, source )
  634.                         end
  635.                     end
  636.                     mdata = resName..'.'..name
  637.                     mdata2 = type(value) == "table" and string.gsub(toJSON(value),"^(%[ %[ )(.*)( %] %])$", "%2") or tostring(value)
  638.                 end
  639.             end
  640.         elseif ( cmd == "getall" ) then
  641.             tableOut = aGetResourceSettings( resName )
  642.             for name,value in pairs(tableOut) do
  643.                 if type(value.default) == "table" then
  644.                     tableOut[name].default = string.gsub(toJSON(value.default),"^(%[ %[ )(.*)( %] %])$", "%2")
  645.                     tableOut[name].current = string.gsub(toJSON(value.current),"^(%[ %[ )(.*)( %] %])$", "%2")
  646.                 end
  647.             end
  648.         end
  649.         triggerClientEvent ( source, "aAdminSettings", _root, cmd, resName, tableOut )
  650.         if mdata == "" then
  651.             action = nil
  652.         end
  653.     elseif ( action == "sync" ) then
  654.         local type = arg[1]
  655.         local tableOut = {}
  656.         if ( type == "aclgroups" ) then
  657.             tableOut["groups"] = {}
  658.             for id, group in ipairs ( aclGroupList() ) do
  659.                 table.insert ( tableOut["groups"] ,aclGroupGetName ( group ) )
  660.             end
  661.             tableOut["acl"] = {}
  662.             for id, acl in ipairs ( aclList() ) do
  663.                 table.insert ( tableOut["acl"] ,aclGetName ( acl ) )
  664.             end
  665.         elseif ( type == "aclobjects" ) then
  666.             local group = aclGetGroup ( tostring ( arg[2] ) )
  667.             if ( group ) then
  668.                 tableOut["name"] = arg[2]
  669.                 tableOut["objects"] = aclGroupListObjects ( group )
  670.                 tableOut["acl"] = {}
  671.                 for id, acl in ipairs ( aclGroupListACL ( group ) ) do
  672.                     table.insert ( tableOut["acl"], aclGetName ( acl ) )
  673.                 end
  674.             end
  675.         elseif ( type == "aclrights" ) then
  676.             local acl = aclGet ( tostring ( arg[2] ) )
  677.             if ( acl ) then
  678.                 tableOut["name"] = arg[2]
  679.                 tableOut["rights"] = {}
  680.                 for id, name in ipairs ( aclListRights ( acl ) ) do
  681.                     tableOut["rights"][name] = aclGetRight ( acl, name )
  682.                 end
  683.             end
  684.         end
  685.         triggerClientEvent ( source, "aAdminACL", _root, type, tableOut )
  686.     elseif ( action == "aclcreate" ) then
  687.         local name = arg[2]
  688.         if ( ( name ) and ( string.len ( name ) >= 1 ) ) then
  689.             if ( arg[1] == "group" ) then
  690.                 mdata = "Group "..name
  691.                 if ( not aclCreateGroup ( name ) ) then
  692.                     action = nil
  693.                 end
  694.             elseif ( arg[1] == "acl" ) then
  695.                 mdata = "ACL "..name
  696.                 if ( not aclCreate ( name ) ) then
  697.                     action = nil
  698.                 end
  699.             end
  700.             triggerEvent ( "aAdmin", source, "sync", "aclgroups" )
  701.         else
  702.             outputChatBox ( "Error - Invalid "..arg[1].." name", source, 255, 0, 0 )
  703.         end
  704.     elseif ( action == "acldestroy" ) then
  705.         local name = arg[2]
  706.         if ( arg[1] == "group" ) then
  707.             if ( aclGetGroup ( name ) ) then
  708.                 mdata = "Group "..name
  709.                 aclDestroyGroup ( aclGetGroup ( name ) )
  710.             else
  711.                 action = nil
  712.             end
  713.         elseif ( arg[1] == "acl" ) then
  714.             if ( aclGet ( name ) ) then
  715.                 mdata = "ACL "..name
  716.                 aclDestroy ( aclGet ( name ) )
  717.             else
  718.                 action = nil
  719.             end
  720.         end
  721.         triggerEvent ( "aAdmin", source, "sync", "aclgroups" )
  722.     elseif ( action == "acladd" ) then
  723.         if ( arg[3] ) then
  724.             action = action
  725.             mdata = "Group '"..arg[2].."'"
  726.             if ( arg[1] == "object" ) then
  727.                 local group = aclGetGroup ( arg[2] )
  728.                 local object = arg[3]
  729.                 if ( not aclGroupAddObject ( group, object ) ) then
  730.                     action = nil
  731.                     outputChatBox ( "Error adding object '"..tostring ( object ).."' to group '"..tostring ( arg[2] ).."'", source, 255, 0, 0 )
  732.                 else
  733.                     mdata2 = "Object '"..arg[3].."'"
  734.                     triggerEvent ( "aAdmin", source, "sync", "aclobjects", arg[2] )
  735.                 end
  736.             elseif ( arg[1] == "acl" ) then
  737.                 local group = aclGetGroup ( arg[2] )
  738.                 local acl = aclGet ( arg[3] )
  739.                 if ( not aclGroupAddACL ( group, acl ) ) then
  740.                     action = nil
  741.                     outputChatBox ( "Error adding ACL '"..tostring ( arg[3] ).."' to group '"..tostring ( arg[2] ).."'", source, 255, 0, 0 )
  742.                 else
  743.                     mdata2 = "ACL '"..arg[3].."'"
  744.                     triggerEvent ( "aAdmin", source, "sync", "aclobjects", arg[2] )
  745.                 end
  746.             elseif ( arg[1] == "right" ) then
  747.                 local acl = aclGet ( arg[2] )
  748.                 local right = arg[3]
  749.                 local enabled = true
  750.                 if ( not aclSetRight ( acl, right, enabled ) ) then
  751.                     action = nil
  752.                     outputChatBox ( "Error adding right '"..tostring ( arg[3] ).."' to group '"..tostring ( arg[2] ).."'", source, 255, 0, 0 )
  753.                 else
  754.                     mdata2 = "Right '"..arg[3].."'"
  755.                     triggerEvent ( "aAdmin", source, "sync", "aclrights", arg[2] )
  756.                 end
  757.             end
  758.         else
  759.             action = nil
  760.         end
  761.     elseif ( action == "aclremove" ) then
  762.         --action = nil
  763.         if ( arg[3] ) then
  764.             action = action
  765.             mdata = "Group '"..arg[2].."'"
  766.             if ( arg[1] == "object" ) then
  767.                 local group = aclGetGroup ( arg[2] )
  768.                 local object = arg[3]
  769.                 if ( not aclGroupRemoveObject ( group, object ) ) then
  770.                     action = nil
  771.                     outputChatBox ( "Error - object '"..tostring ( object ).."' does not exist in group '"..tostring ( arg[2] ).."'", source, 255, 0, 0 )
  772.                 else
  773.                     mdata2 = "Object '"..arg[3].."'"
  774.                     triggerEvent ( "aAdmin", source, "sync", "aclobjects", arg[2] )
  775.                 end
  776.             elseif ( arg[1] == "acl" ) then
  777.                 local group = aclGetGroup ( arg[2] )
  778.                 local acl = aclGet ( arg[3] )
  779.                 if ( not aclGroupRemoveACL ( group, acl ) ) then
  780.                     action = nil
  781.                     outputChatBox ( "Error - ACL '"..tostring ( arg[3] ).."' does not exist in group '"..tostring ( arg[2] ).."'", source, 255, 0, 0 )
  782.                 else
  783.                     mdata2 = "ACL '"..arg[3].."'"
  784.                     triggerEvent ( "aAdmin", source, "sync", "aclobjects", arg[2] )
  785.                 end
  786.             elseif ( arg[1] == "right" ) then
  787.                 local acl = aclGet ( arg[2] )
  788.                 local right = arg[3]
  789.                 if ( not aclRemoveRight ( acl, right ) ) then
  790.                     action = nil
  791.                     outputChatBox ( "Error - right '"..tostring ( arg[3] ).."' does not exist in ACL '"..tostring ( arg[2] ).."'", source, 255, 0, 0 )
  792.                 else
  793.                     mdata = "ACL '"..arg[2].."'"
  794.                     mdata2 = "Right '"..arg[3].."'"
  795.                     triggerEvent ( "aAdmin", source, "sync", "aclrights", arg[2] )
  796.                 end
  797.             end
  798.         else
  799.             action = nil
  800.         end
  801.     end
  802.     if ( action ~= nil ) then aAction ( "admin", action, source, false, mdata, mdata2 ) end
  803. end )
  804.  
  805.  
  806. -- seconds to description i.e. "10 mins"
  807. function secondsToTimeDesc( seconds )
  808.     if seconds then
  809.         local tab = { {"day",60*60*24},  {"hour",60*60},  {"min",60},  {"sec",1} }
  810.         for i,item in ipairs(tab) do
  811.             local t = math.floor(seconds/item[2])
  812.             if t > 0 or i == #tab then
  813.                 return tostring(t) .. " " .. item[1] .. (t~=1 and "s" or "")
  814.             end
  815.         end
  816.     end
  817.     return ""
  818. end
  819.  
  820. addEvent ( "aPlayer", true )
  821. addEventHandler ( "aPlayer", _root, function ( player, action, data, additional, additional2 )
  822.     if checkClient( "command."..action, source, 'aPlayer', action ) then return end
  823.     if not isElement( player ) then
  824.         return  -- Ignore if player is no longer valid
  825.     end
  826.     if ( hasObjectPermissionTo ( source, "command."..action ) ) then
  827.         local admin = source
  828.         local mdata = ""
  829.         local more = ""
  830.         if ( action == "kick" ) then
  831.             local reason = data or ""
  832.             mdata = reason~="" and ( "(" .. reason .. ")" ) or ""
  833.             setTimer ( kickPlayer, 100, 1, player, source, reason )
  834.         elseif ( action == "ban" ) then
  835.             local reason = data or ""
  836.             local seconds = tonumber(additional) and tonumber(additional) > 0 and tonumber(additional)
  837.             local bUseSerial = additional2
  838.             mdata = reason~="" and ( "(" .. reason .. ")" ) or ""
  839.             more = seconds and ( "(" .. secondsToTimeDesc(seconds) .. ")" ) or ""
  840.             if bUseSerial and getPlayerName ( player ) then
  841.                 -- Add banned player name to the reason
  842.                 reason = reason .. " (nick: " .. getPlayerName ( player ) .. ")"
  843.             end
  844.             -- Add account name of banner to the reason
  845.             local adminAccountName = getAccountName ( getPlayerAccount ( source ) )
  846.             if adminAccountName and adminAccountName ~= getPlayerName( source ) then
  847.                 reason = reason .. " (by " .. adminAccountName .. ")"
  848.             end
  849.             if bUseSerial then
  850.                 outputChatBox ( "You banned serial " .. getPlayerSerial( player ), source, 255, 100, 70 )
  851.                 setTimer ( addBan, 100, 1, nil, nil, getPlayerSerial(player), source, reason, seconds )
  852.             else
  853.                 outputChatBox ( "You banned IP " .. getPlayerIP( player ), source, 255, 100, 70 )
  854.                 setTimer ( banPlayer, 100, 1, player, true, false, false, source, reason, seconds )
  855.             end
  856.             setTimer( triggerEvent, 1000, 1, "aSync", _root, "bansdirty" )
  857.         elseif ( action == "mute" )  then
  858.             if ( isPlayerMuted ( player ) ) then action = "un"..action end
  859.             local reason = data or ""
  860.             local seconds = tonumber(additional) and tonumber(additional) > 0 and tonumber(additional)
  861.             mdata = reason~="" and ( "(" .. reason .. ")" ) or ""
  862.             more = seconds and ( "(" .. secondsToTimeDesc(seconds) .. ")" ) or ""
  863.             aSetPlayerMuted ( player, not isPlayerMuted ( player ), seconds )
  864.         elseif ( action == "freeze" )  then
  865.             if ( isPlayerFrozen ( player ) ) then action = "un"..action end
  866.             aSetPlayerFrozen ( player, not isPlayerFrozen ( player ) )
  867.         elseif ( action == "nick" )  then
  868.             local playername = getPlayerName(player)
  869.             if setPlayerName( player, data ) then
  870.                 outputChatBox ( "You changed '"..playername.."' to '"..data.."'!", source, 255, 100, 70 )
  871.                 outputChatBox ( "'"..getPlayerName( source ).."' changed your nick to '"..data.."'!", player, 255, 100, 70 )
  872.             else
  873.                 outputChatBox ( "Invalid Nick", source, 255, 0, 0 )
  874.             end
  875.         elseif ( action == "shout" ) then
  876.             local textDisplay = textCreateDisplay ()
  877.             local textItem = textCreateTextItem ( "(ADMIN)"..getPlayerName ( source )..":\n\n"..data, 0.5, 0.5, 2, 255, 100, 50, 255, 4, "center", "center" )
  878.             textDisplayAddText ( textDisplay, textItem )
  879.             textDisplayAddObserver ( textDisplay, player )
  880.             setTimer ( textDestroyTextItem, 5000, 1, textItem )
  881.             setTimer ( textDestroyDisplay, 5000, 1, textDisplay )
  882.         elseif ( action == "sethealth" ) then
  883.             local health = tonumber ( data )
  884.             if ( health ) then
  885.                 if ( health > 200 ) then health = 100 end
  886.                 if ( not setElementHealth ( player, health ) ) then
  887.                     action = nil
  888.                 end
  889.                 mdata = health
  890.             else
  891.                 action = nil
  892.             end
  893.         elseif ( action == "setarmour" ) then
  894.             local armour = tonumber ( data )
  895.             if ( armour ) then
  896.                 if ( armour > 200 ) then armour = 100 end
  897.                 if ( not setPedArmor ( player, armour ) ) then
  898.                     action = nil
  899.                 end
  900.                 mdata = armour
  901.             else
  902.                 action = nil
  903.             end
  904.         elseif ( action == "setskin" ) then
  905.             local vehicle = getPedOccupiedVehicle ( player )
  906.             local jetpack = doesPedHaveJetPack ( player )
  907.             local seat = 0
  908.             if ( vehicle ) then seat = getPedOccupiedVehicleSeat ( player ) end
  909.             local x, y, z = getElementPosition ( player )
  910.             data = tonumber ( data )
  911.             if ( spawnPlayer ( player, x, y, z, getPedRotation ( player ), data, getElementInterior ( player ), getElementDimension ( player ), getPlayerTeam ( player ) ) ) then
  912.                 fadeCamera ( player, true )
  913.                 if ( vehicle ) then warpPedIntoVehicle ( player, vehicle, seat ) end
  914.                 if ( jetpack ) then givePedJetPack ( player ) end
  915.                 mdata = data
  916.             else
  917.                 action = nil
  918.             end
  919.         elseif ( action == "setmoney" ) then
  920.             mdata = data
  921.             if ( not setPlayerMoney ( player, data ) ) then
  922.                 outputChatBox ( "Invalid money data", source, 255, 0, 0 )
  923.                 action = nil
  924.             end
  925.         elseif ( action == "setstat" ) then
  926.             if ( additional ) then
  927.                 if ( tonumber ( data ) == 300 ) then
  928.                     if ( setPedFightingStyle ( player, tonumber ( additional ) ) ) then
  929.                         mdata = "Fighting Style"
  930.                         more = additional
  931.                     else
  932.                         action = nil
  933.                     end
  934.                 else
  935.                     if ( setPedStat ( player, tonumber ( data ), tonumber ( additional ) ) ) then
  936.                         mdata = aStats[data]
  937.                         more = additional
  938.                     else
  939.                         action = nil
  940.                     end
  941.                 end
  942.             else
  943.                 action = nil
  944.             end
  945.         elseif ( action == "setteam" ) then
  946.             if ( getElementType ( data ) == "team" ) then
  947.                 setPlayerTeam ( player, data )
  948.                 mdata = getTeamName ( data )
  949.             else
  950.                 action = nil
  951.             end
  952.         elseif ( action == "removefromteam" ) then
  953.             mdata = getTeamName( getPlayerTeam( player ) )
  954.             setPlayerTeam ( player, nil )
  955.         elseif ( action == "setinterior" ) then
  956.             action = nil
  957.             for id, interior in ipairs ( aInteriors ) do
  958.                 if ( interior["id"] == data ) then
  959.                     local vehicle = getPedOccupiedVehicle ( player )
  960.                     setElementInterior ( player, interior["world"] )
  961.                     local x, y, z = interior["x"] or 0, interior["y"] or 0, interior["z"] or 0
  962.                     local rot = interior["r"] or 0
  963.                     if ( vehicle ) then
  964.                         setElementInterior ( vehicle, interior["world"] )
  965.                         setElementPosition ( vehicle, x, y, z + 0.2 )
  966.                     else
  967.                         setElementPosition ( player, x, y, z + 0.2 )
  968.                         setPedRotation ( player, rot )
  969.                     end
  970.                     action = "interior"
  971.                     mdata = data
  972.                 end
  973.             end
  974.         elseif ( action == "setdimension" ) then
  975.             local dimension = tonumber ( data )
  976.             if ( dimension ) then
  977.                 if ( dimension > 65535 ) or ( dimension < 0 ) then dimension = 0 end
  978.                 if ( not setElementDimension ( player, dimension ) ) then
  979.                     action = nil
  980.                 end
  981.                 mdata = dimension
  982.             else
  983.                 action = nil
  984.             end
  985.         elseif ( action == "jetpack" ) then
  986.             if ( doesPedHaveJetPack ( player ) ) then
  987.                 removePedJetPack ( player )
  988.                 action = "jetpackr"
  989.             else
  990.                 if ( getPedOccupiedVehicle ( player ) ) then outputChatBox ( "Unable to give a jetpack - "..getPlayerName ( player ).." is in a vehicle", source, 255, 0, 0 )
  991.                 else
  992.                     if ( givePedJetPack ( player ) ) then
  993.                         action = "jetpacka"
  994.                     end
  995.                 end
  996.             end
  997.         elseif ( action == "setgroup" ) then
  998.             local account = getPlayerAccount ( player )
  999.             if ( not isGuestAccount ( account ) ) then
  1000.                 local group = aclGetGroup ( "Admin" )
  1001.                 if ( group ) then
  1002.                     if ( data == true ) then
  1003.                         aclGroupAddObject ( group, "user."..getAccountName ( account ) )
  1004.                         bindKey ( player, "p", "down", "admin" )
  1005.                         action = "admina"
  1006.                     elseif ( data == false ) then
  1007.                         unbindKey ( player, "p", "down", "admin" )
  1008.                         aclGroupRemoveObject ( group, "user."..getAccountName ( account ) )
  1009.                         aPlayers[player]["chat"] = false
  1010.                         action = "adminr"
  1011.                     end
  1012.                     for id, p in ipairs ( getElementsByType ( "player" ) ) do
  1013.                         if ( hasObjectPermissionTo ( p, "general.adminpanel" ) ) then triggerEvent ( "aSync", p, "admins" ) end
  1014.                     end
  1015.                 else
  1016.                     outputChatBox ( "Error - Admin group not initialized. Please reinstall admin resource.", source, 255, 0 ,0 )
  1017.                 end
  1018.             else
  1019.                 outputChatBox ( "Error - Player is not logged in.", source, 255, 100 ,100 )
  1020.             end
  1021.         elseif ( action == "givevehicle" ) then
  1022.             local vehicle = getPedOccupiedVehicle ( player )
  1023.             if ( vehicle ) then
  1024.                 setElementModel(vehicle, data)
  1025.                 fixVehicle(vehicle)
  1026.             else
  1027.                 local x, y, z = getElementPosition ( player )
  1028.                 local r = getPedRotation ( player )
  1029.                 local vx, vy, vz = getElementVelocity ( player )
  1030.                 vehicle = createVehicle ( data, x, y, z, 0, 0, r )
  1031.                 setElementDimension ( vehicle, getElementDimension ( player ) )
  1032.                 setElementInterior ( vehicle, getElementInterior ( player ) )
  1033.                 warpPedIntoVehicle ( player, vehicle )
  1034.                 setElementVelocity ( vehicle, vx, vy, vz )
  1035.             end
  1036.             mdata = getVehicleName ( vehicle )
  1037.         elseif ( action == "giveweapon" ) then
  1038.             if ( giveWeapon ( player, data, additional, true ) ) then
  1039.                 mdata = getWeaponNameFromID ( data )
  1040.                 more = additional
  1041.             else
  1042.                 action = nil
  1043.             end
  1044.         elseif ( action == "slap" ) then
  1045.             if ( getElementHealth ( player ) > 0 ) and ( not isPedDead ( player ) ) then
  1046.                 if ( ( not data ) or ( not tonumber ( data ) ) ) then data = 20 end
  1047.                 if ( ( tonumber ( data ) >= 0 ) ) then
  1048.                     if ( tonumber ( data ) > getElementHealth ( player ) ) then setTimer ( killPed, 50, 1, player )
  1049.                     else setElementHealth ( player, getElementHealth ( player ) - data ) end
  1050.                     local x, y, z = getElementVelocity ( player )
  1051.                     setElementVelocity ( player, x , y, z + 0.2 )
  1052.                     mdata = data
  1053.                 else
  1054.                     action = nil
  1055.                 end
  1056.             else
  1057.                 action = nil
  1058.             end
  1059.         elseif ( action == "warp" ) or ( action == "warpto" ) then
  1060.                 function warpPlayer ( p, to )
  1061.                 function warp ( p, to )
  1062.                     local x, y, z = getElementPosition ( to )
  1063.                     local r = getPedRotation ( to )
  1064.                     x = x - math.sin ( math.rad ( r ) ) * 2
  1065.                     y = y + math.cos ( math.rad ( r ) ) * 2
  1066.                     setTimer ( setElementPosition, 1000, 1, p, x, y, z + 1 )
  1067.                     fadeCamera ( p, false, 1, 0, 0, 0 )
  1068.                     setElementDimension ( p, getElementDimension ( to ) )
  1069.                     setElementInterior ( p, getElementInterior ( to ) )
  1070.                     setTimer ( fadeCamera, 1000, 1, p, true, 1 )
  1071.                 end
  1072.                 if ( isPedInVehicle ( to ) ) then
  1073.                     local vehicle = getPedOccupiedVehicle ( to )
  1074.                     local seats = getVehicleMaxPassengers ( vehicle ) + 1
  1075.                     local i = 0
  1076.                     while ( i < seats ) do
  1077.                         if ( not getVehicleOccupant ( vehicle, i ) ) then
  1078.                             setTimer ( warpPedIntoVehicle, 1000, 1, p, vehicle, i )
  1079.                             fadeCamera ( p, false, 1, 0, 0, 0 )
  1080.                             setTimer ( fadeCamera, 1000, 1, p, true, 1 )
  1081.                             break
  1082.                         end
  1083.                         i = i + 1
  1084.                     end
  1085.                     if ( i >= seats ) then
  1086.                         warp ( p, to )
  1087.                         outputConsole ( "Player's vehicle is full ("..getVehicleName ( vehicle ).." - Seats: "..seats..")", p )
  1088.                     end
  1089.                 else
  1090.                     warp ( p, to )
  1091.                 end
  1092.             end
  1093.             if ( action == "warp" ) then
  1094.                 warpPlayer ( source, player )
  1095.             else
  1096.                 warpPlayer ( player, data )
  1097.                 mdata = getPlayerName ( data )
  1098.             end
  1099.         else
  1100.             action = nil
  1101.         end
  1102.         if ( action ~= nil ) then aAction ( "player", action, admin, player, mdata, more ) end
  1103.         return true
  1104.     end
  1105.     outputChatBox ( "Access denied for '"..tostring ( action ).."'", source, 255, 168, 0 )
  1106.     return false
  1107. end )
  1108.  
  1109. addEvent ( "aVehicle", true )
  1110. addEventHandler ( "aVehicle", _root, function ( player, action, data )
  1111.     if checkClient( "command."..action, source, 'aVehicle', action ) then return end
  1112.     if ( hasObjectPermissionTo ( source, "command."..action ) ) then
  1113.         if ( not player ) then return end
  1114.         local vehicle = getPedOccupiedVehicle ( player )
  1115.         if ( vehicle ) then
  1116.             local mdata = ""
  1117.             if ( action == "repair" ) then
  1118.                 fixVehicle ( vehicle )
  1119.                 local rx, ry, rz = getVehicleRotation ( vehicle )
  1120.                 if ( rx > 110 ) and ( rx < 250 ) then
  1121.                     local x, y, z = getElementPosition ( vehicle )
  1122.                     setVehicleRotation ( vehicle, rx + 180, ry, rz )
  1123.                     setElementPosition ( vehicle, x, y, z + 2 )
  1124.                 end
  1125.             elseif ( action == "customize" ) then
  1126.                 if ( data[1] == "remove" ) then
  1127.                     for id, upgrade in ipairs ( getVehicleUpgrades ( vehicle ) ) do
  1128.                         removeVehicleUpgrade ( vehicle, upgrade )
  1129.                     end
  1130.                     action = "customizer"
  1131.                 else
  1132.                     for id, upgrade in ipairs ( data ) do
  1133.                         addVehicleUpgrade ( vehicle, upgrade )
  1134.                         if ( mdata == "" ) then mdata = tostring ( upgrade )
  1135.                         else mdata = mdata..", "..upgrade end
  1136.                     end
  1137.                 end
  1138.             elseif ( action == "setpaintjob" ) then
  1139.                 mdata = data
  1140.                 if ( not setVehiclePaintjob ( vehicle, data ) ) then
  1141.                     action = nil
  1142.                     outputChatBox ( "Invalid Paint job ID", source, 255, 0, 0 )
  1143.                 end
  1144.             elseif ( action == "setcolor" ) then
  1145.                 for k, color in ipairs ( data ) do
  1146.                     local c = tonumber ( color )
  1147.                     if ( c ) then
  1148.                         if ( c < 0 ) or ( c > 126 ) then
  1149.                             action = nil
  1150.                         end
  1151.                     else
  1152.                         action = nil
  1153.                     end
  1154.                 end
  1155.                 if ( action ~= nil ) then
  1156.                     if ( not setVehicleColor ( vehicle, tonumber(data[1]), tonumber(data[2]), tonumber(data[3]), tonumber(data[4]) ) ) then
  1157.                         action = nil
  1158.                     end
  1159.                 end
  1160.             elseif ( action == "blowvehicle" ) then
  1161.                 setTimer ( blowVehicle, 100, 1, vehicle )
  1162.             elseif ( action == "destroyvehicle" ) then
  1163.                 setTimer ( destroyElement, 100, 1, vehicle )
  1164.             else
  1165.                 action = nil
  1166.             end
  1167.             if ( action ~= nil ) then
  1168.                 local seats = getVehicleMaxPassengers ( vehicle )
  1169.                 if seats then
  1170.                     for i = 0, seats do
  1171.                         local passenger = getVehicleOccupant ( vehicle, i )
  1172.                         if ( passenger ) then
  1173.                             aAction ( "vehicle", action, source, passenger, mdata )
  1174.                         end
  1175.                     end
  1176.                 end
  1177.             end
  1178.         end
  1179.         return true
  1180.     end
  1181.     outputChatBox ( "Access denied for '"..tostring ( action ).."'", source, 255, 168, 0 )
  1182.     return false
  1183. end )
  1184.  
  1185. addEvent ( "aResource", true )
  1186. addEventHandler ( "aResource", _root, function ( name, action )
  1187.     if checkClient( "command."..action, source, 'aResource', action ) then return end
  1188.     local pname = getPlayerName ( source )
  1189.     if ( hasObjectPermissionTo ( source, "command."..action ) ) then
  1190.         local text = ""
  1191.         if ( action == "start" ) then if ( startResource ( getResourceFromName ( name ), true ) ) then text = "started" end
  1192.         elseif ( action == "restart" ) then if ( restartResource ( getResourceFromName ( name ) ) ) then text = "restarted" end
  1193.         elseif ( action == "stop" ) then if ( stopResource ( getResourceFromName ( name ) ) ) then text = "stopped" end
  1194.         else action = nil
  1195.         end
  1196.         if ( text ~= "" ) then
  1197.             outputServerLog ( "ADMIN: Resource \'" .. name .. "\' " .. text .. " by " .. getAdminNameForLog ( source )  )
  1198.             for id, player in ipairs(getElementsByType("player")) do
  1199.                 triggerClientEvent ( player, "aClientLog", _root, text  )
  1200.             end
  1201.         end
  1202.         return true
  1203.     end
  1204.     outputChatBox ( "Access denied for '"..tostring ( action ).."'", source, 255, 168, 0 )
  1205.     return false
  1206. end )
  1207.  
  1208. addEvent ( "aServer", true )
  1209. addEventHandler ( "aServer", _root, function ( action, data, data2 )
  1210.     if checkClient( "command."..action, source, 'aServer', action ) then return end
  1211.     if ( hasObjectPermissionTo ( source, "command."..action ) ) then
  1212.         local mdata = tostring ( data )
  1213.         local mdata2 = ""
  1214.         if ( action == "setgame" ) then
  1215.             if ( not setGameType ( tostring ( data ) ) ) then
  1216.                 action = nil
  1217.                 outputChatBox ( "Error setting game type.", source, 255, 0, 0 )
  1218.             end
  1219.             triggerEvent ( "aSync", source, "server" )
  1220.         elseif ( action == "setmap" ) then
  1221.             if ( not setMapName ( tostring ( data ) ) ) then
  1222.                 action = nil
  1223.                 outputChatBox ( "Error setting map name.", source, 255, 0, 0 )
  1224.             end
  1225.             triggerEvent ( "aSync", source, "server" )
  1226.         elseif ( action == "setwelcome" ) then
  1227.             if ( ( not data ) or ( data == "" ) ) then
  1228.                 action = "resetwelcome"
  1229.                 aRemoveSetting ( "welcome" )
  1230.             else
  1231.                 aSetSetting ( "welcome", tostring ( data ) )
  1232.                 mdata = data
  1233.             end
  1234.         elseif ( action == "settime" ) then
  1235.             if ( not setTime ( tonumber ( data ), tonumber ( data2 ) ) ) then
  1236.                 action = nil
  1237.                 outputChatBox ( "Error setting time.", source, 255, 0, 0 )
  1238.             end
  1239.             mdata = data..":"..data2
  1240.         elseif ( action == "setpassword" ) then
  1241.             if ( not data or data == "" ) then
  1242.                 setServerPassword ( nil )
  1243.                 action = "resetpassword"
  1244.             elseif ( string.len ( data ) > 32 ) then
  1245.                 outputChatBox ( "Set password: 32 characters max", source, 255, 0, 0 )
  1246.             elseif ( not setServerPassword ( data ) ) then
  1247.                 action = nil
  1248.                 outputChatBox ( "Error setting password", source, 255, 0, 0 )
  1249.             end
  1250.             triggerEvent ( "aSync", source, "server" )
  1251.         elseif ( action == "setweather" ) then
  1252.             if ( not setWeather ( tonumber ( data ) ) ) then
  1253.                 action = nil
  1254.                 outputChatBox ( "Error setting weather.", source, 255, 0, 0 )
  1255.             end
  1256.             mdata = data.." "..getWeatherNameFromID ( tonumber ( data ) )
  1257.         elseif ( action == "blendweather" ) then
  1258.             if ( not setWeatherBlended ( tonumber ( data ) ) ) then
  1259.                 action = nil
  1260.                 outputChatBox ( "Error setting weather.", source, 255, 0, 0 )
  1261.             end
  1262.         elseif ( action == "setgamespeed" ) then
  1263.             if ( not setGameSpeed ( tonumber ( data ) ) ) then
  1264.                 action = nil
  1265.                 outputChatBox ( "Error setting game speed.", source, 255, 0, 0 )
  1266.             end
  1267.         elseif ( action == "setgravity" ) then
  1268.             if ( setGravity ( tonumber ( data ) ) ) then
  1269.                 for id, player in ipairs ( getElementsByType ( "player" ) ) do
  1270.                     setPedGravity ( player, getGravity() )
  1271.                 end
  1272.             else
  1273.                 action = nil
  1274.                 outputChatBox ( "Error setting gravity.", source, 255, 0, 0 )
  1275.             end
  1276.         elseif ( action == "setwaveheight" ) then
  1277.             if ( not setWaveHeight ( data ) ) then
  1278.                 outputChatBox ( "Error setting wave height.", source, 255, 0, 0 )
  1279.                 action = nil
  1280.             else
  1281.                 mdata = data
  1282.             end
  1283.         else
  1284.             action = nil
  1285.         end
  1286.         if ( action ~= nil ) then aAction ( "server", action, source, false, mdata, mdata2 ) end
  1287.         return true
  1288.     end
  1289.     outputChatBox ( "Access denied for '"..tostring ( action ).."'", source, 255, 168, 0 )
  1290.     return false
  1291. end )
  1292.  
  1293. addEvent ( "aMessage", true )
  1294. addEventHandler ( "aMessage", _root, function ( action, data )
  1295.     if checkClient( false, source, 'aMessage', action ) then return end
  1296.     if ( action == "new" ) then
  1297.         local time = getRealTime()
  1298.         local id = #aReports + 1
  1299.         aReports[id] = {}
  1300.         aReports[id].author = getPlayerName ( source )
  1301.         aReports[id].category = tostring ( data.category )
  1302.         aReports[id].subject = tostring ( data.subject )
  1303.         aReports[id].text = tostring ( data.message )
  1304.         aReports[id].time = string.format( '%04d-%02d-%02d %02d:%02d', time.year + 1900, time.month + 1, time.monthday, time.hour, time.minute )
  1305.         aReports[id].read = false
  1306.         -- PM all admins to say a new message has arrived
  1307.         for _, p in ipairs ( getElementsByType ( "player" ) ) do
  1308.             if ( hasObjectPermissionTo ( p, "general.adminpanel" ) ) then
  1309.                 outputChatBox( "New Admin message from " .. aReports[id].author .. " (" .. aReports[id].subject .. ")", p, 255, 0, 0 )
  1310.             end
  1311.         end
  1312.         -- Keep message count no greater that 'maxmsgs'
  1313.         while #aReports > g_Prefs.maxmsgs do
  1314.             table.remove( aReports, 1 )
  1315.         end
  1316.     end
  1317.     if ( hasObjectPermissionTo ( source, "general.adminpanel" ) ) then
  1318.         if ( action == "get" ) then
  1319.             triggerClientEvent ( source, "aMessage", source, "get", aReports )
  1320.         elseif ( action == "read" ) then
  1321.             if ( aReports[data] ) then
  1322.                 aReports[data].read = true
  1323.             end
  1324.         elseif ( action == "delete" ) then
  1325.             if ( aReports[data] ) then
  1326.                 table.remove ( aReports, data )
  1327.             end
  1328.             triggerClientEvent ( source, "aMessage", source, "get", aReports )
  1329.         else
  1330.             action = nil
  1331.         end
  1332.     end
  1333.     for id, p in ipairs ( getElementsByType ( "player" ) ) do
  1334.         if ( hasObjectPermissionTo ( p, "general.adminpanel" ) ) then triggerEvent ( "aSync", p, "messages" ) end
  1335.     end
  1336. end )
  1337.  
  1338. addEvent ( "aBans", true )
  1339. addEventHandler ( "aBans", _root, function ( action, data )
  1340.     if checkClient( "command."..action, source, 'aBans', action ) then return end
  1341.     if ( hasObjectPermissionTo ( source, "command."..action ) ) then
  1342.         local mdata = ""
  1343.         local more = ""
  1344.         if ( action == "banip" ) then
  1345.             mdata = data
  1346.             if ( not addBan ( data,nil,nil,source ) ) then
  1347.                 action = nil
  1348.             end
  1349.         elseif ( action == "banserial" ) then
  1350.             mdata = data
  1351.             if ( isValidSerial ( data ) ) then
  1352.                 if ( not addBan ( nil,nil, string.upper ( data ),source ) ) then
  1353.                     action = nil
  1354.                 end
  1355.             else
  1356.                 outputChatBox ( "Error - Invalid serial", source, 255, 0, 0 )
  1357.                 action = nil
  1358.             end
  1359.         elseif ( action == "unbanip" ) then
  1360.             mdata = data
  1361.             action = nil
  1362.             for i,ban in ipairs(getBans ()) do
  1363.                 if getBanIP(ban) == data then
  1364.                     action = removeBan ( ban, source )
  1365.                 end
  1366.             end
  1367.         elseif ( action == "unbanserial" ) then
  1368.             mdata = data
  1369.             action = nil
  1370.             for i,ban in ipairs(getBans ()) do
  1371.                 if getBanSerial(ban) == string.upper(data) then
  1372.                     action = removeBan ( ban, source )
  1373.                 end
  1374.             end
  1375.         else
  1376.             action = nil
  1377.         end
  1378.    
  1379.         if ( action ~= nil ) then
  1380.             aAction ( "bans", action, source, false, mdata, more )
  1381.             triggerEvent ( "aSync", source, "sync", "bansdirty" )
  1382.         end
  1383.         return true
  1384.     end
  1385.     outputChatBox ( "Access denied for '"..tostring ( action ).."'", source, 255, 168, 0 )
  1386.     return false
  1387. end )
  1388.  
  1389. addEvent ( "aExecute", true )
  1390. addEventHandler ( "aExecute", _root, function ( action, echo )
  1391.     if checkClient( "command.execute", source, 'aExecute', action ) then return end
  1392.     if ( hasObjectPermissionTo ( source, "command.execute" ) ) then
  1393.         local result = loadstring("return " .. action)()
  1394.         if ( echo == true ) then
  1395.             local restring = ""
  1396.             if ( type ( result ) == "table" ) then
  1397.                 for k,v in pairs ( result ) do restring = restring..tostring ( v )..", " end
  1398.                 restring = string.sub(restring,1,-3)
  1399.                 restring = "Table ("..restring..")"
  1400.             elseif ( type ( result ) == "userdata" ) then
  1401.                 restring = "Element ("..getElementType ( result )..")"
  1402.             else
  1403.                 restring = tostring ( result )
  1404.             end
  1405.             outputChatBox( "Command executed! Result: " ..restring, source, 0, 0, 255 )
  1406.         end
  1407.         outputServerLog ( "ADMIN: "..getAdminNameForLog ( source ).." executed command: "..action )
  1408.     end
  1409. end )
  1410.  
  1411. addEvent ( "aAdminChat", true )
  1412. addEventHandler ( "aAdminChat", _root, function ( chat )
  1413.     if checkClient( true, source, 'aAdminChat' ) then return end
  1414.     for id, player in ipairs(getElementsByType("player")) do
  1415.         if ( aPlayers[player]["chat"] ) then
  1416.             triggerClientEvent ( player, "aClientAdminChat", source, chat )
  1417.         end
  1418.     end
  1419. end )
  1420.  
  1421. addEventHandler('onElementDataChange', root,
  1422.     function(dataName, oldValue )
  1423.         if getElementType(source)=='player' and checkClient( false, source, 'onElementDataChange', dataName ) then
  1424.             setElementData( source, dataName, oldValue )
  1425.             return
  1426.         end
  1427.     end
  1428. )
  1429.  
  1430. -- returns true if there is trouble
  1431. function checkClient(checkAccess,player,...)
  1432.     if client and client ~= player and g_Prefs.securitylevel >= 2 then
  1433.         local desc = table.concat({...}," ")
  1434.         local ipAddress = getPlayerIP(client)
  1435.         outputDebugString( "Admin security - Client/player mismatch from " .. tostring(ipAddress) .. " (" .. tostring(desc) .. ")", 1 )
  1436.         cancelEvent()
  1437.         if g_Prefs.clientcheckban then
  1438.             local reason = "admin checkClient (" .. tostring(desc) .. ")"
  1439.             addBan ( ipAddress, nil, nil, getRootElement(), reason )
  1440.         end
  1441.         return true
  1442.     end
  1443.     if checkAccess and g_Prefs.securitylevel >= 1 then
  1444.         if type(checkAccess) == 'string' then
  1445.             if hasObjectPermissionTo ( player, checkAccess ) then
  1446.                 return false    -- Access ok
  1447.             end
  1448.             if hasObjectPermissionTo ( player, "general.adminpanel" ) then
  1449.                 outputDebugString( "Admin security - Client does not have required rights ("..checkAccess.."). " .. tostring(ipAddress) .. " (" .. tostring(desc) .. ")" )
  1450.                 return true     -- Low risk fail - Can't do specific command, but has access to admin panel
  1451.             end
  1452.         end
  1453.         if not hasObjectPermissionTo ( player, "general.adminpanel" ) then
  1454.             local desc = table.concat({...}," ")
  1455.             local ipAddress = getPlayerIP(client or player)
  1456.             outputDebugString( "Admin security - Client without admin panel rights trigged an admin panel event. " .. tostring(ipAddress) .. " (" .. tostring(desc) .. ")", 2 )
  1457.             return true         -- High risk fail - No access to admin panel
  1458.         end
  1459.     end
  1460.     return false
  1461. end
  1462.  
  1463. function checkNickOnChange(old, new)
  1464.     if aNickChangeTime[source] and aNickChangeTime[source] + tonumber(get("*nickChangeDelay")) > getTickCount() then
  1465.         cancelEvent()
  1466.         outputChatBox("You can only change your name once every "..(tonumber(get("*nickChangeDelay"))/1000).." seconds", source, 255, 0, 0)
  1467.         return false
  1468.     else
  1469.         aNickChangeTime[source] = getTickCount()
  1470.     end
  1471. end
  1472. addEventHandler("onPlayerChangeNick", root, checkNickOnChange)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement