Skip to content

Commit

Permalink
Add playerMove event with "usercmd" and "movedata" types and getter f…
Browse files Browse the repository at this point in the history
…unctions (#2779)
  • Loading branch information
Mikey-Mikey authored Oct 9, 2023
1 parent e824652 commit 56ee9b9
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 0 deletions.
82 changes: 82 additions & 0 deletions lua/entities/gmod_wire_expression2/core/player.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,33 @@ registerCallback("e2lib_replace_function", function(funcname, func, oldfunc)
end
end)

local M_CUserCmd = FindMetaTable("CUserCmd")
local M_CMoveData = FindMetaTable("CMoveData")

registerType("usercmd", "xuc", nil,
nil, nil,
function(retval)
if retval == nil then return end
if not istable(retval) then error("Return value is neither nil nor a table, but a " .. type(retval) .. "!",0) end
if getmetatable(retval) ~= M_CUserCmd then error("Return value is not a CUserCmd!", 0) end
end,
function(v)
return not istable(v) or getmetatable(v) ~= M_CUserCmd
end
)

registerType("movedata", "xmv", nil,
nil, nil,
function(retval)
if retval == nil then return end
if not istable(retval) then error("Return value is neither nil nor a table, but a " .. type(retval) .. "!",0) end
if getmetatable(retval) ~= M_CMoveData then error("Return value is not a CMoveData!", 0) end
end,
function(v)
return not istable(v) or getmetatable(v) ~= M_CMoveData
end
)

--------------------------------------------------------------------------------

__e2setcost(5) -- temporary
Expand Down Expand Up @@ -958,6 +985,61 @@ E2Lib.registerEvent("playerChangedTeam", {
{ "NewTeam", "n" }
})

--[[--------------------------------------------------------------------------------------------]]--

__e2setcost(1)


e2function number usercmd:getMouseDeltaX()
return this:GetMouseX()
end

e2function number usercmd:getMouseDeltaY()
return this:GetMouseY()
end

e2function number usercmd:getForwardMove()
return this:GetForwardMove()
end

e2function number usercmd:getSideMove()
return this:GetSideMove()
end

e2function number usercmd:getUpMove()
return this:GetUpMove()
end

e2function number movedata:getForwardSpeed()
return this:GetForwardSpeed()
end

e2function number movedata:getSideSpeed()
return this:GetSideSpeed()
end

e2function number movedata:getUpSpeed()
return this:GetUpSpeed()
end

e2function number movedata:getMaxSpeed()
return this:GetMaxSpeed()
end

e2function angle movedata:getMoveAngles()
return this:GetMoveAngles()
end

hook.Add("SetupMove", "E2_PlayerMove", function(ply, mv, cmd)
E2Lib.triggerEvent("playerMove", { ply, mv, cmd })
end)

E2Lib.registerEvent("playerMove", {
{ "Player", "e" },
{ "MoveData", "xmv" },
{ "Command", "xuc" }
})

--******************************************--


Expand Down
12 changes: 12 additions & 0 deletions lua/wire/client/e2descriptions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,18 @@ E2Helper.Descriptions["getCollisionGroup(e:)"] = "Returns the collision group of
E2Helper.Descriptions["setCollisionGroup(e:n)"] = "Sets the collision group of the entity. Does not work on players. Use one of the _COLLISION_GROUP constants"
E2Helper.Descriptions["noCollideAll"] = "Nocollides an entity to all entities/players, just like the tool's right-click"

-- Movedata/Usercmd
E2Helper.Descriptions["getMouseDeltaX(xuc:)"] = "Returns the mouse delta of this command on the x-axis"
E2Helper.Descriptions["getMouseDeltaY(xuc:)"] = "Returns the mouse delta of this command on the y-axis"
E2Helper.Descriptions["getForwardMove(xuc:)"] = "Returns the forward/back movement of this command"
E2Helper.Descriptions["getSideMove(xuc:)"] = "Returns the strafe movement of this command"
E2Helper.Descriptions["getUpMove(xuc:)"] = "Returns the up/down movement of this command"
E2Helper.Descriptions["getForwardSpeed(xmv:)"] = "Returns the forward/back speed of the movedata"
E2Helper.Descriptions["getSideSpeed(xmv:)"] = "Returns the strafe speed of the movedata"
E2Helper.Descriptions["getUpSpeed(xmv:)"] = "Returns the up/down speed of the movedata"
E2Helper.Descriptions["getMaxSpeed(xmv:)"] = "Returns the movedata's maximum movement speed"
E2Helper.Descriptions["getMoveAngles(xmv:)"] = "Returns movedata's angles"

-- Attachment
E2Helper.Descriptions["lookupAttachment(e:s)"] = "Returns Es attachment ID associated with attachmentName"
E2Helper.Descriptions["attachmentPos(e:n)"] = "Returns Es attachment position associated with attachmentID"
Expand Down

0 comments on commit 56ee9b9

Please sign in to comment.