Forum

> > CS2D > Scripts > Spawn weapons randomly
ForenübersichtCS2D-Übersicht Scripts-ÜbersichtEinloggen, um zu antworten

Englisch Spawn weapons randomly

5 Antworten
Zum Anfang Vorherige 1 Nächste Zum Anfang

alt Spawn weapons randomly

knight-
User Off Offline

Zitieren
Hi everyone.
I want to make a lua that spawn weapon(Primary ammo,Secondary ammo,AK-47 and M4A1)one of them randomly in the random place of the map.I want it per 30s spawn one time.
It is hard for me so please help.

alt Re: Spawn weapons randomly

mafia_man
User Off Offline

Zitieren
There's script:
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
spawning_items = {
	30,32,61,62;
}

function placeitem()
	local x, y;
	x = math.random(0, map('xsize'));
	y = math.random(0, map('ysize'));
	if tile(x, y, 'walkable') and tile(x, y, 'frame') > 0 then
		local i = math.random(1,#spawning_items);
		parse('spawnitem '.. i ..' '.. x ..' '.. y);
		return 0;
	end
	placeitem();
end

seconds = 0;
addhook("second", "everySecond")
function everySecond()
	seconds = seconds + 1;
	if seconds >= 30 then
		seconds = 0;
		placeitem();
	end
end

alt Re: Spawn weapons randomly

Avo
User Off Offline

Zitieren
There are lots of way to do this. You can use entities for example. You must remember than position of item must be walkable tile which player can reach (de_dust - there are some empty places around a map, items would spawn there, too.)
@user mafia_man Remember that if frame isn't 0 it doesn't mean player can go there

Here is my idea:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
walkable_tiles={}

addhook("second","_second",2)
function _second()
	math.randomseed(os.time())
	if #player(0,"tableliving")>0 then
		msg("spawn set"..os.time())
		local pl=player(0,"tableliving")[math.random(1,#player(0,"tableliving"))]
		table.insert(walkable_tiles,{player(pl,"tilex"),player(pl,"tiley")})
	end
end
timer(30000,"_minute","",0)
function _minute()
	math.randomseed(os.time())
	local wp={31,32,33,45,51,61,62,76,83,89,90,91,88,85,82,64,10}
	local r=wp[math.random(1,math.random(1,#wp))]
	local pos=math.random(1,#walkable_tiles)
	pos=walkable_tiles[pos]
	parse("spawnitem "..r.." "..pos[1].." "..pos[2])
	msg("spawned")
	walkable_tiles={}
end

EDIT:
@user mafia_man again:
1
2
local i = math.random(1,#spawning_items);
parse('spawnitem '.. i ..' '.. x ..' '.. y);
with this part of code, only pistols would be spawned if table spawning_items have 4 values.

alt Re: Spawn weapons randomly

Avo
User Off Offline

Zitieren
Edit:
1
local wp={31,32,33,45,51,61,62,76,83,89,90,91,88,85,82,64,10}
(my)

or
1
2
3
spawning_items = {
     30,32,61,62;
}
(mafia_man)

alt Re: Spawn weapons randomly

knight-
User Off Offline

Zitieren
user Avo hat geschrieben
Edit:
1
local wp={31,32,33,45,51,61,62,76,83,89,90,91,88,85,82,64,10}
(my)

or
1
2
3
spawning_items = {
     30,32,61,62;
}
(mafia_man)

@user Avo: Can u fix your version?
Zum Anfang Vorherige 1 Nächste Zum Anfang
Einloggen, um zu antworten Scripts-ÜbersichtCS2D-ÜbersichtForenübersicht