rublisk19 Posted January 27, 2012 Share Posted January 27, 2012 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
FatalTerror Posted January 27, 2012 Share Posted January 27, 2012 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
rublisk19 Posted January 27, 2012 Author Share Posted January 27, 2012 ok i will try and this ? if not playerexp then setElementData(source, "Exp", 0) end i will delete it becouse this are on my login Link to comment
rublisk19 Posted January 27, 2012 Author Share Posted January 27, 2012 Not work error: bad argument @ 'getElementData' [Expected element at argument 1, got nil] attemptto compare boolean with number Link to comment
JR10 Posted January 28, 2012 Share Posted January 28, 2012 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
rublisk19 Posted January 28, 2012 Author Share Posted January 28, 2012 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
DiSaMe Posted January 28, 2012 Share Posted January 28, 2012 That wasn't "wrong", you probably changed the way the event is triggered. Link to comment
JR10 Posted January 28, 2012 Share Posted January 28, 2012 It's not wrong, you added player argument and edited outputChatBox, which won't work, because it's not triggered with an argument. Link to comment
rublisk19 Posted January 28, 2012 Author Share Posted January 28, 2012 how to trigger gui then player hit marker ? Link to comment
rublisk19 Posted January 28, 2012 Author Share Posted January 28, 2012 It's not wrong, you added player argument and edited outputChatBox, which won't work, because it's not triggered with an argument. your doesn't work bad argument Link to comment
JR10 Posted January 28, 2012 Share Posted January 28, 2012 Are you sure? It should work, because you're triggering it with a source. Link to comment
rublisk19 Posted January 28, 2012 Author Share Posted January 28, 2012 yes scripts works good but i have other idea. My target is then player hit marker it open gui Link to comment
Blaawee Posted January 29, 2012 Share Posted January 29, 2012 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
TAPL Posted January 29, 2012 Share Posted January 29, 2012 -- 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
rublisk19 Posted January 31, 2012 Author Share Posted January 31, 2012 thanks works fine and now how to make multiple jobs i make more markers then how to make gui that if i hit medic marker it writes medic info then if i accept that info i trigger 1 function and that function gets what marker triggered and sets job Link to comment
TAPL Posted February 2, 2012 Share Posted February 2, 2012 -- 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
rublisk19 Posted February 3, 2012 Author Share Posted February 3, 2012 I have problem then player hitmarker it open gui for all players how to fix that ?? Link to comment
Castillo Posted February 3, 2012 Share Posted February 3, 2012 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
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now