ID:168036
 
turf
water2
icon = 'turf.dmi'
icon_state = "water"
Entered()
if(usr.fly ==0)
usr.icon_state = "swim"
usr.swim = 1
var/gain = rand(1,20)
if(gain == 20)
usr.exp += 30
else
..()
if(usr.fly ==1)
..()


How would i make it so only clients (players) can enter? I tryed to do it how i thought i would be done, but it didnt work! How would I do this? Possibly, the water should have a density of 1?, and then when you bump it it sets that to 0 only if your a client? and then when u leave it, it resets it to density = 1?
Entered(mob/M)
if(istype(mob/M/player)
if(usr.fly ==0)
usr.icon_state = "swim"
usr.swim = 1
var/gain = rand(1,20)
if(gain == 20)
usr.exp += 30
else
..()
if(usr.fly ==1)
..()
else
return




Change the mob(the players) to mob/player in the login.



In response to Sharingan_User
That would not work, due to the fact that, player is not defined.

~Xz
In response to Xziaon
Ya thats why i said change the mob to mob/player in the login.

mob/player
base
icon='Icon.dmi'

mob/Login()
usr.icon= /mob/player/base
You should never use usr in a proc, especially one like Entered(), since it can be anything. usr isn't always the player that enters it, but could be the player that tells the object to enter. That is why you should rely on the argument for Entered() for the accurate enterer.

The way that you can only let real players enter is to check if they have a client controlling it. You can considerably shorten your code by checking one variable, then using else. You also can take off the "== 1" or "== 0", since if it is a boolean value (one with 1 or 0), you wouldn't need those.

turf/water2
Enter(mob/M)
if(ismob(M) && M.client) // check if they have a client
if(!M.fly) // if they aren't flying, make them swim
M.icon_state = "swim"
M.swim = 1
if(rand(1,20) == 20) // no need for the temporary variable if you only use it once
M.exp += 30
return ..() // allow the player to go in
return 0


~~> Unknown Person
In response to Sharingan_User
Sharingan, don't give bad advice.. Don't put usr in procs

At topicstarter, in Entered() and whatnot, use src instead of usr. Also, if(usr.flying==0) ..() means if the usr (should be src) is NOT flying ((src.flying==0) should just be (!src.flying)), then do the usual. Aka, enter the turf. I hope this is what you're looking for? If you don't want it to enter when flying, use return 0 instead of ..().
In response to Unknown Person
woops i missed that. >.<. I've only been coding for 2 weeks lol, but trying to help people is nice.
In response to Mysame
Now, your giving bad advice, the src would be the turf.

~Xz
In response to Unknown Person
the return 0 came up with an error

loading Nexus.dme
Turfs.dm:398:error::missing expression

Nexus.dmb - 1 error, 0 warnings (double-click on an error to jump to it)
In response to Xziaon
Xziaon wrote:
the return 0 came up with an error

It shouldn't have, unless you made an error somewhere near it, or you mistyped my example. It compiles fine for me.

~~> Unknown Person
In response to Unknown Person
What does return 0 do exactly? Shouldnt it be under an else? (else indicating a mob that is not "if(ismob(M) && M.client)."

~Xz
In response to Xziaon
In Enter(), return 0 denies the enterer to go to its contents (a turf's contents is basically on it). So if you do return 0, it will never allow anything to go through it. You do not need an else there because return stops the proc, making else unneccesary.

~~> Unknown Person
In response to Unknown Person
I got errors with it though, why?

~Xz
In response to Xziaon
I figured out why I had an error, so i fixed it. It should do what your speaking of, but it doesnt..It is still letting npcs enter the water.