Wei Posted April 11, 2012 Share Posted April 11, 2012 Here I have scoreboar role show script. but it doesn't work... No debug errors or anything: CODE: exports [ 'scoreboard' ]:addScoreboardColumn ( 'Role' ) addEventHandler ( 'onPlayerLogin', root, function ( _, uAccount ) local group = 'None' local playerTeam = getTeamFromName ( source ) if ( playerTeam == Police ) then group = 'Police Officer' elseif ( playerTeam == Staff ) then group = 'Staff Member' elseif ( playerTeam == Criminal ) then group = 'Criminal' elseif ( playerTeam == Military ) then group = 'Solider' end setElementData ( source, 'Role', group ) end ) Link to comment
Guest Guest4401 Posted April 11, 2012 Share Posted April 11, 2012 Check your code once again. getTeamFromName requires a string to get a team element whereas in your case you have used a player element . I guess what you want is the player's team. So instead of : local playerTeam = getTeamFromName ( source ) use local playerTeam = getPlayerTeam(source) Link to comment
Guest Guest4401 Posted April 11, 2012 Share Posted April 11, 2012 Are Police, Staff, Criminal and Military team elements..? and when you tested the script, were you in that team? Link to comment
Wei Posted April 11, 2012 Author Share Posted April 11, 2012 Are Police, Staff, Criminal and Military team elements..? and when you tested the script, were you in that team? no and yes Link to comment
Guest Guest4401 Posted April 11, 2012 Share Posted April 11, 2012 Are Police, Staff, Criminal and Military team elements..? and when you tested the script, were you in that team? no and yes Are they team names? If they are team names then define them in a way such that you get the team element. local Police = getTeamFromName("Police") local Staff = getTeamFromName("Staff") local Criminal = getTeamFromName("Criminal") local Military = getTeamFromName("Military") If they aren't team names also, then can you tell me what they are? Link to comment
TAPL Posted April 11, 2012 Share Posted April 11, 2012 i don't understand why you are using event onPlayerLogin when an player join to server it's almost will not be in team also what do you think? the element data will set only when the player join, you're joining your server and restart the script and you will say (not work) lol you should set the element data when you using setPlayerTeam. Link to comment
SAbJaN Posted April 11, 2012 Share Posted April 11, 2012 Client: local SCOREBOARD_WIDTH = 420 -- The scoreboard window width local SCOREBOARD_HEIGHT = 360 -- The scoreboard window height local SCOREBOARD_HEADER_HEIGHT = 25 -- Height for the header in what you can see the server info local SCOREBOARD_TOGGLE_CONTROL = "tab" -- Control/Key to toggle the scoreboard visibility local SCOREBOARD_PGUP_CONTROL = "mouse_wheel_up" -- Control/Key to move one page up local SCOREBOARD_PGDN_CONTROL = "mouse_wheel_down"-- Control/Key to move one page down local SCOREBOARD_DISABLED_CONTROLS = { "next_weapon", -- Controls that are disabled when the scoreboard is showing "previous_weapon", "aim_weapon", "radio_next", "radio_previous" } local SCOREBOARD_TOGGLE_TIME = 50 -- Time in miliseconds to make the scoreboard (dis)appear local SCOREBOARD_POSTGUI = true -- Set to true if it must be drawn over the GUI local SCOREBOARD_INFO_BACKGROUND = { 255,0,0, 200 } -- RGBA color for the info header background local SCOREBOARD_SERVER_NAME_COLOR = { 0, 255,50, 160 } -- RGBA color for the server name text local SCOREBOARD_PLAYERCOUNT_COLOR = { 255, 255,50, 160 } -- RGBA color for the server player count text local SCOREBOARD_BACKGROUND = { 0,0,0, 200} -- RGBA color for the background local SCOREBOARD_BACKGROUND_IMAGE = { 255, 255, 255, 0 } -- RGBA color for the background image local SCOREBOARD_HEADERS_COLOR = { 0, 0, 0, 255 } -- RGBA color for the headers local SCOREBOARD_SEPARATOR_COLOR = { 82, 82, 82, 140 } -- RGBA color for the separator line between headers and body content local SCOREBOARD_SCROLL_BACKGROUND = { 0, 10, 20, 0 } -- RGBA color for the scroll background local SCOREBOARD_SCROLL_FOREGROUND = { 15, 177, 253, 0 } -- RGBA color for the scroll foreground local SCOREBOARD_SCROLL_HEIGHT = 40 -- Size for the scroll marker local SCOREBOARD_COLUMNS_WIDTH = { 0.08, 0.74, 0.14, 0.04 } -- Relative width for each column: id, player name, ping and scroll position local SCOREBOARD_ROW_GAP = 0 -- Gap between rows = 0 -- Gap between rows --[[ Global variables to this context ]]-- local g_isShowing = false -- Marks if the scoreboard is showing local g_currentWidth = 0 -- Current window width. Used for the fade in/out effect. local g_currentHeight = 0 -- Current window height. Used for the fade in/out effect. local g_scoreboardDummy -- Will contain the scoreboard dummy element to gather info from. local g_windowSize = { guiGetScreenSize () } -- The window size local g_localPlayer = getLocalPlayer () -- The local player... local g_currentPage = 0 -- The current scroll page local g_players -- We will keep a cache of the conected player list local g_oldControlStates -- To save the old control states before disabling them for scrolling --[[ Pre-calculate some stuff ]]-- -- Scoreboard position local SCOREBOARD_X = math.floor ( ( g_windowSize[1] - SCOREBOARD_WIDTH ) / 2 ) local SCOREBOARD_Y = math.floor ( ( g_windowSize[2] - SCOREBOARD_HEIGHT ) / 2 ) -- Scoreboard colors SCOREBOARD_INFO_BACKGROUND = tocolor ( unpack ( SCOREBOARD_INFO_BACKGROUND ) ) SCOREBOARD_SERVER_NAME_COLOR = tocolor ( unpack ( SCOREBOARD_SERVER_NAME_COLOR ) ) SCOREBOARD_PLAYERCOUNT_COLOR = tocolor ( unpack ( SCOREBOARD_PLAYERCOUNT_COLOR ) ) SCOREBOARD_BACKGROUND = tocolor ( unpack ( SCOREBOARD_BACKGROUND ) ) SCOREBOARD_BACKGROUND_IMAGE = tocolor ( unpack ( SCOREBOARD_BACKGROUND_IMAGE ) ) SCOREBOARD_HEADERS_COLOR = tocolor ( unpack ( SCOREBOARD_HEADERS_COLOR ) ) SCOREBOARD_SCROLL_BACKGROUND = tocolor ( unpack ( SCOREBOARD_SCROLL_BACKGROUND ) ) SCOREBOARD_SCROLL_FOREGROUND = tocolor ( unpack ( SCOREBOARD_SCROLL_FOREGROUND ) ) SCOREBOARD_SEPARATOR_COLOR = tocolor ( unpack ( SCOREBOARD_SEPARATOR_COLOR ) ) -- Columns width in absolute units for k=1,#SCOREBOARD_COLUMNS_WIDTH do SCOREBOARD_COLUMNS_WIDTH[k] = math.floor ( SCOREBOARD_COLUMNS_WIDTH[k] * SCOREBOARD_WIDTH ) end -- Pre-calculate each row horizontal bounding box. local rowsBoundingBox = { { SCOREBOARD_X, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 } } -- ID rowsBoundingBox[1][2] = SCOREBOARD_X + SCOREBOARD_COLUMNS_WIDTH[1] -- Name rowsBoundingBox[2][1] = rowsBoundingBox[1][2] rowsBoundingBox[2][2] = rowsBoundingBox[2][1] + SCOREBOARD_COLUMNS_WIDTH[2] -- Ping rowsBoundingBox[3][1] = rowsBoundingBox[2][2] rowsBoundingBox[3][2] = rowsBoundingBox[3][1] + SCOREBOARD_COLUMNS_WIDTH[3] -- Scrollbar rowsBoundingBox[4][1] = rowsBoundingBox[3][2] rowsBoundingBox[4][2] = SCOREBOARD_X + SCOREBOARD_WIDTH --[[ Pre-declare some functions ]]-- local onRender local fadeScoreboard local drawBackground local drawScoreboard --[[ * clamp Clamps a value into a range. --]] local function clamp ( valueMin, current, valueMax ) if current < valueMin then return valueMin elseif current > valueMax then return valueMax else return current end end --[[ * createPlayerCache Generates a new player cache. --]] local function createPlayerCache ( ignorePlayer ) -- Optimize the function in case of not having to ignore a player if ignorePlayer then -- Clear the gloal table g_players = {} -- Get the list of connected players local players = getElementsByType ( "player" ) -- Dump them to the global table for k, player in ipairs(players) do if ignorePlayer ~= player then table.insert ( g_players, player ) end end else g_players = getElementsByType ( "player" ) end --[[ Uncomment to test with dummies ]]-- --[[ for k,v in ipairs(getElementsByType("playerDummy")) do table.insert(g_players, v) end --]] -- Sort the player list by their ID, giving priority to the local player table.sort ( g_players, function ( a, b ) local idA = getElementData ( a, "playerid" ) or 0 local idB = getElementData ( b, "playerid" ) or 0 -- Perform the checks to always set the local player at the beggining if a == g_localPlayer then idA = -1 elseif b == g_localPlayer then idB = -1 end return tonumber(idA) < tonumber(idB) end ) end --[[ * onClientResourceStart Handles the resource start event to create the initial player cache --]] addEventHandler ( "onClientResourceStart", getResourceRootElement(getThisResource()), function () createPlayerCache () end, false ) --[[ * onClientElementDataChange Handles the element data changes event to update the player cache if the playerid was changed. --]] addEventHandler ( "onClientElementDataChange", root, function ( dataName, dataValue ) if dataName == "playerid" then createPlayerCache () end end ) --[[ * onClientPlayerQuit Handles the player quit event to update the player cache. --]] addEventHandler ( "onClientPlayerQuit", root, function () createPlayerCache ( source ) end ) --[[ * toggleScoreboard Toggles the visibility of the scoreboard. --]] local function toggleScoreboard ( show ) -- Force the parameter to be a boolean local show = show == true -- Check if the status has changed if show ~= g_isShowing then g_isShowing = show if g_isShowing and g_currentWidth == 0 and g_currentHeight == 0 then -- Handle the onClientRender event to start drawing the scoreboard. addEventHandler ( "onClientPreRender", root, onRender, false ) end -- Little hack to avoid switching weapons while moving through the scoreboard pages. if g_isShowing then g_oldControlStates = {} for k, control in ipairs ( SCOREBOARD_DISABLED_CONTROLS ) do g_oldControlStates[k] = isControlEnabled ( control ) toggleControl ( control, false ) end else for k, control in ipairs ( SCOREBOARD_DISABLED_CONTROLS ) do toggleControl ( control, g_oldControlStates[k] ) end g_oldControlStates = nil end end end --[[ * onToggleKey Function to bind to the appropiate key the function to toggle the scoreboard visibility. --]] local function onToggleKey ( key, keyState ) -- Check if the scoreboard element has been created if not g_scoreboardDummy then local elementTable = getElementsByType ( "scoreboard" ) if #elementTable > 0 then g_scoreboardDummy = elementTable[1] else return end end -- Toggle the scoreboard, and check that it's allowed. toggleScoreboard ( keyState == "down" and getElementData ( g_scoreboardDummy, "allow" ) ) end bindKey ( SCOREBOARD_TOGGLE_CONTROL, "both", onToggleKey ) --[[ * onScrollKey Function to bind to the appropiate key the function to change the current page. --]] local function onScrollKey ( direction ) if g_isShowing then if direction then g_currentPage = g_currentPage + 1 else g_currentPage = g_currentPage - 1 if g_currentPage < 0 then g_currentPage = 0 end end end end bindKey ( SCOREBOARD_PGUP_CONTROL, "down", function () onScrollKey ( false ) end ) bindKey ( SCOREBOARD_PGDN_CONTROL, "down", function () onScrollKey ( true ) end ) --[[ * onRender Event handler for onClientPreRender. It will forward the flow to the most appropiate function: fading-in, fading-out or drawScoreboard. --]] onRender = function ( timeshift ) -- Boolean to check if we must draw the scoreboard. local drawIt = false if g_isShowing then -- Check if the scoreboard has been disallowed if not getElementData ( g_scoreboardDummy, "allow" ) then Link to comment
Castillo Posted April 11, 2012 Share Posted April 11, 2012 @SAbJaN: May I ask what has that to do with his problem? Link to comment
Wei Posted April 11, 2012 Author Share Posted April 11, 2012 It works. Thanks man. What do you think on witch handler sould i make it ? On timer ? Link to comment
SAbJaN Posted April 11, 2012 Share Posted April 11, 2012 @Solidsnake14 That's a working scoreboard? He says it works fine. Link to comment
Castillo Posted April 11, 2012 Share Posted April 11, 2012 His problem has nothing related to a Scoreboard, I guess he said that karthik184's code worked. Link to comment
Wei Posted April 11, 2012 Author Share Posted April 11, 2012 @Solidsnake14 That's a working scoreboard? He says it works fine. not yours Link to comment
SAbJaN Posted April 11, 2012 Share Posted April 11, 2012 Oh sorry, Didn't realize, I feel stupid D: 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