ID:176613
 
Im helping make a paintball game. I just need to know the answer to this question. Theres an object called a Nitro Tank which powers paintballs and is required to be supplied in order to fire a projectile. In this case. The object Nitro supplies "air".

mob/var/air = 0

How would i write a code that gives 100 air points when a nitro tank is equipped?
<code>obj/nitro/verb/equip() set src in usr usr.air+=100</code>
RainZero wrote:
Im helping make a paintball game. I just need to know the answer to this question. Theres an object called a Nitro Tank which powers paintballs and is required to be supplied in order to fire a projectile. In this case. The object Nitro supplies "air".

mob/var/air = 0

How would i write a code that gives 100 air points when a nitro tank is equipped?

I'd recommend something similar to Crispy's example, but slightly more complete. Instead of using equip/unequip, I'll make a leap here and assume that you just want to use the tank automatically if you have it in your inventory.
obj/item/nitro
name="nitro tank"
var/air
var/capacity=100

New()
air=capacity
suffix="([air] ml: full)"

// assume obj/item has Get() and Drop() verbs
Get()
..()
usr.air+=air

Drop()
..()
usr.air-=air

// return amount used
// automatically deplete other tanks
proc/Use(amount)
.=min(amount,air)
air-=.
amount-=.
var/mob/M=loc
M.air-=. // deplete mob's air by total used
if(!air) suffix="(empty)"
else suffix="([air] ml - [round(air/capacity*100)]% full)"
if(amount) // use more if possible
var/obj/item/nitro/N=FindNext()
if(N) .+=N.Use(amount) // this is recursive, but basically safe

proc/FindNext()
var/obj/item/nitro/chosen
var/obj/item/nitro/N
for(N in loc)
if(N==src || !N.air) continue // skip empties
if(!chosen || chosen.air<N.air)
chosen=N // choose the lowest
return chosen

// return amount of air actually added
proc/Refill(amount)
.=min(capacity-air,amount)
air+=.
amount-=.
var/mob/M=loc
M.air+=.
if(air==capacity) suffix="([air] ml - full)"
else suffix="([air] ml - [round(air/capacity*100)]% full)"
if(amount) // use more if possible
var/obj/item/nitro/N=FindNextEmpty()
if(N) .+=N.Refill(amount) // this is recursive, but basically safe

// for refills
proc/FindNextEmpty()
var/obj/item/nitro/chosen
var/obj/item/nitro/N
for(N in loc)
if(N==src || N.air>=N.capacity) continue // skip full
if(!chosen || chosen.capacity-chosen.air<N.capacity-N.air)
chosen=N // choose the fullest
return chosen
The system I've presented here will deplete the lowest tanks first; ideally this means you'll use one at a time. I threw in the capacity var so that you can use larger or smaller tanks in the game if you want.

Lummox JR
In response to Lummox JR
Or you could have lots of different sized tanks.
In response to Hazman
I think that's what he meant... :-)