Hello there!
I have a little problem with a script I'm making for TTT:
It's supposed to be an RTD system, and there's a positive effect where it modifies someone's speed for a few seconds.
I'm trying to use ply.SetMaxSpeed, ply.SetWalkSpeed, and all of these functions that change specific speeds for each move but it doesn't work.
So I made it do a think hook, and it won't work either.
I tried "GAMEMODE:SetPlayerSpeed(ply,desiredspeed,desiredspeed)" but that won't work either.
I don't know what to do now!
Here's the code I have for my effect:
[lua]
["RunFaster"] = function(player)
if IsValid(player) and player:IsPlayer() and not player:IsBot() then
local duration = 10
hook.Add("Think","TTT_RTD_"..tostring(player:EntIndex()).."_RunFaster",function()
GAMEMODE:SetPlayerSpeed(player,400,400)
end)
net.Start("TTT_RTD_Chat")
net.WriteTable({Color(0,100,255),player:Name(),color_white," will ",color_green,"move faster",color_white," for ",color_green,tostring(duration),color_white," seconds! Gotta go fast!"})
net.Broadcast()
player.RTDEffect = "RunFaster"
timer.Simple(duration,function()
if player.RTDEffect != nil then
hook.Remove("Think","TTT_RTD_"..tostring(player:EntIndex()).."_RunFaster")
timer.Simple(0.1,function()
GAMEMODE:SetPlayerSpeed(player,220,220)
end)
RTD_Effect_Ended_Message(player)
player.RTDEffect = nil
end
end)
end
end,
[/lua]
So what do/try now?
It seems that TTT resets it but...
Thank you!
I don't need the code to be fixed, just a hint on what I'm doing wrong and what I should use to change a player's speed in TTT.
Maybe because there is no func like "SetPlayerSpeed".
[url]http://wiki.garrysmod.com/page/Player/SetRunSpeed[/url]
[url]http://wiki.garrysmod.com/page/Player/SetWalkSpeed[/url]
No, GAMEMODE:SetPlayerSpeed.
[URL]http://wiki.garrysmod.com/page/GM/SetPlayerSpeed[/URL]
But I know these others functions, they don't work.
It's because Think calls SetSpeed on the player in the TTT gamemode depending on whether you are ironsighting or not. You must override this function otherwise your speed will just be reset.
Here: Because you're probably lazy: [URL="https://github.com/garrynewman/garrysmod/blob/master/garrysmod/gamemodes/terrortown/gamemode/player_ext.lua#L207"]https://github.com/garrynewman/garrysmod/blob/master/garrysmod/gamemodes/terrortown/gamemode/player_ext.lua#L207[/URL]
Do what netheous said.
I did this:
[CODE]function META:SetSpeed(slowed)
if not self.RTDEffect == "RunFaster" then
if slowed then
self:SetWalkSpeed(120)
self:SetRunSpeed(120)
self:SetMaxSpeed(120)
else
self:SetWalkSpeed(220)
self:SetRunSpeed(220)
self:SetMaxSpeed(220)
end
end
end
-- Code is separated there, they're just in the same code tags.
["RunFaster"] = function(player)
if IsValid(player) and player:IsPlayer() and not player:IsBot() then
local duration = 10
hook.Add("Think","TTT_RTD_"..tostring(player:EntIndex()).."_RunFaster",function()
player:SetMaxSpeed(400)
player:SetWalkSpeed(400)
player:SetRunSpeed(400)
end)
net.Start("TTT_RTD_Chat")
net.WriteTable({Color(0,100,255),player:Name(),color_white," will ",color_green,"move faster",color_white," for ",color_green,tostring(duration),color_white," seconds! Gotta go fast!"})
net.Broadcast()
player.RTDEffect = "RunFaster"
timer.Simple(duration,function()
if player.RTDEffect != nil then
hook.Remove("Think","TTT_RTD_"..tostring(player:EntIndex()).."_RunFaster")
timer.Simple(0.1,function()
player:SetMaxSpeed(220)
player:SetWalkSpeed(220)
player:SetRunSpeed(220)
end)
RTD_Effect_Ended_Message(player)
player.RTDEffect = nil
end
end)
end
end,[/CODE]
And it still wont work.
Right now, I have no idea of what to do.
Sorry, you need to Log In to post a reply to this thread.