ID:149497
 
ok lets say you have arrows and when you drop them you want to be able to drop an amount and it creates a new object with that amount.
obj
projectiles
arrows
icon = 'weapons.dmi'
icon_state = "arrows"
var/amount = 5
verb/Get()
set src in oview(1)
usr.arrows += src.amount
usr << "You got [src.amount] arrows!"
del(src)
so each packof arrows is defined with an amount
[edit: ACK! My previous was frighteningly faulty, this should be a bit better...]

mob
verb/DropArrows(amount as num) // Verb on the player to drop arrows.
if(amount < 1) // 0 or less is impossible
usr << "You cannot drop [amount] arrows!"
else if(usr.arrows < amount) // you don't have that many...
usr << "You don't have [amount] arrows!"
else // ok to drop.
var/obj/projectiles/arrows/A = new(usr.loc) // Create an arrow object at the users feet.
A.amount = amount // Apply the amount of arrows to the object.
usr.arrows -= amount
I really shouldnt be helping, because im so tired, but i would suggest doing something like this:
mob
verb
Drop_Arrows(amount as num)
usr.arrows -= amount
var/obj/arrows/A = new()
A.amount = amount


Please, someone else help if you see any big things wrong here...ZzzzZzzzz....hmm? *stutters* erm, uh, beh.. I wasnt asleep.. I was doing the uhh... Zilal mating call? :P

-Rcet
Mrhat99au wrote:
ok lets say you have arrows and when you drop them you want to be able to drop an amount and it creates a new object with that amount.

I'd go for a semi-simple counting sytem:
obj
var/count=1
var/countable=0
var/pluralname

New()
..()
if(countable) SetCount(count)

proc/GetPluralName()
if(pluralname) return pluralname
return initial(name)+"s"

proc/SetCount(n)
if(!n) del(src)
count=n
if(n!=1)
gender="plural"
name=GetPluralName()
else
gender=initial(gender)
name=initial(name)

proc/CreateCopy(atom/newloc,n)
var/obj/item/I=new type(newloc)
I.SetCount(n)
return I // EDIT: I forgot this line

proc/IsIdentical(item)
return 1

obj/item
verb/Get(n as null|num)
set src in oview(1)
if(countable)
if(n==null) n=count
else n=max(min(n,count),0)
if(n==1) usr << "You pick up \a [initial(name)]."
else usr << "You pick up [n] [GetPluralName()]."
for(var/obj/item/I in usr.contents)
if(I.type==type && IsIdentical(I))
I.SetCount(I.count+n)
SetCount(count-n)
else usr << "You pick up \a [src]."
loc=usr
verb/Drop(n as null|num)
set src in usr
if(countable)
if(n==null) n=count
else n=max(min(n,count),0)
if(n==1) usr << "You drop \a [initial(name)]."
else usr << "You drop [n] [GetPluralName()]."
if(n<count)
var/obj/item/I=CreateCopy(usr.loc,n)
SetCount(count-n)
return
else usr << "You drop \a [src]."
loc=usr.loc

There are a few things to be wary of here: I'm not sure if "as null|num" will work right for a verb argument. If it does, then you can say "Drop arrows 5" and it will drop 5 arrows. You'd set up an arrow like this:
obj/item/arrow
name="arrow"
countable=1
var/arrowtype
CreateCopy(l,n)
var/obj/item/arrow/A=..()
A.arrowtype=arrowtype
return 1
IsIdentical(obj/item/arrow/A)
return(A.arrowtype==arrowtype)

This is the simplest system I could think up on short notice.

Lummox JR
In response to Lummox JR
var/obj/item/arrow/A=..()

I've never seen that before, what exactly does that do? I'd guess it would assign whatever is returned by the parent proc to A but there is no return statement in the parent proc and I thought procs returned null by default.
In response to English
English wrote:
var/obj/item/arrow/A=..()

I've never seen that before, what exactly does that do? I'd guess it would assign whatever is returned by the parent proc to A but there is no return statement in the parent proc and I thought procs returned null by default.

Whoops! I forgot the return statement. I've edited the post to include it.

Lummox JR