Jump to content

How to make that script?


arer

Recommended Posts

Hi. My question is how to make this script:

When i press LSHIFT and later click W (LSHIFT+W at the same time), player is changing position on X+0.05
The same thing with LSHIFT+S - change position to X-0.05

And.. Repeat this way with Lshift+A, Lshift+D to Y coordinate.

 

bindKey( "lshift", "both", 
function (player) 
    if getKeyState("lshift") == true then 
  local px,py,pz=getElementPosition(player)
    setElementPosition(player, px+0.05, py, pz)
    elseif getKeyState("lshift") == false then 
  local px,py,pz=getElementPosition(player)
    setElementPosition(player, px-0.05, py, pz)
    end 
end ) 

 

I have tried this but it is not working..

Link to comment
  • Scripting Moderators
15 minutes ago, Ahmed Ly said:

You should be used function getKeyState on Client side
Are you used the script on server side?

From the argument, we know he use bindKey on client side. If he pass such arguments on server side, warning will be caused.

Edited by thisdp
  • Like 2
Link to comment
15 minutes ago, Ahmed Ly said:

You should be used function getKeyState on Client side
Are you used the script on server side?

I think this is on client side.

1 minute ago, thisdp said:

From the argument, we know he use bindKey in client side.

 

Im looking for something like this:

https://github.com/lpiob/MTA-XyzzyRP/blob/master/resources/[XyzzyRP]/lss-core/anims_c.lua

 

But this script is made for some gamemode and is not working for me.

Link to comment

You want to move player position when they press lshift + w/a/s/d?

You need to bind w/a/s/d key and check if lshift key is pressed.

bindKey( "w", "down",
	function ()
		if getKeyState( "lshift" ) == true then
			local px,py,pz=getElementPosition(localPlayer)
			setElementPosition(localPlayer, px+0.05, py, pz)
		end
    end
)

-- and more...

Also, adding X coordinate doesn't mean you can go forward (if you trying to make player go forward). You need to get player rotation and finding the +0.05 coordinate in front of player.

  • Thanks 1
Link to comment
4 minutes ago, idarrr said:

You want to move player position when they press lshift + w/a/s/d?

You need to bind w/a/s/d key and check if lshift key is pressed.


bindKey( "w", "down",
	function ()
		if getKeyState( "lshift" ) == true then
			local px,py,pz=getElementPosition(localPlayer)
			setElementPosition(localPlayer, px+0.05, py, pz)
		end
    end
)

-- and more...

Also, adding X coordinate doesn't mean you can go forward (if you trying to make player go forward). You need to get player rotation and finding the +0.05 coordinate in front of player.

You can use this to get position in front etc.

https://wiki.multitheftauto.com/wiki/GetElementMatrix

function getPositionFromElementOffset(element,offX,offY,offZ)
    local m = getElementMatrix ( element )  -- Get the matrix
    local x = offX * m[1][1] + offY * m[2][1] + offZ * m[3][1] + m[4][1]  -- Apply transform
    local y = offX * m[1][2] + offY * m[2][2] + offZ * m[3][2] + m[4][2]
    local z = offX * m[1][3] + offY * m[2][3] + offZ * m[3][3] + m[4][3]
    return x, y, z                               -- Return the transformed point
end

-- Get the position of a point 3 units to the right of the element:
x,y,z = getPositionFromElementOffset(element,3,0,0)

-- Get the position of a point 2 units in front of the element:
x,y,z = getPositionFromElementOffset(element,0,2,0)

-- Get the position of a point 1 unit above the element:
x,y,z = getPositionFromElementOffset(element,0,0,1)

 

  • Thanks 1
Link to comment

Thanks all it works very fine

But how to fill getPositionFromElementOffset good in script to set for example X coordinate as (player front facing angle)+0.5??

function getPositionFromElementOffset(element,offX,offY,offZ)
    local m = getElementMatrix ( element )  -- Get the matrix
    local x = offX * m[1][1] + offY * m[2][1] + offZ * m[3][1] + m[4][1]  -- Apply transform
    local y = offX * m[1][2] + offY * m[2][2] + offZ * m[3][2] + m[4][2]
    local z = offX * m[1][3] + offY * m[2][3] + offZ * m[3][3] + m[4][3]
    return x, y, z                               -- Return the transformed point
end


bindKey( "w", "down",
	function ()
		if getKeyState( "lshift" ) == true then
			local px,py,pz=getElementPosition(localPlayer)
			local x,y,z = getPositionFromElementOffset(localPlayer, px, py, pz)
			setElementPosition(localPlayer, x, y, z)
		end
    end
)

 

It's throwing away my character on some far away coordinates.

 

Link to comment
  • Moderators

Use the camera object.

https://wiki.multitheftauto.com/wiki/GetCamera

 

local camera = getCamera()
bindKey( "w", "down",
	function ()
		if getKeyState( "lshift" ) == true then
      		-- position is already included in the matrix
			local x,y,z = getPositionFromElementOffset(camera, 0, 3, 0)
			setElementPosition(localPlayer, x, y, z)
		end
    end
)

 

Edited by IIYAMA
  • Like 1
Link to comment

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...