ID:156587
 
Well, for a long time now I've been trying to figure out how to make it so that entering land turfs are restricted when on a boat/ship.
So far I'm totally lost.. Maybe someone can help?

Heres what I have so far




atom/var/obj/boat




Ship
Boat//
icon_state = "1"
IsShip = 1//
DblClick()//
if(get_step_away(src,usr,1))
usr.Frozen=1
usr.client.eye = src
usr.client.perspective = EYE_PERSPECTIVE
usr.loc = locate(1,1,2)
alert("Click here to stop steering")
usr.loc = src.loc
usr.Frozen=0
usr.client.eye = usr
usr.client.perspective = MOB_PERSPECTIVE







client/Move(NewLoc,Dir)
if(src)
if(src.eye != src.mob)
var/Ship/M
for(var/Ship/T in view(0,usr.client))
if(T.IsShip)
M = T
if(!T.IsShip)
..()
step(M,Dir)
return 0

else/
..()e
else
..()

Ship
parent_type = /obj/
icon = 'Boats.dmi'
var/IsShip
density = 1
mob
var
Savedfromboat=0
Savedsomeone=0




Thanks in advance.
You could override the /turf/Enter() proc to disallow movement for things that are boats.
turf
Enter(atom/movable/A)
if(A_is_A_Boat)
return 0 // make it so that boats can't enter turfs by default
else
return ..() // let movement for everything else work normally

water
Enter(atom/movable/A)
if(A_is_A_Boat)
return ..() // let boats enter/move normally into water turfs
else
return 0 // not a boat, can't enter the water


For the "if(A_is_A_Boat)" portion, you need some way to identify that the movable atom in question is, in fact, a boat. It looks like your boats are all a subtype of the /Ship type, so a line like if(istype(A, /Ship)) should work okay.
land
parent_type = /turf


water
parent_type = /turf


Doing it that way will allow you to make turfs just as normal, and shortens the pathway when you search for a certain type of turf.

land
parent_type = /turf


water
parent_type = /turf

atom/var/obj/boat
client
North()
. = ..() //The . operator executes itself at the end of a procedure if the procedure does not return.
//This will make the client/North() and everything else do their default procedure if you don't return.
var/turf/T = locate(mob.x,mob.y+1,mob.z) //Check out the turf to the north of them.
if(istype(T,/land) && mob.boat) //If it is derived from the /land turfs and you are on a boat
return //return
//If not, it does the default action because of . = ..()
//Just do this for the South(), West(), and East() as well. Change where it checks the turf accordingly.
In response to Albro1
And that's an excellent example of how not to do things. Thanks for that.
In response to Garthor
If you point out that something is wrong, could you at least point out a better way? If I do something wrong, I want to learn from it and say "I'll make sure to do that next time.", or something along those lines.

I mean no rudeness from this, and I apologize if I came over that way. I am a rather blunt person, and I often inadvertently offend people.
In response to Albro1
In response to Garthor
Thank you.
In response to Skyspark
Skyspark wrote:
You could override the /turf/Enter() proc to disallow movement for things that are boats.
> turf
> Enter(atom/movable/A)
> if(A_is_A_Boat)
> return 0 // make it so that boats can't enter turfs by default
> else
> return ..() // let movement for everything else work normally
>
> water
> Enter(atom/movable/A)
> if(A_is_A_Boat)
> return ..() // let boats enter/move normally into water turfs
> else
> return 0 // not a boat, can't enter the water
>

For the "if(A_is_A_Boat)" portion, you need some way to identify that the movable atom in question is, in fact, a boat. It looks like your boats are all a subtype of the /Ship type, so a line like if(istype(A, /Ship)) should work okay.








I'm still new at coding unfortunately and I appreciate the help but where do i place if(istype(A, /Ship))