Baseplate Posted July 29, 2012 Share Posted July 29, 2012 Well I have created a Ped and here is my ped code ped1 = createPed (280, 1546, -1680.55, 13.56) --Police NPC setPedRotation ( ped1, 90 ) setElementFrozen ( ped1, true ) now, i have a GUI, how can I make it show up when i click on that NPC with the cursor?? Link to comment
Callum Posted July 29, 2012 Share Posted July 29, 2012 Use onClientClick (see the last param for detecting when the ped was clicked). Link to comment
Castillo Posted July 29, 2012 Share Posted July 29, 2012 You can use onElementClicked as well. Link to comment
Baseplate Posted July 29, 2012 Author Share Posted July 29, 2012 Thanks, I didn't really understand how to use it, so would you like please to explain more? Link to comment
Castillo Posted July 29, 2012 Share Posted July 29, 2012 addEventHandler ( "onElementClicked", ped1, function ( ) outputChatBox ( "Clicked ped1!" ) end ) Link to comment
Baseplate Posted July 29, 2012 Author Share Posted July 29, 2012 (edited) Alright! thanks for helping ;D Edit: got this error, ERROR: wip\script.lua:9: attempt to call global 'guiCreateWindow' (a nil value) Edited July 29, 2012 by Guest Link to comment
Baseplate Posted July 29, 2012 Author Share Posted July 29, 2012 got this error, ERROR: wip\script.lua:9: attempt to call global 'guiCreateWindow' (a nil value) Link to comment
Castillo Posted July 29, 2012 Share Posted July 29, 2012 I'm sure that your script is set as server side, GUI is client side only. Link to comment
Baseplate Posted July 29, 2012 Author Share Posted July 29, 2012 yea, i forgot about it lolz, but still it's not working lol, when i click on the ped nothing shows up and no errors are on there EDIT: Code ped1 = createPed (280, 1546, -1680.55, 13.56) --Police NPC setElementData(ped1,"message","Police, click on NPC to get job") setPedRotation ( ped1, 90 ) setElementFrozen ( ped1, true ) addEventHandler ( "onElementClicked", ped1, function ( ) jobPanel = guiCreateWindow(259,170,515,408,"Police",false) acceptButton = guiCreateButton(93,360,119,39,"Accept",false,jobPanel) declineButton = guiCreateButton(258,360,123,39,"Decline",false,jobPanel) descLabel = guiCreateLabel(21,44,90,16,"Job Description",false,jobPanel) descMemo = guiCreateMemo(25,78,478,273,"",false,jobPanel) guiMemoSetReadOnly(descMemo,true) end ) Link to comment
Castillo Posted July 29, 2012 Share Posted July 29, 2012 onElementClicked -> server side event. Link to comment
Baseplate Posted July 29, 2012 Author Share Posted July 29, 2012 alright, still the GUI showing up when i start the resouce...any ideas? and be patient with me lolz, i'm just slow Link to comment
Baseplate Posted July 29, 2012 Author Share Posted July 29, 2012 but still when i click on the Ped the GUI isn't showing loolz Link to comment
Baseplate Posted July 29, 2012 Author Share Posted July 29, 2012 Server: ped1 = createPed (280, 1546, -1680.55, 13.56) --Police NPC setElementData(ped1,"message","Police, click on NPC to get job") setPedRotation ( ped1, 90 ) setElementFrozen ( ped1, true ) exports [ "extra_health" ]:setElementExtraHealth(ped1, 50000000) addEventHandler ( "onElementClicked", ped1, function ( ) end ) Client function changeVisibility ( ) guiSetVisible (policeWindow,true) end policeWindow = guiCreateWindow(259,170,515,408,"Police",true) acceptButton = guiCreateButton(93,360,119,39,"Accept",false,policeWindow) declineButton = guiCreateButton(258,360,123,39,"Decline",false,policeWindow) descLabel = guiCreateLabel(21,44,90,16,"Job Description",false,policeWindow) descMemo = guiCreateMemo(25,78,478,273,"",false,policeWindow) guiMemoSetReadOnly(descMemo,true) Link to comment
Castillo Posted July 29, 2012 Share Posted July 29, 2012 When are you executing: "changeVisibility" function? Link to comment
Castillo Posted July 29, 2012 Share Posted July 29, 2012 You must trigger the event to the player that clicked the element using: triggerClientEvent and add the event handler client side with: addEvent + addEventHandler. Link to comment
TheIceman1 Posted July 29, 2012 Share Posted July 29, 2012 Try this: Server: ped1 = createPed (280, 1546, -1680.55, 13.56) --Police NPC setElementData(ped1,"message","Police, click on NPC to get job") setPedRotation ( ped1, 90 ) setElementFrozen ( ped1, true ) exports [ "extra_health" ]:setElementExtraHealth(ped1, 50000000) addEventHandler ( "onElementClicked", ped1, function ( ) triggerClientEvent ( source, "changeVisibility", source ) end ) Client policeWindow = guiCreateWindow(259,170,515,408,"Police",true) guiSetVisible ( policeWindow, false ) acceptButton = guiCreateButton(93,360,119,39,"Accept",false,policeWindow) declineButton = guiCreateButton(258,360,123,39,"Decline",false,policeWindow) descLabel = guiCreateLabel(21,44,90,16,"Job Description",false,policeWindow) descMemo = guiCreateMemo(25,78,478,273,"",false,policeWindow) guiMemoSetReadOnly(descMemo,true) function changeVisibility ( ) guiSetVisible (policeWindow,true) showCursor ( true ) end addEvent ( "changeVisibility", true ) addEventHandler ( "changeVisibility", root, changeVisibility ) Link to comment
Baseplate Posted July 29, 2012 Author Share Posted July 29, 2012 EDIT: Your code isn't working IceMan but i solved it thanks guys Link to comment
Castillo Posted July 29, 2012 Share Posted July 29, 2012 You're welcome. @TheIceman: 'source' of onElementClicked is the element clicked, not who clicked it. 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