/mdc command only works in first sfpd car help
#1

Код:
CMD:mdc(playerid, params[])
{
	if(eingeloggt[playerid] == 0)return SendClientMessage(playerid,COLOR_RED,"Du bist noch nicht eingeloggt.");
	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.");
    for(new i=0; i<sizeof(sfpdcars); i++)
    if(GetPlayerVehicleID(playerid) == sfpdcars[i])
	{
 		return ShowPlayerDialog(playerid,MDCDIALOG1,DIALOG_STYLE_INPUT,"SAPD - Mobile Data Computer","Gebe das MDC Passwort ein.","Okay","Abbrechen");
	}
	else
	{
	    return SendClientMessage(playerid,COLOR_RED,"Du sitzt in keinem PD Fahrzeug.");
	}
	return 1;
}
I have like 10 Police Cars, and only in the first car the mdc works
Reply
#2

Maybe the other cars aren't stored in the sfpdcars array?
Also, try this:
Код:
CMD:mdc(playerid, params[])
{
	if(eingeloggt[playerid] == 0)return SendClientMessage(playerid,COLOR_RED,"Du bist noch nicht eingeloggt.");
	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.");
    for(new i=0; i<sizeof(sfpdcars); i++)
    {
	    if(GetPlayerVehicleID(playerid) == sfpdcars[i])
		{
	 		return ShowPlayerDialog(playerid,MDCDIALOG1,DIALOG_STYLE_INPUT,"SAPD - Mobile Data Computer","Gebe das MDC Passwort ein.","Okay","Abbrechen");
		}
    }
	
    SendClientMessage(playerid,COLOR_RED,"Du sitzt in keinem PD Fahrzeug.");
	
	return 1;
}
Reply
#3

Didn't work sorry.


Yes, the cars are all stored

Код:
sfpdcars[0] = CreateVehicle(597, -1599.9693, 677.0426, -5.4322, 0.0000, 0, 1, -1); //Police Car (SFPD)
	sfpdcars[1] = CreateVehicle(597, -1596.0677, 676.9625, -5.4322, 0.0000, 0, 1, -1); //Police Car (SFPD)
	sfpdcars[2] = CreateVehicle(597, -1596.1678, 692.9227, -5.4322, 0.0000, 0, 1, -1); //Police Car (SFPD)
	sfpdcars[3] = CreateVehicle(597, -1600.1787, 692.9227, -5.4322, 0.0000, 0, 1, -1); //Police Car (SFPD)
	sfpdcars[4] = CreateVehicle(597, -1604.2593, 692.9227, -5.4322, 0.0000, 0, 1, -1); //Police Car (SFPD)
	sfpdcars[5] = CreateVehicle(597, -1608.4194, 692.9227, -5.4322, 0.0000, 0, 1, -1); //Police Car (SFPD)
	sfpdcars[6] = CreateVehicle(597, -1612.4881, 692.9227, -5.4322, 0.0000, 0, 1, -1); //Police Car (SFPD)
	sfpdcars[7] = CreateVehicle(597, -1616.6889, 692.9227, -5.4322, 0.0000, 0, 1, -1); //Police Car (SFPD)
	for(new i=0; i<sizeof(sfpdcars); i++)
	{
	    SetVehicleNumberPlate(sfpdcars[i],"SFPD");
	}
Reply
#4

Remove the else and put a break; inside the if

Because the loop starts at 0 and if you are in the second or third or any other car, the id of the vehicle won't be equal with sfpdcar[i] which will be sfpdcar[0] first of the time so it will move to the else then to the return which you added and then stop the loop if I am not wrong

you can add another if(i == sizeof(sfpdcar) then throw the error message because the loop reached the end without displaying the mdc
Reply
#5

This is your problem:
PHP код:
<sizeof(sfpdcars); 
You are treating sfpdcars as a string.
What you want to do is this:

PHP код:
for(new i=09i++) 
Reply
#6

Quote:
Originally Posted by jasperschellekens
Посмотреть сообщение
This is your problem:
PHP код:
<sizeof(sfpdcars); 
You are treating sfpdcars as a string.
What you want to do is this:

PHP код:
for(new i=09i++) 
but
PHP код:
<sizeof(sfpdcars); 
is still valid, read my reply above.
Reply
#7

It's now working, but i can't output an error, because then it doesn't work anymore

Код:
CMD:mdc(playerid, params[])
{
	if(eingeloggt[playerid] == 0)return SendClientMessage(playerid,COLOR_RED,"Du bist noch nicht eingeloggt.");
	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.");
        for(new i=0; i <sizeof(sfpdcars); i++)
        {
            if(!IsPlayerInAnyVehicle(playerid))continue;
     	    if(GetPlayerVehicleID(playerid) != sfpdcars[i])continue;
    	    if(i == sizeof(sfpdcars))continue;
    	    ShowPlayerDialog(playerid,MDCDIALOG1,DIALOG_STYLE_INPUT,"SAPD - Mobile Data Computer","Gebe das MDC Passwort ein.","Okay","Abbrechen");
        }
	return 1;
}
Reply
#8

You could also write a function like

Код:
IsAPoliceVehicle(vehicleid)
{
	for(new i = 0; i < sizeof(sfpdcars); i++)
	{
		if(vehicleid == sfpdcars[i]) return true;
	}
	return false;
}
and then check with

Код:
if(IsAPoliceVehicle(GetPlayerVehicleID(playerid)))
{
    ShowPlayerDialog(playerid,MDCDIALOG1,DIALOG_STYLE_INPUT,"SAPD - Mobile Data Computer","Gebe das MDC Passwort ein.","Okay","Abbrechen");
}
else
{
    SendClientMessage(playerid,COLOR_RED,"Du sitzt in keinem PD Fahrzeug.");
}
Reply
#9

Quote:
Originally Posted by Macronix
Посмотреть сообщение
You could also write a function like

Код:
IsAPoliceVehicle(vehicleid)
{
	for(new i = 0; i < sizeof(sfpdcars); i++)
	{
		if(vehicleid == sfpdcars[i]) return true;
	}
	return false;
}
and then check with

Код:
if(IsAPoliceVehicle(GetPlayerVehicleID(playerid)))
{
    ShowPlayerDialog(playerid,MDCDIALOG1,DIALOG_STYLE_INPUT,"SAPD - Mobile Data Computer","Gebe das MDC Passwort ein.","Okay","Abbrechen");
}
else
{
    SendClientMessage(playerid,COLOR_RED,"Du sitzt in keinem PD Fahrzeug.");
}
That worked! Thanks so much! REP+
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)