Whats my problem here?
[code]
function ENT:Think()
ply = self.Entity:GetNetworkedString("Owner")
ply:SendHint("Resource in water will get removed in 20sec", 5)
end
[/code]
Error is
attempt to call method 'SendHint' (a nil value)
i try many thing to get it to work..
Im sure it just some thing stupid i forgot..
ply is a string and you are trying to call a method on it.
[editline]09:27PM[/editline]
What is the networked string 'Owner'? Is it the players name, steammid, entindex?
[QUOTE=MakeR;22287033]ply is a string and you are trying to call a method on it.
[editline]09:27PM[/editline]
What is the networked string 'Owner'? Is it the players name, steammid, entindex?[/QUOTE]
will be players name
Then you need to grab the player object from the name, you can do that like this:
[lua]local function GetPlayerFromName(n)
for _, p in ipairs(player.GetAll()) do
if p:Nick() == n then
return p
end
end
end[/lua]
[editline]10:47PM[/editline]
Then you can use it in your code:
[lua]function ENT:Think()
local ply = GetPlayerFromName(self.Entity:GetNetworkedString("Owner"))
if ValidEntity(ply) then
ply:SendHint("Resource in water will get removed in 20sec", 5)
end
end[/lua]
Got it working.. kinda.. SendHint wont work..
That means ply isn't valid, which means there is no player by the name contained in :GetNetworkedString("Owner")
[QUOTE=MakeR;22288689]Then you need to grab the player object from the name, you can do that like this:
[lua]local function GetPlayerFromName(n)
for _, p in ipairs(player.GetAll()) do
if p:Nick() == n then
return p
end
end
end[/lua]
[editline]10:47PM[/editline]
Then you can use it in your code:
[lua]function ENT:Think()
local ply = GetPlayerFromName(self.Entity:GetNetworkedString("Owner"))
if ValidEntity(ply) then
ply:SendHint("Resource in water will get removed in 20sec", 5)
end
end[/lua][/QUOTE]
That's a bit silly. Instead you should change the NetworkedString into a NetworkedEntity, it would save everyone a lot of trouble and would account for the owner changing his name.
Definitely much better then looping through all players each think.
Networking entities would probably be more efficient than networking integers though. I prefer storing the entity's index in an integer and then just referencing the entity using the Entity(int) function.
[QUOTE=Entoros;22294108]Networking entities would probably be more efficient than networking integers though. I prefer storing the entity's index in an integer and then just referencing the entity using the Entity(int) function.[/QUOTE]
I'm pretty sure a networked entity is just that, a single integer. So there isn't much gain from doing that.
[QUOTE=Crazy Quebec;22293995]That's a bit silly. Instead you should change the NetworkedString into a NetworkedEntity, it would save everyone a lot of trouble and would account for the owner changing his name.
Definitely much better then looping through all players each think.[/QUOTE]
Yea I know, I was helping him with his problem, not suggesting ways around it.
Sorry, you need to Log In to post a reply to this thread.