Hiya my dudes,
I have created a simple Derma menu that opens when an entity is used. Basically, I would like a weapon to spawn above the entity when I click a Derma button, but as you can see below, I get an error.
-- The Error [ERROR] addons/gunorder/lua/entities/orderbox/init.lua:24: Tried to use a NULL entity! 1. Send - [C]:-1 2. unknown - addons/gunorder/lua/entities/orderbox/init.lua:24
I can get the weapon to spawn on the player by using ply:GetPos() instead of the vector of the entity but cannot seem to pass the entity vector position over to the server for the wep:SetPos()
I have tried sending the vector split up into float values before I noticed the error. As I am very new to GLua, I can’t seem to figure out how in gods name I am supposed to fix this NULL entity issue.
Am I supposed to do net.WriteEntity() or something instead? Or will that just write the entity classname much like my cl_init.lua file does using the net.WriteString(“weapon_357”)?
I added in an entity validity check in there as well as a print to the server console for dubugging
--Clientsided stuff, located in the entity -- init.lua --This is all when the entity is used function ENT:Use(ply, caller) if (IsValid(self)) then print("YES I AM A VALID ENTITY") --Just to check the if statement is working net.Start("SwepPos") net.WriteVector(self:GetPos()) net.Send() umsg.Start( "OrderMenu", ply ) umsg.Short( "1" ) umsg.End() end end --cl_init.lua --This is when the button is clicked in the Derma Menu Button.DoClick = function() net.Start("SwepSpawn") --Start spawn message net.WriteString("weapon_357") --Write entity classname to server net.SendToServer() --Send classname to server end ----------------------------------------------------------------------- --All Serverside, located in servers autorun. --Adding Network Strings for net.Reveive("string", function()) util.AddNetworkString("SwepSpawn") net.Receive("SwepSpawn", function(len,ply) wep= ents.Create(net.ReadString()) --Get the classname written earlier local SpawnPos = net.ReadVector() wep:SetPos(Vector(SpawnPos.x, SpawnPos.y, SpawnPos.z + 20) --Spawn at position of entity that was used, add 20 onto Z axis to spawn above entity wep:Spawn() --Spawn the weapon end)
A second question also,
I understand that I must read things in the same order I write them when I send them to the server. Does this rule apply to the individual types of data? As in, if I write a string, a vector and a string, will it read in that order or will the ReadString skip the vector and read the next string in the written order?
Like I said, I am very new to this stuff, so any help would be GREATLY appreciated. Thanks guys