Hi, I tryed to code a sprint script so when players press W two times in less than 0.3 sec the player starts sprinting untill he releases the W key.
This is the code based on another sprint addon, but couldn't get it to work (I'm new at LUA)
[CODE]hook.Add("KeyPress" , "PulsarW" , function(ply, key)
if (key == IN_FORWARD) then
if ply.ultimaW and ply.ultimaW > CurTime()-0.3 then
ply.sprint = true
end
ply.ultimaW = CurTime()
end
end)
hook.Add("KeyRelease" , "SoltarW" , function(ply,key)
if (key == IN_FORWARD) then
ply.sprint = false
end
end)
hook.Add("InitPostEntity", "Esprintar", function()
local pmeta = FindMetaTable("Player")
pmeta.Correr = function(self, slowed)
local multiplicador = 1
if self.sprint then
multiplicador = 1.3
end
if slowed then
self:SetWalkSpeed(120 * multiplicador)
self:SetRunSpeed(120 * multiplicador)
self:SetMaxSpeed(120 * multiplicador)
else
self:SetWalkSpeed(220 * multiplicador)
self:SetRunSpeed(220 * multiplicador)
self:SetMaxSpeed(220 * multiplicador)
end
end
end)[/CODE]
Correr is only ran once. Meaning it will not notice when ply.sprint is changed. Use a think/tick hook.
[editline]6th December 2015[/editline]
[CODE]
hook.Add("KeyPress" , "PulsarW" , function(ply, key)
if (key == IN_FORWARD) then
if (ply.ultimaW and ply.ultimaW > CurTime()) then
ply.sprint = true
end
ply.ultimaW = CurTime() + 0.3
end
end)
hook.Add("KeyRelease" , "SoltarW" , function(ply,key)
if (key == IN_FORWARD) then
ply.sprint = false
end
end)
hook.Add("Think", "Esprintar", function()
for k, v in pairs(player.GetAll()) do
local multiplicador = 1
if (v.sprint) then
multiplicador = 1.3
v:SetWalkSpeed(220 * multiplicador)
v:SetRunSpeed(220 * multiplicador)
v:SetMaxSpeed(220 * multiplicador)
else
v:SetWalkSpeed(120 * multiplicador)
v:SetRunSpeed(120 * multiplicador)
v:SetMaxSpeed(120 * multiplicador)
end
end
end)
[/CODE]
Could you explain that a little better please? :) I do not know what a think/tick hook is, nor the syntax.
EDIT : You wrote the code thank you, let me check it :)
Un hook the think es por asi decir de pensar, se ejecuta muchas veces por segundo.
Es perfecto para lo que tu buscas.
Lo que tu habias puesto es un codigo que no se ejecutaba ninguna vez ya que estaa definiendo una funxion de los jugadores, que por cierto, tendria que ir fuera de InitializePostEntity y ademas en vez de pmeta.Correr = function(self, slowed) mas bien seria function pmeta:Correr(slowed).
Si es ttt podrias cambiar el hook de think por el de TTTPlayerSpeed y con dos argumentos, el de ply y slowed y tendrias que "devolver" (hacer return) solo la escala que multiplicas por la velocidad.
¿Podrías añadirme a steam? Tal vez tenga que hacerte alguna que otra pregunta para que me quede todo toalmente claro >_< este es mi perfil : [url]http://steamcommunity.com/id/FVJohnny/[/url]
Sorry, you need to Log In to post a reply to this thread.