Car lock [NOTOK] =D
#1

HI all
I wanna make a car lock with player name
for exemple if the player name is batman he can enter in the rhino or car or whatever u wants
if is name is not batman he cant =) and receive a message like This car is reserved for batman!
Reply
#2

i check about the team, but by name i make some changes to this...


first i define a red color...

Код:
#define COLOR_RED 0xAA3333AA
and on callback OnPlayerStateChange you put..
Код:
public OnPlayerStateChange(playerid,newstate,oldstate)
 {
   if(newstate==PLAYER_STATE_DRIVER)
    {
      new name;
	  GetPlayerName(playerid, name, sizeof(name));

	  // swat vehicles
      if(GetVehicleModel(vehicleid) == 427 || GetVehicleModel(vehicleid) == 601)
       {
         if(name != "batman")
          {
            RemovePlayerFromVehicle(playerid);
            SendClientMessage(playerid, COLOR_RED, "This car is reserved for batman!");
            SetPlayerWantedLevel(playerid, 2); // coment this line if you dont want set the wanted level
          }
       }
   } 
  return 1;   
 }
Reply
#3

that only for the team "TEAM_SWAT"
Reply
#4

sory, i already change my last post.
ops, my bad. i change some little things later.
i edited my post again, because i forget this little things. ok ?
Reply
#5

Name, Is nothing else than a string, now, do you compare strings by 'if(1 'equal' 1)'?
Using strcmp for this, is the only way, which you will use.

pawn Код:
new Data[24]; GetPlayerName(playerid, Data, 24);
if(strcmp(Data, "batman", true) == 0)
{
  //His name is batman, do what ever you want.
  return true;
}
else // his name isnt batman, do what ever you want.
Reply
#6

errors ..
Reply
#7

Anybody know how to actually lock the cars? So the player trying to take it will get that tugging-on-the-door animation?
Reply
#8

it is only when trying to open passenger seat...

but the way alexiis showed is quite.... hmm... uncomfortable.. what about something like this?

Код:
#define COLOR_RED 0xAA3333AA
new vehicle;

public OnGameModeInit()
{
vehicle=CreateVehicle(520,3761.0186,-1944.1924,4.7032,261.9687,0,0,240);
}

public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
   	new Data[24]; GetPlayerName(playerid, Data, 24); // Thx 2 eldiablo.. I forget it again :/
    if(strcmp(Data, "batman", true) == 0)// Thx 2 eldiablo.. I forget it again :/
   	{
    	SetVehicleParamsForPlayer(vehicle, playerid,0,0);
   	}
   	else
   	{
    	SetVehicleParamsForPlayer(vehicle, playerid,0,1);
    	SendClientMessage(playerid, COLOR_RED, "You're not Batman!");
   	}
}
I think it is better, because player won't enter the vehicle and it is easier, more comfortable and there is less of code

you can edit it easily.. if you want those SWAT cars only locked for Batman, it is this:
Код:
#define COLOR_RED 0xAA3333AA

public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
   	if(IsPlayerConnected(playerid))
	{
  	    if(GetVehicleModel(vehicleid) == 427 || GetVehicleModel(vehicleid) == 601)
   	    {
   		     new Data[24]; GetPlayerName(playerid, Data, 24); // Thx 2 eldiablo.. I forget it again :/
             if(strcmp(Data, "batman", true) == 0)// Thx 2 eldiablo.. I forget it again :/
   	         {
    		     SetVehicleParamsForPlayer(vehicle, playerid,0,0);
   		     }
   		     else
   		     {
    		     SetVehicleParamsForPlayer(vehicle, playerid,0,1);
    		     SendClientMessage(playerid, COLOR_RED, "You're not Batman!");
   		     }
	   }

    }
}
Reply
#9

got errors
Код:
(198) : error 076: syntax error in the expression, or invalid function call
(217) : warning 202: number of arguments does not match definition
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


1 Error.
pawn Код:
198. if(GetPlayerName == Batman)
pawn Код:
217.  vehicle = CreateVehicle(520,71.5316,2000.5625,18.2073,90.7127,43,0); //
Reply
#10

pawn Код:
if(strcmp(cmdtext, "/lock", true)==0)
    {
        new State;
        new Float:X, Float:Y, Float:Z;

        if(IsPlayerInAnyVehicle(playerid))
        {
            State=GetPlayerState(playerid);
            if(State!=PLAYER_STATE_DRIVER)
            {
                SendClientMessage(playerid,COLOR_GREEN,"You can only lock the doors as the driver.");
                return 1;
            }
            new i;
            for(i=0;i<MAX_PLAYERS;i++)
            {
                if(i != playerid)
                {
                    SetVehicleParamsForPlayer(GetPlayerVehicleID(playerid),i, 0, 1);
                }
            }
            SendClientMessage(playerid, COLOR_GREEN, "Vehicle locked!");
            GetPlayerPos(playerid,X,Y,Z);
            PlayerPlaySound(playerid,1056,X,Y,Z);
        }
        else
        {
            SendClientMessage(playerid, COLOR_GREEN, "You're not in a vehicle!");
        }
        return 1;
    }
   
if(strcmp(cmdtext, "/unlock", true)==0)
    {
        new State;
        new Float:X, Float:Y, Float:Z;

        if(IsPlayerInAnyVehicle(playerid))
        {
            State=GetPlayerState(playerid);
            if(State!=PLAYER_STATE_DRIVER)
            {
                SendClientMessage(playerid,COLOR_GREEN,"You can only unlock the doors as the driver.");
                return 1;
            }
            new i;
            for(i=0;i<MAX_PLAYERS;i++)
            {
                if(i != playerid)
                {
                    SetVehicleParamsForPlayer(GetPlayerVehicleID(playerid),i, 0, 0);
                }
            }
            SendClientMessage(playerid, COLOR_GREEN, "Vehicle unlocked!");
            GetPlayerPos(playerid,X,Y,Z);
            PlayerPlaySound(playerid,1056,X,Y,Z);
        }
        else
        {
            SendClientMessage(playerid, COLOR_GREEN, "You're not in a vehicle!");
        }
        return 1;
    }
(Isnt made by me, just found somewhere and fixed the errors. And its working, at least here lol)
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)