Skip to content

Commit

Permalink
New is* E2 functions (#3220)
Browse files Browse the repository at this point in the history
* New is* functions

* entity:weapons() optimization

* Missing description
  • Loading branch information
Astralcircle authored Dec 16, 2024
1 parent eb9451c commit 80c4eb0
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 5 deletions.
22 changes: 22 additions & 0 deletions lua/entities/gmod_wire_expression2/core/entity.lua
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,16 @@ e2function number entity:isNPC()
if this:IsNPC() then return 1 else return 0 end
end

e2function number entity:isNextBot()
if not IsValid(this) then return self:throw("Invalid entity!", 0) end
if this:IsNextBot() then return 1 else return 0 end
end

e2function number entity:isRagdoll()
if not IsValid(this) then return self:throw("Invalid entity!", 0) end
if this:IsRagdoll() then return 1 else return 0 end
end

e2function number entity:isVehicle()
if not IsValid(this) then return self:throw("Invalid entity!", 0) end
if this:IsVehicle() then return 1 else return 0 end
Expand Down Expand Up @@ -587,6 +597,18 @@ e2function number entity:isAsleep()
if phys:IsAsleep() then return 1 else return 0 end
end

e2function number entity:isGravityEnabled()
if not validPhysics(this) then return self:throw("Invalid entity!", 0) end
local phys = this:GetPhysicsObject()
if phys:IsGravityEnabled() then return 1 else return 0 end
end

e2function number entity:isPenetrating()
if not validPhysics(this) then return self:throw("Invalid entity!", 0) end
local phys = this:GetPhysicsObject()
if phys:IsPenetrating() then return 1 else return 0 end
end

--[[******************************************************************************]]

__e2setcost(30) -- temporary
Expand Down
12 changes: 12 additions & 0 deletions lua/entities/gmod_wire_expression2/core/player.lua
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,18 @@ e2function number entity:isFlashlightOn()
return this:FlashlightIsOn() and 1 or 0
end

e2function number entity:isSpeaking()
if not IsValid(this) then return self:throw("Invalid entity!", 0) end
if not this:IsPlayer() then return self:throw("Expected a Player but got Entity", 0) end
return this:IsSpeaking() and 1 or 0
end

e2function number entity:isBot()
if not IsValid(this) then return self:throw("Invalid entity!", 0) end
if not this:IsPlayer() then return self:throw("Expected a Player but got Entity", 0) end
return this:IsBot() and 1 or 0
end

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

e2function number entity:frags()
Expand Down
6 changes: 1 addition & 5 deletions lua/entities/gmod_wire_expression2/core/weapon.lua
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,7 @@ end
e2function array entity:weapons()
if not IsValid(this) then return {} end
if not this:IsPlayer() then return {} end
local ret = {}
for k,v in pairs(this:GetWeapons()) do
ret[#ret + 1] = v
end
return ret
return this:GetWeapons()
end

[nodiscard]
Expand Down
7 changes: 7 additions & 0 deletions lua/wire/client/e2descriptions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,12 @@ E2Helper.Descriptions["isPlayer(e:)"] = "Is the entity a player?"
E2Helper.Descriptions["isOnFire(e:)"] = "Is the entity on fire?"
E2Helper.Descriptions["isWeapon(e:)"] = "Is the entity a weapon?"
E2Helper.Descriptions["isNPC(e:)"] = "Is the entity a NPC?"
E2Helper.Descriptions["isNextBot(e:)"] = "Is the entity a NextBot?"
E2Helper.Descriptions["isRagdoll(e:)"] = "Is the entity a ragdoll?"
E2Helper.Descriptions["isFrozen(e:)"] = "Is the entity frozen?"
E2Helper.Descriptions["isAsleep(e:)"] = "Is the entity asleep?"
E2Helper.Descriptions["isPenetrating(e:)"] = "Is the entity penetrating another entity?"
E2Helper.Descriptions["isGravityEnabled(e:)"] = "Is gravity enabled for the entity?"
E2Helper.Descriptions["isVehicle(e:)"] = "Is the entity a vehicle?"
E2Helper.Descriptions["inVehicle(e:)"] = "Is the player in a vehicle?"
E2Helper.Descriptions["isWorld(e:)"] = "Is the entity the world?"
Expand All @@ -296,6 +301,8 @@ E2Helper.Descriptions["isSuperAdmin(e:)"] = "Is the player a super admin?"
E2Helper.Descriptions["isAlive(e:)"] = "Is the player or NPC alive?"
E2Helper.Descriptions["isCrouch(e:)"] = "Is the player crouching?"
E2Helper.Descriptions["isFlashlightOn(e:)"] = "Returns 1 if the player has flashlight on, 0 otherwise"
E2Helper.Descriptions["isSpeaking(e:)"] = "Returns 1 if the player speaks, 0 otherwise"
E2Helper.Descriptions["isBot(e:)"] = "Returns 1 if the player is a bot, 0 otherwise"
E2Helper.Descriptions["isTyping(e:)"] = "Is the player typing a message in chat?"
E2Helper.Descriptions["isValid(e:)"] = "Returns 1 if the entity is valid, 0 otherwise"
E2Helper.Descriptions["isValidPhysics(e:)"] = "Returns 1 if the entity has valid physics (players don't)"
Expand Down

0 comments on commit 80c4eb0

Please sign in to comment.