Baseplate Posted July 29, 2012 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??
Callum Posted July 29, 2012 Posted July 29, 2012 Use onClientClick (see the last param for detecting when the ped was clicked).
Baseplate Posted July 29, 2012 Author Posted July 29, 2012 Thanks, I didn't really understand how to use it, so would you like please to explain more?
Castillo Posted July 29, 2012 Posted July 29, 2012 addEventHandler ( "onElementClicked", ped1, function ( ) outputChatBox ( "Clicked ped1!" ) end )
Baseplate Posted July 29, 2012 Author 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
Baseplate Posted July 29, 2012 Author Posted July 29, 2012 got this error, ERROR: wip\script.lua:9: attempt to call global 'guiCreateWindow' (a nil value)
Castillo Posted July 29, 2012 Posted July 29, 2012 I'm sure that your script is set as server side, GUI is client side only.
Baseplate Posted July 29, 2012 Author 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 )
Baseplate Posted July 29, 2012 Author 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
Baseplate Posted July 29, 2012 Author Posted July 29, 2012 but still when i click on the Ped the GUI isn't showing loolz
Baseplate Posted July 29, 2012 Author 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)
Castillo Posted July 29, 2012 Posted July 29, 2012 When are you executing: "changeVisibility" function?
Castillo Posted July 29, 2012 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.
TheIceman1 Posted July 29, 2012 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 )
Baseplate Posted July 29, 2012 Author Posted July 29, 2012 EDIT: Your code isn't working IceMan but i solved it thanks guys
Castillo Posted July 29, 2012 Posted July 29, 2012 You're welcome. @TheIceman: 'source' of onElementClicked is the element clicked, not who clicked it.
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