Admin owned vehicles
#1

Hello, I was wondering how can i make a car with "CreateVehicle" but at the same time only rcon logged in admins can use it? or else who gets in gets kicked out automaticly with a message , I would be very glad if you can help me and thanks.
Reply
#2

pawn Код:
new aVeh;

public OnGameModeInit()
{
   aVeh = CreateVehicle(/**/);
}

public OnPlayerStateChange(playerid, newstate, oldstate)
{
    if(newstate == PLAYER_STATE_DRIVER && GetPlayerVehicleID(playerid) == aVeh && !IsPlayerAdmin(playerid))
    {
        SendClientMessage(playerid, -1, "SERVER: You are not allowed to enter this vehicle. Good-bye.");
        Kick(playerid);
    }
    return 1;
}
Reply
#3

Hey , I tried the script u gave me , it worked fine unless it kicks you from the game not the car , any solution?
Reply
#4

Quote:
Originally Posted by [XST]O_x
Посмотреть сообщение
pawn Код:
new aVeh;

public OnGameModeInit()
{
   aVeh = CreateVehicle(/**/);
}

public OnPlayerStateChange(playerid, newstate, oldstate)
{
    if(newstate == PLAYER_STATE_DRIVER && GetPlayerVehicleID(playerid) == aVeh && !IsPlayerAdmin(playerid))
    {
        SendClientMessage(playerid, -1, "SERVER: You are not allowed to enter this vehicle. Good-bye.");
        RemovePlayerFromVehicle(playerid); // Kicks him out of the car instead of the server ;)
    }
    return 1;
}
Edited a small bit
Reply
#5

Got it working fine now , thanks , but how can I make more than 1 vehicle in this script? (multiple)
Reply
#6

pawn Код:
#define MAX_VEHICLES 50

new
    vehicles[ MAX_VEHICLES ]
;

public OnGameModeInit()
{
    vehicles[ 0 ] = CreateVehicle(/**/);
    vehicles[ 1 ] = CreateVehicle(/**/);
    // ..
    vehicles[ 49 ] = CreateVehicle(/**/);
}
Reply
#7

Create new avehicles.
new aVeh2, aVeh3 etc. Then just change the script according to your changes.
Reply
#8

First you gotta make them

Код:
new CAdmin[7]; //Top of the script. Make sure you define the number of the cars. Dont forget 0 counts as number too.

//PLACE THIS UNDER ONGAMEMODEINIT
CAdmin[0] = AddStaticVehicleEx(405,-2036.5665,-123.5742,34.9100,180.4638,1,1,1800); //Change into your positions
	CAdmin[1] = AddStaticVehicleEx(405,-2033.5212,-122.9200,34.9033,178.2843,1,1,1800);
	CAdmin[2] = AddStaticVehicleEx(405,-2030.0134,-123.4365,34.9096,179.7268,1,1,1800);
	CAdmin[3] = AddStaticVehicleEx(405,-2026.8402,-123.3068,34.9058,179.8116,1,1,1800);
	CAdmin[4] = AddStaticVehicleEx(405,-2022.3026,-124.1238,34.9183,177.6386,1,1,1800);
	CAdmin[5] = AddStaticVehicleEx(405,-2018.6248,-123.9074,34.9285,179.4833,1,1,1800);
	CAdmin[6] = AddStaticVehicleEx(405,-2021.2585,-130.0021,34.9722,88.3122,1,1,1800);

public OnPlayerStateChange(playerid, newstate, oldstate)
{
    if(newstate == PLAYER_STATE_DRIVER)
    {
        new CarCheck = GetPlayerVehicleID(playerid);
        for(new i = 0; i < sizeof(CAdmin); i++) /*loop for all CAdmin*/
        {
            if(CarCheck == CAdmin[i])
            {
                if(IsPlayerAdmin(playerid))
                {
                    SendClientMessage(playerid, COLOR_YELLOW, "Welcome into the administrator vehicle!");
                    return 1;
                }
                else
                {
                    SendClientMessage(playerid, COLOR_RED, "<!>You are not an admin!");
                    RemovePlayerFromVehicle(playerid);
                    return 1;
				}
            }
        }
    }
    return 1;
}
OnPlayerStateChange will detect when they are actualy sitting inside the vehicle. If you use OnPlayerEnterVehicle it wont be so effective.
Reply
#9

Thanks everyone , working well!
Reply
#10

Quote:
Originally Posted by Riven
Посмотреть сообщение
Hey , I tried the script u gave me , it worked fine unless it kicks you from the game not the car , any solution?
Oh sorry, when I read "gets kicked out" I automatically assumed you want the player to be kicked out of the server. My bad
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)