Can networked integers be set from a file in one entity and retrieved in another entity? If not, please provide an alternative. Please do not just say it isn't possible without providing an alternative unless there is no alternative.
What is the situation you are trying to use this in? Depending on what you want to accomplish there might be different ways to do it.
I want to set a networked integer in an entity and retrieve it in a seperate NPC entity.
No idea what you're even saying. You just mentioned three mostly-unrelated things:
1. Networked integer
2. File
3. Entities
So I'm going to go ahead and [I]guess[/I] that by Entity, you mean player (or client), and that you want to share a value between 2 clients. There are several ways to do this, but keep in mind that clients NEVER talk to each other directly, everything is always going through the server. So if the player Alice wants to send a message to the player Bob, she will have to send the message to the server, and the server will then relay the message to Bob. This message can be an integer, a string, or whatever the hell you want. Either way, there is no built-in function to do this but it's not difficult to make it yourself: [URL=http://wiki.garrysmod.com/page/Net_Library_Usage]Net Library Usage [/URL]
Assuming you want to retrieve the value of a networked integer from one entity, inside the file of another entity:
As long as you can reference that second entity, then yes.
[QUOTE=NeatNit;50295919]No idea what you're even saying. You just mentioned three mostly-unrelated things:
1. Networked integer
2. File
3. Entities
So I'm going to go ahead and [I]guess[/I] that by Entity, you mean player (or client), and that you want to share a value between 2 clients. There are several ways to do this, but keep in mind that clients NEVER talk to each other directly, everything is always going through the server. So if the player Alice wants to send a message to the player Bob, she will have to send the message to the server, and the server will then relay the message to Bob. This message can be an integer, a string, or whatever the hell you want. Either way, there is no built-in function to do this but it's not difficult to make it yourself: [URL=http://wiki.garrysmod.com/page/Net_Library_Usage]Net Library Usage [/URL][/QUOTE]
I'm not talking about a player. I'm talking about something like a DarkRP entity or a Q Menu entity.
EDITED: Might post some help once I fully understand what is trying to be accomplished.
in that case it's trivial, just use ent:GetNWInt() from wherever
[QUOTE=NeatNit;50295954]in that case it's trivial, just use ent:GetNWInt() from wherever[/QUOTE]
So to answer my question, you can set a NWInt from one entity and retrieve the NWInt from another entity, right?
What I said 7 minutes ago...
[QUOTE]
Assuming you want to retrieve the value of a networked integer from one entity, inside the file of another entity:
As long as you can reference that second entity, then yes.
[/QUOTE]
[QUOTE=McDunkable;50295976]What I said 7 minutes ago...[/QUOTE]
Okay, thanks for all your help, McDunkable and NeatNit. And, one more thing, how would I reference it?
You can't do ent1:SetNWInt("test", 15) and then later do ent2:GetNWInt("test") and expect to get 15. You may want to look into parenting or classes for that. Or maybe you want a global variable instead? I'm not sure since i quickly skimmed the discussion.
Not that.
He mentioned "something like a DarkRP entity or a Q Menu entity" so we're talking about SEnts. Being that he's going to have to program the entity, inside the entity's functions, he can retrieve the value of another entity as long as he has a reference to it, for example:
[code]
function ENT:Initialize()
...
self.Something = MyGlobalEntity:GetNWInt( "Something" )
end
[/code]
[QUOTE=McDunkable;50296120]Not that.
He mentioned "something like a DarkRP entity or a Q Menu entity" so we're talking about SEnts. Being that he's going to have to program the entity, inside the entity's functions, he can retrieve the value of another entity as long as he has a reference to it, for example:
[code]
function ENT:Initialize()
...
self.Something = MyGlobalEntity:GetNWInt( "Something" )
end
[/code][/QUOTE]
Lol, that's the term I've been looking for. SEnts
Also, how would I define the part you call "MyGlobalEntity"?
[QUOTE=brianm109;50296349]Lol, that's the term I've been looking for. SEnts
Also, how would I define the part you call "MyGlobalEntity"?[/QUOTE]
You could define it in many ways, MyGlobalEntity is just an entity.
For example:
[lua]
hook.Add("OnEntityCreated", "SetEntStuff", function(ent)
if ent:IsDank() then
MyDankEntity = ent
end
end)
-- Somewhere else
function ENT:Initialize()
self.Something = MyDankEntity:GetNWInt("Something")
end
[/lua]
[QUOTE=YourStalker;50296381]You could define it in many ways, MyGlobalEntity is just an entity.
For example:
[lua]
hook.Add("OnEntityCreated", "SetEntStuff", function(ent)
if ent:IsDank() then
MyDankEntity = ent
end
end)
-- Somewhere else
function ENT:Initialize()
self.Something = MyDankEntity:GetNWInt("Something")
end
[/lua][/QUOTE]
Nice dank entity you got there. Thanks for your help, YourStalker.
I just tried YourStalker's way and it doesn't seem to work. Paste: [URL="http://pastebin.com/s0uhqhYS"]http://pastebin.com/s0uhqhYS[/URL]
You have
self:SetNWInt ( "kevlarmoney", 1000 )
Then you have
self.worth = Sewing:GetNWInt ( "money" )
[QUOTE=YourStalker;50297139]You have
self:SetNWInt ( "kevlarmoney", 1000 )
Then you have
self.worth = Sewing:GetNWInt ( "money" )[/QUOTE]
Oops, that was a mistake in pasting. It's correct on the actual thing. self:SetNWInt( "money", 1000 )
Still can't figure out why it's not working. The NWInt doesn't seem to be going to the other SENT.
[QUOTE=brianm109;50297159]Oops, that was a mistake in pasting. It's correct on the actual thing. self:SetNWInt( "money", 1000 )
Still can't figure out why it's not working. The NWInt doesn't seem to be going to the other SENT.[/QUOTE]
I see a few issues.
1. You're setting the Sewing variable serverside only and then using it somewhere that is shared. ENT:Initialize() is shared.
2. You are overriding the Sewing variable every time any single entity is being spawned.
3. Also you're using LocalPlayer() in a shared Think hook. Why are you printing every frame anyways?
Overall this could be done in a much better way using DataTables.
Lol, it's a test for something bigger. I remade my code using DataTables, but I can't test it on a server till' tomorrow because I'm busy right now. Thanks for the idea.
Sorry, you need to Log In to post a reply to this thread.