Forum

> > CS2D > Scripts > How to make skin shop lua?
Forums overviewCS2D overview Scripts overviewLog in to reply

English How to make skin shop lua?

4 replies
To the start Previous 1 Next To the start

old How to make skin shop lua?

-AngelOfDeath-
User Off Offline

Quote
Hello everyone, i wanted to ask. How to make a menu with skin shop. I mean that everyone collect money, kill others and something like that and for that money can buy skins. Oh money is not cs2d money, its lua money- like ammo packs in zombie plague. So if anyone know how to do it please write. It would be very helpful

old Re: How to make skin shop lua?

DannyDeth
User Off Offline

Quote
It's relatively simple, all you need is an array containing the money for each player, a 'shop' area + a way to detect when he is in it and a little menu. So here:
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
if not wing_shop then wing_shop = {} end

wing_shop.player_money = {}

wing_shop.money_saves = {}

wing_shop.amount_money_per_kill = 1000

wing_shop.img = {}

wing_shop.tile_area = {
	starting_tile = { TILE_X, TILE_Y }
	ending_tile = { TILE_X, TILE_Y }
}

addhook("join","wing_shop.set_money")
function wing_shop.set_money(id)
	if wing_shop.money_saves[player(id,"usgn")] == nil then wing_shop.player_money[id]=0
	else wing_shop.player_money = wing_shop.money_saves[player(id,"usgn")] end
end

addhook("kill","wing_shop.addmoney")
function wing_shop.addmoney(id)
	wing_shop.player_money[id] = wing_shop.player_money[id] + wing_shop.amount_of_money_per_kill
end

addhook("say","wing_shop.detect")
function wing_shop.detect(id)
	if ( ( (wing_shop.tile_area.starting_tile[0]-player(id,"tilex")) <= ( wing_shop.tile_area.starting_tile[0]- wing_shop.tile_area.ending_tile[0]) ) and  (wing_shop.tile_area.starting_tile[1]-player(id,"tiley")) <= ( wing_shop.tile_area.starting_tile[1]- wing_shop.tile_area.ending_tile[1]) ) then
		msg2(id,"Hi there and welcome to the wing shop, "..player(id,"name").."!")
		menu(id,"Wing Shop, Dragon Wings, Fairy Wing, Random Wings of Doom")
	end
end

addhook("menu","wing_shop.menu_click")
function wing_shop.menu_click(id,title,button)
	if title = "Wing Shop" then
		if button == 1 then
			freeimage(wing_shop.img[id])
			wing_shop.img[id] = image("gfx/MyRandomRPGServer/Dragon_Wings.png",1,0,200+id)
			wing_shop.player_money[id] = wing_shop.player_money[id] - 5000
		elseif button == 2 then
			freeimage(wing_shop.img[id])
			image("gfx/MyRandomRPGServer/Fairy_Wings.png.png",1,0,200+id)
			wing_shop.player_money[id] = wing_shop.player_money[id] - 5000
		elseif button == 3 then
			freeimage(wing_shop.img[id])
			image("gfx/MyRandomRPGServer/Random_Wings_of_Doom.png",1,0,200+id)
			wing_shop.player_money[id] = wing_shop.player_money[id] - 5000
		end
	end
end

addhook("leave","wing_shop.save_and_clear")
function wing_shop.save(id)
	wing_shop.money_saves[player(id,"usgn")] = wing_shop.player_money[id]
	wing_shop.player_money[id] = 0
end

I haven't tested it, just a little 2 minute scratch up.

EDIT: Sorry, one second, I forgot about the specific tile area thing.

EDIT2: I think I now hold a world record: Lua's longest If statement.

Where it says TILE_X and TILE_Y in the ending and starting tiles in the tile_area array, replace them with tile values of the top left corner and bottom right corner of your shop area.

EDIT3: Okay, I've lost it, I forgot to0 save the money on leave as well. One second, imma correct it.

EDIT4: Done, fixed some other mistakes as well. This is what I get for rushing thing, eh.

EDIT5: Remembered to take money off for the wings now. I FORGOT THE IMAGE FREEING! DAMN DAMN DAMN.

EDIT6: If this thing doesnt work now, I'm going to throw a temper tantrum and possibly kill someone.
edited 4×, last 16.08.11 05:54:49 pm

old Re: How to make skin shop lua?

IWhoopedPythagoras
BANNED Off Offline

Quote
user DannyDeth has written
It's relatively simple, all you need is an array containing the money for each player, a 'shop' area + a way to detect when he is in it and a little menu. So here:
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
32
33
34
35
36
37
38
39
40
41
42
43
44
if not wing_shop then wing_shop = {} end

wing_shop.player_money = {}

wing_shop.money_saves = {}

wing_shop.amount_money_per_kill = 1000

wing_shop.tile_area = {
	starting_tile = { TILE_X, TILE_Y }
	ending_tile = { TILE_X, TILE_Y }
}

addhook("join","wing_shop.set_money")
function wing_shop.set_money(id)
	if player_money[player(id,"usgn")] == nil then player_money[player(id,"usgn")]=0 end
	parse("setmoney "..id.." "..player_money[player(id,"usgn")])
end

addhook("kill","wing_shop.addmoney")
function wing_shop.addmoney(id)
	parse("setmoney "..id.." "..(player(id,"money")+amount_money_per_kill))
end

addhook("say","wing_shop.detect")
function wing_shop.detect(id)
	if ( ( (wing_shop.tile_area.starting_tile[0]-player(id,"tilex")) <= ( wing_shop.tile_area.starting_tile[0]- wing_shop.tile_area.ending_tile[0]) ) and  (wing_shop.tile_area.starting_tile[1]-player(id,"tiley")) <= ( wing_shop.tile_area.starting_tile[1]- wing_shop.tile_area.ending_tile[1]) ) then
		msg2(id,"Hi there and welcome to the wing shop, "..player(id,"name").."!")
		menu(id,"Wing Shop, Dragon Wings, Fairy Wing, Random Wings of Doom")
	end
end

addhook("menu","wing_shop.menu_click")
function wing_shop.menu_click(id,title,button)
	if title = "Wing Shop" then
		if button == 1 then
			image("gfx/MyRandomRPGServer/Dragon_Wings.png",1,0,200+id)
		elseif button == 2 then
			image("gfx/MyRandomRPGServer/Fairy_Wings.png.png",1,0,200+id)
		elseif button == 3 then
			image("gfx/MyRandomRPGServer/Random_Wings_of_Doom.png",1,0,200+id)
		end
	end
end

I haven't tested it, just a little 2 minute scratch up.

EDIT: Sorry, one second, I forgot about the specific tile area thing.

EDIT2: I think I now hold a world record: Lua's longest If statement.

Where it says TILE_X and TILE_Y in the ending and starting tiles in the tile_area array, replace them with tile values of the top left corner and bottom right corner of your shop area.

EDIT3: Okay, I've lost it, I forgot to0 save the money on leave as well. One second, imma correct it.


if you use table a lot of times, it's faster to do like this:

1
local starting_tile = wing_shop.tile_area.starting_tile

old Re: How to make skin shop lua?

DannyDeth
User Off Offline

Quote
Actually, it makes the script SLOWER, as you are making lua move values too often. anyway, i need to edit it AGAIN because i forgot something.

And, also, I'm writing to a lot of tables, Lua doesn't have pointers so I have to use the actual tables.
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview