Ryuto Posted December 27, 2022 Share Posted December 27, 2022 I would like to know if there is any way to be able to aim or select a player regardless of whether they are far away with the mouse2 or the right button, without the need for a weapon. What functions could I use? This is what I want to try to achieve: Link to comment
Trust aka Tiffergan Posted January 2, 2023 Share Posted January 2, 2023 @Ryuto Maybe something with https://wiki.multitheftauto.com/wiki/SetCursorPosition https://wiki.multitheftauto.com/wiki/GetCursorPosition And something with getting name of the player when cursor is on them? Hmm hard question... Link to comment
KaMi Posted January 2, 2023 Share Posted January 2, 2023 local playerSelectedTarget local targetMarker = createMarker( 0, 0, 10000, "arrow", 1.5, 255, 0, 0 ) addEventHandler("onClientRender", root, function() if ( getKeyState("mouse2") == true ) then local x,y,z = getElementPosition(localPlayer) for k,target in ipairs(getElementsByType("player",root,true)) do if not ( target == localPlayer ) then local px,py,pz = getElementPosition(target) local distance = getDistanceBetweenPoints3D( px, py, pz, x, y, z ) if ( distance < 10 ) then --target distance playerSelectedTarget = target end end end if isElement(playerSelectedTarget) then local tx,ty,tz = getElementPosition(playerSelectedTarget) setElementPosition( targetMarker, tx, ty, tz+3 ) end else if isElement(playerSelectedTarget) then setElementPosition( targetMarker, 0, 0, 10000 ) end end end ) 1 Link to comment
Ryuto Posted February 6, 2023 Author Share Posted February 6, 2023 On 1/2/2023 at 1:40 PM, KaMi said: local playerSelectedTarget local targetMarker = createMarker( 0, 0, 10000, "arrow", 1.5, 255, 0, 0 ) addEventHandler("onClientRender", root, function() if ( getKeyState("mouse2") == true ) then local x,y,z = getElementPosition(localPlayer) for k,target in ipairs(getElementsByType("player",root,true)) do if not ( target == localPlayer ) then local px,py,pz = getElementPosition(target) local distance = getDistanceBetweenPoints3D( px, py, pz, x, y, z ) if ( distance < 10 ) then --target distance playerSelectedTarget = target end end end if isElement(playerSelectedTarget) then local tx,ty,tz = getElementPosition(playerSelectedTarget) setElementPosition( targetMarker, tx, ty, tz+3 ) end else if isElement(playerSelectedTarget) then setElementPosition( targetMarker, 0, 0, 10000 ) end end end ) It worked perfect for me, thank you. I have another question, how can I use that code to detect if the player is being selected? And if so, what method can I use to make the selected player do an animation? Link to comment
FLUSHBICEPS Posted February 8, 2023 Share Posted February 8, 2023 --server-side code addEvent("doAnimation", true) addEventHandler("doAnimation", root, function(target) setPedAnimation(target, "CRACK", "crckdeth2", -1, false, false, false, false) setTimer( function() setPedAnimation(target) end, 10000, 1 ) -- stop animation after 10 seconds end ) --client-side code local playerSelectedTarget local targetMarker = createMarker( 0, 0, 10000, "arrow", 1.5, 255, 0, 0 ) addEventHandler("onClientRender", root, function() if ( getKeyState("mouse2") == true ) then local x,y,z = getElementPosition(localPlayer) for k,target in ipairs(getElementsByType("player",root,true)) do if not ( target == localPlayer ) then local px,py,pz = getElementPosition(target) local distance = getDistanceBetweenPoints3D( px, py, pz, x, y, z ) if ( distance < 10 ) then --target distance playerSelectedTarget = target triggerServerEvent("doAnimation", root, playerSelectedTarget) -- trigger server event end end end if isElement(playerSelectedTarget) then local tx,ty,tz = getElementPosition(playerSelectedTarget) setElementPosition( targetMarker, tx, ty, tz+3 ) end else if isElement(playerSelectedTarget) then setElementPosition( targetMarker, 0, 0, 10000 ) end end end ) Link to comment
Sr.black Posted February 8, 2023 Share Posted February 8, 2023 (edited) local playerSelectedTarget local targetMarker = createMarker( 0, 0, 10000, "arrow", 1.5, 255, 0, 0 ) addEventHandler("onClientRender", root, function() if ( getKeyState("mouse2") == true ) then local x,y,z = getElementPosition(localPlayer) for k,target in ipairs(getElementsByType("player",root,true)) do if not ( target == localPlayer ) then local px,py,pz = getElementPosition(target) local distance = getDistanceBetweenPoints3D( px, py, pz, x, y, z ) if ( distance < 10 ) then --target distance playerSelectedTarget = target end end end if isElement(playerSelectedTarget) then local tx,ty,tz = getElementPosition(playerSelectedTarget) setElementPosition( targetMarker, tx, ty, tz+3 ) end else if isElement(playerSelectedTarget) then setElementPosition( targetMarker, 0, 0, 10000 ) end end end ) Edited February 8, 2023 by Sr.black Link to comment
Ryuto Posted February 10, 2023 Author Share Posted February 10, 2023 On 2/8/2023 at 9:02 AM, FLUSHBICEPS said: --server-side code addEvent("doAnimation", true) addEventHandler("doAnimation", root, function(target) setPedAnimation(target, "CRACK", "crckdeth2", -1, false, false, false, false) setTimer( function() setPedAnimation(target) end, 10000, 1 ) -- stop animation after 10 seconds end ) --client-side code local playerSelectedTarget local targetMarker = createMarker( 0, 0, 10000, "arrow", 1.5, 255, 0, 0 ) addEventHandler("onClientRender", root, function() if ( getKeyState("mouse2") == true ) then local x,y,z = getElementPosition(localPlayer) for k,target in ipairs(getElementsByType("player",root,true)) do if not ( target == localPlayer ) then local px,py,pz = getElementPosition(target) local distance = getDistanceBetweenPoints3D( px, py, pz, x, y, z ) if ( distance < 10 ) then --target distance playerSelectedTarget = target triggerServerEvent("doAnimation", root, playerSelectedTarget) -- trigger server event end end end if isElement(playerSelectedTarget) then local tx,ty,tz = getElementPosition(playerSelectedTarget) setElementPosition( targetMarker, tx, ty, tz+3 ) end else if isElement(playerSelectedTarget) then setElementPosition( targetMarker, 0, 0, 10000 ) end end end ) How can I add something on the server side that will detect when a player is being targeted and when the targeting is detected run something like an animation. I'm looking for something similar to the getPedTarget function but with this selection system. I hope I explained myself well Link to comment
FLUSHBICEPS Posted February 11, 2023 Share Posted February 11, 2023 --server-side code addEvent("doAnimation", true) addEvent("onTargetSelected", true) -- added trigger for player targeting addEventHandler("onTargetSelected", root, function(target) setPedAnimation(target, "CRACK", "crckdeth2", -1, false, false, false, false) setTimer( function() setPedAnimation(target) end, 10000, 1 ) -- stop animation after 10 seconds end ) --client-side code local playerSelectedTarget local targetMarker = createMarker( 0, 0, 10000, "arrow", 1.5, 255, 0, 0 ) addEventHandler("onClientRender", root, function() if ( getKeyState("mouse2") == true ) then local x,y,z = getElementPosition(localPlayer) for k,target in ipairs(getElementsByType("player",root,true)) do if not ( target == localPlayer ) then local px,py,pz = getElementPosition(target) local distance = getDistanceBetweenPoints3D( px, py, pz, x, y, z ) if ( distance < 10 ) then --target distance playerSelectedTarget = target triggerServerEvent("onTargetSelected", root, playerSelectedTarget) -- trigger server event end end end if isElement(playerSelectedTarget) then local tx,ty,tz = getElementPosition(playerSelectedTarget) setElementPosition( targetMarker, tx, ty, tz+3 ) end else if isElement(playerSelectedTarget) then setElementPosition( targetMarker, 0, 0, 10000 ) end end end ) Link to comment
Ryuto Posted February 13, 2023 Author Share Posted February 13, 2023 On 11/02/2023 at 20:31, FLUSHBICEPS said: --server-side code addEvent("doAnimation", true) addEvent("onTargetSelected", true) -- added trigger for player targeting addEventHandler("onTargetSelected", root, function(target) setPedAnimation(target, "CRACK", "crckdeth2", -1, false, false, false, false) setTimer( function() setPedAnimation(target) end, 10000, 1 ) -- stop animation after 10 seconds end ) --client-side code local playerSelectedTarget local targetMarker = createMarker( 0, 0, 10000, "arrow", 1.5, 255, 0, 0 ) addEventHandler("onClientRender", root, function() if ( getKeyState("mouse2") == true ) then local x,y,z = getElementPosition(localPlayer) for k,target in ipairs(getElementsByType("player",root,true)) do if not ( target == localPlayer ) then local px,py,pz = getElementPosition(target) local distance = getDistanceBetweenPoints3D( px, py, pz, x, y, z ) if ( distance < 10 ) then --target distance playerSelectedTarget = target triggerServerEvent("onTargetSelected", root, playerSelectedTarget) -- trigger server event end end end if isElement(playerSelectedTarget) then local tx,ty,tz = getElementPosition(playerSelectedTarget) setElementPosition( targetMarker, tx, ty, tz+3 ) end else if isElement(playerSelectedTarget) then setElementPosition( targetMarker, 0, 0, 10000 ) end end end ) I really appreciate your help, little by little I'm seeing results. I have a small problem, if I hold mouse2 down, the trigger repeats many times. Isn't there another way to detect if the player is being selected without using the trigger? something like an "if" condition to detect if the player is being selected from the serverside. I have another question, is it possible to use a bind when selecting the player so that he performs an animation? for example I select it with mouse2 and if I press the number one button the selected player does an animation. something like this: Local HitPlayer = getPedTarget(thePlayer) if not HitPlayer then return end if HitPlayer and (getElementType(HitPlayer) = "ped" ) then setPedAnimation 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