-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathfbox_money.lua
More file actions
178 lines (152 loc) · 6.99 KB
/
Copy pathfbox_money.lua
File metadata and controls
178 lines (152 loc) · 6.99 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
--[[
███████╗██╗ ███████╗██╗ ██╗██████╗ ██████╗ ██╗ ██╗
██╔════╝██║ ██╔════╝╚██╗██╔╝██╔══██╗██╔═══██╗╚██╗██╔╝
█████╗ ██║ █████╗ ╚███╔╝ ██████╔╝██║ ██║ ╚███╔╝
██╔══╝ ██║ ██╔══╝ ██╔██╗ ██╔══██╗██║ ██║ ██╔██╗
██║ ███████╗███████╗██╔╝ ██╗██████╔╝╚██████╔╝██╔╝ ██╗
╚═╝ ╚══════╝╚══════╝╚═╝ ╚═╝╚═════╝ ╚═════╝ ╚═╝ ╚═╝
featuring
_ _ . . _
`. / ___ __. _/_ ` ___ / ___ \ ___ ____
\,' / ` .' \ | | .' ` | / ` |/ \ (
,'\ | | | | | | | | | | | ` `--.
/ \ `.__/| `._.' \__/ / `._.' /---/ `.__/| `___,' \___.'
- Security is our priority -
This code is copyrighted by Flex. You are not allowed to redistribute.
--]]
local META = FindMetaTable("Player")
function META:GetMoney()
if SERVER then
if tonumber(self:GetPData("fbox_player_money",100)) < 0 then self:SetPData("fbox_player_money",0) end
self:SetNWInt("fbox_money", self:GetPData("fbox_player_money")) end
return tonumber(self:GetNWInt("fbox_money"))
end
function META:CanAfford(price)
return price <= self:GetMoney()
end
function META:TransferMoney(ply,num)
if ply:IsBot() or not ply:IsPlayer() or ply == self then return false end
if self:GetMoney() < num then num = self:GetMoney() end
if SERVER then
if num <= 0 then return false end
self:TakeMoney(num)
ply:GiveMoney(num)
end
hook.Run("fbox_transfermoney", self,ply,num)
end
function META:SetMoney(num)
if SERVER then
self:SetPData("fbox_player_money",num)
self:SetNWInt("fbox_money", self:GetPData("fbox_player_money"))
end
hook.Run("fbox_setmoney", self,num)
end
function META:GiveMoney(num)
if SERVER then
self:SetPData("fbox_player_money",self:GetPData("fbox_player_money", 100) + num )
self:SetNWInt("fbox_money", self:GetPData("fbox_player_money"))
end
hook.Run("fbox_givemoney", self,num)
end
function META:TakeMoney(num)
if SERVER then
if self:GetMoney() < 0 then return end
self:SetPData("fbox_player_money",self:GetPData("fbox_player_money",100) - num )
self:SetNWInt("fbox_money", self:GetPData("fbox_player_money"))
self:GetMoney()
end
hook.Run("fbox_takemoney", self,num)
end
function META:SaveMoney()
self:SetPData("fbox_player_money", self:GetPData("fbox_player_money")) --useless code but yolo
end
function META:LoadMoney()
if SERVER then self:SetNWInt("fbox_money", self:GetPData("fbox_player_money")) end
end
function META:Katching()
sound.Play("chatsounds/autoadd/dota2/buy.ogg",self:GetPos())
end
hook.Add("PlayerDisconnected","fbox_money_save",function(ply)
if CLIENT then return end
ply:SaveMoney()
MsgN("Money saved for disconnected player: "..ply:Name())
end)
hook.Add("PlayerInitialSpawn","fbox_money_load",function(ply)
ply:LoadMoney()
end)
hook.Add("PlayerInitialSpawn","fbox_money_firstjoin",function(ply)
if !ply:GetPData("fboxhasjoined") then
ply:SetPData("fboxhasjoined", true)
ply:GiveMoney(500)
end
end)
hook.Add("PlayerDeath","fbox_money_death_reward",function(vic,wep,att)
if vic == att then return
elseif vic:IsAFK() then
att:PrintMessage(3,"You got no money as "..vic:GetName().." is AFK.")
return false
elseif vic:IsBot() then
att:PrintMessage(3,"You got no money as "..vic:GetName().." is a BOT.")
return false
elseif not att:IsPlayer() then return
elseif att:IsBot() then return --bots dont need money, they are slaves.
elseif vic:IsWeapon() then return --Just because i love this function.
elseif att:HasGodMode() then
att:PrintMessage(3,"You killed "..vic:Name().." but did not receive any money because you are in Godmode.")
return
end
local value = math.Round(math.Rand(40,120))
if value > tonumber(vic:GetMoney()) and tonumber(vic:GetMoney()) >= 0 then value = tonumber(vic:GetMoney()) end
if tonumber(vic:GetMoney()) <= 0 then att:PrintMessage(3,"You got no money as "..vic:Name().." had no money on him") vic:PrintMessage(3,att:Name().." killed you but you had no money on you") return end
att:PrintMessage(3,"You killed "..vic:Name().." and recieved $"..value)
att:GiveMoney(value)
vic:TakeMoney(value)
vic:PrintMessage(3,att:Name().." killed you and received $"..value)
end)
hook.Add("fbox_transfermoney","fbox_transfermoney_notice",function(sender,receiver,num)
sender:PrintMessage(3,"You gave "..receiver:GetName().." $"..num)
reciever:PrintMessage(3,sender:GetName().." gave you :money:$"..num)
receiver:Katching()
sender:Katching()
end)
hook.Add("fbox_givemoney","fbox_givemoney",function(ply,num)
ply:Katching()
end)
hook.Add("fbox_takemoney","fbox_takemoney",function(ply,num)
ply:Katching()
end)
hook.Add("fbox_setmoney","fbox_setmoney",function(ply,num)
ply:Katching()
end)
if SERVER then //Commands
aowl.AddCommand("transfermoney", function(ply,line,target)
target = easylua.FindEntity(target)
local amount = tonumber(string.sub(line,string.find(line,",")+1))
if not isnumber(amount) or not IsValid(target) then Fply:PrintMessage(3,"Invalid target or amount") return end
ply:TransferMoney(target,amount)
end, "players")
aowl.AddCommand("givemoney", function(ply,line,target)
target = easylua.FindEntity(target)
local amount = tonumber(string.sub(line,string.find(line,",")+1))
if not isnumber(amount) or not IsValid(target) then ply:PrintMessage(3,"Invalid target or amount") return end
target:GiveMoney(amount)
end, "developers")
aowl.AddCommand("takemoney", function(ply,line,target)
target = easylua.FindEntity(target)
local amount = tonumber(string.sub(line,string.find(line,",")+1))
if not isnumber(amount) or not IsValid(target) then ply:PrintMessage(3,"Invalid target or amount") return end
target:TakeMoney(amount)
end, "developers")
aowl.AddCommand("setmoney", function(ply,line,target)
target = easylua.FindEntity(target)
local amount = tonumber(string.sub(line,string.find(line,",")+1))
if not isnumber(amount) or not IsValid(target) then ply:PrintMessage(3,"Invalid target or amount") return end
target:SetMoney(amount)
end, "developers")
end
hook.Add("OnNPCKilled","Zomberino",function( npc,att, infl)
if npc:GetClass() == "npc_zombie" and att:IsPlayer() and not att:HasGodMode() then
amount = math.random(10,100)
att:GiveMoney(amount)
end
end)