Skip to content

Commit

Permalink
Merge pull request #1973 from shadow7483147/master
Browse files Browse the repository at this point in the history
Sun functions
  • Loading branch information
thegrb93 authored Sep 8, 2019
2 parents c5f1a44 + 277ca0a commit 6b5274e
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
33 changes: 33 additions & 0 deletions lua/entities/gmod_wire_expression2/core/entity.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ local validPhysics = E2Lib.validPhysics
local getOwner = E2Lib.getOwner
local isOwner = E2Lib.isOwner

local sun = ents.FindByClass("env_sun")[1] -- used for sunDirection()

hook.Add("InitPostEntity","sunent",function()
sun = ents.FindByClass("env_sun")[1]
timer.Simple(0,function() -- make sure we have a sun first
hook.Remove("InitPostEntity","sunent")
end ) -- then remove this. we don't need it anymore.
end )

registerCallback("e2lib_replace_function", function(funcname, func, oldfunc)
if funcname == "isOwner" then
isOwner = func
Expand Down Expand Up @@ -125,6 +134,24 @@ e2function entity entity:owner()
return getOwner(self, this)
end

__e2setcost(20)

e2function table entity:keyvalues()
local ret = {n={},ntypes={},s={},stypes={},size=0} -- default table
if not IsValid(this) then return ret end
local keyvalues = this:GetKeyValues()
local size = 0
for k,v in pairs( keyvalues ) do
size = size + 1
ret.s[k] = v
ret.stypes[k] = string.lower(type(v)[1]) -- i swear there's a more elegant solution to this but whatever.
end
ret.size = size
return ret
end

__e2setcost(5) -- temporary

/******************************************************************************/
// Functions getting vector
e2function vector entity:pos()
Expand Down Expand Up @@ -171,6 +198,12 @@ e2function vector entity:angVelVector()
return phys:GetAngleVelocity()
end

--- Specific to env_sun because Source is dum. Use this to trace towards the sun or something.
e2function vector sunDirection()
if not isValid(sun) then return { 0, 0, 0 } end
return sun:GetKeyValues().sun_dir
end

/******************************************************************************/
// Functions using vector getting vector

Expand Down
2 changes: 2 additions & 0 deletions lua/wire/client/e2descriptions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,10 @@ E2Helper.Descriptions["owner()"] = "Gets the owner of the expression ( same as e
E2Helper.Descriptions["id(e:)"] = "Gets the numeric id of an entity"
E2Helper.Descriptions["noentity()"] = "Returns an invalid entity"
E2Helper.Descriptions["world()"] = "Returns the world entity"
E2Helper.Descriptions["sunDirection()"] = "Returns the vector direction that points towards the sun"
E2Helper.Descriptions["type(e:)"] = "Gets the class of an entity"
E2Helper.Descriptions["model(e:)"] = "Gets the model of an entity"
E2Helper.Descriptions["keyvalues(e:)"] = "Returns the keyvalue table of an entity"
E2Helper.Descriptions["owner(e:)"] = "Gets the owner of an entity"
E2Helper.Descriptions["name(e:)"] = "Gets the name of a player"
E2Helper.Descriptions["steamID(e:)"] = "Gets the steam ID of the player"
Expand Down

0 comments on commit 6b5274e

Please sign in to comment.