Forum

> > CS2D > Scripts > How can I spawn 30 Headcrabs every 10 seconds?
Forums overviewCS2D overview Scripts overviewLog in to reply

English How can I spawn 30 Headcrabs every 10 seconds?

15 replies
To the start Previous 1 Next To the start

old How can I spawn 30 Headcrabs every 10 seconds?

Bowlinghead
User Off Offline

Quote
Hello,
Here is my question:

I made a new script, but I need help.
I want, if you open the menu and choose "Spawn random headcrabs" then 30 headcrabs spawn. But only after 10 seconds...
Example:
spawn headcrab
wait 10 seconds
spawn headcrab
wait 10 seconds
spawn headcrab
... until 30 headcrabs

I know, its work with cs2d lua cmd timer but i dont know how.
That works:
1
2
3
4
5
6
7
8
9
addhook("second","Lol")
function Lol()
	if headcrab==1 then
		spawn=math.random(1,map("ysize"))
		spawn2=math.random(1,map("xsize"))
		spawn3=math.random(1,360)
		parse("spawnnpc 2 "..spawn2.." "..spawn.." "..spawn3)
	end
end

But then the NPC 2 (Headcrab) spawn only one time...
----------------------------------
That don't work:
More >


Error:
1
LUA ERROR: attempt to call a number value
For 20 times per second...

Or an other question:
In my timer there are 4 parameters. But I need only the 1st,2nd and the 4th. How can I "delete" the 3rd parameter?

old Re: How can I spawn 30 Headcrabs every 10 seconds?

IWhoopedPythagoras
BANNED Off Offline

Quote
this should work

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
addhook("menu","h_menu")
function h_menu(id,title,button)
	if title == "Headcrabs" then
		if button == 1 then
			timer(10000,"spawncrab","",30)
		end
	end
end

addhook("serveraction","h_serveraction")
function h_serveraction(id,button)
	menu(id,"Headcrabs, 30 crabs")
end

math.randomseed(os.time())
math.random()

function spawncrab()
	spawny = math.random(1,map("ysize"))
	spawnx = math.random(1,map("xsize"))	
	spawn3 = math.random(1,360)	
	parse("spawnnpc 2 "..spawnx.." "..spawny.." "..spawn3)
end

old Re: How can I spawn 30 Headcrabs every 10 seconds?

Bowlinghead
User Off Offline

Quote
Thats the problem Factis!

Because the parameters for the timer are this:
timer(timer,"function",string parameter,number)

e.g.
timer(1200,"lol",id,10)
function lol(id)
parse("sethealth "..id.." "..player(id,"health")+1)
end

And I need the 1st,2nd and the 4th parameter. I dont need the 3rd. But that was my question!
user Bowlinghead has written
Or an other question:
In my timer there are 4 parameters. But I need only the 1st,2nd and the 4th. How can I "delete" the 3rd parameter?


And special thanks at user IWhoopedPythagoras for the answer.
Its very easy to skip a parameter with "".
Thank you user IWhoopedPythagoras !
But it still not work :(. But thanks for your help, I dont need it anymore, because I didnt tought that headcrabs are attacking both teams. That may works with self-made-bots but its too much work for me I think

old Re: How can I spawn 30 Headcrabs every 10 seconds?

IWhoopedPythagoras
BANNED Off Offline

Quote
Yes, it is unfortunate that DC hasn't added scripting possibilities for headcrabs and other creeps.
It would be sufficient to have just a few commands, since you don't need much functionality for creeps anyway.

They just need to walk straight to an enemy and attack.
It would be cool to be able to configure them so you can make a kind of Alien Swarm.

Don't mean to advertise, but it's a nice free game available on steam ( http://store.steampowered.com/app/630/)

old Re: How can I spawn 30 Headcrabs every 10 seconds?

Bowlinghead
User Off Offline

Quote
DC sayed, that he maybe will add a new function to move all NPCs.
I love this idea!
example
movenpc <Monster> <x> <y>.
That will be awesome.
I think, if something like that will added, there are new possibilities to make new scripts.

old Re: How can I spawn 30 Headcrabs every 10 seconds?

TimeQuesT
User Off Offline

Quote
user Bowlinghead has written
And I need the 1st,2nd and the 4th parameter. I dont need the 3rd.

I think you don't know how the timer function works.(or i missunderstood you ;))

I explain the parameters:

first one ist the time-intervall. It have to be given in ms.
the second one the function name.
the third one: Here you have to put the paramerter. It's given as string. the 4th one is how often the timer will "count". <=0 will loop it for infinity times.

example:

timer (10,"myfunc",20,10) --this will call every 10 ms the function "myfunc" with the parameter "20"(as string).After 10 times it called the function it will stop.

function myfunc(number)

msg(tonumber(number)); --tonumber, because the given value "number" will be given as string.

end


my tip:

if you want to give more then 1 parameter you have to overgive them as "formated" string. for example you have to split every value/parameter with a semicolon or something else.

old Re: How can I spawn 30 Headcrabs every 10 seconds?

Bowlinghead
User Off Offline

Quote
Thanks for your describtion, but was it, what I know actually. I also tried that the 3rd parameter is a unused parameter
e.g.
timer(1200,"myfunc","id",20)
function myfunc(id)
parse(blablabla)
end
----------
So, my idea was, that I make "headcrabs round".
For example on start, the headcrab will spawn randomly. For that team, where are the less player they get the "headcrabs" but if I cant make the NPCs teambased, I cant do my script.
I dont know why IWhoopedPythagoras's tactic doesnt work...

but if all works (with the spawn) there will be a problem with the team.
-----------
But thanks for your help@ all

old Re: How can I spawn 30 Headcrabs every 10 seconds?

EngiN33R
Moderator Off Offline

Quote
Randomly putting headcrabs over the map won't be random anymore.

Here's my code (yay for recursion):
1
2
3
4
5
6
7
8
9
10
11
function randcrab()
	local x=math.random(0,map("xsize"))
	local y=math.random(0,map("ysize"))
	if (tile(x,y,"walkable")) then
		parse("spawnnpc 2 "..x.." "..y)
	else
		randcrab()
	end
end

timer(10000,"randcrab",30)

It should work, I'm not too sure though, bleh. What I'm not sure about is the recursion... Tell me if it works or not.

all-thread-not-read

old Re: How can I spawn 30 Headcrabs every 10 seconds?

Bowlinghead
User Off Offline

Quote
I had the idea with the walbable too .
Your idea works! Thank you.
Now I can do, what I want do :).

But 1 problem. They spawn also outside of the map, but here is the fix:
1
2
3
4
5
6
7
8
9
10
function randcrab()
	local x=math.random(0,map("xsize"))
	local y=math.random(0,map("ysize"))
	local z=math.random(0,360)
	if tile(x,y,"walkable") and tile(x,y,"frame")>=1 then
		parse("spawnnpc 2 "..x.." "..y.." "..z)
	else
		randcrab()
	end
end

Thank you I cant believe, its work!
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview