Jump to content

spawn when clicking on button


swag_k_dog

Recommended Posts

Posted

local sScreen, bCrim, bEnf
local screenW, screenH = guiGetScreenSize()

addEventHandler("onClientResourceStart", resourceRoot,
    function() 
        showCursor(true)
		sScreen = guiCreateStaticImage((screenW - 1366) / 2, (screenH - 768) / 2, 1366, 768, "images/scrn.png", false)
        bCrim = guiCreateButton(376, 369, 162, 63, "", false, sScreen)
		guiSetAlpha(bCrim, 0.00)
        bEnf = guiCreateButton(743, 369, 162, 63, "", false, sScreen)
		guiSetAlpha(bEnf, 0.00)
        
        function closePanel()
            destroyElement(sScreen) 
            removeEventHandler("onClientGUIClick", resourceRoot, guiClicked) 
            showCursor(false)
        end
        
        function guiClicked(btn, state)
            if btn == "left" and state == "up" then 
                if source == bCrim then
                    triggerServerEvent("onClientTeamPicked", localPlayer, "Criminal", 67) 
					closePanel() 
                elseif source == bEnf then
                    triggerServerEvent("onClientTeamPicked", localPlayer, "Enforcer", 124) 
					closePanel()					
                end
            end
        end
        addEventHandler("onClientGUIClick", resourceRoot, guiClicked) 
		
	function graveyard()
	if btn == "left" and state =="up" then
	if source == bCrim then
	spawnPlayer (source, 881, -1101, 24.3, 0) 
	fadeCamera (source, true)
	setCameraTarget (source, source)
elseif source == bEnf then
	spawnPlayer (source, 883, -1101, 24.3, 0) 
	fadeCamera (source, true)
	setCameraTarget (source, source)
	end
    end
	end
	
	addEventHandler("onClientGUIClick", resourceRoot, graveyard)
   
	
	
		
		
		
        
    end
)

the graveyard function doesnt work, can you explain why? thanks! ((sorry for so many posts, I started to script few days ago))

Posted

btn and state is not defined.

function graveyard() = > function graveyard(btn, state)

 

Make yourself an admin on your server if you haven't already and use /debugscript 3 command at ALL times. You could have easily spotted this error. 

Posted
38 minutes ago, swag_k_dog said:

the graveyard function doesnt work, can you explain why? thanks! ((sorry for so many posts, I started to script few days ago))

  • spawnPlayer : it's a server side function you can't use it client side
-- client side
local screenW, screenH = guiGetScreenSize()

addEventHandler("onClientResourceStart", resourceRoot,
    function() 
        showCursor(true)
		sScreen = guiCreateStaticImage((screenW - 1366) / 2, (screenH - 768) / 2, 1366, 768, "images/scrn.png", false)
        bCrim = guiCreateButton(376, 369, 162, 63, "", false, sScreen)
		guiSetAlpha(bCrim, 0.00)
        bEnf = guiCreateButton(743, 369, 162, 63, "", false, sScreen)
		guiSetAlpha(bEnf, 0.00)
        
        function closePanel()
            destroyElement(sScreen) 
            removeEventHandler("onClientGUIClick", resourceRoot, guiClicked) 
            showCursor(false)
        end
        
        function guiClicked(btn, state)
            if btn == "left" and state == "up" then 
                if source == bCrim then
                    triggerServerEvent("onClientTeamPicked", localPlayer, "Criminal", 67) 
					closePanel() 
                elseif source == bEnf then
                    triggerServerEvent("onClientTeamPicked", localPlayer, "Enforcer", 124) 
					closePanel()					
                end
            end
        end
        addEventHandler("onClientGUIClick", resourceRoot, guiClicked) 
    end
)

-- server side
function functionName(team,skin)
    if team and tonumber(skin) then 
        local team = getTeamFromName(tostring(team))
        spawnPlayer (source, 881, -1101, 24.3, 0,tonumber(skin),0,0,team) 
        fadeCamera (source, true)
        setCameraTarget (source, source)
    end 
end 
addEvent("onClientTeamPicked",true)
addEventHandler("onClientTeamPicked",root,functionName)

 

Do not yield your back to your enemy, might feel something strange in your ass.

Two things are infinite the universe and human stupidity and i'm not sure about the universe.

UF: IsTextInGridList | GetGridListRowIndexFromText | Table.removeValue | removeHex | dxDrawTriangle

Skype: SaSuki102 | About Me | Youtube channel | Lua Tips & Tricks | Lua Strings | Lua Tables | Lua Operators

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