Forum

> > CS2D > Scripts > Send coin
Forums overviewCS2D overview Scripts overviewLog in to reply

English Send coin

15 replies
To the start Previous 1 Next To the start

old Send coin

Ridho
User Off Offline

Quote
i want to add "give coin" in my script
example : !givecoin 1 3
3 > how many level will i give to other player
please help me

1
coin=initArray(32)

thanks for all

old Re: Send coin

MikuAuahDark
User Off Offline

Quote
ok im confused. you say
user Ridho has written
give coin

but then you say
user Ridho has written
example : !givecoin 1 3
3 > how many level will i give to other player

user Ridho has written
level

so whay you want??

old Re: Send coin

Ridho
User Off Offline

Quote
I fix my words before

I want to give coins to other people by giving the command:! givecoin 1 3
1 = the person who will i give coin
3 = coin that I will give to the person

1
coin=initArray(32)

thanks

old Re: Send coin

Cure Pikachu
User Off Offline

Quote
This one does not include how to get coins or showing how many coins you have on the HUD.
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
function totable(t,match)
	local cmd = {}
	if not match then
		match = "[^%s]+"
	else
		match = "[^"..match.."]+"
	end
	for word in string.gmatch(t,match) do
		table.insert(cmd,word)
	end
	return cmd
end

function initArray(v)
	local array = {}
	for i = 1, v do
		array[i] = 0
	end
	return array
end

coin = initArray(32)

addhook("say","give")
function give(id,txt)
	local seg = totable(txt)
	local part1 = string.lower(seg[1])
	if part1 == "!givecoin" then
		local part2 = tonumber(seg[2])
		local part3 = tonumber(seg[3])
		if part2 ~= nil and part3 ~= nil then
			if player(part2,"exists") then
				if part3 > 0 then
					if coin[id] >= part3 then
						coin[id] = coin[id] - part3
						coin[part2] = coin[part2] + part3
						msg2(id,"©000255000You gave "..player(part2,"name").." "..part3.." coins!")
					else
						msg2(id,"©255000000You can't give more than what you have!")
					end
				end
			end
		else
			msg2(id,"©255128000Usage: !givecoin <id> <value>")
		end
		return 1
	end
end
edited 1×, last 30.04.12 03:12:40 pm

old Re: Send coin

MikuAuahDark
User Off Offline

Quote
i have better code
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
coin = {}
for id = 1,32 do
	coin[id]=0
end

addhook("say","sendcoin")
function sendcoin(id,txt)
	if txt:sub(1,9)=="!givecoin" then
		if txt:sub(12,12)~=" " then
			pl = tonumber(txt:sub(11,12))
			value = tonumber(txt:sub(13))
		else
			pl = tonumber(txt:sub(11,11))
			value = tonumber(txt:sub(12))
		end
		if coin[id]>=value then
			if player(pl,"exists") then
				if value>0 then
					coin[pl]=coin[pl]+value
					coin[id]=coin[id]-value
					msg2(id,"©000255000You gave "..player(pl,"name").." "..value.." coins!")
				end
			else
				msg2(id,string.char(169).."255000000This player does not exists")
			end
		else
			msg2(id,"©255000000You can't give more than what you have!")
		end
	end
end
please note that not include a adding money, money hud. some message i copy from user Cure Pikachu

old Re: Send coin

Apache uwu
User Off Offline

Quote
making stuff more efficient but removing readability and error messages does not make it better

old Tested

Ridho
User Off Offline

Quote
i tested @user MikuAuahDark: 's code and it works... but, i want other person can't read that message.

old Re: Send coin

Cure Pikachu
User Off Offline

Quote
Add in
1
msg2(pl,"©000255000"..player(id,"name").." gave you "..value.." coins!")
after
1
msg2(id,"©000255000You gave "..player(pl,"name").." "..value.." coins!")
If that's what you meant.

old Re: Send coin

Ridho
User Off Offline

Quote
i want other people can't read my command !givecoin
except me and person i gave coin,

old Re: Send coin

EngiN33R
Moderator Off Offline

Quote
user MikuAuahDark's code isn't exactly better, in some parts it's even worse. You should add
1
return 1
After this part:
1
2
msg2(id,"©255000000You can't give more than what you have!")
          end
To make the chat command invisible.

old Re: Send coin

Ridho
User Off Offline

Quote
@user EngiN33R: i will fix it in my script :
thank you

@user MikuAuahDark: i need full of the code (i want other people can't read my message)
please

i not a good scripter
edited 1×, last 01.05.12 02:45:38 pm

old Re: Send coin

MikuAuahDark
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
24
25
26
27
28
29
30
31
coin = {}
for id = 1,32 do
	coin[id]=0
end

addhook("say","sendcoin")
function sendcoin(id,txt)
	if txt:sub(1,9)=="!givecoin" then
		if txt:sub(12,12)~=" " then
			pl = tonumber(txt:sub(11,12))
			value = tonumber(txt:sub(13))
		else
			pl = tonumber(txt:sub(11,11))
			value = tonumber(txt:sub(12))
		end
		if coin[id]>=value then
			if player(pl,"exists") then
				if value>0 then
					coin[pl]=coin[pl]+value
					coin[id]=coin[id]-value
					msg2(id,"©000255000You gave "..player(pl,"name").." "..value.." coins!")
				end
			else
				msg2(id,string.char(169).."255000000This player does not exists")
			end
		else
			msg2(id,"©255000000You can't give more than what you have!")
		end
		return 1
	end
end
if another player still can see your command, maybe there is a conflicting hooks

old Re: Send coin

Ridho
User Off Offline

Quote
oh, i already completed my script. thank you
and cookie for all
mmmmm

but, need 1 more,...
if bot joined to the server, it just have 1 level, and 1 coins (bot's level and coin reset)

1
2
level=initArray(32)
coin=initArray(32)

pls help me
edited 1×, last 01.05.12 05:43:40 pm

old Re: Send coin

MikuAuahDark
User Off Offline

Quote

1
2
3
4
5
6
7
8
9
10
11
12
coin={}		-- this table work like array
level={}
for id = 1,32 do
	coin[id]=1
	level[id]=1
end
adhook("join","ridhojelek")
function ridhojelek(id)
	if player(id,"bot")~=true then
		-- Your Code
	end
end

old Re: Send coin

Ridho
User Off Offline

Quote
oh thank you soo much
but i will change ridhojelek at hook to ridhohebat
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview