ID:155460
 
hi all. My weight check proc is not working for some reason.

    proc/object_check() //This will check if the object will fit inside players back pack. 
if(src.obj_weight + usr.inv_weight > usr.inv_max)
usr << "Doesn't fit inside your back pack"
return

else
src.loc = usr
src.obj_weight += usr.inv_weight
usr << "picked up [src]"


Even if the object is too heavy, it tells me "Doesnt fit inside your back pack" but it still ends up in my inventory.
Please help me.
Just a question, why are you increasing the object weight with the usr's inv_weight?
A weight check shouldn't actually inform the player of anything or move around items, it should only check to see if the weight is fine. It also looks like you're adding the weight to the wrong atom. Also, try to avoid the use of usr.

obj/item/proc
checkWeight(mob/M)
if(obj_weight + M.inv_weight <= M.inv_max)return 1
else return 0

Pickup(mob/M)
if(checkWeight(M))
M.contents += src
M.inv_weight += obj_weight
M << "You picked up [src]."
In response to Raimo
^ this
In response to Kenpachi12
Thanks. sorry was being a bit stupid.