• Get a player command - Sprint
    15 replies, posted
Hello How can I get a console command which is using by the player. Now it is +speed and -speed. Please help :)
Do you mean this? [lua] if (ply:KeyDown(IN_SPEED )) then [/lua]
Maybe
maybe?
So you want something to say if they are in +speed? If so, this is it: [lua] function PlayerRunning(ply) if (ply:KeyDown(IN_SPEED )) then print("Im Running!") // This is the bit you edit return end hook.Add( "Think", "PlayerRunning", PlayerRunning ) [/lua]
Thanks
lol, it is work but it is buggy, [LUA] ply = LocalPlayer() if (ply:KeyDown(IN_SPEED ) ) then if stamina > 0 then timer.Create("down", 0.5, 0, function() stamina=stamina-1 draw.DrawText(stamina,"Default",ScrW()-80,20) print(stamina) end ) timer.Stop("up") timer.Start("down") else timer.Start("down") end else if stamina < 100 then timer.Create("up", 0.5, 0, function() stamina=stamina+1 draw.DrawText(stamina,"Default",ScrW()-80,20) print(stamina) end ) timer.Stop("down") timer.Start("up") else timer.Stop("up") end end [/LUA] Output: 46 45 44 43 42 41 40 39 38 37 36 35 34 - Here I opened the console 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
[lua] hook.Add("Think", "StaminaThink", function() for _, p in pairs(player.GetAll()) do p.Stamina = p.Stamina or 100; if( p:KeyDown(IN_SPEED) ) then p.Stamina = math.Clamp(p.Stamina-1,0,100) else p.Stamina = math.Clamp(p.Stamina+1,0,100) end if( p.Stamina > 0 ) then p:SetRunSpeed(500) else p:SetRunSpeed(250) end end end) [/lua] iRzilla you forgot to slow them down if stamina is 0
Please, help in a new thing. function SendData2(ply) SendUserMessage("my_message", ply, "hai", 1337) end How does it work?
[QUOTE=runamagic;24885928]Please, help in a new thing. function SendData2(ply) SendUserMessage("my_message", ply, "hai", 1337) end How does it work?[/QUOTE] It send a signal to the client. On the client, you use: [lua] function ReceiveData2(um) Str = um:ReadString() Short = um:ReadShort() end [/lua]
Why is it bad please??? [LUA] function UnderWater(ply) if (ply:WaterLevel() > 0) then if (ply:KeyDown(IN_USE) ) then Water = math.random(8,15) if (ply.Thirst + Water > 100) then ply.Thirst = 100 else ply.Thirst = ply.Thirst + Water end end end end hook.Add("Think","UnderWater",UnderWater) [/LUA]
Can't use ply argument in Think. [lua] hook.Add("Think", "AddThirst", function() for k,v in pairs(player.GetAll()) do if( v:WaterLevel() > 0 && v:KeyDown(IN_USE) ) then local water = math.random(8,15) if( v.Thirst + water > 100 ) then v.Thirst = 100; else v.Thirst = v.Thirst + water; end end end end) [/lua]
Sorry, you need to Log In to post a reply to this thread.