George2 Posted April 13, 2014 Share Posted April 13, 2014 Hi guys , i have a script who show who spectate you it look like : But i want to make it look like : There is the script : Spectators_base_c.lua--[[ * Multi Theft Auto - Spectators * spectators_base_c.lua * Version 2 from October 2013 * Original file by thisisdoge --]] addEventHandler ('onClientResourceStart', resourceRoot, function () -- Whenever the local player is targeted/spectated by someone addEvent ('onClientPlayerTargeted', true) -- Similarly whenever local player is untargeted addEvent ('onClientPlayerUnTargeted', true) end ) Spectators_draw_c.lua--[[ * Multi Theft Auto - Spectators * spectators_draw_c.lua * Version 2 from October 2013 * Original file by thisisdoge --]] --[[ This file draws a list of players spectating you, at the absolute right side of the screen, relatively half way down. Simply remove this file and the entry from meta.xml to draw this yourself. Read spectators_base_c.lua for the events to hook, or use this file as reference. ** ALWAYS ** Remember to verify the validity of a player element. MTA occassionally reuses pointers. Don't rely on the server to call onClientPlayerUnTargeted. See the example below. --]] local pl_Spectators = {} local screenWidth, screenHeight = guiGetScreenSize () function elementCheck (el) return el and isElement(el) and (getElementType(el) == 'player') end addEventHandler ('onClientResourceStart', resourceRoot, function () addEventHandler ('onClientPlayerTargeted', localPlayer, function (pl_Spectator) if (elementCheck(pl_Spectator)) then table.insert (pl_Spectators, pl_Spectator) end end ) addEventHandler ('onClientPlayerUnTargeted', localPlayer, function (pl_Spectator) for key, spec in ipairs (pl_Spectators) do if (spec == pl_Spectator) then table.remove (pl_Spectators, key) end end end ) end ) function cutString (strText, width, options) local str = '' for i = 1, #strText do str = str .. strText:sub (i, i) if (dxGetTextWidth(str, options.scale, options.font) >= width) then str = str .. '..' break end end return str end addEventHandler ('onClientRender', root, function () local str_ToDraw = '' if (#pl_Spectators > 0) then str_ToDraw = str_ToDraw .. 'Spectators:\n' end for key, pl_Spectator in ipairs (pl_Spectators) do if (not elementCheck(pl_Spectator)) then table.remove (pl_Spectators, key) else local pl_Name = getPlayerName (pl_Spectator) pl_Name = cutString (pl_Name, 130, {scale = 0.6, font = 'bankgothic'}) -- second argument = Max. length of a player name before cutting if off (pixels). if (key > 12) then -- Max. amount of players to list str_ToDraw = str_ToDraw .. 'and ' .. (#pl_Spectators-12) .. ' others' break else str_ToDraw = str_ToDraw .. pl_Name .. '\n' end end end dxDrawText (str_ToDraw, screenWidth - 175, -- Left Offset in pixels from the right screenHeight * 0.4, -- Top position in pixels 0, 0, tocolor(255, 255, 255, 210), 0.6, 'bankgothic', nil, nil, false, false, false) end ) Spectators_s.lua--[[ * Multi Theft Auto - Spectators * spectators_s.lua * Version 2 from October 2013 * Original file by thisisdoge --]] --[[ It's not a useful task for the server to keep track of player camera targets When, if, issue #0007813 is fixed a version will be released where a client manages this himself -]] local GATHER_FREQUENCY = 2000 -- how often in ms it should run the "spectator_gather" function local playerData = {} -- Who is a player spectating -- This function retrieves players camera targets as specified by GATHER_FREQUENCY function spectator_gather () for i, player in ipairs (getElementsByType('player')) do local cameraTarget = getCameraTarget (player) if (not cameraTarget) or (cameraTarget == player) then cameraTarget = nil end if (cameraTarget ~= playerData[player]) then if (not cameraTarget) then removeSpectator (playerData[player], player) else if (playerData[player]) then removeSpectator (playerData[player], player) end addSpectator (cameraTarget, player) end triggerEvent ('onPlayerCameraTargetChange', player, cameraTarget) playerData[player] = cameraTarget end end end function addSpectator (client, spectator) if (not elementCheck(client)) or (not elementCheck(spectator)) then return false end triggerClientEvent (client, 'onClientPlayerTargeted', client, spectator) end function removeSpectator (client, spectator) if (not elementCheck(client)) then return false end triggerClientEvent (client, 'onClientPlayerUnTargeted', client, spectator) end function playerQuit () if (playerData[source]) then removeSpectator (playerData[source], source) end end function elementCheck (el) return el and isElement(el) and (getElementType(el) == 'player') end --[[ ********** Exports ********** --]] -- Returns an array of the people spectating "player" -- Returns false on failure, nil if there isn't any function getPlayerSpectators (player) if (not elementCheck(player)) then return false end local t_Res = {} for pl, spec_player in pairs (playerData) do if (spec_player == player) then table.insert (t_Res, pl) end end return ((#t_Res > 0) and t_Res) or nil end --[[ ********** Initialisation ********** --]] addEventHandler ('onResourceStart', resourceRoot, function () -- source refers to the player whose camera target changed -- 1st variable returned is the player he is targetting, nil if it's fixed or facing himself. addEvent ('onPlayerCameraTargetChange') addEventHandler ('onPlayerQuit', root, playerQuit) setTimer (spectator_gather, GATHER_FREQUENCY, 0) end ) Link to comment
Karuzo Posted April 13, 2014 Share Posted April 13, 2014 Oh ofcourse i will do it sir, something else? A cup of tea ? Seriously, this is not a requesting board. Link to comment
George2 Posted April 13, 2014 Author Share Posted April 13, 2014 It's my help request , if you can help me , do it if you can't leave me , i don't care. Link to comment
monumento Posted April 14, 2014 Share Posted April 14, 2014 omg https://community.multitheftauto.com/index.php?p= ... ls&id=5028 Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now