• Changing player speed with Lua
    24 replies, posted
I'm trying to find a lua script (that is, I can simply type lua_openscript) that makes me able to change player speed. Walk speed to 120 and run speed to 240. What must I do for that? Also, any reversing to it? And in case you know how, how can I make it so jumping doesn't make any "boost"? I'm tired of seeing bunnyhopping in scary maps.
Player:SetWalkSpeed( int ) and Player:SetRunSpeed( int )
Doesn't work, when I run it I get this lua error; [ERROR] lua/speed.lua:1: attempt to index global 'Player' (a function value) 1. unknown - lua/speed.lua:1 This is what I put on the lua script if it matters; Player:SetWalkSpeed( 120 ) Player:SetRunSpeed( 240 )
You have to provide a proper player variable in a function or hook. You can't just outright set the player's speed
Then how do I make it so it affects everyone? Even people that just got in the server?
Put it in a PlayerInitialSpawn hook. Alternatively, you could use player classes.
Player class? How? I forgot to say that I know nothing about lua, not sure if that matters though.
[QUOTE=Blitzoreo;47838344]Player class? How? I forgot to say that I know nothing about lua, not sure if that matters though.[/QUOTE] [lua] hook.Add("PlayerInitialSpawn", "nice unique name here", function(ply) ply:MethodHere(arguments_here) end) [/lua]
Like this? [CODE]hook.Add("PlayerInitialSpawn", "speedchange", function(ply) ply:SetWalkSpeed(120) ply:SetRunSpeed(240) end)[/CODE] It doesn't work. I get no lua error but it still doesn't do anything to speed. It still remains at 200 and 400.
You're putting that in autorun/server, right?
No, I'm just making a "Speed.lua" file in the garrysmod/lua folder and just run it on console ("lua_openscript Speed.lua"). I just want this Lua script to be manual, not automatic.
Then it will only start applying to people who first join the server.
I remember being able to make a lua script in which ALL players that were in the server had their speed changed and couldn't be reset when they die. How do I do that? Any full script about it?
Use player.GetAll() in a loop
I put this code [CODE]local Players = player.GetAll() for i = 1, table.Count(Players) do local ply = Players[i] ply:SetWalkSpeed(120) ply:SetRunSpeed(240) ply:SetJumpPower(150) end[/CODE] It works nice, but when a player respawns he gets back to "normal speed" (200 and 400), how can I avoid that? Also, is there any way to remove "Jump Speed"? I mean, with jump power it should be okay, but there's still the way how when a player jumps while running forward will give him like a triple speed boost.
[QUOTE=Blitzoreo;47855336]I put this code [CODE]local Players = player.GetAll() for i = 1, table.Count(Players) do local ply = Players[i] ply:SetWalkSpeed(120) ply:SetRunSpeed(240) ply:SetJumpPower(150) end[/CODE] And it works perfectly. Thanks for the help. Although, is there any way to remove "Jump Speed"? I mean, with jump power it should be okay, but there's still the way how when a player jumps while running forward will give him like a triple speed boost.[/QUOTE] Try adding in an anti-bhop script.
What do you mean by that? The "Velocity Killer" that is on Gmod workshop? Also, I edited my post after that.
Bump
Bump [editline]5th June 2015[/editline] [QUOTE=code_gs;47841265]You're putting that in autorun/server, right?[/QUOTE] Even if I put [CODE]hook.Add("PlayerInitialSpawn", "speedchange", function(ply) ply:SetWalkSpeed(120) ply:SetRunSpeed(240) end)[/CODE] into autorun/server, it doesn't work.
[QUOTE=Blitzoreo;47884709]Bump [editline]5th June 2015[/editline] Even if I put [CODE]hook.Add("PlayerInitialSpawn", "speedchange", function(ply) ply:SetWalkSpeed(120) ply:SetRunSpeed(240) end)[/CODE] into autorun/server, it doesn't work.[/QUOTE] That means something else is setting the player speed. For a *hacky* fix, put it in a 5 second timer.
Can't I put a "Think" function/hook in here? [CODE]local Players = player.GetAll() for i = 1, table.Count(Players) do local ply = Players[i] ply:SetWalkSpeed(120) ply:SetRunSpeed(240) ply:SetJumpPower(150) end[/CODE] So it constantly activates it on every tick or so? I just don't know how, that's what I'd like to know.
No. That's useless and inefficient.
GOD! Please take a look at the official gmod lua wiki! [lua] hook.Add("PlayerSpawn", "Gayfagfunctionhookofallpenissuckingmonsters", function(ply) -- playerspawn hook(important!) timer.Simple(1, function() -- timer for overwriting other shit scripts which sets walk,run speed and jump power :( if ply:IsValid() -- HAHA i Used ply:IsValid() thats totally out of date |||||| IsValid(x) is the new x:IsValid() <3333333 ply:SetWalkSpeed(500000) -- high ply:SetRunSpeed(5000000000) -- super high ply:SetJumpPower(100) -- really low end -- men this took like 2 minutes :( end) -- another end(this looks sooo messed up, but nvm!!) end) -- an end with a ")" awsm -- every player who spawns gets high speed and if they run more high speed (change the speed var else youll never see anyone again on youre server) Well I should sell it on scriptfodder as "dynamic player speed changement without vgui (good performance,yay) (first day sale)". :P [/lua] on TTT this wont work, as TTT resets playerspeed everytime you zoom with a weapon :) if you use TTT and want a ugly method so this is something for you! [lua] hook.Add("PlayerSpawn", "Gayfagfunctionhookofallpenissuckingmonsters", function(ply) -- playerspawn hook(important!) timer.Create("Imgayandthatscool_", ply:UniqueID(), 0.3, 0, function() if IsValid(ply) then -- is player still here ply:SetWalkSpeed(500000) -- high ply:SetRunSpeed(5000000000) -- super high ply:SetJumpPower(100) -- really low end -- another end yay end) -- end again! end) -- an end with a ")" awsm hook.Add("PlayerDeath", "timerfuckyou;death", function(ply) death fuck fuckyoutimer(ply) fucky end hook.Add("PlayerDisconnected", "timerfuckyou;death", function(ply) disconnect fuck fuckyoutimer(ply) -- fuuuuuk you .... end function fuckyoutimer(ply) timer.Remove("Imgayandthatscool_", ply:UniqueID()) -- YOU SHOULD GO AWAY, I said fuck off TIMER!!! end [/lua] This doesnt work for 70% :D, just paste lua error here.
[CODE][ERROR] lua/whogivesafuck.lua:11: '=' expected near 'fuck' 1. unknown - lua/whogivesafuck.lua:0 [/CODE] and the first lua script gives; [CODE][ERROR] lua/speedactionistic.lua:4: 'then' expected near 'ply' 1. unknown - lua/speedactionistic.lua:0[/CODE] Apparently forgot a "then" right in the end of "ply:IsValid()". I tried it though, and it works great. Thank you.
goes to lua/autorun/server Yea i forgot a "then" The 2nd script, I forgot a "--" before "fucky..
Sorry, you need to Log In to post a reply to this thread.