--[[********************************** * * Multi Theft Auto - Admin Panel * * gui\admin_spectator.lua * * Original File by lil_Toady * **************************************]] aSpectating = nil aSpecActions = nil function aSpectate ( player ) if ( player == getLocalPlayer() ) then aMessageBox ( "error", "You can not spectate yourself." ) else bindKey ( "arrow_l", "down", aSpecPlayerPrev ) bindKey ( "arrow_r", "down", aSpecPlayerNext ) aSpectating = player --if ( getPlayerOccupiedVehicle ( player ) ) then -- toggleCameraFixedMode ( false ) -- setCameraTarget ( getPlayerOccupiedVehicle ( player ) ) --else toggleCameraFixedMode ( false ) setCameraTarget ( player ) --end aSetSpectatorEnabled ( true ) end end function aSetSpectatorEnabled ( state ) if ( aSpecActions == nil ) then local x, y = guiGetScreenSize() aSpecActions = guiCreateWindow ( x - 190, y / 2 - 200, 160, 400, "Actions", false ) aSpecBan = guiCreateButton ( 0.10, 0.09, 0.80, 0.05, "Ban", true, aSpecActions ) aSpecKick = guiCreateButton ( 0.10, 0.15, 0.80, 0.05, "Kick", true, aSpecActions ) aSpecFreeze = guiCreateButton ( 0.10, 0.21, 0.80, 0.05, "Freeze", true, aSpecActions ) aSpecSetSkin = guiCreateButton ( 0.10, 0.27, 0.80, 0.05, "Set Skin", true, aSpecActions ) aSpecSetHealth = guiCreateButton ( 0.10, 0.33, 0.80, 0.05, "Set Health", true, aSpecActions ) aSpecSetArmour = guiCreateButton ( 0.10, 0.39, 0.80, 0.05, "Set Armour", true, aSpecActions ) aSpecSetStats = guiCreateButton ( 0.10, 0.45, 0.80, 0.05, "Set Stats", true, aSpecActions ) aSpecSlap = guiCreateButton ( 0.10, 0.51, 0.80, 0.05, "Slap! "..aCurrentSlap.."hp", true, aSpecActions ) aSpecSlaps = guiCreateGridList ( 0.10, 0.51, 0.80, 0.48, true, aSpecActions ) guiGridListAddColumn( aSpecSlaps, "", 0.85 ) guiSetVisible ( aSpecSlaps, false ) local i = 0 while i <= 10 do guiGridListSetItemText ( aSpecSlaps, guiGridListAddRow ( aSpecSlaps ), 1, tostring ( i * 10 ), false, false ) i = i + 1 end aSpecSkip = guiCreateCheckBox ( 0.08, 0.85, 0.84, 0.04, "Skip dead players", true, true, aSpecActions ) guiCreateLabel ( 0.08, 0.89, 0.84, 0.04, "____________________", true, aSpecActions ) aSpecBack = guiCreateButton ( 0.10, 0.93, 0.80, 0.05, "Back", true, aSpecActions ) aSpecPlayers = guiCreateWindow ( 30, y / 2 - 200, 160, 400, "Players", false ) guiWindowSetSizable ( aSpecPlayers, false ) aSpecPlayerList = guiCreateGridList ( 0.03, 0.07, 0.94, 0.92, true, aSpecPlayers ) guiGridListAddColumn( aSpecPlayerList, "Player Name", 0.85 ) for id, player in ipairs ( getElementsByType ( "player" ) ) do local row = guiGridListAddRow ( aSpecPlayerList ) guiGridListSetItemText ( aSpecPlayerList, row, 1, getPlayerName ( player ), false, false ) if ( player == aSpectating ) then guiGridListSetSelectedItem ( aSpecPlayerList, row, 1 ) end end aSpecPrev = guiCreateButton ( x / 2 - 100, y - 50, 70, 30, "< Previous", false ) aSpecNext = guiCreateButton ( x / 2 + 30, y - 50, 70, 30, "Next >", false ) addEventHandler ( "onClientGUIClick", _root, aSpecClientClick ) addEventHandler ( "onClientGUIDoubleClick", _root, aSpecClientDoubleClick ) addEventHandler ( "onClientPlayerWasted", _root, aSpecPlayerCheck ) addEventHandler ( "onClientPlayerQuit", _root, aSpecPlayerCheck ) addEventHandler ( "onClientVehicleEnter", _root, aSpecVehicleEnter ) addEventHandler ( "onClientVehicleExit", _root, aSpecVehicleExit ) aRegister ( "Spectator", aSpecActions, aSpectator, aSpectatorClose ) end guiSetVisible ( aSpecActions, true ) guiSetVisible ( aSpecPlayers, true ) guiSetVisible ( aSpecPrev, true ) guiSetVisible ( aSpecNext, true ) aAdminMenuClose ( false ) end function aSpectatorClose ( destroy ) unbindKey ( "arrow_l", "down", aSpecPlayerPrev ) unbindKey ( "arrow_r", "down", aSpecPlayerNext ) if ( ( destroy ) or ( guiCheckBoxGetSelected ( aPerformanceSpectator ) ) ) then if ( aSpecActions ) then removeEventHandler ( "onClientGUIClick", _root, aSpecClientClick ) removeEventHandler ( "onClientGUIDoubleClick", _root, aSpecClientDoubleClick ) removeEventHandler ( "onClientPlayerWasted", _root, aSpecPlayerCheck ) removeEventHandler ( "onClientPlayerQuit", _root, aSpecPlayerCheck ) removeEventHandler ( "onClientVehicleEnter", _root, aSpecVehicleEnter ) removeEventHandler ( "onClientVehicleExit", _root, aSpecVehicleExit ) destroyElement ( aSpecActions ) destroyElement ( aSpecPlayers ) destroyElement ( aSpecPrev ) destroyElement ( aSpecNext ) aSpecActions = nil end else setCameraTarget ( getLocalPlayer() ) toggleCameraFixedMode ( false ) guiSetVisible ( aSpecActions, false ) guiSetVisible ( aSpecPlayers, false ) guiSetVisible ( aSpecPrev, false ) guiSetVisible ( aSpecNext, false ) aSpectating = nil end aAdminMenu() end function aSpecClientDoubleClick ( button ) if ( source == aSpecSlaps ) then if ( guiGridListGetSelectedItem ( aSpecSlaps ) ~= -1 ) then aCurrentSlap = guiGridListGetItemText ( aSpecSlaps, guiGridListGetSelectedItem ( aSpecSlaps ), 1 ) guiSetText ( aTab1.Slap, "Slap! "..aCurrentSlap.."hp" ) guiSetText ( aSpecSlap, "Slap! "..aCurrentSlap.."hp" ) end guiSetVisible ( aSpecSlaps, false ) end end function aSpecClientClick ( button ) if ( source == aSpecSlaps ) then return end guiSetVisible ( aSpecSlaps, false ) if ( button == "left" ) then if ( source == aSpecBack ) then aSpectatorClose ( false ) elseif ( source == aSpecBan ) then triggerEvent ( "onClientGUIClick", aTab1.Ban, "left" ) elseif ( source == aSpecKick ) then triggerEvent ( "onClientGUIClick", aTab1.Kick, "left" ) elseif ( source == aSpecFreeze ) then triggerEvent ( "onClientGUIClick", aTab1.Freeze, "left" ) elseif ( source == aSpecSetSkin ) then triggerEvent ( "onClientGUIClick", aTab1.SetSkin, "left" ) elseif ( source == aSpecSetHealth ) then triggerEvent ( "onClientGUIClick", aTab1.SetHealth, "left" ) elseif ( source == aSpecSetArmour ) then triggerEvent ( "onClientGUIClick", aTab1.SetArmour, "left" ) elseif ( source == aSpecSetStats ) then triggerEvent ( "onClientGUIClick", aTab1.SetStats, "left" ) elseif ( source == aSpecSlap ) then triggerEvent ( "onClientGUIClick", aTab1.Slap, "left" ) elseif ( source == aSpecNext ) then aSpecPlayerNext() elseif ( source == aSpecPrev ) then aSpecPlayerPrev() elseif ( source == aSpecPlayerList ) then if ( guiGridListGetSelectedItem ( source ) ~= -1 ) then aSpectate ( getPlayerFromNick ( guiGridListGetItemText ( source, guiGridListGetSelectedItem ( source ), 1 ) ) ) end end elseif ( button == "right" ) then if ( source == aSpecSlap ) then guiSetVisible ( aSpecSlaps, true ) end end end function aSpecPlayerCheck () if ( source == aSpectating ) then aSpecPlayerNext() end end function aSpecVehicleEnter ( player, seat ) if ( player == aSpectating ) then --outputChatBox ( "in a vehicle" ) aSetSpectatorEnabled ( true ) toggleCameraFixedMode ( false ) local success = setCameraTarget ( player ) outputChatBox( tostring(success) ) end end function aSpecVehicleExit ( player, seat ) if ( player == aSpectating ) then --outputChatBox ( "out a vehicle" ) aSpectate ( player ) end end function aSpecPlayerNext () local players = getElementsByType ( "player" ) if ( guiCheckBoxGetSelected ( aSpecSkip ) ) then local alive = aSpecGetAlive() if ( #alive <= 0 ) then aSpectatorClose ( false ) toggleCameraFixedMode ( false ) setCameraTarget ( getLocalPlayer() ) aMessageBox ( "warning", "Nobody to spectate" ) else local current = 0 for id, player in ipairs ( players ) do if ( player == aSpectating ) then current = id end if ( current > 0 ) then if ( isPlayerDead ( player ) == false ) then aSpectate ( player ) return end end end aSpectate ( alive[1] ) end else if ( #players == 1 ) then aSpectatorClose ( false ) toggleCameraFixedMode ( false ) setCameraTarget ( getLocalPlayer() ) else for id, player in ipairs ( players ) do if ( player == aSpectating ) then local next = id + 1 if ( next > #players ) then next = 1 end aSpectate ( players[next] ) return end end end end end function aSpecPlayerPrev () local players = getElementsByType ( "player" ) if ( guiCheckBoxGetSelected ( aSpecSkip ) ) then local alive = aSpecGetAlive() if ( #alive <= 0 ) then aSpectatorClose ( false ) toggleCameraFixedMode ( false ) setCameraTarget ( getLocalPlayer() ) aMessageBox ( "warning", "Nobody to spectate" ) else local last = nil for id, player in ipairs ( players ) do if ( player == aSpectating ) then if ( last ~= nil ) then aSpectate ( last ) end return end if ( isPlayerDead ( player ) == false ) then last = player end end aSpectate ( alive[#alive] ) end else if ( #players == 1 ) then aSpectatorClose ( false ) toggleCameraFixedMode ( false ) setCameraTarget ( getLocalPlayer() ) else for id, player in ipairs ( players ) do if ( player == aSpectating ) then local next = id - 1 if ( next <= 0 ) then next = #players end aSpectate ( players[next] ) return end end end end end function aSpecGetAlive () local alive = {} local i = 1 for id, player in ipairs ( getElementsByType ( "player" ) ) do if ( ( not isPlayerDead ( player ) ) and ( player ~= getLocalPlayer() ) ) then alive[i] = player i = i + 1 end end return alive end