is there any way to change a NPC or player to an entity and vice versa?
6 replies, posted
Hey I was wondering is there any way to change a NPC or player to an entity and vice versa?
They're already entities?
no all entities COULD be players and you can call some of the players functions on a entity but there are some limitations maybe its because im new to lua... but i do know how to code... but a handful of functions i wanted to call where not shared between ent and players. I found a way to get around all the trubles so far but i thought it would be a nice function.
Players and NPCs are entities. Therefore, any function belonging to the entity class you can call on a player or an NPC, not vice versa. Hierarchy/inheritance is the first thing you should have learned about programming.
I know about inheritance I mainly work in python XD but you explained it better than I did :). here is a example of where entitys fail.
[code]
local player = self:GetOwner()
if ( !(player.IsAdmin())&&trace.Entity:IsPlayer() ) then return false end
[/code]
[QUOTE=fenderex;48192698]I know about inheritance I mainly work in python XD but you explained it better than I did :). here is a example of where entitys fail.
[code]
local player = self:GetOwner()
if ( !(player.IsAdmin())&&trace.Entity:IsPlayer() ) then return false end
[/code][/QUOTE]
How about player:IsAdmin() rather than player.IsAdmin()?
Also, bad practice to create variables with the same name as other libraries. (ie. player, math, cam, etc.)
haha true i do stupid things like that alot with new library XD player should have stood out to me lol.
thank you for the help XD
Sorry, you need to Log In to post a reply to this thread.