Wei Posted May 3, 2012 Posted May 3, 2012 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)
Castillo Posted May 3, 2012 Posted May 3, 2012 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
Wei Posted May 3, 2012 Author Posted May 3, 2012 (edited) 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 May 3, 2012 by Guest
Kenix Posted May 3, 2012 Posted May 3, 2012 (edited) 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 May 3, 2012 by Guest
Wei Posted May 3, 2012 Author Posted May 3, 2012 It doesn't open the window. Whats wrong ? You not make your window showing. Edited. I forgot then at the end. Window is working now but it doesn't blip player
Kenix Posted May 3, 2012 Posted May 3, 2012 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.
Jaysds1 Posted May 3, 2012 Posted May 3, 2012 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)
Wei Posted May 4, 2012 Author Posted May 4, 2012 If you just copied, it will never work. I did not only copy it I've added the getPlayerFromName and stuff but not work
Jaysds1 Posted May 4, 2012 Posted May 4, 2012 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)
Michael# Posted May 4, 2012 Posted May 4, 2012 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.
Jaysds1 Posted May 4, 2012 Posted May 4, 2012 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)
Wei Posted May 4, 2012 Author Posted May 4, 2012 Jayz your code is not working Jaysds1 your code is workin thank you very much
Michael# Posted May 4, 2012 Posted May 4, 2012 Obviously don't work, you just copy the codes. You don't even see what I say.
Jaysds1 Posted May 4, 2012 Posted May 4, 2012 Jayz your code is not workingJaysds1 your code is workin thank you very much np
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