Forum

> > CS2D > Scripts > When kill NPCs....
ForenübersichtCS2D-Übersicht Scripts-ÜbersichtEinloggen, um zu antworten

Englisch When kill NPCs....

14 Antworten
Zum Anfang Vorherige 1 Nächste Zum Anfang

alt When kill NPCs....

Eternal
User Off Offline

Zitieren
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

alt Re: When kill NPCs....

Jela331
User Off Offline

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

alt Re: When kill NPCs....

Eternal
User Off Offline

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

Sorry for bad English

alt Re: When kill NPCs....

Jela331
User Off Offline

Zitieren
user Eternal hat geschrieben
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?

alt Re: When kill NPCs....

Cure Pikachu
User Off Offline

Zitieren
@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

alt Re: When kill NPCs....

Apache uwu
User Off Offline

Zitieren
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?

alt Re: When kill NPCs....

Eternal
User Off Offline

Zitieren
user Cure Pikachu hat geschrieben
@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 ??

alt Re: When kill NPCs....

Cure Pikachu
User Off Offline

Zitieren
@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

alt Re: When kill NPCs....

BcY
Reviewer Off Offline

Zitieren
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

alt Re: When kill NPCs....

Avo
User Off Offline

Zitieren
@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
Zum Anfang Vorherige 1 Nächste Zum Anfang
Einloggen, um zu antworten Scripts-ÜbersichtCS2D-ÜbersichtForenübersicht