• Place a entity?
    5 replies, posted
i want this npc to be placed near my spawn point and the co-ords are correct but when i start up the gamemode the npc is nowhere to be seen. any help guys? [QUOTE] AddCSLuaFile( "cl_init.lua" ) AddCSLuaFile( "shared.lua" ) include('shared.lua') function ENT:Initialize() self:SetModel( "models/Humans/Group01/Female_01.mdl" ) self:SetNWString("Text","Weapons / Ammo") self:SetHullType( HULL_HUMAN ); self:SetHullSizeNormal(); self:SetNPCState( NPC_STATE_SCRIPT ) self:SetSolid( SOLID_BBOX ) self:CapabilitiesAdd( CAP_ANIMATEDFACE ) self:SetUseType(SIMPLE_USE) self:DropToFloor() self:SetMaxYawSpeed( 45 ) self:SetPos(Vector(-1914.501831 -1392.158325 -131.968750)) self:Spawn() self:Activate() local sequence = self:LookupSequence("idle") self:SetSequence(sequence) end function ENT:OnTakeDamage() return false end function ENT:AcceptInput( Name, Activator, Caller ) if Name == "Use" and Caller:IsPlayer() then self.Entity:EmitSound("vo/npc/female01/hi0"..math.random(1,2)..".wav",100,math.random(80,120)) umsg.Start("WeaponVendorMenu",Caller) umsg.End() end end function ENT:Think() self:NextThink(CurTime()) return true end [/QUOTE]
ENT_Initialize is only called once the NPC has been told to spawn. Your code seems to correct, but it is simply never told to spawn. Somewhere in your gamemode, say init.lua, write [code] npc = ENT.create("name of the folder your NPC is in") npc:SetPos(your coords) [/code] Then remove your setpos in your initial code. I think that should work!
[QUOTE=Warsheep;35638548]ENT_Initialize is only called once the NPC has been told to spawn. Your code seems to correct, but it is simply never told to spawn. Somewhere in your gamemode, say init.lua, write [code] npc = ENT.create("name of the folder your NPC is in") npc:SetPos(your coords) [/code] Then remove your setpos in your initial code. I think that should work![/QUOTE] i get this my code [QUOTE] npc = ENT.create("npc_weapon_vendor") function npc npc:SetPos(431.492950 -1764.236938 -79.968750) end[/QUOTE] [QUOTE] [gamemodes\darkrp\gamemode\init.lua:170] '<eof>' expected near 'end' [cpp] There was a problem opening the gamemode file 'DarkRP/gamemode/init.lua' [/QUOTE] not very familiar with lua so may have done it wrong.
bumb
[lua] local function SpawnVendor() local npc = ents.Create( "npc_weapon_vendor" ) npc:SetPos( Vector( 430, -1765, -80 ) ) npc:Spawn() end hook.Add( "InitPostEntity", "spawn_vendor", SpawnVendor ) [/lua]
Thanks alot, it works now.
Sorry, you need to Log In to post a reply to this thread.