Check if Player is in one of 4 Vehicle ids
#1

I have an Problem, yea i know, i have lots of problems with scripting XD
I have an siren command, where an object spawns and it attaches to the vehicle and all, but my problem is, i want that it works on 4-5 different ids, and if the player is in non of these ids then an error would display. And if he is in one of these ids, example: if im in id 560 then the object spawns, and in 426 the same, and if he's not in one of those then error.


My whole command:

Код:
CMD:bl(playerid, params[])
{
	new vID = GetPlayerVehicleID(playerid);
    if(eingeloggt[playerid] == 0)return SendClientMessage(playerid,COLOR_RED,"Du bist noch nicht eingeloggt.");
    if(pTazed[playerid] == 1)return SendClientMessage(playerid,COLOR_RED,"Du bist getazed.");
    if(pInfo[playerid][fraktion] != 1)return SendClientMessage(playerid,COLOR_RED,"Du bist kein Mitglied vom SFPD.");
    if(pInfo[playerid][fraktion] == 1 && pInfo[playerid][duty] != 1)return SendClientMessage(playerid,COLOR_RED,"Du bist nicht im Dienst.");
    if(GetPVarInt(playerid,"SireneAn") == 1)
    {
    	DestroyObject(blaulicht[playerid]);
    	DestroyObject(blaulicht2[playerid]);
    	DestroyObject(blaulicht3[playerid]);
     	GameTextForPlayer(playerid,"~r~Blaulicht Deaktiviert",2000,3);
   		SetPVarInt(playerid,"SireneAn",0);
     	return 1;
	}
    if(!IsPlayerInAnyVehicle(playerid))return SendClientMessage(playerid,COLOR_RED,"Du sitzt in keinem Fahrzeug.");
    if(!IsAPoliceVehicle(vID))return SendClientMessage(playerid,COLOR_RED,"Du sitzt in keinem PD Fahrzeug.");
    if(GetVehicleModel(vID) != 426 | 560)return SendClientMessage(playerid,COLOR_RED,"Du sitzt in keinem PD Premier/Sultan/Cheetah/Securicar");
    if(GetVehicleModel(vID) == 426)
    {
        if(GetPVarInt(playerid,"SireneAn") == 1)
        {
            DestroyObject(blaulicht[playerid]);
	    	DestroyObject(blaulicht2[playerid]);
	    	DestroyObject(blaulicht3[playerid]);
            GameTextForPlayer(playerid,"~r~Blaulicht Deaktiviert",2000,3);
            SetPVarInt(playerid,"SireneAn",0);
            return 1;
        }
        DestroyObject(blaulicht[playerid]);
		new Float:x,Float:y,Float:z;
		GetPlayerPos(playerid,x,y,z);
        blaulicht[playerid] = CreateObject(19797,0.0,0.0,0.0,0.0,0.0,0.0);
        blaulicht2[playerid] = CreateObject(19797,0.0,0.0,0.0,0.0,0.0,0.0);
        blaulicht3[playerid] = CreateObject(19797,0.0,0.0,0.0,0.0,0.0,0.0);
        AttachObjectToVehicle(blaulicht[playerid],vID,0.0,0.35,0.65,0.0,0.0,180.0);
        AttachObjectToVehicle(blaulicht2[playerid],vID,0.5,-1.35,0.40,0.0,0.0,0.0);
        AttachObjectToVehicle(blaulicht3[playerid],vID,-0.5,-1.35,0.40,0.0,180.0,0.0);
        GameTextForPlayer(playerid,"~g~Blaulicht Aktiviert",2000,3);
        SetPVarInt(playerid,"SireneAn",1);
        return 1;
    }
    if(GetVehicleModel(vID) == 560)
    {
        if(GetPVarInt(playerid,"SireneAn") == 1)
        {
            DestroyObject(blaulicht[playerid]);
	    	DestroyObject(blaulicht2[playerid]);
	    	DestroyObject(blaulicht3[playerid]);
            GameTextForPlayer(playerid,"~r~Blaulicht Deaktiviert",2000,3);
            SetPVarInt(playerid,"SireneAn",0);
            return 1;
        }
        DestroyObject(blaulicht[playerid]);
		new Float:x,Float:y,Float:z;
		GetPlayerPos(playerid,x,y,z);
        blaulicht[playerid] = CreateObject(19797,0.0,0.0,0.0,0.0,0.0,0.0);
        blaulicht2[playerid] = CreateObject(19797,0.0,0.0,0.0,0.0,0.0,0.0);
        blaulicht3[playerid] = CreateObject(19797,0.0,0.0,0.0,0.0,0.0,0.0);
        AttachObjectToVehicle(blaulicht[playerid],vID,0.0,0.35,0.65,0.0,0.0,180.0);
        AttachObjectToVehicle(blaulicht2[playerid],vID,0.5,-1.35,0.40,0.0,0.0,0.0);
        AttachObjectToVehicle(blaulicht3[playerid],vID,-0.5,-1.35,0.40,0.0,180.0,0.0);
        GameTextForPlayer(playerid,"~g~Blaulicht Aktiviert",2000,3);
        SetPVarInt(playerid,"SireneAn",1);
    }
	return 1;
}
my Error:

Код:
if(GetVehicleModel(vID) != 426 | 560)return SendClientMessage(playerid,COLOR_RED,"Du sitzt in keinem PD Premier/Sultan/Cheetah/Securicar");
Reply
#2

please replace | with ||

pawn Код:
if(GetVehicleModel(vID) != 426 || 560)return SendClientMessage(playerid,COLOR_RED,"Du sitzt in keinem PD Premier/Sultan/Cheetah/Securicar");
Reply
#3

Quote:
Originally Posted by std
Посмотреть сообщение
please replace | with ||

pawn Код:
if(GetVehicleModel(vID) != 426 || 560)return SendClientMessage(playerid,COLOR_RED,"Du sitzt in keinem PD Premier/Sultan/Cheetah/Securicar");
i tried that already, wait i'm gonna try it again
Reply
#4

Quote:
Originally Posted by std
Посмотреть сообщение
please replace | with ||

pawn Код:
if(GetVehicleModel(vID) != 426 || 560)return SendClientMessage(playerid,COLOR_RED,"Du sitzt in keinem PD Premier/Sultan/Cheetah/Securicar");
Didn't work
Reply
#5

Try adding a space before return so it's ) return and not )return
Reply
#6

Quote:
Originally Posted by std
Посмотреть сообщение
Try adding a space before return so it's ) return and not )return
That doesn't make an difference. Because an Space doesn't do anything.
And it didn't work
Reply
#7

Код:
new
	a = 426,
	b = 560;
Код:
if(GetVehicleModel(vID) a == 426 && b != 426)return SendClientMessage(playerid,COLOR_RED,"Du sitzt in keinem PD Premier/Sultan/Cheetah/Securicar");
this one?
Reply
#8

There's a simple way to deal with it. You can create an array of siren-only vehicles and check if it is in the list.
On my server, I used to check whether some skin I chose is faction only. That's how it looked like:

Код:
new DoCSkins[] =
{
	70, 71, 74, 280, 281, 282, 288, 284, 285, 283, 265, 266, 267, 274, 275, 276, 277, 278, 300,
	301, 302, 306, 307, 308, 309, 310, 311, 279
};

...

stock IsDoCSkin(id)
{
	for(new i = 0; i < sizeof(DoCSkins); i++)
	{
	    if(id == DoCSkins[i]) return 1;
	}
	return 0;
}
The check itself is done like that in my case:

Код:
if(IsDoCSkin(modelid))
{
   //Do your actions here
}
Reestablish the same structure for the checks you need, and it'll be fine.

P.S. This array is defined globally, don't initialise it in some functions or whatever.
P.P.S. imo this approach is comfortable since it simply requires you to add newly picked vehicles/skins/whatever you use it with into the array to then do the same check which requires no changes in its code.
Reply
#9

Quote:
Originally Posted by Maxandmov
Посмотреть сообщение
There's a simple way to deal with it. You can create an array of siren-only vehicles and check if it is in the list.
On my server, I used to check whether some skin I chose is faction only. That's how it looked like:

Код:
new DoCSkins[] =
{
	70, 71, 74, 280, 281, 282, 288, 284, 285, 283, 265, 266, 267, 274, 275, 276, 277, 278, 300,
	301, 302, 306, 307, 308, 309, 310, 311, 279
};

...

stock IsDoCSkin(id)
{
	for(new i = 0; i < sizeof(DoCSkins); i++)
	{
	    if(id == DoCSkins[i]) return 1;
	}
	return 0;
}
The check itself is done like that in my case:

Код:
if(IsDoCSkin(modelid))
{
   //Do your actions here
}
Reestablish the same structure for the checks you need, and it'll be fine.

P.S. This array is defined globally, don't initialise it in some functions or whatever.
P.P.S. imo this approach is comfortable since it simply requires you to add newly picked vehicles/skins/whatever you use it with into the array to then do the same check which requires no changes in its code.
I did it this way now:

Код:
IsAUndercoverVehicle(vehicleid)
{
	new vModel = GetVehicleModel(vehicleid);
    for(new i = 0; i < sizeof(UCAutos); i++)
    {
    	if(vModel == UCAutos[i]) return true;
	}
	return false;
}

Код:
if(!IsAUndercoverVehicle(vID))return SendClientMessage(playerid,COLOR_RED,"Du sitzt in keinem PD Premier/Sultan/Cheetah/Securicar");
Код:
new UCAutos[] = {
	428,
	415,
	560,
	426
};
Thanks, it works now
Reply
#10

@ImTobi, you're welcome.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)