• Getting the map creation ID of an ent
    6 replies, posted
Hello i have been having a problem lately im trying to get a doors map creation id and it keeps spitting out an error Code: [LUA] local entMeta = FindMetaTable("Entity") function entMeta:doorIndex() return self:CreatedByMap() and self:MapCreationID() or nil end [/LUA] Error: [LUA] Error in hook HUDPaint: gamemodes/emsrp/gamemode/modules/base/cl_functions.lua:34: attempt to call method 'CreatedByMap' (a nil value) stack traceback: gamemodes/emsrp/gamemode/modules/base/cl_functions.lua:34: in function 'doorIndex' gamemodes/emsrp/gamemode/modules/doorsystem/cl_doors.lua:41: in function 'DoorTitle' gamemodes/emsrp/gamemode/modules/hud/cl_hud.lua:317: in function 'DrawEntityDisplay' gamemodes/emsrp/gamemode/modules/hud/cl_hud.lua:415: in function 'fn' addons/ulib/lua/ulib/shared/hook.lua:105: in function <addons/ulib/lua/ulib/shared/hook.lua:88> [C]: in function '•&#8236;•&#8300;•&#8206;&#8303;&#8302;&#8301;' [ERROR] 1. unknown - [C]:-1 [/LUA] Can anyone help me fix it and btw this is mainly how im calling it [LUA] function SWEP:PrimaryAttack() self.Owner:ChatPrint("DoorID: "..self.Owner:GetEyeTrace().Entity:doorIndex()) end [/LUA] and [LUA] function entMeta:DoorTitle() if EMSRP.doorInfo[tostring(self:doorIndex())] then if !EMSRP.doorInfo[tostring(self:doorIndex())].Title == "" then return EMSRP.doorInfo[tostring(self:doorIndex())].Title else return "Door" end else return "Door" end end [/LUA]
It's serverside only
how can i get it from clientside then? sorry im very new to networking
[QUOTE=rtm516;47417113]how can i get it from clientside then? sorry im very new to networking[/QUOTE] [url]http://wiki.garrysmod.com/page/Net_Library_Usage[/url]
Ive done this Clientside: [LUA] function entMeta:doorIndex() local ret net.Start( "doorIndexSend" ) net.WriteEntity(self) net.SendToServer() net.Receive( "doorIndexRecive", function( len ) ret = tonumber(net.ReadString()) end ) return ret or nil end [/LUA] Serverside: [LUA] util.AddNetworkString( "doorIndexSend" ) util.AddNetworkString( "doorIndexRecive" ) net.Receive( "doorIndexSend", function( len, ply ) net.Start( "doorIndexRecive" ) net.WriteString(tostring(self:CreatedByMap() and self:MapCreationID() or nil)) net.Broadcast() end ) [/LUA] but is gives me this error [LUA] [ERROR] gamemodes/emsrp/entities/weapons/emsrp_doors/shared.lua:51: attempt to concatenate a nil value 1. unknown - gamemodes/emsrp/entities/weapons/emsrp_doors/shared.lua:51 [/LUA] Edit: that line is [LUA] self.Owner:ChatPrint("DoorID: "..self.Owner:GetEyeTrace().Entity:doorIndex()) [/LUA]
net messages are not instant, there will be time before a net message is received by the other side. And you can't use net.Receive like that in your CL code.
Is there anyway i can do it. I had an idea that i could just check for all map creation ids and send them all to the client somehow on join but i dont know where to start or how to do it. [editline]29th March 2015[/editline] Ive fixed it on gamemode load i do [LUA] for i=1,table.Count(ents.GetAll()) do local allEnts = ents.GetAll() local ent = allEnts[i] ent:SetNWInt("DoorID", ent:CreatedByMap() and ent:MapCreationID() or nil) end [/LUA] and to get the var i do [LUA] function entMeta:doorIndex() return self:GetNWInt("DoorID") end [/LUA]
Sorry, you need to Log In to post a reply to this thread.