Forum

> > CS2D > Scripts > [LUA]Random Spawn Point for Npc
Forums overviewCS2D overview Scripts overviewLog in to reply

English [LUA]Random Spawn Point for Npc

10 replies
To the start Previous 1 Next To the start

old [LUA]Random Spawn Point for Npc

commanderdean
User Off Offline

Quote
hi all
NEED SERIOUS TO ANSWER THIS FORUM
I ask to smart lua maker to:
1.make randomspawn lua to NPC: Zombie, Soldier, Snark, Headcrab
for example: I made ​​a map with a desert theme
and in the desert there are a lot of zombies but appear in different places on the map

i hope u can help me

Bad english √

old Re: [LUA]Random Spawn Point for Npc

Yates
Reviewer Off Offline

Quote
cs2d cmd spawnobject combined with math.random and cs2d lua cmd map x & y. Go and make it yourself, there is more to learn than the art of asking nicely (Which you don't really do either - thanks for the smart note, though).

You can also add objects in the map. Not sure if you haven't figured this out already (Going to guess not).
edited 1×, last 18.12.13 08:55:21 am

old Re: [LUA]Random Spawn Point for Npc

tonton2d
User Off Offline

Quote
I don't knw if there are a special fonction like mp_randomspawn for npc, if not you have to make it with spawnnpc. first you have to search which places you can/want spawn your npc, (x : 2 to 10 & y : 3 to 11 for exemple), you will get differents places, (place1,place2 etc) then you random the number of the place.

old Re: [LUA]Random Spawn Point for Npc

tonton2d
User Off Offline

Quote
alright, Yates's right, make two randoms to get the x & y, && check with the tiles value if the spawn place is walkable, if not make an other 2 randoms.

old Re: [LUA]Random Spawn Point for Npc

kalis
User Off Offline

Quote
i think you find that :
it my very old code
1
2
3
local radx = math.random(0,(map('xsize')*32))
local rady = math.random(0,(map('ysize')*32))
parse("spawnnpc 1 "..(radx/32).." "..((rady/32)+1).." 0")

but in my scripts , i did n't use random @@
this code didn't test :
1
2
local radx = math.random(0,(map('xsize')*32))
local rady = math.random(0,(map('ysize')*32))

old Re: [LUA]Random Spawn Point for Npc

Necr0
User Off Offline

Quote
1
2
3
4
5
6
7
function randomnpcspawn(npctype)
	local x=math.random(0,map('xsize'))-1
	local y=math.random(0,map('ysize'))-1
	if tile(x,y,"frame")~=0 and tile(x,y,"walkable") and not tile(x,y,"deadly") and tile(x,y,"entity")==0 then
		parse("spawnnpc "..npctype.." "..x.." "..y.." 0")
	end
end
the random spawning positions

1
2
3
4
5
6
7
8
9
10
11
12
13
14
randomnpcs_max=50	--change this depending on the map size

addhook("ms100","randomnpcs_ms100")
function randomnpcs_ms100()
	local n
	for i,j in pairs(object(0,"table")) do
		if object(j,"type")==30 then
			n=n+1
		end
	end
	while n<randomnpcs_max do
		randomnpcspawn(math.random(1,5))
	end
end
the spawning

not tested

old #ChristmasHatOrNoPresents

Avo
User Off Offline

Quote
I'm going to pwn you all with a simple recursion function, guys:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
GetTiles = function()
	local gn, ch = GetNeigh, Check
	GetNeigh = function(x, y)
		return { {x + 1, y}, {x, y + 1}, {x - 1, y}, {x, y - 1} }
	end
	Check = function(x, y, list, chlist)
		for _, P in pairs(GetNeigh(x, y)) do
			if chlist[P[1].."x"..P[2]] == nil then
				chlist[P[1].."x"..P[2]] = true
				if tile(P[1], P[2], "walkable") then
					table.insert(list, {P[1], P[2]})
					list, chlist = Check(P[1], P[2], list, chlist)
				end
			end
		end
		return list, chlist
	end
	local List, CheckList = {}, {}
	for _, ent in pairs({0, 1, 2}) do							--// info_T, info_CT, info_VIP
		for __, e in pairs(entitylist(ent)) do					--// entitylist
			List, CheckList = Check(e.x, e.y, List, CheckList)
		end
	end
	GetNeigh, Check = gn, ch
	return List
end
It returns all positions where player can move from spawnpoints.
Wanna spawn 100 zombies? Nothing easier:
1
2
3
4
5
T = GetTiles()
for i = 1, 100 do
	local r = T[math.random(1, #T)]
	parse("spawnnpc 1 "..r[1].." "..r[2])
end

Tested on de_dust:
http://screencloud.net/v/FCKq

Enjoy but don't forget to add Santa's hat to your avatar, merry christmas (I hope you're not a muslim, huehue).

old Re: [LUA]Random Spawn Point for Npc

KimKart
Idiot Off Offline

Quote
@user Avo: I'll put on my santa hat when it's the summer in Latvia.

More >
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview