[request] Teleport to certain location

Results 1 to 8 of 8
  1. #1
    Enthusiast 444k is offline
    MemberRank
    Feb 2008 Join Date
    SeattleLocation
    26Posts

    [request] Teleport to certain location

    I was wondering if someone could help me out with this, as I'm new to C++ and coming from a Pawno based background I'm adapting slowly to it.

    I was wondering if anyone could help me with a quick command that would teleport you somewhere if you're at a location.

    GigaToni helped me out a lot with detecting if a player is in range of a position, just can't figure out the teleport function, getting a lot of errors in what I've done so far.

    Quote Originally Posted by GigaToni View Post
    Look in the server at ZombieSpawn it detects if the is in range


    EDIT:
    Here it is:


    ServerGameLogic.cpp Line ~1191:


    pos is your position
    plr->GetPosition() is obviously the player pos
    and distSq is the max distance squared (x²)
    Say I'm at
    1090.5113.1
    1604.9

    & I want to get teleported to

    932.8
    135.8
    170.9

    Thanks in advance if someone helps <3


  2. #2
    Apprentice WarZReborn is offline
    MemberRank
    Aug 2014 Join Date
    9Posts

    Re: [request] Teleport to certain location

    /tp 932.8 170.9

  3. #3
    Custom Title Enabled GigaToni is offline
    MemberRank
    Aug 2009 Join Date
    GER / FRLocation
    2,329Posts

    Re: [request] Teleport to certain location

    Code:
    PKT_S2C_MoveTeleport_s n;
    n.teleport_pos = pos;
    p2pBroadcastToActive(plr, &n, sizeof(n));
    plr->SetLatePacketsBarrier("teleport");
    plr->TeleportPlayer(pos);
    r3dOutToLog("%s teleported to %f, %f, %f\n", plr->userName, pos.x, pos.y, pos.z);
    Last edited by GigaToni; 10-09-14 at 11:09 AM.

  4. #4
    Enthusiast 444k is offline
    MemberRank
    Feb 2008 Join Date
    SeattleLocation
    26Posts

    Re: [request] Teleport to certain location

    Ahh see I started there but I don't necessarily know how to define pos or much of the rest. I'm trying to learn what most of this stuff does under obj_serverplayer but I'm not having luck with it.

    I can't figure out how the detect function works either. I'm getting frustrated, I've been working on this for 3 days now trying to get this working.

  5. #5
    Custom Title Enabled GigaToni is offline
    MemberRank
    Aug 2009 Join Date
    GER / FRLocation
    2,329Posts

    Re: [request] Teleport to certain location

    You can define pos as:

    (I think. Didn't worked with the code for over 2 months)

    r3dPoint3D pos = r3dPoint3D(X, Y, Z);

  6. #6
    Enthusiast 444k is offline
    MemberRank
    Feb 2008 Join Date
    SeattleLocation
    26Posts

    Re: [request] Teleport to certain location

    So I headed that direction and found something similar, was messing with
    Code:
    r3dPoint3D pos = AdjustPositionToFloor(r3dPoint3D(x, 0, z));
    I think I'm having more of an issue to define if((plr->GetPosition() - pos).LengthSq() < DistSq) though and getting the pos to work.

    I'm trying to make a way to just you can teleport from one point on the map to the other, I never knew there'd be so many things behind it haha it's so simple in pawno with SAMP.

  7. #7
    Custom Title Enabled GigaToni is offline
    MemberRank
    Aug 2009 Join Date
    GER / FRLocation
    2,329Posts

    Re: [request] Teleport to certain location

    Something like this should work.


    Code:
    float distance = 20.0f;
    float DistSq = distance * distance;
    r3dPoint3D pos = r3dPoint3D(X, Y, Z);
    r3dPoint3D pos2 = r3dPoint3D(X2, Y2, Z2);
    
    if((plr->GetPosition() - pos).LengthSq() < DistSq)
    {
       PKT_S2C_MoveTeleport_s n;
       n.teleport_pos = pos2;
       p2pBroadcastToActive(plr, &n, sizeof(n));
       plr->SetLatePacketsBarrier("teleport");
       plr->TeleportPlayer(pos2);
    }
    If player is in a "distance" (or rather 20.0f) units range of X, Y, Z (or rather pos) he gets teleported to X2, Y2, Z2 (or rather pos2)

  8. #8
    Enthusiast 444k is offline
    MemberRank
    Feb 2008 Join Date
    SeattleLocation
    26Posts

    Re: [request] Teleport to certain location

    Quote Originally Posted by GigaToni View Post
    Something like this should work.


    Code:
    float distance = 20.0f;
    float DistSq = distance * distance;
    r3dPoint3D pos = r3dPoint3D(X, Y, Z);
    r3dPoint3D pos2 = r3dPoint3D(X2, Y2, Z2);
    
    if((plr->GetPosition() - pos).LengthSq() < DistSq)
    {
       PKT_S2C_MoveTeleport_s n;
       n.teleport_pos = pos2;
       p2pBroadcastToActive(plr, &n, sizeof(n));
       plr->SetLatePacketsBarrier("teleport");
       plr->TeleportPlayer(pos2);
    }
    If player is in a "distance" (or rather 20.0f) units range of X, Y, Z (or rather pos) he gets teleported to X2, Y2, Z2 (or rather pos2)

    If you had any idea how much I loved you right now, like seriously thank you so much. You're the best.



Advertisement