[HELP]OnVehicleDeath Message doesn't send -
Lilcuete - 08.07.2010
Well my problem is that when ever my owned vehicle explodes it is supposed to send a message lets says i have 5 insurance and my car explodes it is supposed to say EX:"You now have 4 insurance left",but sometimes it does and sometimes it doesnt only sends it to id 0 please tell me whats wrong or help me fix this code.
Код:
public OnVehicleDeath(vehicleid)
{
foreach (Player, i)
{
new str[256];
new plname[MAX_PLAYER_NAME];
GetPlayerName(i, plname, sizeof(plname));
new string[64];
if(strcmp(plname, VehicleInfo[vehicleid][vOwner], true) == 0)
{
if(VehicleInfo[vehicleid][vOwned])
{
if(VehicleInfo[vehicleid][vInsurances] >= 1)
{
VehicleInfo[vehicleid][vInsurances]--;
VehicleInfo[vehicleid][vScratch] += 1;
new file[256];
format(file, sizeof(file), "Vehicles/Vehicles/%s.%s.cfg", plname, VehicleNames[GetVehicleModel(vehicleid)-400]);
if(dini_Exists(file))
{
dini_IntSet(file, "Scratches", VehicleInfo[vehicleid][vScratch]);
dini_IntSet(file, "Insurances", VehicleInfo[vehicleid][vInsurances]);
}
DestroyVehicle(vehicleid);
SetVehicleToRespawn(vehicleid);
format(string, sizeof(string), "You have %d insurance left.", VehicleInfo[vehicleid][vInsurances]);
SendClientMessage(i, COLOR_LIGHTRED, string);
format(string, sizeof(string), "You have now %d Scratches in your car.", VehicleInfo[vehicleid][vScratch]);
SendClientMessage(i, COLOR_LIGHTRED, string);
return 1;
}
else
{
if(strfind(plname, VehicleInfo[vehicleid][vOwner], true) == 0)
{
format(string, sizeof(string), "You have 0 insurance left and now your car has been destroyed.");
SendClientMessage(i, COLOR_LIGHTRED, string);
new plname[MAX_PLAYER_NAME];
GetPlayerName(i, plname, sizeof(plname));
format(string, sizeof(string), "Vehicles/Vehicles/%s.%s.cfg", plname, VehicleNames[GetVehicleModel(vehicleid)-400]);
new str[256];
format(str, sizeof(str), "%s.%s.cfg", plname, VehicleNames[GetVehicleModel(vehicleid)-400]);
if(strfind(str, PlayerVehicle[i][pVeh1], true) == 0)
{
DestroyVehicle(vehicleid);
fremove(string);
strmid(PlayerVehicle[i][pVeh1], "None", 0, strlen("None"), 255);
return 1;
}
else if(strfind(str, PlayerVehicle[i][pVeh2], true) == 0)
{
DestroyVehicle(vehicleid);
fremove(string);
strmid(PlayerVehicle[i][pVeh2], "None", 0, strlen("None"), 255);
return 1;
}
else if(strfind(str, PlayerVehicle[i][pVeh3], true) == 0)
{
DestroyVehicle(vehicleid);
fremove(string);
strmid(PlayerVehicle[i][pVeh3], "None", 0, strlen("None"), 255);
return 1;
}
else if(strfind(str, PlayerVehicle[i][pVeh4], true) == 0)
{
DestroyVehicle(vehicleid);
fremove(string);
strmid(PlayerVehicle[i][pVeh4], "None", 0, strlen("None"), 255);
return 1;
}
else if(strfind(str, PlayerVehicle[i][pVeh5], true) == 0)
{
DestroyVehicle(vehicleid);
fremove(string);
strmid(PlayerVehicle[i][pVeh5], "None", 0, strlen("None"), 255);
return 1;
}
}
}
}
}
}
return 1;
}
Re: [HELP]OnVehicleDeath Message doesn't send -
Lilcuete - 08.07.2010
Or heres a note Foreach(playerid,i); is just like for(new i=0;i<MAX_PLAYERS;i++)
{
Re: [HELP]OnVehicleDeath Message doesn't send -
Lilcuete - 09.07.2010
Oh also its sometimes sends the message when im in the car not out the car.
Re: [HELP]OnVehicleDeath Message doesn't send -
Zezombia - 09.07.2010
Your biggest problem is your using "return" in a loop. That will Break the loop, and we don't want that.
I haven't tested this, but you could give it a shot:
pawn Код:
public OnVehicleDeath(vehicleid)
{
foreach(Player, i)
{
new string[64], str[128], plname[MAX_PLAYER_NAME];
GetPlayerName(i, plname, sizeof(plname));
if(strcmp(plname, VehicleInfo[vehicleid][vOwner], true) != 0) continue;
if(VehicleInfo[vehicleid][vOwned] == 0) continue;
if(VehicleInfo[vehicleid][vInsurances] >= 1)
{
VehicleInfo[vehicleid][vInsurances]--;
VehicleInfo[vehicleid][vScratch] ++;
new file[128];
format(file, sizeof(file), "Vehicles/Vehicles/%s.%s.cfg", plname, VehicleNames[GetVehicleModel(vehicleid)-400]);
if(dini_Exists(file))
{
dini_IntSet(file, "Scratches", VehicleInfo[vehicleid][vScratch]);
dini_IntSet(file, "Insurances", VehicleInfo[vehicleid][vInsurances]);
}
DestroyVehicle(vehicleid);
SetVehicleToRespawn(vehicleid);
format(string, sizeof(string), "You have %d insurance left.", VehicleInfo[vehicleid][vInsurances]);
SendClientMessage(i, COLOR_LIGHTRED, string);
format(string, sizeof(string), "You have now %d Scratches in your car.", VehicleInfo[vehicleid][vScratch]);
SendClientMessage(i, COLOR_LIGHTRED, string);
continue;
}
else
{
if(strfind(plname, VehicleInfo[vehicleid][vOwner], true) != 0) continue;
format(string, sizeof(string), "You have 0 insurance left and now your car has been destroyed.");
SendClientMessage(i, COLOR_LIGHTRED, string);
GetPlayerName(i, plname, sizeof(plname));
format(string, sizeof(string), "Vehicles/Vehicles/%s.%s.cfg", plname, VehicleNames[GetVehicleModel(vehicleid)-400]);
format(str, sizeof(str), "%s.%s.cfg", plname, VehicleNames[GetVehicleModel(vehicleid)-400]);
if(strfind(str, PlayerVehicle[i][pVeh1], true) == 0)
{
DestroyVehicle(vehicleid);
fremove(string);
strmid(PlayerVehicle[i][pVeh1], "None", 0, strlen("None"), 255);
continue;
}
else if(strfind(str, PlayerVehicle[i][pVeh2], true) == 0)
{
DestroyVehicle(vehicleid);
fremove(string);
strmid(PlayerVehicle[i][pVeh2], "None", 0, strlen("None"), 255);
continue;
}
else if(strfind(str, PlayerVehicle[i][pVeh3], true) == 0)
{
DestroyVehicle(vehicleid);
fremove(string);
strmid(PlayerVehicle[i][pVeh3], "None", 0, strlen("None"), 255);
continue;
}
else if(strfind(str, PlayerVehicle[i][pVeh4], true) == 0)
{
DestroyVehicle(vehicleid);
fremove(string);
strmid(PlayerVehicle[i][pVeh4], "None", 0, strlen("None"), 255);
continue;
}
else if(strfind(str, PlayerVehicle[i][pVeh5], true) == 0)
{
DestroyVehicle(vehicleid);
fremove(string);
strmid(PlayerVehicle[i][pVeh5], "None", 0, strlen("None"), 255);
continue;
}
}
}
return 1;
}
Re: [HELP]OnVehicleDeath Message doesn't send -
Lilcuete - 09.07.2010
Ok let me check.
Re: [HELP]OnVehicleDeath Message doesn't send -
Lilcuete - 09.07.2010
No still didn't work.
Re: [HELP]OnVehicleDeath Message doesn't send -
Zezombia - 09.07.2010
What's it doing now?
Re: [HELP]OnVehicleDeath Message doesn't send -
Lilcuete - 09.07.2010
It doesn't send the message when im outside the car.
Re: [HELP]OnVehicleDeath Message doesn't send -
Zezombia - 09.07.2010
That's because your sending the message to "i" instead of to "VehicleInfo[vehicleid][vOwner]".
Re: [HELP]OnVehicleDeath Message doesn't send -
Lilcuete - 09.07.2010
Ok,so it has to send to the owner like this? SendClientMessage(VehicleInfo[vehicleid][vOwner], COLOR_LIGHTRED, string);