ID:149606
 
If anyone knows how i can make this turf code attack mobs when they walk on it unless they have a certain object.


turf/security_system
icon = 'security.dmi'

turf/security_system
proc/shock(mob/m)

Entered(atom/movable/m)
shock(m)
var/damage = 5



please help me fix this code!!!


here is a good code that you would like
turf
Hurtspot
Enter()
if(usr.whateve var you want here>=1)
var/damage=5
usr.HP-=damage.
else
usr<<""
return ..()
Now when the character picks up the object that makes it so he gets hurt on the turf give him a var and make sure it goes in the if(usr.whateve var you want here>=1)
part
if you still need help just ask
i hope this helps



~Richter
In response to Richter
Gads. Don't post in reply to a topic like this unless you can actually help; if you don't know what you're doing, then it's a case of the blind leading the blind. Or in this case, the blind leading the slightly disoriented, since your code is actually considerably worse than the code that was posted by Nobody--his was pretty close to what he needs, except for the key check. And your method of key checking is, as I explaiend in response to your post in Newbie Central last night, very very bad.

Enter() is absolutely the wrong thing to be using here (Entered() is correct), and usr is absolutely the wrong var to use in it, since the proc is given a reference to the obj or mob that's entering.
Again, the remedial version:
Enter(atom/movable/A)
Returns 1 if A is allowed to enter this turf, 0 if it is not.

Entered(atom/movable/A,atom/oldloc)
Called when A enters the turf via the Move() proc (which is also used for normal walking).
Although I said those apply to a turf, it really works for any atom you try to Move() things into. Entered() is what you should be using for almost all of these situations, not Enter() which does a completely different thing.

Lummox JR
Nobody wrote:
If anyone knows how i can make this turf code attack mobs when they walk on it unless they have a certain object.


turf/security_system
icon = 'security.dmi'

turf/security_system
proc/shock(mob/m)

Entered(atom/movable/m)
shock(m)
var/damage = 5

Well, you're pretty close here. Ther's a slight indent problem, but we can take care of that.
What you basically need is something like this:
obj/key
var/keycode

turf/security_system
icon='security.dmi'
var/hitdamage=5 // the damage done when it goes off
var/keycode // the keycode needed to bypass it

Entered(atom/movable/m)
if(ismob(m)) // you probably don't want an obj to trigger it
var/obj/key/thekey
for(thekey in m)
if(thekey.keycode==src.keycode) break
if(!thekey)
m << "You triggered the security system!"
oview(m) << "[m.name] triggers the security system!"
m.Hurt(hitdamage) // Hurt() would be whatever proc deals out damage

That ought to be enough to get you started, if you want to make it more complex than that.

Lummox JR
In response to Lummox JR
thank you Lummox JR I have been trying to get a code for that and you are the only person that actually knows how to make those
In response to Nobody
Nobody wrote:
thank you Lummox JR I have been trying to get a code for that and you are the only person that actually knows how to make those

That's not true -- lots of us know how. It's just a matter of how arrogant, stuck-up, or rude some of us are. ;-)
In response to Spuzzum
Spuzzum wrote:
Nobody wrote:
thank you Lummox JR I have been trying to get a code for that and you are the only person that actually knows how to make those

That's not true -- lots of us know how. It's just a matter of how arrogant, stuck-up, or rude some of us are. ;-)

Hey don't forget those of us lurking, too busy, or too late. ;)