ID:139403
 
obj
NPCs
Banker
icon = 'banker.dmi'
icon_state = "banker"
density = 1
name = "Banker"

verb
Bank()
set src in oview(1)

/*
We check to see if usr.bank is null or not, if this is the first time the player has visited the bank
then the variable will be null. Keep in mind, with a savefile the variable will not be null if a
revisiting player goes to the bank when he logs in.
*/

if(!usr.bank)
usr.bank = new/BankClass
switch(alert("[src.name]: Hola! Would you like to work with you money banking or our item banking?","Banking","Money","Item"))
if("Money")
switch(alert("[src.name]: Would you like to deposit or withdraw money?","Banking","Deposit","Withdraw"))



if("Deposit")
var/DepositNum = round(input("[src.name]: How much would you like to deposit?") as num)
if(DepositNum > 0)
if(usr.money >= DepositNum)
usr.money -= usr.bank.DepositMoney(DepositNum)
else
usr << "You do not much enough money!"
else
usr << "You cannot deposit less than 1!"
else if("Withdraw")
var/WithdrawNum = round(input("[src.name]: How much would you like to withdraw?") as num)
if(WithdrawNum > 0)
if(usr.bank.GetBalance() >= WithdrawNum)
usr.money += usr.bank.WithdrawMoney(WithdrawNum)
else
usr << "You don't have enough in your bank!"
else
usr << "You cannot withdraw less than 1!"
else if("Item")
switch(alert("[src.name]: Would you like to deposit or withdraw an item?","Banking", "Deposit", "Withdraw"))



if("Deposit")
var/obj/O = input("Which item would you like to deposit?") as obj in usr.contents
if(O)
usr.bank.DepositItem(O)
usr << "You have deposited [O.name]!"
else
usr << "You have no items to deposit!"
else if("Withdraw")
var/obj/O = input("Which item would you like to withdraw?") as obj in usr.bank.GetItems()
if(O)
usr.bank.WithdrawItem(O)
usr << "You have withdrawn [O.name]!"
else
usr << "You have no items in your bank!"





BankClass
var
balance = 0 //Holds how much money is in the bank
list/items = list()
proc
GetBalance()
return src.balance

DepositMoney(var/num)
src.balance += num
return num

WithdrawMoney(var/num)
balance -= num
return num

DepositItem(var/obj/O)
src.items.Add(O)
usr.contents.Remove(O)

WithdrawItem(var/obj/O)
src.items.Remove(O)
usr.contents.Add(O)

GetItems()
return src.items


I am trying to get this banking system to work but I keep getting these errors: banking.dm:19:error: usr.bank: undefined var
banking.dm:20:error: usr.bank: undefined var
banking.dm:30:error: usr.money: undefined var
banking.dm:31:error: usr.money: undefined var
banking.dm:31:error: usr.bank.DepositMoney: undefined var
banking.dm:39:error: usr.bank.GetBalance: undefined var
banking.dm:40:error: usr.money: undefined var
banking.dm:40:error: usr.bank.WithdrawMoney: undefined var
banking.dm:53:error: usr.bank.DepositItem: undefined var
banking.dm:58:error: usr.bank.GetItems: undefined var
banking.dm:60:error: usr.bank.WithdrawItem: undefined var


Where did you define bank in the usr?
In response to Pirion (#1)
What do you mean?
In response to Bigmnm (#2)
The compiler tells you. You have to create the vars. Like this for your money.

<DM>mob/var
money=0 // Or whatever the amount you want the mob to have.
In response to Gtgoku55 (#3)
It already had that and it still was having errors. Why is this?
In response to Bigmnm (#2)
You never told the compiler what path usr is. Without it, it does not know where bank is defined.
obj
NPCs
Banker
icon = 'banker.dmi'
icon_state = "banker"
density = 1
name = "Banker"

verb
Bank()
set src in oview(1)
***try this section of code into your project***
if(istype(usr,/mob))
var/mob/M = usr
***you will need to replace usr with M for every variable in this proc***

/*
We check to see if usr.bank is null or not, if this is the first time the player has visited the bank
then the variable will be null. Keep in mind, with a savefile the variable will not be null if a
revisiting player goes to the bank when he logs in.
*/
***and also you will need to indent everything 1 step further so highlight all the code and press tab to do that easily***
if(!M.bank)
M.bank = new/BankClass
***etc..***
In response to SamuraiJei (#6)
Thank you but I figured it out already.