Forum

> > CS2D > Scripts > How To Give players to money?
Forums overviewCS2D overview Scripts overviewLog in to reply

English How To Give players to money?

8 replies
To the start Previous 1 Next To the start

old How To Give players to money?

kRm
User Off Offline

Quote
I have a Money system like that
1
2
3
4
5
6
7
8
9
10
11
function initArray(m)
	local array = {}
	for i = 1, m do
		array[i]=0
	end
	return array
end
ms.money=initArray(32)
function ms.moneyshow(id)
	parse('hudtxt2 '..id..' 1 "©255075000 Jail Packs: '..ms.money[id]..' " 13 400')
end

how Can I give players ms.money?

old Re: How To Give players to money?

Devil-Thanh
GAME BANNED Off Offline

Quote
Add this function into your script
1
2
3
4
function ms.addmoney(id, amount)
	ms.money[id] = ms.money[id] + amount
	ms.moneyshow(id)
end

then add money to them by using
1
ms.addmoney(id, amount)

old Re: How To Give players to money?

Mora
User Off Offline

Quote
In the addition of what user Devil-Thanh said:
If you wan to give these moneys through commands i have an example for you
use this command to give items. You can limit possibility with table and loops (common way to recognize staff):
!addmoney id amount
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
ms={}

function initArray(m)
     local array = {}
     for i = 1, m do
          array[i]=0
     end
     return array
end
ms.money=initArray(32)
function ms.moneyshow(id)
     parse('hudtxt2 '..id..' 1 "\169255075000 Jail Packs: '..ms.money[id]..' " 13 400')
end

function ms.addmoney(id, amount)
     ms.money[id] = ms.money[id] + amount
     ms.moneyshow(id)
end

addhook("say","ms.say")
function ms.say(id,txt)
	if string.sub(txt,1,10)=="!addmoney " then
		local pid, amount=string.match(txt,"!addmoney (.*) (.*)")
		pid=math.floor(tonumber(pid))
		amount=math.floor(tonumber(amount))
		if pid~=0 and pid~=nil then
			if amount~=0 and amount~=nil then
				ms.addmoney(pid, amount)
			else
				msg2(id,"Error: incorrect money value")
			end
		else
			msg2(id,"Error: incorrect player id")
		end
	end
end

old Re: How To Give players to money?

Mora
User Off Offline

Quote
Well. People have their own reasons of inactivity. I told you that you can add me on discord but you did not.
Btw use "\169" instead of "©".
and better use colours table:
1
2
3
4
5
6
7
ms.colours={
["White"]="\169255255255",
["Red"]="\169255000000",
["Green"]="\169000255000",
["Blue"]="\169000000255",
["Orange"]="\169255075000",
}
so you can use them in the code below:
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
ms={}
ms.adminlist={42632,114940}
ms.colours={
	["White"]="\169255255255",
	["Red"]="\169255000000",
	["Green"]="\169000255000",
	["Blue"]="\169000000255",
	["Orange"]="\169255075000",
}

function initArray(m)
     local array = {}
     for i = 1, m do
          array[i]=0
     end
     return array
end
ms.money=initArray(32)
function ms.moneyshow(id)
	parse('hudtxt2 '..id..' 1 "'..ms.colours["Orange"]..' Jail Packs: '..ms.money[id]..' " 13 400')
end

function ms.addmoney(id, amount)
	ms.money[id] = ms.money[id] + amount
	ms.moneyshow(id)
end

addhook("say","ms.say")
function ms.say(id,txt)
	if string.sub(txt,1,10)=="!addmoney " then
		for _,usgn in ipairs(ms.adminlist) do
			if player(id,"usgn")==usgn then
				local pid, amount=string.match(txt,"!addmoney (.*) (.*)")
				pid=tonumber(pid)
				amount=tonumber(amount)
				if pid~=0 and pid~=nil then
					if amount~=0 and amount~=nil then
						if player(pid,"exists") then
							ms.addmoney(pid, amount)
							msg2(id,ms.colours["Green"].."Successfuly added "..amount.." money to "..player(pid,"name"))
							msg2(pid,ms.colours["Green"]..player(id,"name").." used to !addmoney command and added you "..amount.." money")
						else
							msg2(id,ms.colours["Red"].."Error: player is not exists")
						end
					else
						msg2(id,ms.colours["Red"].."Error: incorrect money value")
					end
				else
					msg2(id,ms.colours["Red"].."Error: incorrect player id")
				end
			break
			end
		end
	return 1
	end
end
edited 3×, last 12.12.17 06:38:14 am

old Re: How To Give players to money?

Yates
Reviewer Off Offline

Quote
user Devil-Thanh has written
@user Mora: you can use
[...]

Fixed that for you.

It's personal preference, the latter is also used for passing variables as key names. He shouldn't use anything without stating why.

By the way it's colour* rippir
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview