Jump to content

[SOLVED] Client GUI keeps showing for other players.


UTurn

Recommended Posts

I have a job system script I wrote, and it has a window that comes up when you enter a marker, everything works fine when i test it, no debugscript errors/warnings, no errors in the console. But I just tested with a second client on my PC using VMWare player, and when I went into the marker on the second client and took the job, the window was showing on the first client as well, even though it previously was not and I was in a completely different area.

At first, I thought it might be that I was using VMWare player, but then I remembered a time when I first started scripting. I had made a simple login system base completely off of the tutorial found at the wiki. I tested it with another friend who lives in a different state, and when he joined the login form would show on my screen, and the other way around as well.

So I don't think testing with a VM had anything to do with it.

Anyways, I can't for the life of me find anything wrong with my script. I created all the GUI elements for the window in the "onClientResourceStart" event handler, and hid the window for later use. That's what the wiki says should be done aswell.

I'm gonna post the entire clientside script, and if none of you can find a problem either, then maybe someone could just give me a general outline of what you yourself would do when creating a GUI that doesn't have this problem.

employ_c.lua

--[[ 
    employ_c.lua 
        - Enables players to accept a job by approaching a Job NPC. 
--]] 
  
GUIEditor = { 
    button = {}, 
    window = {}, 
    label = {}, 
    memo = {} 
} 
  
-- 
-- Prevent Non Playable Characters from being damaged/killed. 
-- 
function cancelNpcDamage() 
    if (getElementData(source, "isNpc") == true) then 
        cancelEvent() 
    end 
end 
  
-- 
-- Create the job employment GUI and hide it for later. 
-- 
addEventHandler("onClientResourceStart", resourceRoot,  
    function () 
        addEventHandler("onClientPedDamage", root, cancelNpcDamage) 
         
        GUIEditor.window[1] = guiCreateWindow(0.36, 0.36, 0.25, 0.38, "GTC Employment", true) 
        guiWindowSetMovable(GUIEditor.window[1], false) 
        guiWindowSetSizable(GUIEditor.window[1], false) 
  
        GUIEditor.label[1] = guiCreateLabel(0.03, 0.08, 0.94, 0.14, "", true, GUIEditor.window[1]) 
        guiSetFont(GUIEditor.label[1], "sa-header") 
        guiLabelSetHorizontalAlign(GUIEditor.label[1], "center", false) 
         
        GUIEditor.memo[1] = guiCreateMemo(0.03, 0.24, 0.94, 0.61, "", true, GUIEditor.window[1]) 
        guiMemoSetReadOnly(GUIEditor.memo[1], true) 
         
        GUIEditor.button[1] = guiCreateButton(0.06, 0.88, 0.39, 0.08, "Accept Job", true, GUIEditor.window[1]) 
        addEventHandler("onClientGUIClick", GUIEditor.button[1], onJobAccepted, false) 
         
        GUIEditor.button[2] = guiCreateButton(0.55, 0.88, 0.39, 0.08, "Close Window", true, GUIEditor.window[1]) 
        addEventHandler("onClientGUIClick", GUIEditor.button[2], hideJobWindow, false) 
         
        guiSetVisible(GUIEditor.window[1], false) 
    end 
) 
  
-- 
-- Assigns the player the job and hides the job window. 
-- 
function onJobAccepted() 
    local jobName = guiGetText(GUIEditor.label[1]) 
     
    if jobName then 
        triggerServerEvent("playerJoinJob", root, jobName) 
        hideJobWindow() 
    end 
end 
  
-- 
-- Displays the GTC Employment window with the given job information. 
function showJobWindow(jobName) 
    if jobName then 
        guiSetVisible(GUIEditor.window[1], true) 
        triggerEvent("onWindowOpen", localPlayer) 
         
        -- Display the jobs name. 
        guiSetText(GUIEditor.label[1], jobName) 
         
        -- Load and display the jobs memo. 
        local memoText = "" 
        local memoConfig = xmlLoadFile("jobmemos.xml") 
         
        if memoConfig then 
            local jobMemos = xmlNodeGetChildren(memoConfig) 
             
            for i,node in ipairs(jobMemos) do 
                if (xmlNodeGetAttribute(node, "jobName") == jobName) then 
                    memoText = xmlNodeGetValue(node) 
                    break 
                end 
            end 
             
            if (memoText == "") then 
                memoText = "..jobName.."'>" 
            end 
             
            xmlUnloadFile(memoConfig) 
        else 
            memoText = "" 
        end 
         
        guiSetText(GUIEditor.memo[1], memoText) 
    end 
end 
  
-- 
-- Hides the GTC Employment window from view. 
-- 
function hideJobWindow() 
    guiSetVisible(GUIEditor.window[1], false) 
    triggerEvent("onWindowClose", localPlayer) 
end 
  
-- 
-- Bring up the job window if a player walks into a job marker. 
-- 
addEventHandler("onClientMarkerHit", root, 
    function (hitPlayer, dimensionMatch) 
        -- If the player isn't flying... 
        if not getElementData(hitPlayer, "superman:flying") then 
            -- If the player isn't too far above the marker... 
            local px,py,px = getElementPosition(hitPlayer) 
            local mx,my,mz = getElementPosition(source) 
             
            if (px <= (mz + 5)) then 
                local markType = getElementData(source, "markType") 
                 
                if (markType == "jobnpc") and (getPedOccupiedVehicle(hitPlayer) == false) then 
                    local jobName = getElementData(source, "jobName") 
                    local playerJob = getTeamName(getPlayerTeam(hitPlayer)) 
                     
                    -- If the player doesn't already have this job, show the job window. 
                    if (playerJob ~= jobName) then 
                        showJobWindow(jobName) 
                    end 
                end 
            end 
        end 
    end 
) 
  

Edited by Guest
Link to comment

You must verify that the item that enters the market than the user.

Use:

  
addEventHandler("onClientMarkerHit", root, 
function (hitPlayer, dimensionMatch) 
    if getElementType(hitPlayer) == "player" and (hitPlayer == localPlayer) then  
    --... 
    end      
end) 

Thus:

  
-- 
-- Bring up the job window if a player walks into a job marker. 
-- 
addEventHandler("onClientMarkerHit", root, 
    function (hitPlayer, dimensionMatch) 
     if getElementType(hitPlayer) == "player" and (hitPlayer == localPlayer) then -- Check the Element 
        -- If the player isn't flying... 
            if not getElementData(hitPlayer, "superman:flying") then 
            -- If the player isn't too far above the marker... 
            local px,py,px = getElementPosition(hitPlayer) 
            local mx,my,mz = getElementPosition(source) 
            
            if (px <= (mz + 5)) then 
                local markType = getElementData(source, "markType") 
                
                if (markType == "jobnpc") and (getPedOccupiedVehicle(hitPlayer) == false) then 
                    local jobName = getElementData(source, "jobName") 
                    local playerJob = getTeamName(getPlayerTeam(hitPlayer)) 
                    
                    -- If the player doesn't already have this job, show the job window. 
                    if (playerJob ~= jobName) then 
                        showJobWindow(jobName) 
                    end 
                end 
            end 
        end 
    end --END    
   end 
) 

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