SA-MP Forums Archive
/mdc command only works in first sfpd car help - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: /mdc command only works in first sfpd car help (/showthread.php?tid=652351)



/mdc command only works in first sfpd car help - ImTobi - 08.04.2018

Код:
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


Re: /mdc command only works in first sfpd car help - zookyy - 08.04.2018

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;
}



Re: /mdc command only works in first sfpd car help - ImTobi - 09.04.2018

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");
	}



Re: /mdc command only works in first sfpd car help - AndreiWow - 09.04.2018

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


Re: /mdc command only works in first sfpd car help - jasperschellekens - 09.04.2018

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++) 



Re: /mdc command only works in first sfpd car help - AndreiWow - 09.04.2018

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.


Re: /mdc command only works in first sfpd car help - ImTobi - 09.04.2018

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;
}



Re: /mdc command only works in first sfpd car help - Macronix - 09.04.2018

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.");
}



Re: /mdc command only works in first sfpd car help - ImTobi - 09.04.2018

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+