Jump to content

[HELP]Attaching GUI to a marker.


brocky

Recommended Posts

Can anyone tell me how can i attach this GUI to a marker? I mean when you hit the Marker and the GUI opens. I know about the "onMarkerHit" function but can you show it in detail. here is the code that I want to attach to a GUI.

  
MyGUI = { 
    button = {}, 
    window = {} 
}  
addEventHandler("onClientResourceStart", resourceRoot, 
    function() 
  
        window1 = guiCreateWindow(81, 102, 631, 447, "TheShop", false) 
        guiWindowSetSizable(window1, false) 
  
        button1 = guiCreateButton(13, 54, 140, 29, "MyGuns", false, window1) 
 end 
  ) 
  

Link to comment

First of all there's a part of your code not used at all so there's no sense to keep it

MyGUI = { 
    button = {}, 
    window = {} 
} 

Second thing, i'm going to answer your main problem,follow me step by step!

-Server-side:

addEventHandler("onResourceStart",resourceRoot, --On the resource start all the data inside this function will be created automaticly. 
function () 
        local marker = createMarker(0, 0, 0, "cylinder", 2, 255, 0, 0, 250) -- We create our marker by this function 'createMarker'. 
        local blip = createBlipAttachedTo(marker, 1) --Attaching our blip on the marker to know where the marker exist. 
        setElementInterior(marker, 0) --Setting interior of the marker to default. 
        setElementDimension(marker, 0) --Setting dimension of the marker to default. 
        addEventHandler("onMarkerHit",marker,onMarkerHit) --We putting the event 'onMarkerHit' inside this function because marker is defined inside it. 
end) 
  
function onMarkerHit(hitPlayer, matchingDimension) --There're two arguments for this event,the element who hit the marker and the dimension! 
     if not matchingDimension then return end --Checking if player is in the same dimension as the marker or not if not it will return false. 
     if ( getElementType (hitPlayer) == 'player' ) then --Checking if the element who hit the marker is a player not something else. 
     triggerClientEvent(hitPlayer,"showGUI",hitPlayer) --We use this function to send data from server to client side. 
    end 
end 

-Client side:

local window1 = guiCreateWindow(81, 102, 631, 447, "TheShop", false) 
 guiWindowSetSizable(window1, false) 
 guiSetVisible(window1,false) 
 local button1 = guiCreateButton(13, 54, 140, 29, "MyGuns", false, window1) 
   
addEvent("showGUI",true) 
addEventHandler("showGUI",getRootElement(), 
function () 
    if ( guiGetVisible(window1) == nil ) then --If the windows isn't visible then we will make it visible when the player hit marker 
    guiSetVisible(window1,true) 
    showCursor(true) 
    end 
end) 

~Regards,KariM

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