SA-MP Forums Archive
Teleporting with Vehicle - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Teleporting with Vehicle (/showthread.php?tid=74244)



Teleporting with Vehicle - Fatboy_Rob - 20.04.2009

Hey guys & gals, I'm in a bit of a rut here, I'm trying to make it so that when I drive into an icon, it teleports me to the x,y,z cords of my choice. It's like a A to B thing.
Icon1 = Teleports infront of a Mod-Garage when you drive into it
Icon2 = Teleports you back to where you started

I have it set up so that if you're not in a car - It doesn't let you teleport (By just setting your position to a few units back from where you were). Thing is, when I drive into the Icon - I don't go anywhere, nor does the car.



TOP OF MY SCRIPT
pawn Код:
new pickup1;
Under OnGameModeInit
pawn Код:
pickup1 = CreatePickup(1239, 23, 1247.8792,-2037.0391,59.7714 ); // Tranfender Icon - Main Hill
pawn Код:
public OnPlayerPickUpPickup(playerid, pickupid)
{
//________________________________________ENTERS ENTERS ENTERS ENTERS______________________________________________________________
    {
        if (IsPlayerInAnyVehicle(playerid))
        {
            SetVehiclePos(GetPlayerVehicleID(playerid), -1943.1667,222.0864,33.7985); // In vehicle
        }
        else
        {
          SetPlayerPos(playerid, 1254.4995,-2036.9609,59.3486); // NOT in vehicle
        }
    }
    return 1;
}
When you try to walk into the icon with no car - It teleports you back like it's supposed to.
With the car, no prevail.

Can anyone help please?

PS: I just started scripting like, today. I know a bit of pawn, like, color & stuff
That's it


Re: Teleporting with Vehicle - yom - 20.04.2009

OnPlayerPickUpPickup isn't called when player is in a vehicle, use a timer instead.


Re: Teleporting with Vehicle - Bearfist - 20.04.2009

if (IsPlayerInAnyVehicle(playerid))
{
SetVehiclePos(GetPlayerVehicleID(playerid), -1943.1667,222.0864,33.7985); // In vehicle
}
try to add this =)
Код:
new vehicleid = GetPlayerVehicleID(playerid);
So It seems like that:
Код:
if (IsPlayerInAnyVehicle(playerid))
		{
            new vehicleid = GetPlayerVehicleID(playerid);
            LinkVehicleToInterior(vehicleid,Interiornumber);
			SetVehiclePos(vehicleid, -1943.1667,222.0864,33.7985); // In vehicle
		}
And on teleports you have to add
Код:
SetPlayerInterior(playerid,Interiornumber);

and

LinkVehicleToInterior(vehicleid,Interiornumber);
The Interior is normal OUT of Houses Interior = 0
but IN houses its a difference ..
so ****** Interior Id's and you're done ...

Hope It's working then

MFG Bearfist


Re: Teleporting with Vehicle - Pyrokid - 20.04.2009

Use a timer and use player to point. It'd be something like this:
pawn Код:
//top of script
forward timer1(playerid);

//OnGameModeInit
SetTimer("timer1", 1000, 1);

//anywhere in the script
public timer1(playerid)
{
    if(PlayerToPoint(2,playerid,1247.8792,-2037.0391,59.7714)) //If the player is anywhere really close to the pickup
    {
        if (IsPlayerInAnyVehicle(playerid))
        {
            SetVehiclePos(GetPlayerVehicleID(playerid), -1943.1667,222.0864,33.7985); // In vehicle
            PutPlayerInVehicle(playerid,GetPlayerVehicleID(playerid),0);
        }
        else
        {
          SetPlayerPos(playerid, 1254.4995,-2036.9609,59.3486); // NOT in vehicle
        }
    }
    return 1;
}
This is PlayerToPoint, put it anywhere in your GM.
pawn Код:
stock PlayerToPoint(Float:radi, playerid, Float:x, Float:y, Float:z)
{
  if(IsPlayerConnected(playerid))
    {
        new Float:oldposx, Float:oldposy, Float:oldposz;
        new Float:tempposx, Float:tempposy, Float:tempposz;
        GetPlayerPos(playerid, oldposx, oldposy, oldposz);
        tempposx = (oldposx -x);
        tempposy = (oldposy -y);
        tempposz = (oldposz -z);
        //printf("DEBUG: X:%f Y:%f Z:%f",posx,posy,posz);
        if (((tempposx < radi) && (tempposx > -radi)) && ((tempposy < radi) && (tempposy > -radi)) && ((tempposz < radi) && (tempposz > -radi)))
        {
            return 1;
        }
    }
    return 0;
}



Re: Teleporting with Vehicle - yom - 20.04.2009

Don't use PlayerToPoint, instead, use GetPlayerPos once, and then check distance between this position to pickups position.

(And also SetTimer can't pass parameters to the timed function, it will result playerid always = 0)


Re: Teleporting with Vehicle - Pyrokid - 20.04.2009

Quote:
Originally Posted by 0rb
Don't use PlayerToPoint, instead, use GetPlayerPos once, and then check distance between this position to pickups position.
Yeah you could do this to, PlayerToPoint was just the first that came to my head.


Re: Teleporting with Vehicle - Fatboy_Rob - 21.04.2009

-Edit: Uneeded Post - Delete please-


Re: Teleporting with Vehicle - Fatboy_Rob - 21.04.2009

Thank you Pyrokid! It works great!
Now, to make all the places do that... and then coming back to the spot we started at >________>

I really appreciate all of your help you guys. Zero, Cueball, and pghpunk in the IRC too, thanks!


Re: Teleporting with Vehicle - DMSOrg - 21.04.2009

RemovePlayerFromVehicle -> DeleteVehicle -> CreateVehicle -> whatever that command to sit the player into the vehicle is

that's my solution - I'm not very logical but I'm sure you can complete this.


Re: Teleporting with Vehicle - Fatboy_Rob - 21.04.2009

Hey, well Pyrokid's suggestion worked fine, but only ID 0 can teleport into any of them. I tried with 2 other players, each of us being Id 0.
Every time - ID - 0 could only TP
Any Idea what's wrong? Here's the teleport snippet

pawn Код:
public timer1(playerid)
{
//---------------------------To Transfender in SF-----------------------------------------------
    if(PlayerToPoint(2,playerid,1247.8792,-2037.0391,59.7714)) //If the player is anywhere really close to the pickup
    {
        if (IsPlayerInAnyVehicle(playerid))
        {
            SetVehiclePos(GetPlayerVehicleID(playerid), -1943.1667,222.0864,33.7985); // In vehicle
            PutPlayerInVehicle(playerid,GetPlayerVehicleID(playerid),0);
        }
        else
        {
          SetPlayerPos(playerid, 1254.4995,-2036.9609,59.3486); // NOT in vehicle
        }
    }
   return 1;
}
The teleporting works like it should. There's enters for each, and seperate exits, all using the code above. I have Pickup Icons only sending GameTextForPlayer (Or whatever) separately. Any help please?