#1

Hi all
I not good at loops so i need help with that problem:
when i use the command /destroycars to the destroy the vehicle i created by command /veh the SendClientMessage is doubling (of course because of the wrong loop)
after /destroycars also i cant spawn anymore vehicles through /veh
thanks in advance




/destroycars command
Код:
CMD:destroycars(playerid, params[])
{
	if(PlayerInfo[playerid][pAdmin] < 2) {
        SendClientMessage(playerid, COLOR_GREY, "You are not authorized to use that command!");
        return 1;
    	}
	   	for(new i = 0; i < sizeof(cVeh); i++) {
        if(cVeh[i] != INVALID_VEHICLE_ID) {
            DestroyVehicle(cVeh[i]);
            cVeh[i] = INVALID_VEHICLE_ID;
			new string[128];
			format(string, sizeof(string), "{FF0000}[Admin Warn]{FF6347} %s has destroyed all Created vehicles (/veh)icle.", NORPN(playerid));
			SendAdminMessage(COLOR_DARKRED, 1, string);	
        }
    }
    SendClientMessage(playerid, COLOR_GREY, "   Created vehicles destroyed!");
    return 1;
}
/veh command

Код:
CMD:veh(playerid, params[])
{
	new id, Float:pos[4], col[2], stringlog[128];
   	if(!IsPlayerLoggedIn(playerid)) return SendClientMessage(playerid, COLOR_GREY, "You need to login first before using any command.");
	if(PlayerInfo[playerid][pAdmin] < 1) return SendClientMessage(playerid, COLOR_GREY, "You are not authorized to use this command.");
//  if(!aDuty[playerid]) return SendClientMessage(playerid, COLOR_GREY, "You are not on admin duty.");
	
	if(sscanf(params, "iii", id, col[0], col[1])) return SendClientMessage(playerid, COLOR_WHITE, "USAGE: /veh [model ID] [color 1] [color 2]");
	if(id < 400 || id > 611) return SendClientMessage(playerid, COLOR_GREY, "Vehicles are between 400 and 611.");
	GetPlayerPos(playerid, pos[0], pos[1], pos[2]);
	GetPlayerFacingAngle(playerid, pos[3]);
	for(new i=0; i<MAX_CUSTOM_VEHICLES; i++)
	{
	    if(!cVeh[i])
	    {
			cVeh[i] = CreateVehicle(id, pos[0], pos[1], pos[2], pos[3], col[0], col[1], 12000);
			LinkVehicleToInterior(cVeh[i], GetPlayerInterior(playerid));
			i = MAX_CUSTOM_VEHICLES;
		}
	}
	new string[128];
	format(string, sizeof(string), "{FF0000}[Admin Warn]{FF6347} %s has spawned a (/veh)icle model %d.", NORPN(playerid), id);
	SendAdminMessage(COLOR_DARKRED, 1, string);
	// veh Log
	Log("logs/veh.log", stringlog);
	return 1;
}
Reply
#2

in your /destroycars cmd
just take the message out of the loop.
just do that:
PHP код:
            new string[128];
            
format(stringsizeof(string), "{FF0000}[Admin Warn]{FF6347} %s has destroyed all Created vehicles (/veh)icle."NORPN(playerid));
            
SendAdminMessage(COLOR_DARKRED1string); 
after the loop's done.
Never use messages in a loop unless you want to spam something :P

the /destroycars cmd should look like this,
PHP код:
CMD:destroycars(playeridparams[])
{
    if(
PlayerInfo[playerid][pAdmin] < 2) return SendClientMessage(playeridCOLOR_GREY"You are not authorized to use that command!");
    new 
string[103];
    for(new 
0sizeof(cVeh); i++)
    {
        if(
cVeh[i] == INVALID_VEHICLE_ID) continue;
        
DestroyVehicle(cVeh[i]);
        
cVeh[i] = -1;
    }
    
format(stringsizeof(string), "{FF0000}[Admin Warn]{FF6347} %s has destroyed all Created vehicles (/veh)icle."NORPN(playerid));
    
SendAdminMessage(COLOR_DARKRED1string);
    
SendClientMessage(playeridCOLOR_GREY"   Created vehicles destroyed!");
    return 
1;

Reply
#3

Add "native IsValidVehicle(vehicleid)" to the top of your script. Then in the loop add: if(!IsValidVehicle(i))return 1;

Also, take the admin message from the loop and place it either before or after it.

Sorry if this is incorrect, but this respawns my vehicle when needed. I'm also drunk, and on the iPad xD

Happy new year guys!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)