ID:263000
 
Code:
mob/var/list/Vault = list("Cancel")

obj/Vault
icon = 'Random.dmi'
icon_state = "Vault"
density = 1
verb/Vault(mob/player/M)
set src in view(1)
flick("Vault flick",src)
icon_state = "Vault open"
switch(input("What Shall You Do?","Storage") in list("Withdraw Item","Deposit Item","View contents","Cancel"))
if("Withdraw Item")
var/obj/item/W = input("What do you want to withdraw?","Withdraw Item") in M.Vault
if(W == "Cancel")
flick("Vault close",src)
src.icon_state = "Vault"
return
var/AS = input("You have [W.count] [W]. How many do you wish to deposit?","How many?") as num
if(AS == 0)
flick("Vault close",src)
src.icon_state = "Vault"
return
if(W.count < AS)
M << "You don't have that many stored!"
flick("Vault close",src)
src.icon_state = "Vault"
return
var/obj/item/L = locate(W) in M.contents
if(L)
L.count += AS
W.count -= AS
if(W.count == 0)
M.Vault -= W
L.suffix = "[L.count]"
M << "You withdrew [AS] [L]!"
else
var/obj/item/O = W
O.count = AS
O.suffix = "[O.count]"
O.loc = M
M << "You withdrew [AS] [O]!"
flick("Vault close",src)
src.icon_state = "Vault"
if("Deposit Item")
if(M.contents == null)
M << "You have nothing to deposit!"
flick("Vault close",src)
src.icon_state = "Vault"
return
else
var/obj/item/D = input("What do you want to deposit?","Deposit") in M.contents
switch(alert("[D] is the item you chose. Are you sure this is what you want to deposit?","Deposit [D]?","Yes","No"))
if("Yes")
var/AS = input("How many would you like to deposit?","How many?") as num
if(AS == 0)
flick("Vault close",src)
src.icon_state = "Vault"
return
if(D.count < AS)
M << "You don't have that many!"
flick("Vault close",src)
src.icon_state = "Vault"
return
var/obj/item/L = locate(D) in M.Vault
if(L)
L.count += AS
D.count -= AS
if(D.count == 0)
del D
L.suffix = "[L.count]"
else
M.Vault += D
del D
flick("Vault close",src)
src.icon_state = "Vault"
if("No")
flick("Vault close",src)
src.icon_state = "Vault"
return
if("Cancel")
flick("Vault close",src)
src.icon_state = "Vault"
return
if("View contents")
var/list/L = list()
for(var/obj/item/O in M.Vault)
L += O
switch(alert("These are the items in your vault, [L]","Items","Done"))
if("Done")
flick("Vault close",src)
src.icon_state = "Vault"
return


Problem description:
As you can see, I making an item storage code here and I've run across some problems.

1. It doesn't show you what's in your vault.

2.You can't withdraw items. This is why.
runtime error: Cannot read null.count
proc name: Vault (/obj/Vault/verb/Vault)
source file: Turfs.dm,3247
usr: Pyrodragon (/mob/player/GM/Admin/Pyro_Dragons)
src: Vault (/obj/Vault)
call stack:
Vault (/obj/Vault): Vault(Pyrodragon (/mob/player/GM/Admin/Pyro_Dragons))

3.I don't know if the deposit part is working right.

Thanks for the help.
verb/Vault(mob/player/M)

You don't need to use mob/player/M here. usr is acceptable.
In response to Crzylme
Ok, after changing that, the same problems still remain.
In response to Pyro_dragons
Help is much appreciated thank you.
In response to Pyro_dragons
Ok, it works now, but it makes the count of the item zero, and doesn't remove it from usr.Vault.

obj/Vault
icon = 'Random.dmi'
icon_state = "Vault"
density = 1
verb/Vault()
set src in view(1)
flick("Vault flick",src)
icon_state = "Vault open"
switch(input("What Shall You Do?","Storage") in list("Withdraw Item","Deposit Item","View contents","Cancel"))
if("Withdraw Item")
var/obj/item/W = input("What do you want to withdraw?","Withdraw Item") in usr.Vault
if(usr.Vault == null)
return
if(W == "Cancel")
flick("Vault close",src)
src.icon_state = "Vault"
return
var/AS = input("You have [W.count] [W]. How many do you wish to deposit?","How many?") as num
if(AS == 0)
flick("Vault close",src)
src.icon_state = "Vault"
return
if(W.count < AS)
usr << "You don't have that many stored!"
flick("Vault close",src)
src.icon_state = "Vault"
return
var/obj/item/L = locate(W) in usr.contents
if(L)
L.count += AS
W.count -= AS
if(W.count == 0)
usr.Vault -= W
else
W.count -= AS
W.suffix = "[W.count]"
L.suffix = "[L.count]"
usr << "You withdrew [AS] [L]!"
else
var/obj/item/O = W
O.count = AS
O.suffix = "[O.count]"
O.loc = usr
usr << "You withdrew [AS] [O]!"
flick("Vault close",src)
src.icon_state = "Vault"
if("Deposit Item")
if(usr.contents == null)
usr << "You have nothing to deposit!"
flick("Vault close",src)
src.icon_state = "Vault"
return
else
var/obj/item/D = input("What do you want to deposit?","Deposit") in usr.contents
switch(alert("[D] is the item you chose. Are you sure this is what you want to deposit?","Deposit [D]?","Yes","No"))
if("Yes")
var/AS = input("How many would you like to deposit?","How many?") as num
if(AS == 0)
flick("Vault close",src)
src.icon_state = "Vault"
return
if(D.count < AS)
usr << "You don't have that many!"
flick("Vault close",src)
src.icon_state = "Vault"
return
var/obj/item/L = locate(D) in usr.Vault
if(L)
L.count += AS
D.count -= AS
if(D.count == 0)
del D
L.suffix = "[L.count]"
else
D.count -= AS
D.suffix = "[D.count]"
usr.Vault += D
for(D in usr.contents)
D.count = AS
if(D.count == 0)
del(D)
flick("Vault close",src)
src.icon_state = "Vault"
if("No")
flick("Vault close",src)
src.icon_state = "Vault"
return
if("Cancel")
flick("Vault close",src)
src.icon_state = "Vault"
return
if("View contents")
var/list/L = list()
for(var/obj/item/O in usr.Vault)
L += O
switch(alert("These are the items in your vault, [L]","Items","Done"))
if("Done")
flick("Vault close",src)
src.icon_state = "Vault"
return


Also, View contents still doesn't work.
In response to Pyro_dragons
I'm not sure but I'll take a stab at it.
var/obj/item/L = locate(W) in usr.contents
if(L)
L.count += AS
W.count -= AS
if(W.count == 0)
usr.Vault -= W
else
W.count -= AS
W.suffix = "[W.count]"
L.suffix = "[L.count]"
usr << "You withdrew [AS] [L]!"
else
var/obj/item/O = W
O.count = AS
O.suffix = "[O.count]"
O.loc = usr
usr << "You withdrew [AS] [O]!"

You are telling it to look for W inside user contents. If it's in there you do if(L) because it equals W, a non-null variable. So you do it and all is well until W.count != 0. You decreased W.count again! Then you didn't tell it to make L.loc = usr.
For else, you make O equal to W. You should make a new W with var/obj/item/O = new/W(usr) where a new W is made and it's called O. It's location is usr.contents. Now you have to decrease W.count and delete it from usr.Vault if it's count becomes zero.
Here's the fixed code:
                var/obj/item/L = locate(W) in usr.contents
if(L)
L.count += AS
W.count -= AS
if(W.count == 0)
del(W)
else
W.suffix = "[W.count]"
L.loc = usr
L.suffix = "[L.count]"
usr << "You withdrew [AS] [L]!""
else
var/obj/item/O = new/W(usr)
O.count = AS
O.suffix = "[O.count]"
usr << "You withdrew [AS] [O]!"


It might work...


Now for View contents,
            if("View contents")
var/list/L = new()
for(var/obj/item/O in usr.Vault)
L += O
switch(alert("These are the items in your vault, [L]","Items","Done"))
if("Done"||"Ok")
flick("Vault close",src)
src.icon_state = "Vault"
del(L)
return

This makes a new list because L is specified as a list. It then deletes L at the end. I also added ||"Ok" in case it always has Ok for a button with alert. If not, just get rid of ||"Ok". In fact if it does have OK, get rid of Done.
In response to SJRDOZER
No, you don't relocate L because if you do, then there will be 2 of the same item in the inventory, which is what item stacking is there to prevent. Anyway, now none of it is working correctly. *sigh* I messed around with depositing a little bit but no luck yet.

mob/var/list/Vault = list("Cancel")

obj/Vault
icon = 'Random.dmi'
icon_state = "Vault"
density = 1
verb/Vault()
set src in view(1)
flick("Vault flick",src)
icon_state = "Vault open"
switch(input("What Shall You Do?","Storage") in list("Withdraw Item","Deposit Item","View contents","Cancel"))
if("Withdraw Item")
var/obj/item/W = input("What do you want to withdraw?","Withdraw Item") in usr.Vault
if(usr.Vault == null)
return
if(W == "Cancel")
flick("Vault close",src)
src.icon_state = "Vault"
return
var/AS = input("You have [W.count] [W]. How many do you wish to deposit?","How many?") as num
if(AS == 0)
flick("Vault close",src)
src.icon_state = "Vault"
return
if(W.count < AS)
usr << "You don't have that many stored!"
flick("Vault close",src)
src.icon_state = "Vault"
return
var/obj/item/L = locate(W) in usr.contents
if(L)
L.count += AS
for(W in usr.Vault)
W.count -= AS
if(W.count == 0)
usr.Vault -= W
else
W.suffix = "[W.count]"
L.suffix = "[L.count]"
usr << "You withdrew [AS] [L]!"
else
var/obj/item/O = W
O.count = AS
O.suffix = "[O.count]"
O.loc = usr
usr << "You withdrew [AS] [O]!"
flick("Vault close",src)
src.icon_state = "Vault"
if("Deposit Item")
if(usr.contents == null)
usr << "You have nothing to deposit!"
flick("Vault close",src)
src.icon_state = "Vault"
return
else
var/obj/item/D = input("What do you want to deposit?","Deposit") in usr.contents
switch(alert("[D] is the item you chose. Are you sure this is what you want to deposit?","Deposit [D]?","Yes","No"))
if("Yes")
var/AS = input("How many would you like to deposit?","How many?") as num
if(AS == 0)
flick("Vault close",src)
src.icon_state = "Vault"
return
if(D.count < AS)
usr << "You don't have that many!"
flick("Vault close",src)
src.icon_state = "Vault"
return
var/obj/item/L = locate(D) in usr.Vault
if(L)
L.count += AS
D.count -= AS
if(D.count == 0)
del D
L.suffix = "[L.count]"
else
D.count -= AS
D.suffix = "[D.count]"
usr.Vault += D
for(D in usr.contents)
D.count = AS
if(D.count == 0)
del(D)
flick("Vault close",src)
src.icon_state = "Vault"
if("No")
flick("Vault close",src)
src.icon_state = "Vault"
return
if("Cancel")
flick("Vault close",src)
src.icon_state = "Vault"
return
if("View contents")
var/list/L = list()
for(var/obj/item/O in usr.Vault)
L += O
switch(alert("These are the items in your vault, [L]","Items","Done"))
if("Done")
flick("Vault close",src)
src.icon_state = "Vault"
return
In response to Pyro_dragons
If W isn't in usr.contents, does that "var/obj/item/O = W" work?
In response to SJRDOZER
Ok, I've fiddled with it some more, and got this runtime here.

Pyrodragon (/mob/player/GM/Admin/Pyro_Dragons): New()
runtime error: Cannot create objects of type /obj/item/Skills_Item/Mining_Hammer.
proc name: Vault (/obj/Vault/verb/Vault)
source file: Turfs.dm,3267
usr: Pyrodragon (/mob/player/GM/Admin/Pyro_Dragons)
src: Vault (/obj/Vault)
call stack:
Vault (/obj/Vault): Vault()

if(L)
L.count += AS
for(W in usr.Vault)
W.count -= AS
if(W.count == 0)
usr.Vault -= W
else
W.suffix = "[W.count]"
L.suffix = "[L.count]"
usr << "You withdrew [AS] [L]!"
else
var/obj/item/O = new W
O.count = AS
O.suffix = "[O.count]"
O.loc = usr
usr << "You withdrew [AS] [O]!"
In response to Pyro_dragons
try
    L = locate(W) in usr.vault // now you know W is only in the vault
L.count = AS
L.suffix = "[L.count]"
new L(usr) // create a new object L(type W) in usr.contents
W.count -= AS
if(!W.count)
del(W)
else
W.suffix = "[W.count]"
usr << "You withdrew [AS] [L]!"