Jump to content

Playerblip panel


Wei

Recommended Posts

Hi. I don't know how to add players to grid and how I can get selected item, how can I remove blip.

Please help me.

This is my gui:

playerBlipWindow = guiCreateWindow(384,150,199,294,"Player blip panel",false) 
guiWindowSetSizable(playerBlipWindow,false) 
gridListOfPlayers = guiCreateGridList(9,23,181,201,false,playerBlipWindow) 
guiGridListSetSelectionMode(gridListOfPlayers,2) 
  
guiGridListAddColumn(gridListOfPlayers,"Players",0.2) 
blipUnblipBut = guiCreateButton(9,232,85,52,"Blip/ \n Unblip",false,playerBlipWindow) 
closeBut = guiCreateButton(97,233,85,52,"Close",false,playerBlipWindow) 
  
  

Link to comment
playerBlipWindow = guiCreateWindow(384,150,199,294,"Player blip panel",false) 
guiWindowSetSizable(playerBlipWindow,false) 
gridListOfPlayers = guiCreateGridList(9,23,181,201,false,playerBlipWindow) 
guiGridListAddColumn(gridListOfPlayers,"Players",0.2) 
blipUnblipBut = guiCreateButton(9,232,85,52,"Blip/ \n Unblip",false,playerBlipWindow) 
closeBut = guiCreateButton(97,233,85,52,"Close",false,playerBlipWindow) 
  
function loadPlayers ( ) 
    guiGridListClear ( gridListOfPlayers ) -- Clear current items. 
  
    for index, player in ipairs ( getElementsByType ( "player" ) ) do -- Loop the current players. 
        guiGridListSetItemText ( gridListOfPlayers, guiGridListAddRow ( gridListOfPlayers ), 1, tostring ( getPlayerName ( player ) ), false, false ) -- Add a row and set the text to the player name. 
    end 
end 
addEventHandler ( "onClientResourceStart", resourceRoot, loadPlayers ) 
addEventHandler ( "onClientPlayerJoin", root, loadPlayers ) 
addEventHandler ( "onClientPlayerQuit", root, loadPlayers ) 
addEventHandler ( "onClientPlayerChangeNick", root, loadPlayers ) 

As for blips you must use:

createBlipAttachedTo 
destroyElement 

Link to comment
function randomFunction(button) 
    if (button) ~= "left" then return end 
    if (source == closeBut) then 
        guiSetVisible( playerBlipWindow, false) 
        showCursor(false) 
    elseif ( source == blipUnblipBut ) then  
        local playerName = guiGridListGetItemText ( gridListOfPlayers, guiGridListGetSelectedItem ( gridListOfPlayers ), 1 ) 
        playerBlip = createBlipAttachedTo( playerName, 40 ) 
        setElementData(getLocalPlayer(), "isPlayerBlipped", true) 
    elseif ( getElementData(getLocalPlayer(), "isPlayerBlipped", true)) and (source == blipUnblipBut) then 
        destroyElement(playerBlip)   
        setElementData(getLocalPlayer(), "isPlayerBlipped", false) 
    end 
end 
addEventHandler("onClientGUIClick", resourceRoot,  randomFunction, true) 

Whats wrong. Error:

Bag argument @ createBlipAttachedTo

Edited by Guest
Link to comment

Whats wrong. Error:

Bag argument @ createBlipAttachedTo

CUT

local playerName = guiGridListGetItemText ( gridListOfPlayers, guiGridListGetSelectedItem ( gridListOfPlayers ), 1 ) 
        playerBlip = createBlipAttachedTo( playerName, 40 ) 

You use string. But you need use element.

Read arguments.

getPlayerFromName 

Edited by Guest
Link to comment
  
local pPlayerBlip 
  
function randomFunction( sButton ) 
    if sButton ~= 'left' then  
        return  
    end 
    if source == closeBut then 
        guiSetVisible( playerBlipWindow, false ) 
        showCursor( false ) 
    elseif source == blipUnblipBut then  
        local sPlayerName = guiGridListGetItemText ( gridListOfPlayers, guiGridListGetSelectedItem ( gridListOfPlayers ), 1 ) 
        if pPlayerBlip then -- Check 
            destroyElement( pPlayerBlip ) -- Delete 
        end 
        pPlayerBlip = createBlipAttachedTo( sPlayerName, 40 ) 
    end 
end 
addEventHandler( 'onClientGUIClick', guiRoot,  randomFunction, true ) -- Use guiRoot instead of resourceRoot 

?

Updated.

Link to comment

try this:

function randomFunction(button) 
    if (button) == "left" then 
    if (source == closeBut) then 
        guiSetVisible( playerBlipWindow, false) 
        showCursor(false) 
    elseif ( source == blipUnblipBut ) then 
        playerBlip = createBlipAttachedTo( playerName, 40 ) 
        local playerName = guiGridListGetItemText ( gridListOfPlayers, guiGridListGetSelectedItem ( gridListOfPlayers ), 1 ) 
        setElementData(getPlayerFromName(playerName), "isPlayerBlipped", true) 
        if(getElementData(getPlayerFromName(playerName), "isPlayerBlipped"))then 
            destroyElement(playerBlip)   
            setElementData(getPlayerFromName(playerName), "isPlayerBlipped", false) 
        end 
    end 
    end 
end 
addEventHandler("onClientGUIClick", guiRoot,randomFunction, true) 

Link to comment

try this now:

  
addEventHandler("onClientGUIClick", guiRoot,function(button) 
    if (button) == "left" then 
    if (source == closeBut) then 
        guiSetVisible( playerBlipWindow, false) 
        showCursor(false) 
    elseif ( source == blipUnblipBut ) then 
        playerBlip = createBlipAttachedTo( playerName, 40 ) 
        local playerName = guiGridListGetItemText ( gridListOfPlayers, guiGridListGetSelectedItem ( gridListOfPlayers ), 1 ) 
        setElementData(getPlayerFromName(playerName), "isPlayerBlipped", true) 
        if(getElementData(getPlayerFromName(playerName), "isPlayerBlipped"))then 
            destroyElement(playerBlip)   
            setElementData(getPlayerFromName(playerName), "isPlayerBlipped", false) 
        end 
    end 
    end 
end,false) 

Link to comment
addEventHandler ( 'onClientGUIClick', root, 
    function ( btnSide ) 
        if ( btnSide == 'left' ) then 
            if ( source == closeBut ) then 
                guiSetVisible ( playerBlipWindow, false ) 
                showCursor ( false ) 
            elseif ( source == blipUnblipBut ) then 
                local uRow, uCol = guiGridListGetSelectedItem ( gridListOfPlayers ) 
                if ( uRow and uCol and uRow ~= -1 and uCol ~= -1 ) then 
                    local playerName = guiGridListGetItemText ( gridListOfPlayers, uRow, uCol ) 
                    local playerBlip = createBlipAttachedTo ( getPlayerFromName ( playerName ), 40 ) 
                    setElementData ( getPlayerFromName ( playerName ), 'isPlayerBlipped', true ) 
                end 
            end 
        end 
    end 
) 

You should use a var or button text to know if player is 'blipped' or not.

Link to comment

Sorry, I found my mistake:

addEventHandler("onClientGUIClick", guiRoot,function(button) 
    if (button == "left") then 
        if (source == closeBut) then 
            guiSetVisible( playerBlipWindow, false) 
            showCursor(false) 
        elseif ( source == blipUnblipBut ) then 
            local playerName = guiGridListGetItemText ( gridListOfPlayers, guiGridListGetSelectedItem ( gridListOfPlayers ), 1 ) 
            if(getElementData(getPlayerFromName(playerName), "isPlayerBlipped"))then 
                destroyElement(playerBlip)   
                setElementData(getPlayerFromName(playerName), "isPlayerBlipped", false) 
            else 
                playerBlip = createBlipAttachedTo( playerName, 40 ) 
                setElementData(getPlayerFromName(playerName), "isPlayerBlipped", true) 
            end 
        end 
    end 
end,true) 

Link to comment

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...