i got this lua for a bankvault ent for gmod but it has 2 problems.
1. i cant seem to spawn it and i dont have enough lua knowlage to find the problem.
2. the vault (it more of an atm) wont give the money back, it only keeps and gives intrest but you cant withdraw it.
can some1 help lua this peice please i need it for a server im working with.
i will paste the init.lua but i also have the shared.lua and cl_init.lua, if those are needed i will paste them later.
here is the init.lua for it
AddCSLuaFile("cl_init.lua")
AddCSLuaFile("shared.lua")
include("shared.lua")
debug = true
//setup a table to hold accounts
account = {}
//account[activator] stores how much money each player has put in
function ENT:Initialize()
self:SetModel("models/props_lab/tpswitch.mdl")
self.Entity:PhysicsInit(SOLID_VPHYSICS)
self.Entity:SetMoveType(MOVETYPE_VPHYSICS)
self.Entity:SetSolid(SOLID_VPHYSICS)
local phys = self.Entity:GetPhysicsObject()
if phys and phys:IsValid() then phys:Wake() end
end
function ENT:Use(activator,caller)
local startingamount = 50
local extraamount = 50
// This makes the entity semi-automatic rather than a continuous.
if ( !activator:KeyPressed( IN_USE ) ) then return end
//if the player does not have enough money return
if( !activator:CanAfford(startingamount) or !activator:CanAfford(extraamount) ) then
Notify(activator, 1, 4, "Sorry, you don't have enough money to make a transaction" )
return
end
//Either setup a new account, or add to existing funds
if ( activator:IsPlayer()) then
if( !account[activator] ) then //If there is no account for this player
account[activator] = startingamount
activator:AddMoney(-startingamount)
Notify(activator, 1, 4, "You Started a New Account with " .. startingamount .. "$ in it!" )
timer.Create(activator:Nick() .. "_bankaccount", 60, 0, function()
interest = math.floor(account[activator]/10) + math.random(1,9)
activator:AddMoney(interest)
Notify(activator, 1, 4, "Interest on your Bank Account made you " .. tostring(interest) .. "$!")
end )
if( debug ) then
stringOut = table.ToString(account,"Accounts: " , true)
Msg(stringOut .. "\n")
end
return
end
if( account[activator] ) then //If an account already Exists
account[activator] = account[activator] + extraamount
activator:AddMoney(-extraamount)
Notify(activator, 1, 4, "You Deposited an Additional " .. tostring(extraamount) .. "$, for a Grand total of " .. tostring(account[activator]) .. "$!")
if( debug ) then
stringOut = table.ToString(account,"Accounts: " , true)
Msg(stringOut .. "\n")
end
return
end
end
end
function ENT:OnRemove() //destroy all timers
for k,v in pairs(player.GetAll()) do
if timer.IsTimer(v:Nick().."_bankaccount") then
timer.Destroy(v:Nick().."_bankaccount")
if( debug ) then
Msg("Removing: " .. v:Nick().."_bankaccount" .. "\n")
end
end
end
end
function removeOldAccounts( ply )
if timer.IsTimer(ply:Nick().."_bankaccount") then
timer.Destroy(ply:Nick().."_bankaccount")
if( debug ) then
Msg("Removing: " .. ply:Nick().."_bankaccount" .. "\n")
end
end
end // End the function
hook.Add( "PlayerDisconnected", "playerdisconnected", removeOldAccounts ) // Add PlayerDisconnected hook that calls our function.
[highlight](User was banned for this post ("Wrong forum" - mahalis))[/highlight]
Is it giving an error in the console? You should post it if it does.
i will check
[editline]12:54PM[/editline]
here, this comes up
ERROR: GAMEMODE:'PlayerSay' Failed: DarkRP\gamemode\modules/banker.lua:26: Tried to use a NULL entity!
Error: hook->PlayerSay returned a non-string!
[editline]01:05PM[/editline]
please someone help
[editline]01:12PM[/editline]
anyone please help, another thing i ment to add, when i say i doesnt spawn i mean it takes your $50 but not even a crate comes up. please help
Put your code in Lua tags. Otherwise we cant tell what line is line 26.
[lua]
AddCSLuaFile("cl_init.lua")
AddCSLuaFile("shared.lua")
include("shared.lua")
debug = true
//setup a table to hold accounts
account = {}
//account[activator] stores how much money each player has put in
function ENT:Initialize()
self:SetModel("models/props_lab/tpswitch.mdl")
self.Entity:PhysicsInit(SOLID_VPHYSICS)
self.Entity:SetMoveType(MOVETYPE_VPHYSICS)
self.Entity:SetSolid(SOLID_VPHYSICS)
local phys = self.Entity:GetPhysicsObject()
if phys and phys:IsValid() then phys:Wake() end
end
function ENT:Use(activator,caller)
local startingamount = 50
local extraamount = 50
// This makes the entity semi-automatic rather than a continuous.
if ( !activator:KeyPressed( IN_USE ) ) then return end
//if the player does not have enough money return
if( !activator:CanAfford(startingamount) or !activator:CanAfford(extraamount) ) then
Notify(activator, 1, 4, "Sorry, you don't have enough money to make a transaction" )
return
end
//Either setup a new account, or add to existing funds
if ( activator:IsPlayer()) then
if( !account[activator] ) then //If there is no account for this player
account[activator] = startingamount
activator:AddMoney(-startingamount)
Notify(activator, 1, 4, "You Started a New Account with " .. startingamount .. "$ in it!" )
timer.Create(activator:Nick() .. "_bankaccount", 60, 0, function()
interest = math.floor(account[activator]/10) + math.random(1,9)
activator:AddMoney(interest)
Notify(activator, 1, 4, "Interest on your Bank Account made you " .. tostring(interest) .. "$!")
end )
if( debug ) then
stringOut = table.ToString(account,"Accounts: " , true)
Msg(stringOut .. "\n")
end
return
end
if( account[activator] ) then //If an account already Exists
account[activator] = account[activator] + extraamount
activator:AddMoney(-extraamount)
Notify(activator, 1, 4, "You Deposited an Additional " .. tostring(extraamount) .. "$, for a Grand total of " .. tostring(account[activator]) .. "$!")
if( debug ) then
stringOut = table.ToString(account,"Accounts: " , true)
Msg(stringOut .. "\n")
end
return
end
end
end
function ENT:OnRemove() //destroy all timers
for k,v in pairs(player.GetAll()) do
if timer.IsTimer(v:Nick().."_bankaccount") then
timer.Destroy(v:Nick().."_bankaccount")
if( debug ) then
Msg("Removing: " .. v:Nick().."_bankaccount" .. "\n")
end
end
end
end
function removeOldAccounts( ply )
if timer.IsTimer(ply:Nick().."_bankaccount") then
timer.Destroy(ply:Nick().."_bankaccount")
if( debug ) then
Msg("Removing: " .. ply:Nick().."_bankaccount" .. "\n")
end
end
end // End the function
hook.Add( "PlayerDisconnected", "playerdisconnected", removeOldAccounts ) // Add PlayerDisconnected hook that calls our function.
[/lua]
[QUOTE=Mmmaaattt94;16690910]i will check
[editline]12:54PM[/editline]
here, this comes up
ERROR: GAMEMODE:'PlayerSay' Failed: DarkRP\gamemode\modules/banker.lua:26: Tried to use a NULL entity!
Error: hook->PlayerSay returned a non-string!
[editline]01:05PM[/editline]
please someone help
[editline]01:12PM[/editline]
anyone please help, another thing i ment to add, when i say i doesnt spawn i mean it takes your $50 but not even a crate comes up. please help[/QUOTE]
Give us the banker.lua then
[QUOTE=ecabc;16700879]Give us the banker.lua then[/QUOTE]
Banker.lua is the code he just posted us...
[QUOTE=Jamie932;16713020]Banker.lua is the code he just posted us...[/QUOTE]
Are you Stupid.
[QUOTE=Mmmaaattt94]here is the init.lua for it[/QUOTE]
[QUOTE=ecabc;16716645]Are you Stupid.[/QUOTE]
Perhaps I am.
I just misread.
here is the banker.lua
function BuyBankVault(ply)
if ( !ply:IsValid() ) then return end
if ( !SERVER ) then return end
local cost = 50
local tr = ply:GetEyeTrace()
if ( !tr.HitWorld ) then return end
if RPArrestedPlayers[ply:SteamID()] then return "" end
if not ply:CanAfford(cost) then
Notify(ply, 1, 4, "Can not afford this!")
return ""
end
if ply:Team() == TEAM_BANKER then
ply:AddMoney(-cost)
Notify(ply, 1, 4, "You bought a Bank Vault for " .. CUR .. tostring(cost))
local bvault = ents.Create("sent_bankvault")
bvault:SetNWEntity("owning_ent", ply)
bvault:SetNWString("Owner", ply:Nick())
bvault:SetPos( tr.HitPos + ply:GetAimVector() * -80 )
bvault:SetAngles( tr.HitNormal:Angle() )
bvault.nodupe = true
bvault.SID = ply.SID
bvault.onlyremover = true
bvault:Spawn()
return ""
else
Notify(ply, 1, 4, "Must be a Banker to Spawn This!")
end
return ""
end
AddChatCommand("/buybvault", BuyBankVault)
function GM:PlayerDisconnected(ply)
for k, v in pairs(ents.FindByClass("sent_bankvault")) do
if v.SID == ply.SID then v:Remove() end
end
end
Use lua tags: [lua] [/ lua] (Without the space)
[lua]function BuyBankVault(ply)
if ( !ply:IsValid() ) then return end
if ( !SERVER ) then return end
local cost = 50
local tr = ply:GetEyeTrace()
if ( !tr.HitWorld ) then return end
if RPArrestedPlayers[ply:SteamID()] then return "" end
if not ply:CanAfford(cost) then
Notify(ply, 1, 4, "Can not afford this!")
return ""
end
if ply:Team() == TEAM_BANKER then
ply:AddMoney(-cost)
Notify(ply, 1, 4, "You bought a Bank Vault for " .. CUR .. tostring(cost))
local bvault = ents.Create("sent_bankvault")
bvault:SetNWEntity("owning_ent", ply)
bvault:SetNWString("Owner", ply:Nick())
bvault:SetPos( tr.HitPos + ply:GetAimVector() * -80 )
bvault:SetAngles( tr.HitNormal:Angle() )
bvault.nodupe = true
bvault.SID = ply.SID
bvault.onlyremover = true
bvault:Spawn()
return ""
else
Notify(ply, 1, 4, "Must be a Banker to Spawn This!")
end
return ""
end
AddChatCommand("/buybvault", BuyBankVault)
function GM:PlayerDisconnected(ply)
for k, v in pairs(ents.FindByClass("sent_bankvault")) do
if v.SID == ply.SID then v:Remove() end
end
end [/lua]
tyvm
Sorry, you need to Log In to post a reply to this thread.