Forum

> > CS2D > Scripts > NPC sell the food?
Forums overviewCS2D overview Scripts overviewLog in to reply

English NPC sell the food?

5 replies
To the start Previous 1 Next To the start

moved NPC sell the food?

KabirDuy
User Off Offline

Quote
I want one NPC to sell food in one location. And buy food that will subtract $ and its recovery Hp each.

old Re: NPC sell the food?

Alistaire
User Off Offline

Quote
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
npcs = {
	{x = 32, y = 16, cost = 100, heal = 5, name = 'chillidog', npcname = 'Jack the Ripper'},
	{x = 30, y = 12, cost = 200, heal = 9, name = 'lasagna', npcname = 'your mother'}
}

addhook('usebutton', 'usebuttonHook')

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

Add a trigger_button on the place you want the npc to be, and add the tilex and tiley position, name etc. to the npcs[] table.

old Re: NPC sell the food?

KabirDuy
User Off Offline

Quote
I don't quite understand, can you tell me how i stand in any position (x, y). And using for trigger button.
Sr for bad english

old Re: NPC sell the food?

Rainoth
Moderator Off Offline

Quote
user KabirDuy has written
I don't quite understand, can you tell me how i stand in any position (x, y). And using for trigger button.
Sr for bad english


Go to "editor" and place entity called "trigger_use" then look up it's cordinates and enter them in Alistaire's script where it says "x = and y =" at second line.
You can also change the name of food that you bought (like chillidog to donut and lasagna to omelette) you can also change cost, healing amount.

It's quite obvious when you look at his script.
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview