SA-MP Forums Archive
Problem with /respawncars - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Problem with /respawncars (/showthread.php?tid=146100)



Problem with /respawncars - sobolanux - 05.05.2010

Hi there. I`ve made a little command to respawn the all the unused vehicles

Code:
Код:
dcmd_respawncars(playerid, params[])
{
	#pragma unused params
	new pname[MAX_PLAYER_NAME], file[128];
	GetPlayerName(playerid, pname, sizeof(pname));
	format(file, sizeof(file), "\\Users\\%s.ini", pname);
	if(dini_Int(file, "level") >= 4)
	{
		for(new i=0; i <= MAX_VEHICLES; i++)
		{
		  for(new a=0; a < MAX_PLAYERS; a++)
		  {
				if(!IsPlayerInVehicle(a, i))
				{
					SetVehicleToRespawn(i);
					return 1;
				}
				return 1;
			}
			return 1;
		}
		SendClientMessageToAll(COLOUR_YELLOW, "[ADMIN]: Vehicles respawned by admin!");
		return 1;
	}
	else SendClientMessage(playerid, COLOUR_RED, "You are not allowed to use this command!");
	return 1;
}
The problem is that it doesn`t do anything....


Re: Problem with /respawncars - dice7 - 05.05.2010

pawn Код:
dcmd_respawncars(playerid, params[])
{
    #pragma unused params
    new pname[MAX_PLAYER_NAME], file[128];
    GetPlayerName(playerid, pname, sizeof(pname));
    format(file, sizeof(file), "\\Users\\%s.ini", pname);
    if(dini_Int(file, "level") >= 4)
    {
        for(new i=0; i <= MAX_VEHICLES; i++) for(new a=0; a < MAX_PLAYERS; a++)if(!IsPlayerInVehicle(a, i)) SetVehicleToRespawn(i);
        {
          for(new a=0; a < MAX_PLAYERS; a++)if(!IsPlayerInVehicle(a, i)) SetVehicleToRespawn(i);
          {
                if(!IsPlayerInVehicle(a, i)) SetVehicleToRespawn(i);
                {
                    SetVehicleToRespawn(i);
                }
            }
        }
        SendClientMessageToAll(COLOUR_YELLOW, "[ADMIN]: Vehicles respawned by admin!");
        return 1;
    }
    else SendClientMessage(playerid, COLOUR_RED, "You are not allowed to use this command!");
    return 1;
}
A return breaks the code with no question, so your code stopped at the first iteration (respawning vehicle id 0, which doesn't exist)


Re: Problem with /respawncars - sobolanux - 05.05.2010

Ehm ye now it works , but it respawns all the cars, even the used ones


Re: Problem with /respawncars - dice7 - 05.05.2010

Woops, I pasted the code wrong

pawn Код:
dcmd_respawncars(playerid, params[])
{
    #pragma unused params
    new IsInCar = 0;
    new pname[MAX_PLAYER_NAME], file[128];
    GetPlayerName(playerid, pname, sizeof(pname));
    format(file, sizeof(file), "\\Users\\%s.ini", pname);
    if(dini_Int(file, "level") >= 4)
    {
        for(new i=1; i < MAX_VEHICLES; i++)
        {
          for(new a=0; a < MAX_PLAYERS; a++)
          {
                if(IsPlayerInVehicle(a, i)) IsInCar = 1;
            }
            if (IsInCar == 1) SetVehicleToRespawn(i);
            IsInCar = 0;
        }
        SendClientMessageToAll(COLOUR_YELLOW, "[ADMIN]: Vehicles respawned by admin!");
        return 1;
    }
    else SendClientMessage(playerid, COLOUR_RED, "You are not allowed to use this command!");
    return 1;
}



Re: Problem with /respawncars - sobolanux - 05.05.2010

Ehm, now it respawns only the car I use and the other cars stay where they are xD