Hey guys, I'm here again because just like my last problem, even after doing some research I'm still struggling to get what I want.
I'm trying to use the net library (yes I have read the wiki page on it) to get a vehicle's name (or essentially just an entity)
Currently I'm trying to do it as such:
Serverside lua script
[CODE]
util.AddNetworkString( "Vehicle_name" )
if SERVER then
net.Recieve("Vehicle_name")
for k, v in pairs(ents.GetAll()) do
v:GetName()
end
end
[/CODE]
and then a client side EXAMPLE of what I'm trying to do:
[code]DrawText("Vehicle: "..v:GetModel(), Color(0, 255, 255, 255), Pos.x, Pos.y + 13 * 0)[/code]
Obviously the v:GetModel() would be replaced with the string received from the serverside lua, however even after reading the wiki page and some other sources, I am confused at how to do this and even make it part of the DrawText argument (Maybe assigning it to a function?), so if anyone could help me out that would be great.
oh and for k, v in pairs(ents.GetAll()) is already earlier in the client side code so don't worry:P
Thanks ahead.
This is kind of confusing...
You're calling net.Recieve server side and you aren't reading any data from it. If you read the wiki, you would know it has a callback and you would have to read the string that was sent using net.ReadString() in the callback.
But this is still quite confusing because I don't understand what you're trying to accomplish.
Here's a little example that should send a table of all ent names to the client
[code]
SERVER
util.AddNetworkString("entnames")
local entnames = {}
for k,v in pairs(ents.GetAll()) do
table.insert(entnames, v:GetName())
end
net.Start("entnames")
net.WriteTable(entnames)
net.Send(ply) -- or net.Broadcast()
CLIENT
net.Receive("entnames", function(len)
local entnames = net.ReadTable()
PrintTable(entnames)
end)
[/code]
[QUOTE=Nick78111;51831505]This is kind of confusing...
You're calling net.Recieve server side and you aren't reading any data from it. If you read the wiki, you would know it has a callback and you would have to read the string that was sent using net.ReadString() in the callback.
But this is still quite confusing because I don't understand what you're trying to accomplish.
Here's a little example that should send a table of all ent names to the client
[code]
SERVER
util.AddNetworkString("entnames")
local entnames = {}
for k,v in pairs(ents.GetAll()) do
table.insert(entnames, v:GetName())
end
net.Start("entnames")
net.WriteTable(entnames)
net.Send(ply) -- or net.Broadcast()
CLIENT
net.Receive("entnames", function(len)
local entnames = net.ReadTable()
PrintTable(entnames)
end)
[/code][/QUOTE]
Yea, sorry, I'm trying to get it so that it the DrawText is displaying the vehicle's name on the vehicle.
Here's another snippet of the client code
[CODE]for k, v in pairs(ents.GetAll()) do
if(!IsValid(v)) then continue end
if (v:IsPlayer()) then
--working code here already
elseif (v:IsVehicle()) then
DrawText("Vehicle: "..v:GetModel(), Color(0, 255, 255, 255), Pos.x, Pos.y + 13 * 0)
end
end[/CODE]
It's kinda an ESP type of thing that I'm trying to write just for fun and experience.
Sorry, you need to Log In to post a reply to this thread.