ID:1032849
 
Keywords: eat, food, health, hp, obj
(See the best response by Dj dovis.)
Code:
obj
orange
desc = "Yummy!"
icon = 'Icons.dmi'
icon_state="orange"
verb
eat()
switch(alert("Do you want to eat this orange?",,"Yes","No"))
if("No")
..()
if("Yes")
alert("Yum")
//eats food?


does anybody know how to make the orange delete from my inventory after eating, and how to make it give the player health? thanks

obj
orange
desc = "Yummy!"
icon = 'Icons.dmi'
icon_state="orange"
verb
eat()
switch(alert("Do you want to eat this orange?",,"Yes","No"))
if("No")
..()
if("Yes")
alert("Yum")
for(var/obj/orange/i in inventory)
del(i)

done it, getting this

new.dm:45:error: inventory: undefined var
//well, u have to have ur health declared somewhere.
mob/var/health = 100
obj
orange
desc = "Yummy!"
icon = 'Icons.dmi'
icon_state="orange"
verb
eat()
switch(alert("Do you want to eat this orange?",,"Yes","No"))
if("No")
..()
if("Yes")
alert("Yum");usr.health+=rand(1,5);src.loc = null;
i already have this

mob
var
HP = 10
In response to Forcorrie1996
Forcorrie1996 wrote:
i already have this

mob
var
HP = 10

than all u need is dis D:
obj
orange
desc = "Yummy!"
icon = 'Icons.dmi'
icon_state="orange"
verb
eat()
switch(alert("Do you want to eat this orange?",,"Yes","No"))
if("No")
..()
if("Yes")
alert("Yum");usr.HP+=rand(1,5);src.loc = null;
okay so ive made the HP gain work, but the orange stays in my inventory
^ and yeah sorry i figured it out just after i sent about the HP, sorry about that

 mob
var
hp = 100
obj
orange
desc = "Yummy!"
icon = 'Icons.dmi'
icon_state="orange"
verb
eat(mob/m)
switch(alert("Do you want to eat this orange?",,"Yes","No"))
if("No")
..()
if("Yes")
alert("Yum")
m.hp += 30 //Adds 30 hp to the mob's health.
del(src)


First of all I added an Hp variable to your basic mob.

I edited that last line Phat T's code would delete every orange in your inventory using that for loop, this one will delete only that orange you ate. Also that "inventory" he had should've been m.contents
Nvm! it goes away now, no idea why it didnt before
Best response
zohan has a nice solution but why use ..() in a verb ? ..() is used to call the parent procedure/verb and not to end the process. I think it be better to use return in that verb to end it. Also Phat T id like to point out that its contents and not inventory.

EDIT: lol the amount of responses that were made while I was trying to type this.
..() was from my coding, im new to this and dont really get it all yet haha, thanks for the help, ive also made items equip able, do you know how to make it so only specific objs are? so it doesnt let me equip an orange? haha
well just make a variable which can be either true or false(1 or 0) and check it using an if statement to see if its true or not so that should solve the equiping issue.
could you please explain how i would do that? Like i said before, im a noob :( haha
In response to Forcorrie1996
It's always convenient to separate item functionality through inheritance. This is the most basic example.
//  everything in here can be picked up
obj/item
verb/pick_up()
set src in oview(1)
Move(usr)
usr << "You pick up [src]."

verb/drop()
Move(usr.loc)
usr << "You drop [src]."

// everything in here can be eaten
food
verb/eat()
usr << "You eat [src]."
del src

apple
orange

// everything in here can be worn
gear
var equipped
verb/wear()
if(equipped)
return
equipped = 1
usr << "You put on [src]."

verb/take_off()
if(!equipped)
return
equipped = 0
usr << "You take off [src]."

shirt
pants


/*
Now, we have defined these types:
/obj/item - can be picked up

/obj/item/food - can be eaten
/obj/item/food/orange

/obj/item/gear - can be worn
/obj/item/gear/shirt
/obj/item/gear/pants
*/


By the way, you probably should've made a new topic for this.
so declaring the variable would be like

var/equipable=1//allow to equip the item


then check if its allowed like this.

if(equipable)
//do your equip stuff
else {return}
In response to Phat T
Phat T wrote:
                        for(var/obj/orange/i in inventory)
del(i)


Bad. You don't seem to understand what for() loops are for, and you shouldn't be trying to help out a newbie by showing him code that doesn't make sense.
In response to Zohan98
Zohan98 wrote:
>                         alert("Yum");usr.health+=rand(1,5);src.loc = null;


You really shouldn't be trying to help out newbies by showing them bad programming style. It's also probably best to just delete the object in this case.
In response to Kaiochao
Ill take the liberty of explaining it. The for loop searches through a list and looks for a type specified. It outputs the object found in the list into a variable in this case the variable is i. You can basically do stuff to the object in question. In the example that Phat T wrote the loop searches through some list named inventory(ill assume he meant the contents from now on) and deleted every orange in it. If he wanted to delete only one orange he should have used the break label.

so it should have been like this :
 
for(var/obj/orange/i in contents)
del(i)
break


well im done with this
In response to Dj dovis
It would've been much better (and a lot easier) to delete the specific object that was actually acted upon, which was src.
Page: 1 2