Forum

> > CS2D > Scripts > NPC Sell weapons
Forums overviewCS2D overview Scripts overviewLog in to reply

English NPC Sell weapons

6 replies
To the start Previous 1 Next To the start

old NPC Sell weapons

KabirDuy
User Off Offline

Quote
Sorry I asked the same one topic.
One certain place, for example (id, "tilex"). There will be one NPC, click on the table is one of the weapons for money.

Sorry for bad english.

old Re: NPC Sell weapons

Alistaire
User Off Offline

Quote
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
npcs = {
	{type = 'food', x = 32, y = 16, cost = 100, heal = 5, name = 'a chillidog', npcname = 'Jack the Ripper'},
	{type = 'food', x = 30, y = 12, cost = 200, heal = 9, name = 'some lasagna', npcname = 'your mother'},
	{type = 'weapon', x = 40, y = 14, cost = 500, weapon = 32, name = 'an M4A1', npcname = 'some anonymous weapondealer'}
}

addhook('usebutton', 'usebuttonHook')

function usebuttonHook(id, x, y)
	for npc = 1, #npcs do
		if x == npcs[npc].x and y == npcs[npc].y then
			if player(id, 'money') >= npcs[npc].cost then
				if npcs[npc].type == 'food' then
					parse('sethealth '..id..' '..(player(id, 'health') + npcs[npc].heal))
				elseif npcs[npc].type == 'weapon' then
					parse('equip '..id..' '..npcs[npc].weapon)
				end
				parse('setmoney '..id..' '..(player(id, 'money') - npcs[npc].cost))
				msg2(id, "You bought '..npcs[npc].name..' from '..npcs[npc].npcname..'")
			end
		end
	end
end

<_<
edited 1×, last 20.03.13 09:11:28 am

old Re: NPC Sell weapons

Alistaire
User Off Offline

Quote
user KabirDuy has written
how to use? I use x and y but not work, why?


Add a line in the table for your shop, and add the X and Y tile position there..

{type = 'weapon', x = 72, y = 64, etc etc}

----

Oh and also, take my script again, there was a bug in it.

old Re: NPC Sell weapons

KabirDuy
User Off Offline

Quote
Oh! I know! But instead of that, then I saw one table? Food and weapons are in the table and choose to buy.
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview