ID:180142
 
Isn't there any way to have something happen to an item when the item enters a mob, besides having every mob check every item that enters it to see if that item matches a certain item which you want to change? There has to be a simpler way to do this...
Foomer wrote:
Isn't there any way to have something happen to an item when the item enters a mob, besides having every mob check every item that enters it to see if that item matches a certain item which you want to change? There has to be a simpler way to do this...

Not sure how you're doing it without seeing some of your code. Are you saying you have a mob/Entered() proc which checks the type of the obj that entered it and does something based on that? Like:

mob/Entered(obj/O)
if (istype(O, /obj/apple))
// do something for apples
else if (istype(O, /obj/stinkbomb))
// make it stinky

and so on?

If so, one approach to simplify this would be to make an obj proc called EnteredMob(). Call it from mob/Entered() and put specific stuff in each obj's EnteredMob() proc. Like this:

obj
proc/EnteredMob() // do nothing by default

apple
EnteredMob()
// do apple stuff

stinkbomb
EnteredMob()
var/mob/m = src.loc // the mob we just entered
m.stinky = TRUE

mob
Entered(obj/O)
O.EnteredMob()


Of course, maybe I misunderstood you and all of this is totally useless.
In response to Air Mapster (#1)
Hmm, that sounds like it's exactly what I was looking for, even though I wasn't honestly expecting a responce to that. :oP Looks good to me!
In response to Air Mapster (#1)
Air Mapster wrote:
Foomer wrote:
Isn't there any way to have something happen to an item when the item enters a mob, besides having every mob check every item that enters it to see if that item matches a certain item which you want to change? There has to be a simpler way to do this...

Not sure how you're doing it without seeing some of your code. Are you saying you have a mob/Entered() proc which checks the type of the obj that entered it and does something based on that? Like:

mob/Entered(obj/O)
if (istype(O, /obj/apple))
// do something for apples
else if (istype(O, /obj/stinkbomb))
// make it stinky

and so on?

If so, one approach to simplify this would be to make an obj proc called EnteredMob(). Call it from mob/Entered() and put specific stuff in each obj's EnteredMob() proc. Like this:

obj
proc/EnteredMob() // do nothing by default

apple
EnteredMob()
// do apple stuff

stinkbomb
EnteredMob()
var/mob/m = src.loc // the mob we just entered
m.stinky = TRUE

mob
Entered(obj/O)
O.EnteredMob()


Of course, maybe I misunderstood you and all of this is totally useless.

That's a great idea... and it helps me solve a few of my own problems, too. It's amazing how handy a technique "inverted procs" can be (like making a Bumped proc, called from Bump).