Jump to content

[Help]Panel open command


Lorder

Recommended Posts

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
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 by Lorder
Link to comment
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 by msyyn
  • Like 1
Link to comment
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

c9fb9jg5.png 

Link to comment
  • Moderators

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
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

  • Haha 2
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...