Been playing around with lua, and I need help...

Hello, I am basically brand new to modding Gmod and to this forum, so I don’t know if this is even the right place to post…

Anyway, through tutorials online with lua and gmod I have managed to make a very simple mod that can change walk and run speed. It is technically a gamemode derived from sandbox, with a few extra scripts to add new console commands and hopefully(if I can figure this out) more. However my problem with this is that when I try to set the walk speed to anything higher than around 3500 I get some strange movement distortions(I will post a vid). Also the ground speed is “psuedo-capped” at around 4000, even when setting Player:SetWalkSpeed to something like 10,000 I can’t get anywhere near 5,000. Something else interesting is that upon setting the speed to below 6.67 there is no movement from input.

NOTE: I really have no idea if any of this is right, first lua, first game mod :confused:

Code:

cl_init.lua


include("shared.lua")

include("NewStuff/NewCommands.lua")
include("NewStuff/NewFunctions.lua")

init.lua


AddCSLuaFile("cl_init.lua")
AddCSLuaFile("shared.lua")
AddCSLuaFile("NewStuff/NewCommands.lua")
AddCSLuaFile("NewStuff/NewFunctions.lua")

include("shared.lua")

include("NewStuff/NewCommands.lua")
include("NewStuff/NewFunctions.lua")

shared.lua


GM.Name = "sandbox"
GM.author = "KingOfPigs"

DeriveGamemode("sandbox")

NewFunctions.lua


function NewSpeed(me, cmd, speed)
	print(speed[1])
	if speed==nil then speed[1] = 190
	end
	local runSpeed = speed[1] * 1.68421052632
	--local plycon = LocalPlayer()
	me:SetWalkSpeed(speed[1])
	me:SetRunSpeed(runSpeed)
end

function continuousJumpVar(me, cmd, arg)
	isTrue = 0
	if arg[1] == 0 or 1 then
		isTrue = arg[1]
	else print("Only 1 or 0 is accepted")
	isTrue = 0
	end
end

function jumper (me, cmd, arg)
	if isTrue == 1 then
		if me:KeyDown(IN_JUMP) == true then
		print("works")
			if me:IsOnGround() == true then
				RunConsoleCommand("+jump")
				print("jump")
			end
		end
	end
end

NewCommands.lua


include ( "Newfunctions.lua")

concommand.Add("setspeedvar" , NewSpeed)

concommand.Add("jumping" , continuousJumpVar)

Folder Structure:
C:\Steam\steamapps\common\GarrysMod\garrysmod\gamemodes\ExtendedSandbox

inside ExtendedSandbox:
\entities
\gamemode
\ExtendedSandbox.txt

inside gamemode:
\cl_init.lua \init.lua \shared.lua
\NewStuff

inside NewStuff:
\NewFunctions.lua
\NewCommands.lua

[editline]11th October 2017[/editline]

The videos of these events:
Wait until they are processed by youtube

Haven’t watched your videos, but I had a similar problem with setting an entity speed, and it turned out that there is a convar that (by default) limits entity speeds to 3500. However, the speed limit is implemented incorrectly. It checks each component of the speed Vector instead of the magnitude, so when it performs a correction, it changes the direction in addition to the magnitude. This is likely the cause of the “strange movement distortions” you mentioned.

You can try using this, is it still doesn’t work you can try directly setting the velocity yourself with this:

If that still doesn’t work try this:



perf = physenv.GetPerformanceSettings()
perf.MaxVelocity = 10000
physenv.SetPerformanceSettings(perf)

Thank you! Will check it out when I have time