This is kinda hard to explain. Various mods have things like ent:isRolling (just an example). how do you define things like that? I just don't know what it is actually called or what it can do. Like I wanted to do CustomDoor:IsBreaching or something but I dunno how
Its just a function name so you can easily tell what it returns.
[code]
function IsTraitor(ply)
if ply:GetRole() == ROLE_TRAITOR then
return true
else
return false
end
end
[/code]
No...
What you're looking for is something like this.
[LUA]
local theMeta = FindMetaTable("Player")
function theMeta:AddPoints( num )
self.points = self.points + num
end
[/LUA]
You refer to the entity types metatable and add a function to it.
'self' in the function is the entity you are calling the function on.
There's no need of go into Metatable for add custom methods to entities
[lua]
--[[
:Entity code:
--]]
//An entity function that already exists
function ENT:Use()
//When player uses the entity, this call our custom method and uses an argument
self:SetFire(math.random(50))
end
//Custom method with a random name, with an argument if we need it
function ENT:SetFire(arg)
self:Ignite(arg)
end
[/lua]
If you want to do it inside an entity you've made, it's as simple as defining a function inside it:
[lua]
function ENT:SetTargetOwner( plyr )
self.TargetOwner = plyr
end
function ENT:GetTargetOwner( plyr )
return self.TargetOwner
end
[/lua]
Just an excerpt from a decoy or something. If you want to call it it's as simple as sticking the entity instance in a variable (e.g. from findbyclass) and calling the function on it
[lua]
local myEntity = someMethodOfGettingTheEntity()
myEntity:SetTargetOwner( somePlayer )
myEntity:GetTargetOwner()
[/lua]
Would return the somePlayer if it was set.
Due to these several mixed posts it's clear you aren't very clear, so I may not be what you're looking for.
edit: GUAHUA, ninja'd
[QUOTE=Exho;46052163]Its just a function name so you can easily tell what it returns.
[code]
function IsTraitor(ply)
if ply:GetRole() == ROLE_TRAITOR then
return true
else
return false
end
end
[/code][/QUOTE]
Exacatly what I'm talking about. Like what is GetRole, how do you make it? Something like that
Oh, if what you're asking for is an extension to an object (player, for :GetRole()) you do it from a metatable like Pablo said. If it's your entity use what gonz or I posted.
[QUOTE=zerf;46052472]Oh, if what you're asking for is an extension to an object (player, for :GetRole()) you do it from a metatable like Pablo said. If it's your entity use what gonz or I posted.[/QUOTE]
That'll teach you for your disagree >:]
GG
Sorry, you need to Log In to post a reply to this thread.