• Map mechanic trough LUA?
    13 replies, posted
So well in order to fix my gamemode NPC Problem im thinking on instead of SPAWN some npc on the map via hammer what about spawning them trough lua? i mean lets say the player spawns he press a button then that button triggers a function that spawn 6 combine npc at the entity called Npc_combine_spawn then after some time spawn More combines and then helicopter and so on so thats my question is it possible to create the map npc spawn logic trough lua? and if its possible how would i go to do it? any hints or help are always appreciated
you can use the lua_run entity to run a lua spawn function when a button is pressed. You just need to add the garrysmod.fdg file in the hammer options. Then just set the button to activate the lua_run and in the lua run put the name of the spawn function you created.
so i could link lets say lua_run MySpawnNpcFunction to the button once its pressed and then on MySpawnNpcFunction located on init.lua spawn the npc?
yes
well now im stuck into another problem is it possible to spawn a npc on a entity? lets say i make a empty entity called npc spawn point i could make my npc spawn there instead of having to use getpos every time i add a new npc
anyone? what i want to do is just get a empty entity info on my map and then make a NPC Spawn on it
Name your button and your infos something. If you dont want to name your infos something then use ents.FindByClass("info_target or whatever") rather than ents.FindByName() then. [lua] local lastnpctime = 0 hook.Add("PlayerUse","SpawnNpcButton",function(ply,ent) if ent:GetName()=="yourbuttonname" and lastnpctime<CurTime()-3 then lastnpctime = CurTime() for k, v in pairs(ents.FindByName("Your info tagetname")) do local npc = ents.Create("npc_whatevernpc") npc:SetPos(v:GetPos()) npc:Spawn() end end end) [/lua] [editline]7th February 2011[/editline] [QUOTE=werewolf0020;27816598]well now im stuck into another problem is it possible to spawn a npc on a entity? lets say i make a empty entity called npc spawn point i could make my npc spawn there instead of having to use getpos every time i add a new npc[/QUOTE] [lua] for k, v in pairs(ents.FindByName("npc spawn point")) do local npc = ents.Create("npc_whatever") npc:SetPos(v:GetPos()) npc:Spawn() end [/lua]
thank you
sorry to bump the tread but this still isnt working i use the button and it doesnt spawn the npc heres the whole code if someone can help me local lastnpctime = 0 hook.Add("PlayerUse","SpawnNpcButton",function(ply,ent) if ent:GetName()=="func_button" and lastnpctime<CurTime()-3 then lastnpctime = CurTime() for k, v in pairs(ents.FindByName("info_spawn_destination")) do local npc = ents.Create("npc_combine_s") npc:SetPos(v:GetPos()) npc:Spawn() end end end) for k, v in pairs(ents.FindByName("info_spawn_destination")) do local npc = ents.Create("npc_combine_s") npc:SetPos(v:GetPos()) npc:Spawn() end sorry for lack of lua tags my keyboard doesnt have the key to put them
Change ent:GetName() to ent:GetClass()
They should have a red banner saying .. "Please use [lua[b][/b]] and [lua[b][/b]] tags around lua code."
[QUOTE=zzaacckk;28135665]They should have a red banner saying .. "Please use [lua[b][/b]] and [lua[b][/b]] tags around lua code."[/QUOTE] Just like you should have a red title that says [b]Dumb Ass[/b]
Still it doesnt work actually the button is just a stuff placed on the map called func_button
Try changing this line [lua] if ent:GetName()=="func_button" and lastnpctime<CurTime()-3 then --[/lua] to [lua] if ent:GetName()=="func_button" then --[/lua] I think it may have to do with that time calculation, If it works without it try using this [lua] if ent:GetName()=="func_button" and CurTime() > (lastnpctime + 3) then -- [/lua] Won't let you spawn them faster than 3 seconds that way. NOTE: Ignore the comments in the lua, if they're not there it cuts off the underscores.
Sorry, you need to Log In to post a reply to this thread.