• SetPos() issue with a food menu.
    1 replies, posted
I have made a Food NPC which will give you entities when you buy them from the menu however I can't for the life of me get the position to set when the entity spawns. The entity spawns yet the position I have tried to set has been ignored. I also couldn't get the NPC to spawn in to the map when the server starts up. Map Spawn issue - line 35 - 44 Entity Spawn issue - 77 - 86 [B]init.lua [/B] [lua] AddCSLuaFile( "cl_init.lua" ) AddCSLuaFile( "shared.lua" ) include('shared.lua') function ENT:Initialize( ) self:SetModel( "models/Humans/Group02/Female_07.mdl" ) self:SetHullType( HULL_HUMAN ) self:SetNPCState( NPC_STATE_SCRIPT ) self:SetSolid( SOLID_BBOX ) self:CapabilitiesAdd( CAP_ANIMATEDFACE ) self:CapabilitiesAdd( CAP_TURN_HEAD ) self:SetUseType( SIMPLE_USE ) self:DropToFloor() self:SetMaxYawSpeed( 90 ) GunDealer = true end function ENT:OnTakeDamage() return false -- This NPC won't take damage from anything. end function ENT:AcceptInput( Name, Activator, Caller ) if Name == "Use" and Caller:IsPlayer() then net.Start("ShopNPCFood") net.Send(Caller) end end local function SpawnFoodNPC() if SERVER then if game.GetMap() == "rp_rockford_v2b" then local npc = ents.Create("food_npc") npc:SetPos(Vector(-4715.208008, -5466.481934, 128.031250)) npc:SetAngles(Angle(5.213976, 98.292542, 0.000000)) npc:Spawn() end end end hook.Add( "InitPostEntity", "SpawnMyNPC", SpawnFoodNPC) util.AddNetworkString("ShopNPCFood") util.AddNetworkString("dorito") util.AddNetworkString("maccies") util.AddNetworkString("cake") util.AddNetworkString("apple") util.AddNetworkString("lays") util.AddNetworkString("cookies") util.AddNetworkString("can01") util.AddNetworkString("can05") util.AddNetworkString("can04") util.AddNetworkString("canc") util.AddNetworkString("canb") util.AddNetworkString("sprunk") local ServerSpawnTable = { {Desc = "Doritos", Ent = "chipsdoritos", Msg = "dorito"}, {Desc = "McDonaldsMeal", Ent = "mcdmeal2", Msg = "maccies"}, {Desc = "SliceofCake", Ent = "bdcakeslice3", Msg = "cake"}, {Desc = "Apple", Ent = "fruitapple2", Msg = "apple"}, {Desc = "FlaminHotCrisps", Ent = "chipslays6", Msg = "lays"}, {Desc = "Cookies", Ent = "cookies", Msg = "cookies"}, {Desc = "CocaCola", Ent = "sodacan01", Msg = "can01"}, {Desc = "Sprite", Ent = "sodacan05", Msg = "can05"}, {Desc = "Pepsi", Ent = "sodacan04", Msg = "can04"}, {Desc = "RedBull", Ent = "sodacanc01", Msg = "canc"}, {Desc = "MonsterEnergy", Ent = "sodacanb01", Msg = "canb"}, {Desc = "Sprunk", Ent = "sodasprunk1", Msg = "sprunk"} } for k,v in pairs(ServerSpawnTable) do net.Receive("v.Msg", function(len,ply) local v.Desc = ents.Create(v.Ent) v.Ent:SetPos(ply:GetPos() + Vector(6,7,8)) v.Ent:Spawn() end) end [/lua] Also the numbers on the Vector don't mean anything, it's just so I could see if I was getting the numbers wrong.
why are you calling net receive in a loop? it'll just override the netmessage with the last entity in that table your tables aren't even proper syntax, your code won't even run. also there's much better ways of doing things than having a netmessage per entity, use one netmessage instead if you absolutely have to and use [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/net/WriteEntity]net.WriteEntity[/url] to broadcast the specific type
Sorry, you need to Log In to post a reply to this thread.