ID:169142
 
I created a battle system, and want to incoörperate a drop system when the monster dies, I have unfortunately been unable to get the monster to drop items from a variable array.
So here i am requesting a sample code for such a system.
Thanks in advance, Oipo
I assume you have the icons and the vars ready, as with the attack proc and monster movement and all that jazz you need

if(monster.health<=0)
del(monster)//i assume you dont let a monster just go to a place to be revived
switch(rand(1,4))
if(1)
usr<<"[monster] drops an item!"
var/obj/items/item1/O=new/obj/items/item1(monster.loc)
if(2)
usr<<"[monster] drops an item!"
var/obj/items/item2/O=new/obj/items/item2(monster.loc)
if(3)
usr<<"[monster] drops an item!"
var/obj/items/item3/O=new/obj/items/item3(monster.loc)
if(4)
usr<<"[monster] had no items."

[Untested]
In response to JKyd
JKyd wrote:
I assume you have the icons and the vars ready, as with the attack proc and monster movement and all that jazz you need

> 
> if(monster.health<=0)
> del(src)//i assume you dont let a monster just go to a place to be revived
> switch(rand(1,4))
> if(1)
> usr<<"[monster] drops an item!"
> new/obj/items/item1(monster.loc)
> if(2)
> usr<<"[monster] drops an item!"
> new/obj/items/item2(monster.loc)
> if(3)
> usr<<"[monster] drops an item!"
> new/obj/items/item3(monster.loc)
> if(4)
> usr<<"[monster] had no items."

[Untested]

If you plan on using that, check into prob() and pick().
In response to Sinoflife
No thanks guys...Those two are way to much coding for me...I already fixed it by dropping a item randomly from an array...Thanks anyways though
In response to Oipo
Wouldn't deleting the monster stop the script, thus canceling out everything after that?
In response to Flame Sage
It depends on what you do.
In response to Flame Sage
Flame Sage wrote:
Wouldn't deleting the monster stop the script, thus canceling out everything after that?

Yes, and it would work if he put del(src) after the end of each if() statement.
In response to Sinoflife
I always thought when you called del() it would stop the current proc from executing......
In response to Flame Sage
Flame Sage wrote:
Wouldn't deleting the monster stop the script, thus canceling out everything after that?

No it wouldn't instead you'd get a runtime error for an undefined variable.Then the script would crash.
In response to Sinoflife
=/
No.
Try this:
mob/proc/asdf()
world<<"I feel like deleting myself."
var/mob/m=src
src=null
del(m)
world<<"The proc lives on, even after deletion."

Also, you wouldn't have to add one after every if, and you shouldn't even have tons of if statements for a drop procedure!
monster
proc/drop()
for(var/a in drops)
if(prob(drops[a]))
new a (loc)
break
del(src)
garthor
drops=list(/item/sarcasm=75,/item/funny=100,/item/forumbanned=100)