Forum

> > CS2D > Scripts > When kill NPCs....
Forums overviewCS2D overview Scripts overviewLog in to reply

English When kill NPCs....

14 replies
To the start Previous 1 Next To the start

old When kill NPCs....

Eternal
User Off Offline

Quote
Hello Everyone on us

i want a script

that script is when i kill a NPC then appear items such as gold , money , other things

can someone give me that code??

Thank you

old Re: When kill NPCs....

Jela331
User Off Offline

Quote
Just use env_npc and put an item's name in the ''Trigger'' section.
No need to make a some badass script.

old Re: When kill NPCs....

Eternal
User Off Offline

Quote
But i want when that npc died then spawn items around what point that was died

Sorry for bad English

old Re: When kill NPCs....

Jela331
User Off Offline

Quote
user Eternal has written
But i want when that npc died then spawn items around what point that was died

Sorry for bad English


You mean, on his death spot gold will appear around it?

old Re: When kill NPCs....

Cure Pikachu
User Off Offline

Quote
@user Infinite Rain: The NPC ID is right, but the hook is almost correct.

@user Eternal: Here's the code. This one spawns a Gold around the NPC you killed.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
addhook("objectkill","spwnitm")
function spwnitm(oid,pid)
	if object(oid,"type") == 30 then
		local a = math.random(1,8)
		local xx = object(oid,"tilex")
		local xx2 = xx - 1
		local xx3 = xx + 1
		local yy = object(oid,"tiley")
		local yy2 = yy + 1
		local yy3 = yy - 1
		if a == 1 then parse("spawnitem 68 "..xx2.." "..yy)
		elseif a == 2 then parse("spawnitem 68 "..xx3.." "..yy)
		elseif a == 3 then parse("spawnitem 68 "..xx.." "..yy2)
		elseif a == 4 then parse("spawnitem 68 "..xx.." "..yy3)
		elseif a == 5 then parse("spawnitem 68 "..xx2.." "..yy2)
		elseif a == 6 then parse("spawnitem 68 "..xx2.." "..yy3)
		elseif a == 7 then parse("spawnitem 68 "..xx3.." "..yy2)
		elseif a == 8 then parse("spawnitem 68 "..xx3.." "..yy3)
		end
	end
end

old Re: When kill NPCs....

Apache uwu
User Off Offline

Quote
Nice! I like the randomization around the tile. However since it only spawns 1 gold item--would it not be better to spawn right on the npc death tile?

old Re: When kill NPCs....

Eternal
User Off Offline

Quote
user Cure Pikachu has written
@user Infinite Rain: The NPC ID is right, but the hook is almost correct.

@user Eternal: Here's the code. This one spawns a Gold around the NPC you killed.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
addhook("objectkill","spwnitm")
function spwnitm(oid,pid)
	if object(oid,"type") == 30 then
		local a = math.random(1,8)
		local xx = object(oid,"tilex")
		local xx2 = xx - 1
		local xx3 = xx + 1
		local yy = object(oid,"tiley")
		local yy2 = yy + 1
		local yy3 = yy - 1
		if a == 1 then parse("spawnitem 68 "..xx2.." "..yy)
		elseif a == 2 then parse("spawnitem 68 "..xx3.." "..yy)
		elseif a == 3 then parse("spawnitem 68 "..xx.." "..yy2)
		elseif a == 4 then parse("spawnitem 68 "..xx.." "..yy3)
		elseif a == 5 then parse("spawnitem 68 "..xx2.." "..yy2)
		elseif a == 6 then parse("spawnitem 68 "..xx2.." "..yy3)
		elseif a == 7 then parse("spawnitem 68 "..xx3.." "..yy2)
		elseif a == 8 then parse("spawnitem 68 "..xx3.." "..yy3)
		end
	end
end


Thank you , It works well

EDIT :

How can i make this code spawn more than one gold ??

old Re: When kill NPCs....

Cure Pikachu
User Off Offline

Quote
@user Eternal: Just repeat the spawning.
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
addhook("objectkill","spwnitm")
function spwnitm(oid,pid)
	if object(oid,"type") == 30 then
		local a = math.random(1,8)
		local xx = object(oid,"tilex")
		local xx2 = xx - 1
		local xx3 = xx + 1
		local yy = object(oid,"tiley")
		local yy2 = yy + 1
		local yy3 = yy - 1
		if a == 1 then
			for b = 1, 3 do parse("spawnitem 68 "..xx2.." "..yy) end
		elseif a == 2 then
			for c = 1, 3 do parse("spawnitem 68 "..xx3.." "..yy) end
		elseif a == 3 then
			for d = 1, 3 do parse("spawnitem 68 "..xx.." "..yy2) end
		elseif a == 4 then
			for e = 1, 3 do parse("spawnitem 68 "..xx.." "..yy3) end
		elseif a == 5 then
			for f = 1, 3 do parse("spawnitem 68 "..xx2.." "..yy2) end
		elseif a == 6 then
			for g = 1, 3 do parse("spawnitem 68 "..xx2.." "..yy3) end
		elseif a == 7 then
			for h = 1, 3 do parse("spawnitem 68 "..xx3.." "..yy2) end
		elseif a == 8 then
			for i = 1, 3 do parse("spawnitem 68 "..xx3.." "..yy3) end
		end
	end
end

old Re: When kill NPCs....

BcY
Reviewer Off Offline

Quote
1
2
3
4
5
6
7
8
9
10
11
12
addhook("objectkill","_objkill")
function _objkill(b,id)
if object(b,"type")==30 then
parse('spawnitem '..math.random(1,88)..' '..object(b,"tilex")..' '..object(b,"tiley"))
end
end
addhook("objectkill","_objkilll")
function _objkilll(b,id)
if object(b,"type")==30 then
parse("setscore "..id.." "..(player(id,"score")+1))
end
end

old Re: When kill NPCs....

Avo
User Off Offline

Quote
@user BcY 's code:
This code won't work if random item it's item id that don't exists. For example 13,14 etc. Better use this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
npc_items={64,65,66,67}
addhook("objectkill","_objkill")
function _objkill(b,id)
if object(b,"type")==30 then
local itm=npc_items[math.random(1,#npc_items)]
parse('spawnitem '..itm..' '..object(b,"tilex")..' '..object(b,"tiley"))
end
end
addhook("objectkill","_objkilll")
function _objkilll(b,id)
if object(b,"type")==30 then
parse("setscore "..id.." "..(player(id,"score")+1))
end
end
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview