So i added the Restriction in Range(500) and the ability to provide another Entity, which might be more near to the targetentity.
Also I changed the Player-Entity, that is supplied with the "Use" to be the Owner of the Expression Gate Calling the function.
Moar suggestions? Is it "Ok" like that?
Code:
local function use_entity_from_e2(self,this,otherent)
local ent = self.entity
if not this then
return 0
end
if not this:IsValid() then
return 0
end
if (this.IsWorld()) then
return 0
end
if otherent then
if not otherent:IsValid() then
return 0
end
if otherent:IsWorld() then
return 0
end
if not (E2Lib.getOwner(self,otherent)==self.entity:GetPlayer()) then
return 0
end
ent=otherent
end
-- range calculation stolen from vector.lua
local rv1, rv2 = ent:GetPos(), this:GetPos()
local rvd1, rvd2, rvd3 = rv1[1] - rv2[1], rv1[2] - rv2[2], rv1[3] - rv2[3]
local range = ((rvd1 * rvd1 + rvd2 * rvd2 + rvd3 * rvd3) ^ 0.5)
if(range > 500) then
return 0
end
if this.Use and this.GetPlayer then
hook.Call("PlayerUse") -- because sk89q said so
this:Use(self.entity:GetPlayer())
return 1
end
end
e2function normal entity:use()
return use_entity_from_e2(self,this)
end
e2function normal entity:use(entity otherent)
return use_entity_from_e2(self,this,otherent)
end
Bookmarks