File: preload.lua

package info (click to toggle)
cataclysm-dda 0.C%2Bgit20190228.faafa3a-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 181,636 kB
  • sloc: cpp: 256,609; python: 2,621; makefile: 862; sh: 495; perl: 37; xml: 33
file content (31 lines) | stat: -rw-r--r-- 784 bytes parent folder | download
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
27
28
29
30
31
function pick_from_list(list)
	local rand = math.random(1, #list)
	return list[rand]
end

function iuse_manhack(item, active)
	-- find a bunch of locations where we might spawn the manhack
	local locs = {}
	for delta_x = -1, 1 do
		for delta_y = -1, 1 do
			local point = player:pos()
			point.x = point.x + delta_x
			point.y = point.y + delta_y
			if g:is_empty(point) then
				table.insert(locs, point )
			end
		end
	end

	if #locs == 0 then
		game.add_msg("You can't use this here!")
		return 0 -- 0 charges used
	end

	-- okay, we got a bunch of locations, pick one and spawn a manhack there
	local loc = pick_from_list(locs)
	local monster = game.create_monster(mtype_id("mon_manhack"), loc)
	return 1 -- 1 charge used
end

game.register_iuse("IUSE_LUA_MANHACK", iuse_manhack)