English How To Give players to money?

8 replies
Goto Page
To the start Previous 1 Next To the start
11.12.17 06:45:59 pm
Up
kRm
User
Offline Off
I have a Money system like that
Code:
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?
11.12.17 08:05:06 pm
Up
Devil-Thanh
GAME BANNED
Offline Off
Add this function into your script
Code:
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
Code:
1
ms.addmoney(id, amount)
11.12.17 08:24:45 pm
Up
Mora_rus
User
Offline Off
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
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
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
S.T.A.L.K.E.R. - The Lost Land dev. https://discord.gg/aABCkHQ
11.12.17 08:30:40 pm
Up
kRm
User
Offline Off
@Mora_rus ty man It worked

Btw I wanna do this only admins.
I have a line like that on top
adminlist = {42632}
11.12.17 08:33:06 pm
Up
Mora_rus
User
Offline Off
Discord.. Tomorrow.. Maybe somebody can help u for the time i wont be active.
S.T.A.L.K.E.R. - The Lost Land dev. https://discord.gg/aABCkHQ
11.12.17 08:39:50 pm
Up
kRm
User
Offline Off
I really need that right now... Ty anyway
12.12.17 06:24:26 am
Up
Mora_rus
User
Offline Off
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:
Code:
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:
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
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
S.T.A.L.K.E.R. - The Lost Land dev. https://discord.gg/aABCkHQ
12.12.17 12:18:23 pm
Up
Devil-Thanh
GAME BANNED
Offline Off
@user Mora_rus: you should use
Code:
1
ms.colours.Color
instead of
Code:
1
ms.colours["Color"]


Btw, they're the same
12.12.17 01:11:35 pm
Up
Yates
Reviewer
Offline Off
user Devil-Thanh has written:
@user Mora_rus: 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