HerculePoirot Posted March 24, 2014 Posted March 24, 2014 Is there any way to detect click on a specific ped?
cheez3d Posted March 24, 2014 Posted March 24, 2014 getCursorPosition() returns besides the 2D coordinates from the screen, 3D world coordinates of the position you are pointing at.
OGF Posted March 24, 2014 Posted March 24, 2014 onClientClick https://wiki.multitheftauto.com/wiki/OnClientClick 8th argument The example should give you an idea how it's done
HerculePoirot Posted March 24, 2014 Author Posted March 24, 2014 (edited) there are no errors in console or debugscript but still its not working:- function pedClick(button, state, x, y, fx, fy, fz, clickedElement) if (button == "left" and state == "up") then if (clickedElement == "pedFreightJob") then guiSetVisible(GUIEditor.window[1], true) end end end addEventHandler("onClientClick", root, pedClick) function cursorShowing(button, press) if (button == "m") then if (press == "false") then showCursor(not isCursorShowing) end end end addEventHandler("onClientKey", root, cursorShowing) Edited March 24, 2014 by Guest
HerculePoirot Posted March 24, 2014 Author Posted March 24, 2014 What are you trying to do? I am trying to make a ped which gives a player job, whenever a player clicks on the ped the job take window should open. Whenever a player presses m cursor should show up or hide.
iPrestege Posted March 24, 2014 Posted March 24, 2014 addEventHandler ( 'onClientClick',root, function ( button, state, absoluteX, absoluteY, worldX, worldY, worldZ, clickedElement ) if ( clickedElement ) and ( getElementType ( clickedElement ) == 'ped' ) then if ( clickedElement == pedFreightJob ) then if ( guiGetVisible ( GUIEditor.window[1] ) == false ) then guiSetVisible ( GUIEditor.window[1],true ) end end end end ) bindKey ( 'm','down', function ( ) showCursor ( not isCursorShowing ( ) ) end ) Try that.
HerculePoirot Posted March 24, 2014 Author Posted March 24, 2014 addEventHandler ( 'onClientClick',root, function ( button, state, absoluteX, absoluteY, worldX, worldY, worldZ, clickedElement ) if ( clickedElement ) and ( getElementType ( clickedElement ) == 'ped' ) then if ( clickedElement == pedFreightJob ) then if ( guiGetVisible ( GUIEditor.window[1] ) == false ) then guiSetVisible ( GUIEditor.window[1],true ) end end end end ) bindKey ( 'm','down', function ( ) showCursor ( not isCursorShowing ( ) ) end ) Try that. The showing cursor part works but clicking on ped part does not work.
iPrestege Posted March 24, 2014 Posted March 24, 2014 Can you please tell me if there's any errors? And does the ped exists? pedFreightJob ?
HerculePoirot Posted March 24, 2014 Author Posted March 24, 2014 Can you please tell me if there's any errors? And does the ped exists? pedFreightJob ? The ped exists and there are no errors in script.
iPrestege Posted March 24, 2014 Posted March 24, 2014 The ped variable is pedFreightJob ? If yes then it should work .
HerculePoirot Posted March 24, 2014 Author Posted March 24, 2014 Well it should work . Its not working
HerculePoirot Posted March 24, 2014 Author Posted March 24, 2014 I defined it in the server side script to create the ped
Castillo Posted March 24, 2014 Posted March 24, 2014 Well, there you got the problem, variables ain't shared between client and server side.
iPrestege Posted March 24, 2014 Posted March 24, 2014 Do you have any more PED except that one in the resource? If NO then you can modify it to : addEventHandler ( 'onClientClick',root, function ( button, state, absoluteX, absoluteY, worldX, worldY, worldZ, clickedElement ) if ( clickedElement ) and ( getElementType ( clickedElement ) == 'ped' ) then for _,ped in ipairs ( getElementsByType ( 'ped',resourceRoot ) ) do if ( clickedElement == ped ) then if ( guiGetVisible ( GUIEditor.window[1] ) == false ) then guiSetVisible ( GUIEditor.window[1],true ) end end end end end ) bindKey ( 'm','down', function ( ) showCursor ( not isCursorShowing ( ) ) end ) And it should work as well .
HerculePoirot Posted March 25, 2014 Author Posted March 25, 2014 Thanks Soldsnake14, I didn't knew about that. Thanks Mr.Pres[T]ege, it worked.
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