ID:150010
 
Anyone know how I would go about changing the property of a turf when someone enters it, if they have say 10 gold.

This is something I go now, so a bar won't let you inside unless you have 10 gold.


turf
welcome
icon = 'welcome_mat.dmi'
density = 1
Entered(mob/pc/M)
if(M.gold > 9)
density = 0
I see at least two problems with this...

One, the Entered() proc is exactly what it sounds like... it is called (ran) only after someone enters a square. What you're telling the computer is this: "If someone enters a dense square, check their gold. If it's greater than 9, let them in!" That's like saying, "If someone can fly by flapping their arms, give them a jetpack." In other words, by the time the Entered() proc is called, the computer has already made the decision on whether or not the object can occupy that location... any changes to density at this point are meaningless until the next object comes along.

Which brings me to my next point... assuming your method worked, it would not only let in the player with 10 gold, it would let in any other player who came along afterward, wouldn't it? You set the density to 0... but where do you set it back to 1?

Here's how I handle my "variable entry" tiles in most of my games:

turf/water/Enter(O)
if (ismob(O))
var/mob/m = O
if (m.swim)
src.density = 0
. = ..() //calls the default Enter() proc, but holds the result until you're ready to return.
src.density = 1
else
. = ..()
return .


What this does is set the density to 0 only for the purposes of determining whether or not the player can enter the square. As soon as this has been determined, the density is reset to 0.
In response to Lesbian Assassin
Cool thanks alot.. funny I rewrote the gold bit, was actually for a swim skill. And it works great now thanks ;)

LJR