ID:264285
 
Code:
#define isWhole(number) (number==round(number,1))
obj/Weaponry
Knife
icon = 'Knife.dmi'
Price = 500
var/Material
Bump(atom/A)
var/mob/O = Owner
if(ismob(A))
var/mob/M = A
var/dmg = round(O.NeedleSkill + O.Taijutsu)
switch(Material)
if("Bronze") dmg*=1
if("Iron") dmg*=1.5
if("Steel") dmg*=2
M.Health -= dmg
view(M)<<"[M] was hit by \a [src] for [dmg]"
O.NeedleEXP += M.Level
O.NeedleLvlUp()
M.Death(O)
if(istype(A,/obj/Training/Training_Log))
var/rndm = rand(20,30)
O.NeedleEXP += rndm
O.NeedleLvlUp()
O<<output("<font size=1>You gained [rndm] Needle experience","Crap")
del(src)
New()
src.name = "[src.Material] Knife"
src.suffix = "([Amount])"
..()
Bronze
Material = "Bronze"
Amount = 5
Iron
Material = "Iron"
Amount = 5
Steel
Material = "Steel"
Amount = 5
verb
Drop()
for(var/obj/Weaponry/Needle/K in usr.contents)
if(!src.Amount)
del(src)
var/drop = input("How many do you want to drop?\n- You have [src.Amount] [src]\s","Drop") as num|null
if(drop > src.Amount || !isWhole(drop) || drop <= 0) return
src.Amount -= abs(drop)
src.suffix = "([src.Amount])"
var/obj/Weaponry/Needle/D = new(usr.loc)
D.Amount = drop
if(!src.Amount) del(src)
usr.AutoSave()


Problem description:
Okay I have the weapon in my inventory. When I right click it and select Drop, nothing happens but the AutoSave() proc. Any reason for this? It worked before, now it just stopped working.
Should this be /obj/Weaponry/Knife/K?

for(var/obj/Weaponry/Needle/K in usr.contents)
In response to Jp
Yeah sorry. Mistype. Still won't work.
//Yadda
verb
Drop()
for(var/obj/Weaponry/Knife/K in usr.contents)
if(!K.Amount) del(K)
else
var/drop = input("How many do you want to drop?\n- You have [src.Amount] [src]\s","Drop") as num|null
if(drop > src.Amount || !isWhole(drop) || drop <= 0) return
src.Amount -= abs(drop)
src.suffix = "([src.Amount])"
var/obj/Weaponry/Knife/D = new(usr.loc)
D.Amount = drop
if(!K.Amount) del(K)
usr.AutoSave()
In response to Mizukouken Ketsu
Mizukouken Ketsu wrote:

Did you consider applying debug messages?
It's a great case for them to prove useful!

                for(var/obj/Weaponry/Knife/K in usr.contents)
if(!K.Amount) del(K)
else
//(...)
usr.AutoSave()


You're either not entering the for loop, or you don't get to the else statement, so set up a little message within the for loop and one inside the if clause and you'll be one step further ;)
Why are you still using that for() loop? Your whole input() part is looping, and is also depending on the if() statement. That's improper. Remove the loop and just use src
In response to Kaioken
Not 100% sure what you meant by only using src, but I think that's it (or at least close to it). I tested it, and same problem persists :\
//Yadda
verb
Drop()
if(!src.Amount) del(src)
else if(src.Amount)
var/drop = input("How many do you want to drop?\n- You have [src.Amount] [src]\s","Drop") as num|null
if(drop > src.Amount || !isWhole(drop) || drop <= 0) return
src.Amount -= abs(drop)
src.suffix = "([src.Amount])"
var/obj/Weaponry/Knife/D = new(usr.loc)
D.Amount = drop
if(!src.Amount) del(src)
usr.AutoSave()
In response to Mizukouken Ketsu
Apparently it's supposed to work, but you don't need the 'else if' anyway. Not only you shouldn't need to check the same condition twice, but del src effectively stops the proc similarly to returning, so an else check afterwards is superfluous.
Also, mind you've allowed the player to choose 'cancel' with the input(), which will return null, likely passing your current checking methods.
In response to Kaioken
It's still skipping everything except the AutoSave() proc.

//Yadda
verb
Drop()
if(!src.Amount) del(src)
var/drop = input("How many do you want to drop?\n- You have [src.Amount] [src]\s","Drop") as num
if(drop > src.Amount || !isWhole(drop) || drop <= 0) return
src.Amount -= abs(drop)
src.suffix = "([src.Amount])"
var/obj/Weaponry/Knife/D = new(usr.loc)
D.Amount = drop
if(!src.Amount) del(src)
usr.AutoSave()
In response to Mizukouken Ketsu
So you're not even getting the input() window? That's, honestly, quite strange. I assume amount isn't 0, null, or ""?
In response to Mizukouken Ketsu
Hm, it is weird. Meh, try removing the if() check to see if the condition is really [not] satisfied. Maybe AutoSave() is really just called... automatically.

If it still doesn't work after that, while it normally shouldn't make a difference, try sticking input()'s first argument explicitly, to target the player usr.
In response to Jp
Nope. The amount is not false/null.
In response to Kaioken
Still won't happen :\

        verb
Drop()
//if(!src.Amount) del(src)
var/drop = input(usr,"How many do you want to drop?\n- You have [src.Amount] [src]\s","Drop") as num
//if(drop > src.Amount || !isWhole(drop) || drop <= 0) return
src.Amount -= abs(drop)
src.suffix = "([src.Amount])"
var/obj/Weaponry/Knife/D = new(usr.loc)
D.Amount = drop
//if(!src.Amount) del(src)
usr.AutoSave()
In response to Mizukouken Ketsu
What about if you do-
verb
Drop()
world << "[src],[usr]"

Make sure the verb is really executing.. perhaps some other Drop() is?
In response to Kaioken
How's that possible when I'm right clicking the object in my contents xD
In response to Kaioken
Nevermind I fixed it. An error elsewhere caused it to not execute the verb correctly.
In response to Mizukouken Ketsu
mob/New()
contents+=new/obj/blargh()

obj/blargh/verb/Test()
set src in usr
usr << "This is a blargh tet"

obj/verb/Test()
set src in usr
usr << "This is a test"


Try it.
In response to Mizukouken Ketsu
If you want to get into the semantics of whether it is technically possible, then it is. =P What I'm not sure about is how come that input() isn't executed when you click the verb. Even if I copy and paste it to a test project, it works for me (as far as the input() is concerned at least), as expected. Does a debug message appear?
Might be worth posting the full node path of the verb (for example, /obj/myitem/verb/MyVerb), and checking if you have another Drop() anywhere. Might.

EDIT: Ah, you fixed it. >_>
Not enlightening us on what it was, though? :P
In response to Kaioken
Problem solved. An error elsewhere prevented the verb from being executed properly.
In response to Jp
(This won't compile because of a duplicate definition error, but your example is good if you change obj/verb/Test() to mob/verb/Test())
In response to Kaioken
Not quite. I'm going for lack-of-default-proc-screwing-up-inheritance here.

But yes, that'll probably give you a duplicate definition error. This won't:

mob/New()
contents+=new/obj/blargh()

obj/blargh/Test()
set src in usr
usr << "This is a blargh tet"

obj/verb/Test()
set src in usr
usr << "This is a test"