setting a virtual world for each interior on each different vehicle
#1

Each plane has an interior, but i'm not sure on how i would go about adding a new interior for each plane.

e.g, person 1 enters shamal at LV, person 2 enters shamal at LS, they can both see each other.., but how could i make it so you can only see the person who enters the same plane as you do.

Thank you to anybody who can help,
also i if i need to post my objects just say, cheers.

my code:
pawn Код:
new InAndrom[MAX_PLAYERS];
new InShamal[MAX_PLAYERS];
new InNevada[MAX_PLAYERS];

//onplayerconnect
InAndrom[playerid]=0;
InShamal[playerid]=0;
InNevada[playerid]=0;

public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
    if (GetVehicleModel(vehicleid) == 592 && ispassenger == 1)
        {
                SetPlayerInterior(playerid,9);
                SetPlayerFacingAngle(playerid,0.0);
                SetPlayerPos(playerid, 315.856170,1024.496459,1949.797363);
                SetCameraBehindPlayer(playerid);
                InAndrom[playerid]=vehicleid;
        }
    if (GetVehicleModel(vehicleid) == 519 && ispassenger == 1)
        {
                TogglePlayerControllable(playerid, 0);
                SetTimerEx("UnfreezePlayer", 3000, false, "d", playerid);
                SetPlayerFacingAngle(playerid,270.0);
                SetPlayerPos(playerid, 1377.7186,-3785.6904,1226.5165);
                SetCameraBehindPlayer(playerid);
                InShamal[playerid]=vehicleid;
        }
    if (GetVehicleModel(vehicleid) == 553 && ispassenger == 1)
        {
                TogglePlayerControllable(playerid, 0);
                SetTimerEx("UnfreezePlayer", 3000, false, "d", playerid);
                SetPlayerFacingAngle(playerid,15.0);
                SetPlayerPos(playerid, 1777.8147,-3872.2085,1206.4860);
                SetCameraBehindPlayer(playerid);
                InNevada[playerid]=vehicleid;
        }
        return 1;
}

public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
if (newkeys & 16 && InAndrom[playerid] > 0)
        {
                new Float:X,Float:Y,Float:Z,Float:A;
                GetVehiclePos(InAndrom[playerid],X,Y,Z);
                GetVehicleZAngle(InAndrom[playerid],A);
                X+=(5*floatsin(-floatsub(A,45.0),degrees)),
                Y+=(5*floatcos(-floatsub(A,45.0),degrees));
                SetPlayerInterior(playerid,0);
                SetPlayerPos(playerid,X,Y,floatsub(Z,0.94));
                SetPlayerFacingAngle(playerid,A);
                SetCameraBehindPlayer(playerid);
                InAndrom[playerid]=0;
        }
if (newkeys & 16 && InShamal[playerid] > 0)
        {
                new Float:X,Float:Y,Float:Z,Float:A;
                GetVehiclePos(InShamal[playerid],X,Y,Z);
                GetVehicleZAngle(InShamal[playerid],A);
                X+=(5*floatsin(-floatsub(A,45.0),degrees)),
                Y+=(5*floatcos(-floatsub(A,45.0),degrees));
                SetPlayerInterior(playerid,0);
                SetPlayerPos(playerid,X,Y,floatsub(Z,0.94));
                SetPlayerFacingAngle(playerid,A);
                SetCameraBehindPlayer(playerid);
                InShamal[playerid]=0;
        }
if (newkeys & 16 && InNevada[playerid] > 0)
        {
                new Float:X,Float:Y,Float:Z,Float:A;
                GetVehiclePos(InNevada[playerid],X,Y,Z);
                GetVehicleZAngle(InNevada[playerid],A);
                X+=(5*floatsin(-floatsub(A,45.0),degrees)),
                Y+=(5*floatcos(-floatsub(A,45.0),degrees));
                SetPlayerInterior(playerid,0);
                SetPlayerPos(playerid,X,Y,floatsub(Z,0.94));
                SetPlayerFacingAngle(playerid,A);
                SetCameraBehindPlayer(playerid);
                InNevada[playerid]=0;
        }
        return 1;
}
Reply
#2

bump sorry :/
Reply
#3

Oh, Hayden I thought you meant something else.

pawn Код:
SetPlayerVirtualWorld ( playerid, vehicleid ) ;
Reply
#4

https://sampwiki.blast.hk/wiki/SetPlayerVirtualWorld
https://sampwiki.blast.hk/wiki/SetVehicleVirtualWorld

Use them only players in the same virtualworld can see see each other, same for vehicles.

EDIT: If you want a different virtual world for each one use an integer variable as a counter and set the world of the player/vehicle to that number. And increase it by one everytime its used.

eg,
pawn Код:
new counter;//global

public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
    if (GetVehicleModel(vehicleid) == 592 && ispassenger == 1)
    {
        counter++; //decrease by one when they leave the interior
        SetPlayerInterior(playerid,9);
        SetPlayerVirtualWorld(playerid, counter);//*
        SetPlayerFacingAngle(playerid,0.0);
        SetPlayerPos(playerid, 315.856170,1024.496459,1949.797363);
        SetCameraBehindPlayer(playerid);
        InAndrom[playerid]=vehicleid;
    }
    return 1;
}
If you want players in the same vehicle to see each other you will need to check if a player is already in the vehicle and if so... Set The player who is entering to the same world as the player in the vehicle......... (and thats why i don't write tutorials)
Reply
#5

Quote:
Originally Posted by iggy1
Посмотреть сообщение
https://sampwiki.blast.hk/wiki/SetPlayerVirtualWorld
https://sampwiki.blast.hk/wiki/SetVehicleVirtualWorld

Use them only players in the same virtualworld can see see each other, same for vehicles.

EDIT: If you want a different virtual world for each one use an integer variable as a counter and set the world of the player/vehicle to that number. And increase it by one everytime its used.

eg,
pawn Код:
new counter;//global

public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
    if (GetVehicleModel(vehicleid) == 592 && ispassenger == 1)
    {
        counter++; //decrease by one when they leave the interior
        SetPlayerInterior(playerid,9);
        SetPlayerVirtualWorld(playerid, counter);//*
        SetPlayerFacingAngle(playerid,0.0);
        SetPlayerPos(playerid, 315.856170,1024.496459,1949.797363);
        SetCameraBehindPlayer(playerid);
        InAndrom[playerid]=vehicleid;
    }
    return 1;
}
If you want players in the same vehicle to see each other you will need to check if a player is already in the vehicle and if so... Set The player who is entering to the same world as the player in the vehicle......... (and thats why i don't write tutorials)
The problem there is that if the player enters the same Shamal as passenger, he won't be able to see the other players in it. The easiest solution to this problem is quite simply to set the virtual world to the vehicleid, as the vehicleid never changed and it will always be different for each unique vehicle.

For example:

pawn Код:
new InAndrom[MAX_PLAYERS];
new InShamal[MAX_PLAYERS];
new InNevada[MAX_PLAYERS];

//onplayerconnect
InAndrom[playerid]=0;
InShamal[playerid]=0;
InNevada[playerid]=0;

public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
    if (GetVehicleModel(vehicleid) == 592 && ispassenger == 1)
    {
        SetPlayerInterior(playerid,9);
        SetPlayerFacingAngle(playerid,0.0);
        SetPlayerPos(playerid, 315.856170,1024.496459,1949.797363);
        SetCameraBehindPlayer(playerid);
        InAndrom[playerid]=vehicleid;
        SetPlayerVirtualWorld(playerid,vehicleid);
    }
    else if (GetVehicleModel(vehicleid) == 519 && ispassenger == 1)
    {
        TogglePlayerControllable(playerid, 0);
        SetTimerEx("UnfreezePlayer", 3000, false, "d", playerid);
        SetPlayerFacingAngle(playerid,270.0);
        SetPlayerPos(playerid, 1377.7186,-3785.6904,1226.5165);
        SetCameraBehindPlayer(playerid);
        InShamal[playerid]=vehicleid;
        SetPlayerVirtualWorld(playerid,vehicleid);
    }
    else if (GetVehicleModel(vehicleid) == 553 && ispassenger == 1)
    {
        TogglePlayerControllable(playerid, 0);
        SetTimerEx("UnfreezePlayer", 3000, false, "d", playerid);
        SetPlayerFacingAngle(playerid,15.0);
        SetPlayerPos(playerid, 1777.8147,-3872.2085,1206.4860);
        SetCameraBehindPlayer(playerid);
        InNevada[playerid]=vehicleid;
        SetPlayerVirtualWorld(playerid,vehicleid);
    }
    return 1;
}

public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    if (newkeys & 16 && InAndrom[playerid] > 0)
    {
        new Float:X,Float:Y,Float:Z,Float:A;
        GetVehiclePos(InAndrom[playerid],X,Y,Z);
        GetVehicleZAngle(InAndrom[playerid],A);
        X+=(5*floatsin(-floatsub(A,45.0),degrees)),
        Y+=(5*floatcos(-floatsub(A,45.0),degrees));
        SetPlayerInterior(playerid,0);
        SetPlayerPos(playerid,X,Y,floatsub(Z,0.94));
        SetPlayerFacingAngle(playerid,A);
        SetCameraBehindPlayer(playerid);
        InAndrom[playerid]=0;
        SetPlayerVirtualWorld(playerid,0);
    }
    if (newkeys & 16 && InShamal[playerid] > 0)
    {
        new Float:X,Float:Y,Float:Z,Float:A;
        GetVehiclePos(InShamal[playerid],X,Y,Z);
        GetVehicleZAngle(InShamal[playerid],A);
        X+=(5*floatsin(-floatsub(A,45.0),degrees)),
        Y+=(5*floatcos(-floatsub(A,45.0),degrees));
        SetPlayerInterior(playerid,0);
        SetPlayerPos(playerid,X,Y,floatsub(Z,0.94));
        SetPlayerFacingAngle(playerid,A);
        SetCameraBehindPlayer(playerid);
        InShamal[playerid]=0;
        SetPlayerVirtualWorld(playerid,0);
    }
    if (newkeys & 16 && InNevada[playerid] > 0)
    {
        new Float:X,Float:Y,Float:Z,Float:A;
        GetVehiclePos(InNevada[playerid],X,Y,Z);
        GetVehicleZAngle(InNevada[playerid],A);
        X+=(5*floatsin(-floatsub(A,45.0),degrees)),
        Y+=(5*floatcos(-floatsub(A,45.0),degrees));
        SetPlayerInterior(playerid,0);
        SetPlayerPos(playerid,X,Y,floatsub(Z,0.94));
        SetPlayerFacingAngle(playerid,A);
        SetCameraBehindPlayer(playerid);
        InNevada[playerid]=0;
        SetPlayerVirtualWorld(playerid,0);
    }
    return 1;
}
Also consider using else if's like I have done in the example, as the player cannot be in more than one vehicle at a time, it is better coding practice.
Reply
#6

Thanks all for your help,wolfs way worked perfectly. Also learnt some other stuff from the jatoch and iggy.
Reply
#7

Yh i never thought of that JaToc, maybe this type would be appropriate
pawn Код:
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
    if (GetVehicleModel(vehicleid) == 592 && ispassenger == 1)
    {
        new vw;
        for(new i; i < MAX_PLAYERS; i++)
        {
            if(!IsPlayerConnected(i) || playerid == i)continue;
            if(IsPlayerInVehicle(i, vehicleid) && GetPlayerState(i) == PLAYER_STATE_PASSENGER)
            {
                vw = GetPlayerVirtualWorld(i);
                SetPlayerVirtualWorld(playerid, vw);
                SetPlayerInterior(playerid,9);
                SetPlayerFacingAngle(playerid,0.0);
                SetPlayerPos(playerid, 315.856170,1024.496459,1949.797363);
                SetCameraBehindPlayer(playerid);
                InAndrom[playerid] = vehicleid;
                return 1;
            }
        }
        counter++; //decrease by one when they leave the interior
        SetPlayerInterior(playerid,9);
        SetPlayerVirtualWorld(playerid, counter);
        SetPlayerFacingAngle(playerid,0.0);
        SetPlayerPos(playerid, 315.856170,1024.496459,1949.797363);
        SetCameraBehindPlayer(playerid);
        InAndrom[playerid]=vehicleid;
        return 1;
    }
    //else if
    return 1;
}
That should work better i think.

EDIT: Come to think of it you could send the players to a virtualworld that is the vehicleid that way you know players will only see each other in the same vehicle... can't beleive i never thought of that before.
pawn Код:
SetPlayerVirtualWorld(playerid, vehicleid);//much better method
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)