Some simple help with lua D:

Hey so im basically just starting to code in glua, and im making a script for DarkRp which will get all players playing as a certain job, and if their speed on the x axis is too great it will lessen it.

The problem i’m having is how can i return the x speed of a player and set the x speed instead of the entire players velocity?

My second question is: is there a better way of changing the x speeds of only players playing as a certain team than using a for loop to loop all the players and check their team every tick?

Thanks in advance, sorry if i’m unclear cos i just started ;-;

Why do you only want the X speed?

[editline]5th February 2016[/editline]

Also, to only get the X speed, you could do this:



local xspeed = ply:GetVelocity().x


ah thanks a lot man, i guess i can go one step further here.
I’m basically trying to prevent the player from falling faster than 500 speed and to try to make them not take fall damage because of that without actually disabling fall damage, their supposed to float down with their wings and shit u know.

Here is the script i have now, would you mind just telling me everything thats wrong with it please? xD

EDIT: up and down is the y axis isnt it? i make mistakes like this xd, besides that code doesnt work anyway and idk why D:

If you’re talking about falling speed, its on the Z axis, and you can do it like this:


hook.Add("PlayerPostThink", "SlowFall", function(ply)
	-- Check for job here. Return if it's not the job you want.
	local vel = ply:GetVelocity()
	local limit = 500 -- Some arbitrary speed limit number
	if vel.z > limit then
		vel.z = limit -- Shorten the fall speed to the limit.
		ply:SetVelocity(vel - ply:GetVelocity()) -- ply:SetVelocity adds to the player's velocity, so minus the original velocity and put our new one in.
	end
end

Also to answer your second question about a better method rather than looping through all players, I’ve used the hook PlayerPostThink in my example. It runs every frame for each player.

oh wow thanks a lot man, is that completely serverside there?

GM/PlayerPostThink,

Entity:GetVelocity,

Entity:SetVelocity. Yes.