English [LUA]Random Spawn Point for Npc

10 replies
Goto Page
To the start Previous 1 Next To the start
Up
commanderdean
User
Offline Off
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 √
18.12.13 08:48:38 am
Up
Yates
Reviewer
Offline Off
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
18.12.13 08:55:14 am
Up
tonton2d
User
Offline Off
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.
"Akounamatata"
18.12.13 08:56:24 am
Up
Yates
Reviewer
Offline Off
@user tonton2d: Waste of time there. Just check the whole map and if it is walkable and not the outside (Normally black tile).
18.12.13 09:03:30 am
Up
tonton2d
User
Offline Off
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.
"Akounamatata"
18.12.13 02:14:01 pm
Up
kalis
User
Offline Off
i think you find that :
it my very old code
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 :
Code:
1
2
local radx = math.random(0,(map('xsize')*32))
local rady = math.random(0,(map('ysize')*32))
18.12.13 06:45:33 pm
Up
Necr0
User
Offline Off
Code:
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

Code:
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
18.12.13 06:53:48 pm
Up
Avo
User
Offline Off
I'm going to pwn you all with a simple recursion function, guys:
Code:
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:
Code:
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).
18.12.13 07:16:33 pm
Up
Infinite Rain
Reviewer
Offline Off
@user Avo:
I will put santa hat on my avatar! ...Oh.
A thousand may fall at your side, ten thousand at your right hand, but it will not come near you. You will only look with your eyes and see the recompense of the wicked. - Psalm 91:7-8 ESV
19.12.13 09:54:56 pm
Up
Avo
User
Offline Off
@user Infinite Rain: And that's why your Factis avatar was better.

@topic: I used GetTiles() function and combined it with some other stuff, check it out:
file cs2d [Bolt]Yet Another NPC Survival (9). It took me about 4 hours to make it, enjoy.
19.12.13 10:13:07 pm
Up
KimKart
Idiot
Offline Off
@user Avo: I'll put on my santa hat when it's the summer in Latvia.

More >
my meme big
To the start Previous 1 Next To the start