From 56ee9b9b609d24420c0321dacd35fc531e7babee Mon Sep 17 00:00:00 2001 From: Mikey <67529953+Mikey-Mikey@users.noreply.github.com> Date: Sun, 8 Oct 2023 20:02:20 -0400 Subject: [PATCH] Add playerMove event with "usercmd" and "movedata" types and getter functions (#2779) --- .../gmod_wire_expression2/core/player.lua | 82 +++++++++++++++++++ lua/wire/client/e2descriptions.lua | 12 +++ 2 files changed, 94 insertions(+) diff --git a/lua/entities/gmod_wire_expression2/core/player.lua b/lua/entities/gmod_wire_expression2/core/player.lua index 59d1910550..c1c3ad785c 100644 --- a/lua/entities/gmod_wire_expression2/core/player.lua +++ b/lua/entities/gmod_wire_expression2/core/player.lua @@ -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 @@ -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" } +}) + --******************************************-- diff --git a/lua/wire/client/e2descriptions.lua b/lua/wire/client/e2descriptions.lua index fd3f3eaee1..2bb66d13f4 100644 --- a/lua/wire/client/e2descriptions.lua +++ b/lua/wire/client/e2descriptions.lua @@ -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"