TSR_ECS/main/scripts/player.lua
2023-12-29 20:03:34 +01:00

76 lines
1.8 KiB
Lua

g_require("scripts/input.lua")
local tick = 1 / g_gettps()
local player = nil
local playertimer = nil
local standanim = "stand"
local walkanim = "walk2"
function setupplayer(ent)
player = ent
mdl_anim(player, "init", 0, 0)
mdl_anim(player, standanim, 0, 0)
cct_add(player, 0.25, 1.2)
local walking = false
playertimer = g_settimer(0, true, function ()
local fb = 0
local rl = 0
if keyheld["forward"] then fb = fb + 1 end
if keyheld["backward"] then fb = fb - 1 end
if keyheld["right"] then rl = rl + 1 end
if keyheld["left"] then rl = rl - 1 end
local move_x = 0
local move_y = -3.0
local move_z = 0
local movespeed = 10.0
if fb ~= 0 or rl ~= 0 then
local foward_x, forward_z = g_getcameraforwardxz()
local right_x, right_z = g_getcamerarightxz()
local x = foward_x * fb + right_x * rl
local z = forward_z * fb + right_z * rl
local angle = math.atan(x, z)
move_x, move_z = cct_getforwardxz(player)
cct_turntoangle(player, angle, 6)
if not walking then
mdl_anim(player, walkanim, 6, 0.2)
walking = true
end
-- print(angle * 57.2957795)
else
if walking then
mdl_stopanim(player, walkanim, 0.1)
walking = false
end
end
cct_move(player, move_x * tick * movespeed, move_y * tick, move_z * tick * movespeed)
end)
end
function cleanupplayer()
if playertimer ~= nil then
g_cleartimer(playertimer)
playertimer = nil
end
if player ~= nil then
cct_remove(player)
player = nil
end
end