greentumbleweed Posted January 28, 2017 Share Posted January 28, 2017 local sprint = true function updateSprint () local state = getControlState ( "forwards" ) local playeR = getLocalPlayer() local speedx, speedy, speedz = getElementVelocity (playeR) if state and sprint == false then setElementVelocity(playeR, speedx * 2, speedy * 2, speedz) elseif sprint == true then return end end addEventHandler ( "onClientElementStreamIn", getRootElement(), updateSprint ) function startSprint() if sprint then sprint = false else sprint = true end end bindKey ( "mouse2", "down", startSprint ) im not even sure im going the right way about this but its not seeming to work Link to comment
Mr.Loki Posted January 28, 2017 Share Posted January 28, 2017 It's pretty close but you need to use onClientRender instead of streamIn. instead of using getLocalPlayer() just use localPlayer it is a predefined variable for example x,y,a = getElementVelocity(localPlayer) This wont work unless you jump because you can't set a ped's velocity while it is on the ground. easiest way is to just get the pisition to the front of the player and teleport him to it but the distance to the position in front of you should be very small like .01 Here's a simpler way of writing the function. addEventHandler ( "onClientRender", root, function () if getKeyState( "mouse2" ) then ----------- --CODE ----------- end end ) Link to comment
greentumbleweed Posted January 29, 2017 Author Share Posted January 29, 2017 well, i dont think teleporting the player wll do what im trying to do. i just want to increase the acceleration of the player. you have any idea if setElementSpeed would work? ive tried but... failed! Link to comment
Mr.Loki Posted January 29, 2017 Share Posted January 29, 2017 Is it not this that you are trying to accomplish? https://streamable.com/5jw0g Link to comment
greentumbleweed Posted January 30, 2017 Author Share Posted January 30, 2017 yes, you did that with setElementPosition? Link to comment
Mr.Loki Posted January 30, 2017 Share Posted January 30, 2017 yes by teleporting the player a distance of 0.3m to the front of the model on render. Link to comment
Rose Posted January 30, 2017 Share Posted January 30, 2017 vel =.8 function sPeedUp() if isElement(element) then if getElementData(element, "charging") == "on" then local x, y, z = getElementPosition(element) local prot = getPedRotation(element) local nx, ny = getPointFromDistanceRotation(x, y, vel, (prot)*-1) local clear = isLineOfSightClear( x, y, z, nx, ny, z, true, true, true, true, true, true, true) if clear == true then local lx, ly = getPointFromDistanceRotation(x, y, 1, (prot-8)*-1) local rx, ry = getPointFromDistanceRotation(x, y, 1, (prot+8)*-1) local clearl = isLineOfSightClear( x, y, z, lx, ly, z, true, true, true, true, true, true, true) local clearr = isLineOfSightClear( x, y, z, rx, ry, z, true, true, true, true, true, true, true) if clearl == true and clearr == true then local task = getPedSimplestTask(element) if task == "TASK_SIMPLE_PLAYER_ON_FOOT" then local nz = getGroundPosition ( nx, ny, z+1 ) if getDistanceBetweenPoints3D( x, y, z, nx, ny, nz) < 2 then setElementPosition(element, nx, ny, nz+1, false) end end end end end end end addEventHandler("onClientRender", root, sPeedUp) 1 Link to comment
greentumbleweed Posted January 30, 2017 Author Share Posted January 30, 2017 (edited) thanks a whole lot of lots! this has been giving me headaches, never would have thought setElementPosition was the answer Edited January 30, 2017 by greentumbleweed Link to comment
greentumbleweed Posted January 30, 2017 Author Share Posted January 30, 2017 well ive ran into a few more problems trying to make it work better. Im not sure how you made it teleport in front of the player, im trying to get it to work for all keys WSAD, also when i jump and im moving forward sometimes it still teleports me back on the ground function startSprint() local wep = getPedWeaponSlot (localPlayer) if not (wep == 0) then return end if sprint then sprint = false setElementData(localPlayer, "charging","on") else sprint = true setElementData(localPlayer, "charging","off") end end bindKey ( "mouse2", "down", startSprint ) vel = 0.05 function sPeedUp() if isElement(localPlayer) then if getElementData(localPlayer, "charging") == "on" then local x, y, z = getElementPosition(localPlayer) local prot = getPedRotation(localPlayer) local nx, ny = getPointFromDistanceRotation(x, y, vel, (prot)*-1) local clear = isLineOfSightClear( x, y, z, nx, ny, z, true, true, true, true, true, true, true) if clear == true then local lx, ly = getPointFromDistanceRotation(x, y, 1, (prot-8)*-1) local rx, ry = getPointFromDistanceRotation(x, y, 1, (prot+8)*-1) local clearl = isLineOfSightClear( x, y, z, lx, ly, z, true, true, true, true, true, true, true) local clearr = isLineOfSightClear( x, y, z, rx, ry, z, true, true, true, true, true, true, true) if clearl == true and clearr == true then local W = getControlState ( "forwards" ) local S = getControlState ( "backwards" ) local A = getControlState ( "left" ) local D = getControlState ( "right" ) local jump = getControlState ( "jump" ) if jump then return end local nz = getGroundPosition ( nx, ny, z+1 ) if getDistanceBetweenPoints3D( x, y, z, nx, ny, nz) < 2 then if W or S or A or D then setElementPosition(localPlayer, nx, ny, nz+1, false) end end end end end end end addEventHandler("onClientRender", root, sPeedUp) Link to comment
ViRuZGamiing Posted January 30, 2017 Share Posted January 30, 2017 Wouldn't get camera matrix' 4th, 5th and 6th returned float help? I suppose that Position is always where you're looking at of you'd need to Ignore the height of where it's looking else you'd teleport on top of things. At least that's what I think Link to comment
greentumbleweed Posted January 30, 2017 Author Share Posted January 30, 2017 1 hour ago, ViRuZGamiing said: Wouldn't get camera matrix' 4th, 5th and 6th returned float help? I suppose that Position is always where you're looking at of you'd need to Ignore the height of where it's looking else you'd teleport on top of things. At least that's what I think "else you'd teleport on top of things" - this only happens when i aim my weapon and im teleporting forward into a light pole, so yes it happens but, other than that i do not teleport ontop of things. not much of a point in speeding up the player while aiming anyways "I suppose that Position is always where you're looking at" - not exactly, W works perfectly fine in any direction however moving left right and backwards still moves me forwards. im assuming it has something to do with getPedRotation "wouldn't get camera matrix' 4th, 5th and 6th returned float help?" - i only need the direction of the player not the camera 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