Don't spectate vehicle when admin enters it
#1

Hi everyone.
What do I need is to make spectating vehicle stop when admin enters it and also to not allow to start spectating it if admin is already there.

Unfortunately, I did not have any such experience previously, so my attempts to make it may seem funny. Here is my dialog for spectating vehicles:

pawn Код:
if(dialogid==105_2)//Spectating vehicle
    {
        if(response)
        {
            new tmp[255];
            tmp = strtOK(inputtext, idx);
            if(!strlen(tmp))
            {
                SendClientMessage(playerid, COLOR_LIGHTBLUE, " You didn't enter vehicle ID.");
                return 1;
            }
            specvehicleid = strval(tmp);
            for(new i=0; i<MAXPLAYERS; i++)
            {
                if(IsPlayerInVehicle(i, specvehicleid)&&((tmpAdmin[i]==1&&admin[i]==1))||IsPlayerAdmin(i))
                {
                    SendClientMessage(playerid,COLOR_RED," You are not allowed to spectate this vehicle, since an admin is sitting in it.");
                    return 1;
                }
            }
            if(GetPlayerVehicleID(playerid)==specvehicleid) SendClientMessage(playerid,COLOR_RED," You cannot spectate vehicle you are sitting in.");
            if(specvehicleid < MAX_VEHICLES)
            {
                TogglePlayerSpectating(playerid, 1);
                PlayerSpectateVehicle(playerid, specvehicleid);
                gSpectateID[playerid] = specvehicleid;
                gSpectateType[playerid] = ADMIN_SPEC_TYPE_VEHICLE;
                camer[playerid]=1;
                format(string, sizeof(string), " You are spectating vehicle with ID %d. Press 2 to exit.",specvehicleid);
                SendClientMessage(playerid,COLOR_LIGHTBLUE,string);
                for(new i=0; i<MAXPLAYERS; i++)
                {
                    if(IsPlayerInVehicle(i, specvehicleid)&&((tmpAdmin[i]==1&&admin[i]==1))||IsPlayerAdmin(i))
                    {
                        TogglePlayerSpectating(playerid, 0);
                        gSpectateID[playerid] = INVALID_PLAYER_ID;
                        gSpectateType[playerid] = ADMIN_SPEC_TYPE_NONE;
                        SetPlayerVirtualWorld(playerid,0);
                        camer[playerid]=0;
                        ShowDialog(playerid,43,DIALOG_STYLE_MSGBOX,"Info","{FCAC00}Another administrator has entered the vehicle you're spectating,\nso spectating is stopped.","OK","");
                        return 1;
                    }
                }
            }
            else SendClientMessage(playerid, COLOR_LIGHTBLUE, " Wrong ID.");
            return 1;
        }
        else ShowDialog105(playerid);
    }

Obviously wrong conditions are those which return "You are not allowed to spectate this vehicle, since an admin is sitting in it" and "Another administrator has entered the vehicle you're spectating,\nso spectating is stopped".


Please tell me how to make them in a right way.
Thank you in advance.
Reply
#2

Try this
pawn Код:
if(dialogid==105_2)//Spectating vehicle
    {
        if(response)
        {
            new tmp[255];
            tmp = strtOK(inputtext, idx);
            if(!strlen(tmp))
            {
                SendClientMessage(playerid, COLOR_LIGHTBLUE, " You didn't enter vehicle ID.");
                return 1;
            }
            specvehicleid = strval(tmp);
            for(new i=0; i<MAXPLAYERS; i++)
            {
                if(IsPlayerInVehicle(i, specvehicleid)&&((tmpAdmin[i]==1&&admin[i]==1))||IsPlayerAdmin(i))
                {
                    SendClientMessage(playerid,COLOR_RED," You are not allowed to spectate this vehicle, since an admin is sitting in it.");
                    return 1;
                }
            }
            if(GetPlayerVehicleID(playerid)==specvehicleid) SendClientMessage(playerid,COLOR_RED," You cannot spectate vehicle you are sitting in.");
            if(specvehicleid < MAX_VEHICLES)
            {
                TogglePlayerSpectating(playerid, 1);
                PlayerSpectateVehicle(playerid, specvehicleid);
                gSpectateID[playerid] = specvehicleid;
                gSpectateType[playerid] = ADMIN_SPEC_TYPE_VEHICLE;
                camer[playerid]=1;
                format(string, sizeof(string), " You are spectating vehicle with ID %d. Press 2 to exit.",specvehicleid);
                SendClientMessage(playerid,COLOR_LIGHTBLUE,string);
                for(new i=0; i<MAXPLAYERS; i++)
                {
                    if(IsPlayerInVehicle(i, specvehicleid)&&((tmpAdmin[i]==1&&admin[i]==1))||IsPlayerAdmin(i))
                    {
                        TogglePlayerSpectating(playerid, 0);
                        gSpectateID[playerid] = INVALID_PLAYER_ID;
                        gSpectateType[playerid] = ADMIN_SPEC_TYPE_NONE;
                        SetPlayerVirtualWorld(playerid,0);
                        camer[playerid]=0;
                        ShowDialog(playerid,43,DIALOG_STYLE_MSGBOX,"Info","{FCAC00}Another administrator has entered    the vehicle you're spectating,\nso spectating is stopped.","OK","");
                      }
                }
        return 1;
            }
            else SendClientMessage(playerid, COLOR_LIGHTBLUE, " Wrong ID.");
            return 1;
        }
        else ShowDialog105(playerid);
    }
Reply
#3

Sorry for the delayed reply, didn't have anybody to test.

And nope, it's not working - when an admin enters vehicle, nothing happens, though I want it to stop spectating.



I was able to create a public function IsAdminInVehicle and therefore to successfully create check if an admin is in vehicle when you try to start spectating it:

pawn Код:
if(dialogid==105_2)//Spectating vehicle
    {
        if(response)
        {
            new tmp[255];
            tmp = strtOK(inputtext, idx);
            if(!strlen(tmp))
            {
                SendClientMessage(playerid, COLOR_LIGHTBLUE, " You didn't enter vehicle ID.");
                return 1;
            }
            specvehicleid = strval(tmp);
            if(IsAdminInVehicle(specvehicleid))
            {
                SendClientMessage(playerid,COLOR_RED," You are not allowed to spectate this vehicle, since an admin is sitting in it.");
                return 1;
            }
            if(GetPlayerVehicleID(playerid)==specvehicleid)
            {
                SendClientMessage(playerid,COLOR_RED," You cannot spectate vehicle you are sitting in.");
                return 1;
            }
            if(specvehicleid < MAX_VEHICLES)
            {
                TogglePlayerSpectating(playerid, 1);
                PlayerSpectateVehicle(playerid, specvehicleid);
                gSpectateID[playerid] = specvehicleid;
                gSpectateType[playerid] = ADMIN_SPEC_TYPE_VEHICLE;
                camer[playerid]=1;
                format(string, sizeof(string), " You are spectating vehicle with ID %d. Press 2 to exit.",specvehicleid);
                SendClientMessage(playerid,COLOR_LIGHTBLUE,string);
                for(new i=0; i<MAXPLAYERS; i++)
                {
                    if(IsPlayerInVehicle(i, specvehicleid)&&((tmpAdmin[i]==1&&admin[i]==1))||IsPlayerAdmin(i))
                    {
                        TogglePlayerSpectating(playerid, 0);
                        gSpectateID[playerid] = INVALID_PLAYER_ID;
                        gSpectateType[playerid] = ADMIN_SPEC_TYPE_NONE;
                        SetPlayerVirtualWorld(playerid,0);
                        camer[playerid]=0;
                        ShowDialog(playerid,43,DIALOG_STYLE_MSGBOX,"Info","{FCAC00}Another administrator has entered the vehicle you're spectating,\nso spectating is stopped.","OK","");
                        return 1;
                    }
                }
            }
            else SendClientMessage(playerid, COLOR_LIGHTBLUE, " Wrong ID.");
            return 1;
        }
        else ShowDialog105(playerid);
    }



But I still can't get to figure out how to put player out of spectating when admin is entering already spectated vehicle.
Reply
#4

try this

PHP код:

new IsitInCar[MAX_PLAYERS];
new 
AdminInThisCar[MAX_VEHICLES];
public 
OnPlayerStateChange(playeridnewstateoldstate)
{
    if(
newstate == PLAYER_STATE_DRIVER)
    {
        
IsitInCar[playerid] = GetPlayerVehicleID(playerid;
        if(
ifplayerdmin)AdminInThisCar[GetPlayerVehicleID(playerid)] = 1;
    }
    if(
oldstate == PLAYER_STATE_DRIVER)
    {
        if(
AdminInThisCar[IsitInCar[playerid]] == 1)AdminInThisCar[GetPlayerVehicleID(playerid)] = 0;
        
IsitInCar[playerid] = 0;
    }
    return 
1;
}
if(
dialogid==105_2)//Spectating vehicle
    
{
        if(
response)
        {
            new 
tmp[255];
            
tmp strtOK(inputtextidx);
            if(!
strlen(tmp))
            {
                
SendClientMessage(playeridCOLOR_LIGHTBLUE" You didn't enter vehicle ID.");
                return 
1;
            }
            
specvehicleid strval(tmp);
            if(
AdminInThisCar[specvehicleid] == 1)
            {
                 
SendClientMessage(playerid,COLOR_RED," You are not allowed to spectate this vehicle, since an admin is sitting in it.");
                 return 
1;
            }
            if(
GetPlayerVehicleID(playerid)==specvehicleid)
            {
                
SendClientMessage(playerid,COLOR_RED," You cannot spectate vehicle you are sitting in.");
                return 
1;
            }
            if(
specvehicleid MAX_VEHICLES)
            {
                
TogglePlayerSpectating(playerid1);
                
PlayerSpectateVehicle(playeridspecvehicleid);
                
gSpectateID[playerid] = specvehicleid;
                
gSpectateType[playerid] = ADMIN_SPEC_TYPE_VEHICLE;
                
camer[playerid]=1;
                
format(stringsizeof(string), " You are spectating vehicle with ID %d. Press 2 to exit.",specvehicleid);
                
SendClientMessage(playerid,COLOR_LIGHTBLUE,string);
                for(new 
i=0i<MAXPLAYERSi++)
                {
                    if(
IsPlayerInVehicle(ispecvehicleid)&&((tmpAdmin[i]==1&&admin[i]==1))||IsPlayerAdmin(i))
                    {
                        
TogglePlayerSpectating(playerid0);
                        
gSpectateID[playerid] = INVALID_PLAYER_ID;
                        
gSpectateType[playerid] = ADMIN_SPEC_TYPE_NONE;
                        
SetPlayerVirtualWorld(playerid,0);
                        
camer[playerid]=0;
                        
ShowDialog(playerid,43,DIALOG_STYLE_MSGBOX,"Info","{FCAC00}Another administrator has entered the vehicle you're spectating,\nso spectating is stopped.","OK","");
                        return 
1;
                    }
                }
            }
            else 
SendClientMessage(playeridCOLOR_LIGHTBLUE" Wrong ID.");
            return 
1;
        }
        else 
ShowDialog105(playerid);
    } 
Reply
#5

brawrr, thank you, but I already did the part with not allowing to start spectating if an admin is already there using public function IsAdminInVehicle.

What do I need now is to make spectating stop when an admin is entering vehicle...


The wrong code is:

pawn Код:
for(new i=0; i<MAXPLAYERS; i++)
                {
                    if(IsPlayerInVehicle(i, specvehicleid)&&((tmpAdmin[i]==1&&admin[i]==1))||IsPlayerAdmin(i))
                    {
                        TogglePlayerSpectating(playerid, 0);
                        gSpectateID[playerid] = INVALID_PLAYER_ID;
                        gSpectateType[playerid] = ADMIN_SPEC_TYPE_NONE;
                        SetPlayerVirtualWorld(playerid,0);
                        camer[playerid]=0;
                        ShowDialog(playerid,43,DIALOG_STYLE_MSGBOX,"Info","{FCAC00}Another administrator has entered the vehicle you're spectating,\nso spectating is stopped.","OK","");
                        return 1;
                    }
                }


I need something like OnPlayerSpectatingVehicle, but I have no idea how to make it.

I also thought about creating some variable for the vehicle being spectated and then turning it to zero when an admin enters the vehicle, but I have no idea how to make it do something with the player spectating.

I mean... Variables can prevent something from happening, but not interrupt it when it's already going.
So I need some public function which can send a command to spectating player when an admin enters spectated vehicle.
Reply
#6

just check in some global timer
Reply
#7

Still no idea how to do it.
Reply
#8

tell me what timers u have in ongamemodeinit?
Reply
#9

Quote:
Originally Posted by brawrr
Посмотреть сообщение
tell me what timers u have in ongamemodeinit?
pawn Код:
SetTimer("ProvTimer",1000,1);
SetTimer("PropertyScoreUpdate", 120000, 1);
SetTimer("TimeUpdate",61000, 1);
And a few more.
These are for example.

//I sent you a few private messages, not sure if you recieved them.
Reply
#10

try this

PHP код:

public ProvTimer()
{
    for(new 
iMAX_PLAYERSi++)
    {
        if(
IsPlayerConnected(i))
        {
            if(
GetPlayerState(i) == PLAYER_STATE_SPECTATING)
            {
                if(
AdminInThisCar[gSpectateID[i]])
                {
                    
SendClientMessage(playerid,COLOR_RED,"Now you cant spectate this vehicle, in this vehicle sit admin!");
                    
TogglePlayerSpectating(i0);
                    
gSpectateID[i] = 0;
                }
            }
        }
    }
    return 
1;

Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)