Jump to content

Gui and serverside HELP!!!


rublisk19

Recommended Posts

Hi am working on gui what checks if player have enough exp and then sets player job

script ClientSide :

function createJobWindow() 
    local sWidth, sHeight = guiGetScreenSize() 
  
    local Width,Height = 231,150 
    local X = (sWidth/2) - (Width/2) 
    local Y = (sHeight/2) - (Height/2) 
  
    jobWindow = guiCreateWindow(X,Y,Width,Height,"Darbas",false) 
  
    guiWindowSetSizable(jobWindow,false) 
  
    jonLabel = guiCreateLabel(18,23,191,33,"Isidarbinti pareigunu",false,jobWindow) 
  
    guiLabelSetHorizontalAlign(jonLabel,"center",true)   
  
    -- create the button for teleporting to Los Santos 
    taip = guiCreateButton(18,63,195,35,"Taip",false,jobWindow) 
  
    -- slightly below that, create another button for teleporting to San Fierro 
    ne = guiCreateButton(18,103,195,35,"Ne",false,jobWindow) 
  
    -- hide the gui 
    guiSetVisible(jobWindow,false) 
    -- attach the event onClientGUIClick to teleportButtonLS and set it to trigger the 'teleportPlayer' function 
    addEventHandler("onClientGUIClick", taip, givejobPlayer, false) 
  
-- attach the event onClientGUIClick to teleportButtonSF and set it to trigger the 'teleportPlayer' function 
    addEventHandler("onClientGUIClick", ne, givejobPlayer, false) 
end 
  
-- create our function, and add button and state parameters (these are passed automatically with onClickGUIClick) 
function givejobPlayer(button,state) 
    -- if our button was clicked with the left mouse button, and the state of the mouse button is up 
    if button == "left" and state == "up" then 
        -- if the player clicked on the LS teleport button 
        if source == taip then 
        triggerServerEvent("giveJob", getLocalPlayer()) 
            -- output a message to the player 
        -- otherwise, if the player clicked on the SF teleport button 
        elseif source == ne then 
            -- output a message to the player 
        outputChatBox ( "Viso gero. Sekmes zaidime!") 
        end 
  
        -- hide the window and all the components 
        guiSetVisible(jobWindow, false) 
  
        -- hide the mouse cursor 
        showCursor(false)        
    end  
end 
  
-- add our event handler, using the root element of the resource 
-- this means it will only trigger when its own resource is started 
addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()),  
    function () 
        -- call the createTeleportWindow function to create our gui 
        createJobWindow() 
    end 
) 
  
-- create our function 
function openJobWindow() 
    -- show the window 
    guiSetVisible(jobWindow,true) 
  
    -- show the mouse cursor 
    showCursor(true,true) 
end 
  
-- define the command /teleportme to call the openTeleportWindow function 
addCommandHandler("me",openJobWindow) 

and ServerSide :

function moveThePlayer(source) 
local playerexp = getElementData(source) 
if (playerexp) <= 500 then 
setElementData(source, "JOB", "POLICININKAS") 
setElementModel(source, 280) 
outputChatBox ( "Sveikiname jus nuo siol esate pareigunas. Dirbkite atsakingai!", source ) 
else 
outputChatBox ( "Jus neturite pakankamai patirties!", source ) 
end 
end 
  
-- define our custom event, and allow it to be triggered from the client ('true') 
addEvent("giveJob",true) 
-- add an event handler so that when movePlayerToPosition is triggered, the function moveThePlayer is called 
addEventHandler("giveJob",root,moveThePlayer) 

this scripts don't work got error: Bad argument @ 'getElementData' [Expected element at argument 1, got nil]

attempt to compare boolean with number

Link to comment
  
function moveThePlayer(source) 
local playerexp = getElementData(source, "Exp") 
if not playerexp then 
setElementData(source, "Exp", 0) 
end 
if (playerexp) <= 500 then 
setElementData(source, "JOB", "POLICININKAS") 
setElementModel(source, 280) 
outputChatBox ( "Sveikiname jus nuo siol esate pareigunas. Dirbkite atsakingai!", source ) 
else 
outputChatBox ( "Jus neturite pakankamai patirties!", source ) 
end 
end 
  
-- define our custom event, and allow it to be triggered from the client ('true') 
addEvent("giveJob",true) 
-- add an event handler so that when movePlayerToPosition is triggered, the function moveThePlayer is called 
addEventHandler("giveJob",root,moveThePlayer) 
  

You have forget the second argument in getElementData

Link to comment
  
function moveThePlayer() 
local playerexp = getElementData(source, "Exp") 
if not playerexp then 
setElementData(source, "Exp", 0) 
playerexp = 0 
end 
if (playerexp) <= 500 then 
setElementData(source, "JOB", "POLICININKAS") 
setElementModel(source, 280) 
outputChatBox ( "Sveikiname jus nuo siol esate pareigunas. Dirbkite atsakingai!", source) 
else 
outputChatBox ( "Jus neturite pakankamai patirties!", source) 
end 
end 
  
-- define our custom event, and allow it to be triggered from the client ('true') 
addEvent("giveJob",true) 
-- add an event handler so that when movePlayerToPosition is triggered, the function moveThePlayer is called 
addEventHandler("giveJob",root,moveThePlayer) 
  

Link to comment
  
function moveThePlayer() 
local playerexp = getElementData(source, "Exp") 
if not playerexp then 
setElementData(source, "Exp", 0) 
playerexp = 0 
end 
if (playerexp) <= 500 then 
setElementData(source, "JOB", "POLICININKAS") 
setElementModel(source, 280) 
outputChatBox ( "Sveikiname jus nuo siol esate pareigunas. Dirbkite atsakingai!", source) 
else 
outputChatBox ( "Jus neturite pakankamai patirties!", source) 
end 
end 
  
-- define our custom event, and allow it to be triggered from the client ('true') 
addEvent("giveJob",true) 
-- add an event handler so that when movePlayerToPosition is triggered, the function moveThePlayer is called 
addEventHandler("giveJob",root,moveThePlayer) 
  

Your was wrong i fixed it :

function moveThePlayer(player) 
local playerexp = getElementData(source, "EXP") 
if not playerexp then 
setElementData(source, "EXP", 0) 
playerexp = 0 
end 
if (playerexp) >= 500 then 
setElementData(source, "JOB", "POLICININKAS") 
setElementModel(source, 280) 
outputChatBox ( "Sveikiname jus nuo siol esate pareigunas. Dirbkite atsakingai!", player) 
else 
outputChatBox ( "Jus neturite pakankamai patirties!", player) 
end 
end 
  
-- define our custom event, and allow it to be triggered from the client ('true') 
addEvent("giveJob",true) 
-- add an event handler so that when movePlayerToPosition is triggered, the function moveThePlayer is called 
addEventHandler("giveJob",root,moveThePlayer) 

Thanks for help

Link to comment

first we add check

-- open the window 
function openJobWindow() 
    if guiGetVisible(jobWindow) == false then 
        guiSetVisible(jobWindow, true) 
        showCursor(true) 
    end 
end 
addCommandHandler("me",openJobWindow) 
  
-- hide the window 
  
function hideJobWindow() 
    if guiGetVisible(jobWindow) == true then 
        guiSetVisible(jobWindow, false) 
        showCursor(false) 
    end 
end 
  

then we create the marker

local myMarker = createMarker(-2596.625, 579.358, 15.626, 'cylinder', 2.0, 255, 0, 0, 150) 
  
function MarkerHit( hitElement, matchingDimension ) 
    if getElementType( leaveElement ) == "player" then 
        openJobWindow() 
    end 
end 
addEventHandler( "onMarkerHit", myMarker, MarkerHit )  
  
function markerLeave( leaveElement, matchingDimension ) 
        if getElementType( leaveElement ) == "player" then 
        hideJobWindow() 
        end 
end 
addEventHandler( "onMarkerLeave", myMarker, markerLeave ) 

Link to comment
-- open the window 
function openJobWindow() 
    if not guiGetVisible(jobWindow) then 
        guiSetVisible(jobWindow, true) 
        showCursor(true) 
    end 
end 
addCommandHandler("me",openJobWindow) 
  
-- hide the window 
  
function hideJobWindow() 
    if guiGetVisible(jobWindow) then 
        guiSetVisible(jobWindow, false) 
        showCursor(false) 
    end 
end 

then we create the marker

local myMarker = createMarker(-2596.625, 579.358, 15.626, 'cylinder', 2.0, 255, 0, 0, 150) 
  
function MarkerHit(hitElement) 
    if getElementType(hitElement) == "player" then 
        openJobWindow() 
    end 
end 
addEventHandler("onClientMarkerHit", myMarker, MarkerHit)  
  
function markerLeave(leaveElement) 
        if getElementType(leaveElement) == "player" then 
        hideJobWindow() 
        end 
end 
addEventHandler("onClientMarkerLeave", myMarker, markerLeave) 

Link to comment
-- open the window 
function openJob1Window() 
    if not guiGetVisible(job1Window) then 
        guiSetVisible(job1Window, true) 
        showCursor(true) 
    end 
end 
  
function openJob2Window() 
    if not guiGetVisible(job2Window) then 
        guiSetVisible(job2Window, true) 
        showCursor(true) 
    end 
end 
  
function openJob3Window() 
    if not guiGetVisible(job3Window) then 
        guiSetVisible(job3Window, true) 
        showCursor(true) 
    end 
end 
  
-- hide the window 
  
function hideJob1Window() 
    if guiGetVisible(job1Window) then 
        guiSetVisible(job1Window, false) 
        showCursor(false) 
    end 
end 
  
function hideJob2Window() 
    if guiGetVisible(job2Window) then 
        guiSetVisible(job2Window, false) 
        showCursor(false) 
    end 
end 
  
function hideJob3Window() 
    if guiGetVisible(job3Window) then 
        guiSetVisible(job3Window, false) 
        showCursor(false) 
    end 
end 

then we create the marker

local Job1 = createMarker(-2596.625, 579.358, 15.626, 'cylinder', 2.0, 255, 0, 0, 150) 
local Job2 = createMarker(-2596.625, 579.358, 15.626, 'cylinder', 2.0, 255, 0, 0, 150) 
local Job3 = createMarker(-2596.625, 579.358, 15.626, 'cylinder', 2.0, 255, 0, 0, 150) 
  
function MarkerHit(hitElement) 
if getElementType(hitElement) == "player" then 
     if (source == Job1) then 
        openJob1Window() 
     elseif (source == Job2) then 
        openJob2Window() 
     elseif (source == Job3) then 
        openJob3Window() 
        end 
     end 
end 
addEventHandler("onClientMarkerHit", root, MarkerHit)  
  
function markerLeave(leaveElement) 
        if getElementType(leaveElement) == "player" then 
     if (source == Job1) then 
             hideJob1Window() 
     elseif (source == Job2) then 
             hideJob2Window() 
     elseif (source == Job3) then 
             hideJob3Window() 
        end 
     end 
end 
addEventHandler("onClientMarkerLeave", root, markerLeave) 

Link to comment
local Job1 = createMarker(-2596.625, 579.358, 15.626, 'cylinder', 2.0, 255, 0, 0, 150) 
local Job2 = createMarker(-2596.625, 579.358, 15.626, 'cylinder', 2.0, 255, 0, 0, 150) 
local Job3 = createMarker(-2596.625, 579.358, 15.626, 'cylinder', 2.0, 255, 0, 0, 150) 
  
function MarkerHit(hitElement) 
    if (getElementType(hitElement) == "player" and hitElement == localPlayer) then 
        if (source == Job1) then 
            openJob1Window() 
        elseif (source == Job2) then 
            openJob2Window() 
        elseif (source == Job3) then 
            openJob3Window() 
        end 
    end 
end 
addEventHandler("onClientMarkerHit", root, MarkerHit) 
  
function markerLeave(leaveElement) 
    if (getElementType(leaveElement) == "player" and leaveElement == localPlayer) then 
        if (source == Job1) then 
            hideJob1Window() 
        elseif (source == Job2) then 
            hideJob2Window() 
        elseif (source == Job3) then 
            hideJob3Window() 
        end 
    end 
end 
addEventHandler("onClientMarkerLeave", root, markerLeave) 

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