ID:165219
 
I need to make a person able to enter a portal to go to a mob he had selected before this is what I came up with.

mob
var
Tele_X
Tele_Y
Tele_Z

obj/Portal
icon = 'powers.dmi'
icon_state = "portal"
Enter()
usr.loc = locate(usr.Tele_X,usr.Tele_Y,usr.Tele_Z)





mob/verb/Make_Portal(mob/m in world)
var/obj/M = new /obj/Portal/
usr.Tele_X = m.x
usr.Tele_Y = m.y
usr.Tele_Z = m.z
M.loc = locate(usr.x,usr.y+1,usr.z)


Its not working as you can see.
First off, You have usr in enter(). That's a no-no.
In response to XzDoG
thats not really helpfull
In response to Miran94
Miran94 wrote:
thats not really helpfull

Yes it is.
In response to XzDoG
XzDoG wrote:
Miran94 wrote:
thats not really helpfull

Yes it is.

No, it's not, explain to him why it's a No-no, don't just state that it's one, it needs a backup on why it is.
There are multiple problems with your code.

  • No put usr in proc. Ungh.
  • You shouldn't be using Enter() at all here, but Entered() instead.
  • You need to modify turf's Entered() proc, since the obj's Entered() will never be called unless you Move() directly into the object itself.
  • The Tele_X/Y/Z vars should belong to the portal, not the mob that will be using it.

    Lummox JR
In response to Lummox JR
The reason usr is bad in procs is because, usr is the client who does the action. If an obj Entered and you used usr you would get a null usr error, since obj have no usr. The only time you should ever use usr is in something that uses the mouse, where usr != src, and usr is a verb. You also should use usr in set src. If thats not the case you should use src or an argument.
// proper usr example
atom
Click()
usr<<"You have clicked [src]"
// bad usr example
atom
Entered()
usr<<"blah blah"


http://bwicki.byond.com/ByondBwicki.dmb?WhenToUseusr

Made a bwiki page if anyones wants to edit
In response to Xx Dark Wizard xX
mob/verb/Make_Portal(mob/m in world)
var/obj/T = new /obj/Portal/
T.travel = m.loc
T.loc = locate(usr.x,usr.y+1,usr.z)



obj/Portal
icon = 'powers.dmi'
icon_state = "portal"
Entered(mob/M)
if(ismob(M)
M.Teleport(src.travel)


mob/proc
Teleport(travel)
var/mob/M = src
var/obj/Portal/P = locate("[travel]")
M.Move(locate(P.x,P.y-1,P.z))


Thats what I figured out but its still not working.
In response to Miran94
The mob is not entering the obj, it is entering the turf that the obj is in. http://bwicki.byond.com/ByondBwicki.dmb?TriggeredObjs may help.
In response to Shadowdarke
turf/var/weretoy = 0
turf/var/weretox = 0
turf/var/weretoz = 0

mob/verb/Portal(mob/who in world)
set category = "Skills"
var/turf/T = new/turf/Portal(usr.loc)
usr << "You Have Created A Portal!"
T.weretoy = who:y
T.weretox = who:x
T.weretoz = who:z


turf/Portal
icon = 'turfs.dmi'
icon_state = "portal"
Entered(O)
var/mob/m = O
m.loc = locate(src.weretoy,src.weretox,src.weretoz)


It works but it makes the screen blank and I dont see if I teleported or not.
In response to Miran94
You've got x and y in the wrong order. And, no abuse : operator. Ungh.

Lummox JR
In response to Lummox JR
thank you it works
In response to Miran94
You should really get used to not using the : operator. The only place it belongs is in a 4k challenge where you don't have room to typecast.
In response to Xx Dark Wizard xX
(Or when you 'have no speed to lose' to typecasting :P)
In response to Xx Dark Wizard xX
But there is a black thing that shows up behind it once it works and when it gets deleted it deletes the turf it was on wat can I do?
In response to Miran94
Make a proc to make a teleporter, thats atleast how my game does it. I store a global list of all the teleports. When a teleport is created it adds its location and warp location to the list.
obj
teleporter
var/warpto
New(location, mob/creator)
if(creator && ismob(creator))
creator.SetTeleport()
Entered(O)
if(ismob(O))
var/mob/M = O
if(M.client)
M.loc = locate(src.warpto)
obj/teleporter/proc
SetTeleport()
var/_x = input("")as num
var/_y = input("")as num
var/_z = input("")as num
var/obj/teleporter/O = new obj/teleporter(src.loc,src)
O.warpto = (_x,_y,_z)

That is just an example. Don't expect to plug it into your game and it will magically work.
In response to Miran94
Since there can be only one turf on a single tile.
In response to Xx Dark Wizard xX
Xx Dark Wizard xX wrote:
That is just an example. Don't expect to plug it into your game and it will magically work.

Heck, it won't work in any game. We already covered this same problem on this thread, where Miran learned that you can't expected Entered() to be called for an obj like that. The player is entering a turf, not the obj.

However, I do think it's not a bad idea to make the teleporter an obj. The trick is, the turf it's on has to look for it.

obj/teleporter
var/farx, fary, farz

turf
Entered(atom/movable/A)
if(ismob(A))
var/obj/teleporter/T = locate() in src
if(O)
A.loc = locate(T.farx, T.fary, T.farz)


Lummox JR
In response to Lummox JR
Ok it works but it causes alot of erors when I run it.
obj
var
farx
fary
farz

mob/verb/Tele(mob/M in world)
var/obj/S = new /obj/teleporter(src.loc)
S.farx = M.x
S.fary = M.y
S.farz = M.z




obj/teleporter
icon = 'powers.dmi'
icon_state = "portal"


turf
Entered(atom/movable/A)
if(ismob(A))
var/obj/teleporter/T = locate() in src
A.loc = locate(T.farx, T.fary, T.farz)
In response to Lummox JR
Yes. That approach is basically the same as having a Trigger() proc, but the latter is better especially if you happen to have lots of objects requiring that functionality.
Page: 1 2