Lorder Posted November 20, 2017 Share Posted November 20, 2017 how to add open command ? function aPlayerWarp ( player ) if ( aWarpForm == nil ) then local x, y = guiGetScreenSize() aWarpForm = guiCreateWindow ( x / 2 - 110, y / 2 - 150, 200, 300, "Player Warp Management", false ) aWarpList = guiCreateGridList ( 0.03, 0.08, 0.94, 0.73, true, aWarpForm ) guiGridListAddColumn( aWarpList, "Player", 0.9 ) aWarpSelect = guiCreateButton ( 0.03, 0.82, 0.94, 0.075, "Select", true, aWarpForm ) aWarpCancel = guiCreateButton ( 0.03, 0.90, 0.94, 0.075, "Cancel", true, aWarpForm ) addEventHandler ( "onClientGUIDoubleClick", aWarpForm, aClientWarpDoubleClick ) addEventHandler ( "onClientGUIClick", aWarpForm, aClientWarpClick ) aRegister ( "PlayerWarp", aWarpForm, aPlayerWarp, aPlayerWarpClose ) end aWarpSelectPointer = player guiGridListClear ( aWarpList ) for id, player in ipairs ( getElementsByType ( "player" ) ) do guiGridListSetItemPlayerName ( aWarpList, guiGridListAddRow ( aWarpList ), 1, getPlayerName ( player ), false, false ) end guiSetVisible ( aWarpForm, true ) guiBringToFront ( aWarpForm ) end function aPlayerWarpClose ( destroy ) if ( ( destroy ) or ( aPerformanceWarp and guiCheckBoxGetSelected ( aPerformanceWarp ) ) ) then if ( aWarpForm ) then removeEventHandler ( "onClientGUIDoubleClick", aWarpForm, aClientWarpDoubleClick ) removeEventHandler ( "onClientGUIClick", aWarpForm, aClientWarpClick ) destroyElement ( aWarpForm ) aWarpForm = nil end else guiSetVisible ( aWarpForm, false ) end end function aClientWarpDoubleClick ( button ) if ( button == "left" ) then if ( source == aWarpList ) then if ( guiGridListGetSelectedItem ( aWarpList ) ~= -1 ) then triggerServerEvent ( "aPlayer", getLocalPlayer(), aWarpSelectPointer, "warpto", getPlayerFromNick ( guiGridListGetItemPlayerName ( aWarpList, guiGridListGetSelectedItem ( aWarpList ), 1 ) ) ) aPlayerWarpClose ( false ) end end end end function aClientWarpClick ( button ) if ( button == "left" ) then if ( source == aWarpSelect ) then if ( guiGridListGetSelectedItem ( aWarpList ) ~= -1 ) then triggerServerEvent ( "aPlayer", getLocalPlayer(), aWarpSelectPointer, "warpto", getPlayerFromNick ( guiGridListGetItemPlayerName ( aWarpList, guiGridListGetSelectedItem ( aWarpList ), 1 ) ) ) aPlayerWarpClose ( false ) end elseif ( source == aWarpCancel ) then aPlayerWarpClose ( false ) end end end Link to comment
Miika Posted November 20, 2017 Share Posted November 20, 2017 (edited) Add this to your script: if not guiGetVisible(aWarpForm) then guiSetVisible(aWarpForm, true) showCursor(true) else guiSetVisible(aWarpForm, false) showCursor(false) end Edited November 20, 2017 by Miika Link to comment
Lorder Posted November 20, 2017 Author Share Posted November 20, 2017 8 hours ago, Miika said: Add this to your script: if not guiGetVisible(aWarpForm) then guiSetVisible(aWarpForm, true) showCursor(true) else guiSetVisible(aWarpForm, false) showCursor(false) end where open command ? Link to comment
Lorder Posted November 20, 2017 Author Share Posted November 20, 2017 (edited) function aPlayerWarp ( player ) if ( aWarpForm == nil ) then local x, y = guiGetScreenSize() aWarpForm = guiCreateWindow ( x / 2 - 110, y / 2 - 150, 200, 300, "Player Warp Management", false ) aWarpList = guiCreateGridList ( 0.03, 0.08, 0.94, 0.73, true, aWarpForm ) guiGridListAddColumn( aWarpList, "Player", 0.9 ) aWarpSelect = guiCreateButton ( 0.03, 0.82, 0.94, 0.075, "Select", true, aWarpForm ) aWarpCancel = guiCreateButton ( 0.03, 0.90, 0.94, 0.075, "Cancel", true, aWarpForm ) addEventHandler ( "onClientGUIDoubleClick", aWarpForm, aClientWarpDoubleClick ) addEventHandler ( "onClientGUIClick", aWarpForm, aClientWarpClick ) --Register With Admin Form aRegister ( "PlayerWarp", aWarpForm, aPlayerWarp, aPlayerWarpClose ) end aWarpSelectPointer = player guiGridListClear ( aWarpList ) for id, player in ipairs ( getElementsByType ( "player" ) ) do guiGridListSetItemPlayerName ( aWarpList, guiGridListAddRow ( aWarpList ), 1, getPlayerName ( player ), false, false ) end guiSetVisible ( aWarpForm, false ) guiBringToFront ( aWarpForm ) end function openP() if (guiGetVisible (aWarpForm) == true) then guiSetVisible(aWarpForm, false) showCursor(false) elseif (guiGetVisible (aWarpForm) == false) then guiSetVisible(aWarpForm, true) showCursor(true) end addCommandHandler("panel", aWarpForm) end function aPlayerWarpClose ( destroy ) if ( ( destroy ) or ( aPerformanceWarp and guiCheckBoxGetSelected ( aPerformanceWarp ) ) ) then if ( aWarpForm ) then removeEventHandler ( "onClientGUIDoubleClick", aWarpForm, aClientWarpDoubleClick ) removeEventHandler ( "onClientGUIClick", aWarpForm, aClientWarpClick ) destroyElement ( aWarpForm ) aWarpForm = nil end else guiSetVisible ( aWarpForm, false ) end end function aClientWarpDoubleClick ( button ) if ( button == "left" ) then if ( source == aWarpList ) then if ( guiGridListGetSelectedItem ( aWarpList ) ~= -1 ) then triggerServerEvent ( "aPlayer", getLocalPlayer(), aWarpSelectPointer, "warpto", getPlayerFromNick ( guiGridListGetItemPlayerName ( aWarpList, guiGridListGetSelectedItem ( aWarpList ), 1 ) ) ) aPlayerWarpClose ( false ) end end end end function aClientWarpClick ( button ) if ( button == "left" ) then if ( source == aWarpSelect ) then if ( guiGridListGetSelectedItem ( aWarpList ) ~= -1 ) then triggerServerEvent ( "aPlayer", getLocalPlayer(), aWarpSelectPointer, "warpto", getPlayerFromNick ( guiGridListGetItemPlayerName ( aWarpList, guiGridListGetSelectedItem ( aWarpList ), 1 ) ) ) aPlayerWarpClose ( false ) end elseif ( source == aWarpCancel ) then aPlayerWarpClose ( false ) end end end I added the command but it is not opening @IIYAMA Edited November 20, 2017 by Lorder Link to comment
Moderators IIYAMA Posted November 20, 2017 Moderators Share Posted November 20, 2017 Attach the addCommandHandler to a function. Not the GUI element `aWarpForm`. I will take a closer look at it, once you debug your code. Link to comment
msyyn Posted November 21, 2017 Share Posted November 21, 2017 (edited) function openP() local guiState = guiGetVisible(aWarpForm) if guiState then guiSetVisible(aWarpForm, false) showCursor(false) elseif not guiState then guiSetVisible(aWarpForm, true) showCursor(true) end end addCommandHandler("panel", openP) You had the command handler inside the function-- start debugging your code and actually read through it. If a code is not working, 90% cases it's a typo / user error. Also use tabs. pls. PS. the code has other issues aswell Edited November 21, 2017 by msyyn 1 Link to comment
Lorder Posted November 22, 2017 Author Share Posted November 22, 2017 On 21.11.2017 at 11:42, msyyn said: function openP() local guiState = guiGetVisible(aWarpForm) if guiState then guiSetVisible(aWarpForm, false) showCursor(false) elseif not guiState then guiSetVisible(aWarpForm, true) showCursor(true) endendaddCommandHandler("panel", openP) You had the command handler inside the function-- start debugging your code and actually read through it. If a code is not working, 90% cases it's a typo / user error. Also use tabs. pls. PS. the code has other issues aswell Link to comment
Moderators IIYAMA Posted November 23, 2017 Moderators Share Posted November 23, 2017 The element has to exist first before you can have interaction with it. Real world example: How can I help people on this forum, if they haven't been born yet? The answer to that is: I can not. So use: if isElement(aWarpForm) then Before you are going to have interaction with this element. Link to comment
ShayF2 Posted November 23, 2017 Share Posted November 23, 2017 On 11/20/2017 at 09:15, Lorder said: function aPlayerWarp ( player ) if ( aWarpForm == nil ) then local x, y = guiGetScreenSize() aWarpForm = guiCreateWindow ( x / 2 - 110, y / 2 - 150, 200, 300, "Player Warp Management", false ) aWarpList = guiCreateGridList ( 0.03, 0.08, 0.94, 0.73, true, aWarpForm ) guiGridListAddColumn( aWarpList, "Player", 0.9 ) aWarpSelect = guiCreateButton ( 0.03, 0.82, 0.94, 0.075, "Select", true, aWarpForm ) aWarpCancel = guiCreateButton ( 0.03, 0.90, 0.94, 0.075, "Cancel", true, aWarpForm ) addEventHandler ( "onClientGUIDoubleClick", aWarpForm, aClientWarpDoubleClick ) addEventHandler ( "onClientGUIClick", aWarpForm, aClientWarpClick ) --Register With Admin Form aRegister ( "PlayerWarp", aWarpForm, aPlayerWarp, aPlayerWarpClose ) end aWarpSelectPointer = player guiGridListClear ( aWarpList ) for id, player in ipairs ( getElementsByType ( "player" ) ) do guiGridListSetItemPlayerName ( aWarpList, guiGridListAddRow ( aWarpList ), 1, getPlayerName ( player ), false, false ) end guiSetVisible ( aWarpForm, false ) guiBringToFront ( aWarpForm ) end function openP() if (guiGetVisible (aWarpForm) == true) then guiSetVisible(aWarpForm, false) showCursor(false) elseif (guiGetVisible (aWarpForm) == false) then guiSetVisible(aWarpForm, true) showCursor(true) end addCommandHandler("panel", aWarpForm) end function aPlayerWarpClose ( destroy ) if ( ( destroy ) or ( aPerformanceWarp and guiCheckBoxGetSelected ( aPerformanceWarp ) ) ) then if ( aWarpForm ) then removeEventHandler ( "onClientGUIDoubleClick", aWarpForm, aClientWarpDoubleClick ) removeEventHandler ( "onClientGUIClick", aWarpForm, aClientWarpClick ) destroyElement ( aWarpForm ) aWarpForm = nil end else guiSetVisible ( aWarpForm, false ) end end function aClientWarpDoubleClick ( button ) if ( button == "left" ) then if ( source == aWarpList ) then if ( guiGridListGetSelectedItem ( aWarpList ) ~= -1 ) then triggerServerEvent ( "aPlayer", getLocalPlayer(), aWarpSelectPointer, "warpto", getPlayerFromNick ( guiGridListGetItemPlayerName ( aWarpList, guiGridListGetSelectedItem ( aWarpList ), 1 ) ) ) aPlayerWarpClose ( false ) end end end end function aClientWarpClick ( button ) if ( button == "left" ) then if ( source == aWarpSelect ) then if ( guiGridListGetSelectedItem ( aWarpList ) ~= -1 ) then triggerServerEvent ( "aPlayer", getLocalPlayer(), aWarpSelectPointer, "warpto", getPlayerFromNick ( guiGridListGetItemPlayerName ( aWarpList, guiGridListGetSelectedItem ( aWarpList ), 1 ) ) ) aPlayerWarpClose ( false ) end elseif ( source == aWarpCancel ) then aPlayerWarpClose ( false ) end end end I added the command but it is not opening @IIYAMA god i hate it when people format code in a :Oed up way 2 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