Jump to content

[Help] onClientGUIClick (Done)


amm2100

Recommended Posts

I made an Small Script when the Player press btnSanchz , Sanchez will Spawn and He will warp on it

Client Side

local myMarker = createMarker( 1543.4465332031, -1724.4774169922, 12.546875 , "cylinder", 2.0, 250, 250, 250, 200, getRootElement()  ) 
  
function MarkerHit ( hitPlayer, matchingDimension ) 
if (hitPlayer == localPlayer) then 
    outputChatBox ( getPlayerName(hitPlayer) .. " Entered a Died Marker" ) 
end 
end 
  
function createSpawnWindow(hitPlayer) 
if (hitPlayer == localPlayer) then 
  
  
        windowSpawncar = guiCreateWindow(0.36, 0.70, 0.26, 0.29, "", true) 
        guiWindowSetSizable(windowSpawncar, false) 
        btnSancheZ = guiCreateButton(0.05, 0.12, 0.87, 0.14, "1: Sanchez", true, windowSpawncar) 
        local font0_PetitFormalScript = guiCreateFont(":guieditor/fonts/PetitFormalScript.ttf", 10) 
        guiSetFont(btnSancheZ, font0_PetitFormalScript) 
        guiSetProperty(btnSancheZ, "NormalTextColour", "FFFFFFFF") 
        btnVoodoo = guiCreateButton(0.05, 0.39, 0.87, 0.14, "2: Voodoo", true, windowSpawncar) 
        guiSetFont(btnVoodoo, font0_PetitFormalScript) 
        guiSetProperty(btnVoodoo, "NormalTextColour", "FFFFFFFF") 
        btnCaddy = guiCreateButton(0.06, 0.67, 0.86, 0.14, "3: Caddy", true, windowSpawncar) 
        guiSetFont(btnCaddy, font0_PetitFormalScript) 
        guiSetProperty(btnCaddy, "NormalTextColour", "FFFFFFFF")     
        guiSetVisible( windowSpawncar, true ) 
  
end 
end 
  
function markerLeave( localPlayer ) 
    guiSetVisible( windowSpawncar, false) 
end 
addEventHandler ( "onClientMarkerHit", myMarker, MarkerHit ) 
addEventHandler( "onClientMarkerHit", myMarker, createSpawnWindow) 
addEventHandler ( "onClientMarkerLeave", getRootElement(), markerLeave ) 
  
  
function create( ) 
    triggerServerEvent("createSANCHEZ", getRootElement()) 
end  
addEventHandler( "onClientGUIClick", btnSancheZ, create ) 
  

Server Side

local vechical = {} 
function spawncar( thePlayer ) 
    if isElement(vechical[thePlayer]) then 
        destroyElement( vechical[thePlayer] ) 
    end 
    local x,y,z = getElementPosition( thePlayer ) 
    vechical[thePlayer] = createVehicle( 468,  x,  y,  z ) 
    warpPedIntoVehicle ( thePlayer, vechical[thePlayer] ) 
end 
addEvent( "createSANCHEZ" ) 
addEventHandler( "createSANCHEZ", getRootElement(  ), spawncar ) 

but when I press BtnSanchez it doesn't work no thing happen and there is no Error on the Console

Edited by Guest
Link to comment

Try putting the event 'onClientGUIClick' inside the function 'createSpawnWindow'.

Also add an if-statement to see, if its the correct button or not, inside the button function.

  
function create( ) 
    if ( source == btnSancheZ ) then 
        triggerServerEvent("createSANCHEZ", getRootElement()) 
    end 
end 
  

Link to comment
Try putting the event 'onClientGUIClick' inside the function 'createSpawnWindow'.

Also add an if-statement to see, if its the correct button or not, inside the button function.

  
function create( ) 
    if ( source == btnSancheZ ) then 
        triggerServerEvent("createSANCHEZ", getRootElement()) 
    end 
end 
  

Can You Show me How to Put the Event on The Fuction ??

Link to comment
local myMarker = createMarker( 1543.4465332031, -1724.4774169922, 12.546875 , "cylinder", 2.0, 250, 250, 250, 200, getRootElement()  ) 
  
function MarkerHit ( hitPlayer, matchingDimension ) 
if (hitPlayer == localPlayer) then 
    outputChatBox ( getPlayerName(hitPlayer) .. " Entered a Died Marker" ) 
end 
end 
  
function createSpawnWindow(hitPlayer) 
if (hitPlayer == localPlayer) then 
  
  
        windowSpawncar = guiCreateWindow(0.36, 0.70, 0.26, 0.29, "", true) 
        guiWindowSetSizable(windowSpawncar, false) 
        btnSancheZ = guiCreateButton(0.05, 0.12, 0.87, 0.14, "1: Sanchez", true, windowSpawncar) 
        local font0_PetitFormalScript = guiCreateFont(":guieditor/fonts/PetitFormalScript.ttf", 10) 
        guiSetFont(btnSancheZ, font0_PetitFormalScript) 
        guiSetProperty(btnSancheZ, "NormalTextColour", "FFFFFFFF") 
        btnVoodoo = guiCreateButton(0.05, 0.39, 0.87, 0.14, "2: Voodoo", true, windowSpawncar) 
        guiSetFont(btnVoodoo, font0_PetitFormalScript) 
        guiSetProperty(btnVoodoo, "NormalTextColour", "FFFFFFFF") 
        btnCaddy = guiCreateButton(0.06, 0.67, 0.86, 0.14, "3: Caddy", true, windowSpawncar) 
        guiSetFont(btnCaddy, font0_PetitFormalScript) 
        guiSetProperty(btnCaddy, "NormalTextColour", "FFFFFFFF")     
        guiSetVisible( windowSpawncar, true ) 
        addEventHandler( "onClientGUIClick", root, create ) 
  
end 
end 
  
function markerLeave( localPlayer ) 
    guiSetVisible( windowSpawncar, false) 
end 
addEventHandler ( "onClientMarkerHit", myMarker, MarkerHit ) 
addEventHandler( "onClientMarkerHit", myMarker, createSpawnWindow) 
addEventHandler ( "onClientMarkerLeave", getRootElement(), markerLeave ) 
  
  
function create( ) 
    if ( source == btnSancheZ ) then 
        triggerServerEvent("createSANCHEZ", getRootElement()) 
    end 
end 

Also, some errors aren't shown in console only. Use /debugscript 3.

Link to comment
local myMarker = createMarker( 1543.4465332031, -1724.4774169922, 12.546875 , "cylinder", 2.0, 250, 250, 250, 200, getRootElement()  ) 
  
function MarkerHit ( hitPlayer, matchingDimension ) 
if (hitPlayer == localPlayer) then 
    outputChatBox ( getPlayerName(hitPlayer) .. " Entered a Died Marker" ) 
end 
end 
  
function createSpawnWindow(hitPlayer) 
if (hitPlayer == localPlayer) then 
  
  
        windowSpawncar = guiCreateWindow(0.36, 0.70, 0.26, 0.29, "", true) 
        guiWindowSetSizable(windowSpawncar, false) 
        btnSancheZ = guiCreateButton(0.05, 0.12, 0.87, 0.14, "1: Sanchez", true, windowSpawncar) 
        local font0_PetitFormalScript = guiCreateFont(":spawnscar/fonts/PetitFormalScript.ttf", 10) 
        guiSetFont(btnSancheZ, font0_PetitFormalScript) 
        guiSetProperty(btnSancheZ, "NormalTextColour", "FFFFFFFF") 
        btnVoodoo = guiCreateButton(0.05, 0.39, 0.87, 0.14, "2: Voodoo", true, windowSpawncar) 
        guiSetFont(btnVoodoo, font0_PetitFormalScript) 
        guiSetProperty(btnVoodoo, "NormalTextColour", "FFFFFFFF") 
        btnCaddy = guiCreateButton(0.06, 0.67, 0.86, 0.14, "3: Caddy", true, windowSpawncar) 
        guiSetFont(btnCaddy, font0_PetitFormalScript) 
        guiSetProperty(btnCaddy, "NormalTextColour", "FFFFFFFF")     
        guiSetVisible( windowSpawncar, true ) 
        addEventHandler( "onClientGUIClick", btnSancheZ, function ( ) 
        if ( source == btnSancheZ ) then 
        triggerServerEvent("createSANCHEZ", getRootElement()) 
        end 
        end, false ) 
         
end 
end 
  
function markerLeave( localPlayer ) 
    guiSetVisible( windowSpawncar, false) 
end 
addEventHandler ( "onClientMarkerHit", myMarker, MarkerHit ) 
addEventHandler( "onClientMarkerHit", myMarker, createSpawnWindow) 
addEventHandler ( "onClientMarkerLeave", getRootElement(), markerLeave ) 
  
  
  
  

I change some of the Client Side But it still Doesn't Work the Button doesn't do anything

Link to comment

local myMarker = createMarker( 1543.4465332031, -1724.4774169922, 12.546875 , "cylinder", 2.0, 250, 250, 250, 200, getRootElement()  ) 
  
function MarkerHit ( hitPlayer, matchingDimension ) 
if (hitPlayer == localPlayer) then 
    outputChatBox ( getPlayerName(hitPlayer) .. " Entered a Died Marker" ) 
end 
end 
  
function createSpawnWindow(hitPlayer) 
if (hitPlayer == localPlayer) then 
  
  
        windowSpawncar = guiCreateWindow(0.36, 0.70, 0.26, 0.29, "", true) 
        guiWindowSetSizable(windowSpawncar, false) 
        btnSancheZ = guiCreateButton(0.05, 0.12, 0.87, 0.14, "1: Sanchez", true, windowSpawncar) 
        local font0_PetitFormalScript = guiCreateFont(":spawnscar/fonts/PetitFormalScript.ttf", 10) 
        guiSetFont(btnSancheZ, font0_PetitFormalScript) 
        guiSetProperty(btnSancheZ, "NormalTextColour", "FFFFFFFF") 
        btnVoodoo = guiCreateButton(0.05, 0.39, 0.87, 0.14, "2: Voodoo", true, windowSpawncar) 
        guiSetFont(btnVoodoo, font0_PetitFormalScript) 
        guiSetProperty(btnVoodoo, "NormalTextColour", "FFFFFFFF") 
        btnCaddy = guiCreateButton(0.06, 0.67, 0.86, 0.14, "3: Caddy", true, windowSpawncar) 
        guiSetFont(btnCaddy, font0_PetitFormalScript) 
        guiSetProperty(btnCaddy, "NormalTextColour", "FFFFFFFF")     
        guiSetVisible( windowSpawncar, true ) 
        addEventHandler( "onClientGUIClick",resourceRoot, function () 
        if ( source == btnSancheZ ) then 
        triggerServerEvent("createSANCHEZ",root) 
        end 
        end) 
        
end 
end 
  
function markerLeave( localPlayer ) 
    guiSetVisible( windowSpawncar, false) 
end 
addEventHandler ( "onClientMarkerHit", myMarker, MarkerHit ) 
addEventHandler( "onClientMarkerHit", myMarker, createSpawnWindow) 
addEventHandler ( "onClientMarkerLeave", getRootElement(), markerLeave ) 

Link to comment
Replace
addEvent( "createSANCHEZ" ) 

with

addEvent( "createSANCHEZ", true ) 

if this ^ didn't work .. try this

client side:

local myMarker = createMarker( 1543.4465332031, -1724.4774169922, 12.546875 , "cylinder", 2.0, 250, 250, 250, 200, getRootElement()  ) 
  
function MarkerHit ( hitPlayer, matchingDimension ) 
    if (hitPlayer == localPlayer) then 
        outputChatBox ( getPlayerName(hitPlayer) .. " Entered a Died Marker" ) 
    end 
end 
  
function createSpawnWindow(hitPlayer) 
if (hitPlayer == localPlayer) then 
  
  
        windowSpawncar = guiCreateWindow(0.36, 0.70, 0.26, 0.29, "", true) 
        guiWindowSetSizable(windowSpawncar, false) 
        btnSancheZ = guiCreateButton(0.05, 0.12, 0.87, 0.14, "1: Sanchez", true, windowSpawncar) 
        local font0_PetitFormalScript = guiCreateFont(":spawnscar/fonts/PetitFormalScript.ttf", 10) 
        guiSetFont(btnSancheZ, font0_PetitFormalScript) 
        guiSetProperty(btnSancheZ, "NormalTextColour", "FFFFFFFF") 
        btnVoodoo = guiCreateButton(0.05, 0.39, 0.87, 0.14, "2: Voodoo", true, windowSpawncar) 
        guiSetFont(btnVoodoo, font0_PetitFormalScript) 
        guiSetProperty(btnVoodoo, "NormalTextColour", "FFFFFFFF") 
        btnCaddy = guiCreateButton(0.06, 0.67, 0.86, 0.14, "3: Caddy", true, windowSpawncar) 
        guiSetFont(btnCaddy, font0_PetitFormalScript) 
        guiSetProperty(btnCaddy, "NormalTextColour", "FFFFFFFF")     
        guiSetVisible( windowSpawncar, true ) 
        addEventHandler( "onClientGUIClick",resourceRoot, function () 
        if ( source == btnSancheZ ) then 
        triggerServerEvent("createSANCHEZ",localPlayer) 
        end 
        end) 
        
end 
end 
  
function markerLeave( localPlayer ) 
    guiSetVisible( windowSpawncar, false) 
end 
addEventHandler ( "onClientMarkerHit",myMarker, MarkerHit ) 
addEventHandler( "onClientMarkerHit",myMarker, createSpawnWindow) 
addEventHandler ( "onClientMarkerLeave",myMarker,markerLeave) 

server side:

local vechical = {} 
function spawncar() 
    if isElement(vechical[source]) then 
        destroyElement(vechical[source]) 
    end 
    local x,y,z = getElementPosition(source) 
    vechical[source] = createVehicle(468,x, y,z) 
    warpPedIntoVehicle (source,vechical[source]) 
end 
addEvent("createSANCHEZ",true) 
addEventHandler("createSANCHEZ",root,spawncar) 

Link to comment
Replace
addEvent( "createSANCHEZ" ) 

with

addEvent( "createSANCHEZ", true ) 

if this ^ didn't work .. try this

client side:

local myMarker = createMarker( 1543.4465332031, -1724.4774169922, 12.546875 , "cylinder", 2.0, 250, 250, 250, 200, getRootElement()  ) 
  
function MarkerHit ( hitPlayer, matchingDimension ) 
    if (hitPlayer == localPlayer) then 
        outputChatBox ( getPlayerName(hitPlayer) .. " Entered a Died Marker" ) 
    end 
end 
  
function createSpawnWindow(hitPlayer) 
if (hitPlayer == localPlayer) then 
  
  
        windowSpawncar = guiCreateWindow(0.36, 0.70, 0.26, 0.29, "", true) 
        guiWindowSetSizable(windowSpawncar, false) 
        btnSancheZ = guiCreateButton(0.05, 0.12, 0.87, 0.14, "1: Sanchez", true, windowSpawncar) 
        local font0_PetitFormalScript = guiCreateFont(":spawnscar/fonts/PetitFormalScript.ttf", 10) 
        guiSetFont(btnSancheZ, font0_PetitFormalScript) 
        guiSetProperty(btnSancheZ, "NormalTextColour", "FFFFFFFF") 
        btnVoodoo = guiCreateButton(0.05, 0.39, 0.87, 0.14, "2: Voodoo", true, windowSpawncar) 
        guiSetFont(btnVoodoo, font0_PetitFormalScript) 
        guiSetProperty(btnVoodoo, "NormalTextColour", "FFFFFFFF") 
        btnCaddy = guiCreateButton(0.06, 0.67, 0.86, 0.14, "3: Caddy", true, windowSpawncar) 
        guiSetFont(btnCaddy, font0_PetitFormalScript) 
        guiSetProperty(btnCaddy, "NormalTextColour", "FFFFFFFF")     
        guiSetVisible( windowSpawncar, true ) 
        addEventHandler( "onClientGUIClick",resourceRoot, function () 
        if ( source == btnSancheZ ) then 
        triggerServerEvent("createSANCHEZ",localPlayer) 
        end 
        end) 
        
end 
end 
  
function markerLeave( localPlayer ) 
    guiSetVisible( windowSpawncar, false) 
end 
addEventHandler ( "onClientMarkerHit",myMarker, MarkerHit ) 
addEventHandler( "onClientMarkerHit",myMarker, createSpawnWindow) 
addEventHandler ( "onClientMarkerLeave",myMarker,markerLeave) 

server side:

local vechical = {} 
function spawncar() 
    if isElement(vechical[source]) then 
        destroyElement(vechical[source]) 
    end 
    local x,y,z = getElementPosition(source) 
    vechical[source] = createVehicle(468,x, y,z) 
    warpPedIntoVehicle (source,vechical[source]) 
end 
addEvent("createSANCHEZ",true) 
addEventHandler("createSANCHEZ",root,spawncar) 

Finial it is working But , What is the different ?? , Only on Server Side ?

Link to comment

Whenever you want to trigger newly created event, you need to put second attribute to 'true' else it will not work.

In this case, it was:

addEvent( "createSANCHEZ", true ) -- by putting true, we tell the script it is a triggering event 

Total changes are:-

In client side:

triggerServerEvent("createSANCHEZ", getRootElement()).

is replaced with

triggerServerEvent("createSANCHEZ", localPlayer).

In server side

addEvent("createSANCHEZ") is replaced with addEvent("createSANCHEZ", true).

thePlayer is replaced with source.

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