CMD:spawncar(playerid, params[]) { if(playerVariables[playerid][pAdminLevel] >= 1) { if(!isnull(params)) { new carid = strval(params), Float: carSpawnPos[4], // 3 for the usual dimensions, +1 for the rotation/angle. messageString[64]; new message2[64]; if(carid < 400 || carid > 611) return SendClientMessage(playerid, COLOR_WHITE, "Valid car IDs start at 400, and end at 611."); if(systemVariables[vehicleCounts][0] + systemVariables[vehicleCounts][1] + systemVariables[vehicleCounts][2] < MAX_VEHICLES) { GetPlayerPos(playerid, carSpawnPos[0], carSpawnPos[1], carSpawnPos[2]); GetPlayerFacingAngle(playerid, carSpawnPos[3]); AdminSpawnedVehicles[vehCount] = CreateVehicle(carid, carSpawnPos[0], carSpawnPos[1], carSpawnPos[2], carSpawnPos[3], -1, -1, -1); systemVariables[vehicleCounts][2]++; SetVehicleNumberPlate(AdminSpawnedVehicles[vehCount], "ADMCAR"); LinkVehicleToInterior(AdminSpawnedVehicles[vehCount], GetPlayerInterior(playerid)); SetVehicleVirtualWorld(AdminSpawnedVehicles[vehCount], GetPlayerVirtualWorld(playerid)); PutPlayerInVehicle(playerid, AdminSpawnedVehicles[vehCount], 0); switch(carid) { case 427, 428, 432, 601, 528: SetVehicleHealth(AdminSpawnedVehicles[vehCount], 5000.0); } format(messageString, sizeof(messageString), "You have spawned a %s (vehicle ID %d).", VehicleNames[carid - 400], AdminSpawnedVehicles[vehCount]); SendClientMessage(playerid, COLOR_WHITE, messageString); format(message2, sizeof(message2), "AdmCmd: %s has used /spawncar.",GetName(playerid)); submitToHelpersAndAdmins(message2, COLOR_HOTORANGE); vehCount++; } else { SendClientMessage(playerid, COLOR_GREY, "(error) 01x08"); printf("ERROR: Vehicle limit reached (MODEL %d, MAXIMUM %d, TYPE ADMIN) [01x08]", carid, MAX_VEHICLES); } } else { return SendClientMessage(playerid, COLOR_GREY, SYNTAX_MESSAGE"/spawncar [vehicleid]"); } } else return SendClientMessage(playerid, COLOR_WHITE, AdminOnly); return 1; }
CMD:vrespawn(playerid, params[]) { new carid2, deez22[64]; if(sscanf(params, "d", carid2)) return SendClientMessage(playerid, COLOR_GREY, SYNTAX_MESSAGE"/vrespawn [car id]"); if(playerVariables[playerid][pAdminLevel] >= 1) { for(new i = 0; i < MAX_VEHICLES; i++) { new carid3 = AdminSpawnedVehicles[i]; if(carid2 == carid3) { format(szMessage, sizeof(szMessage), "You have successfully despawned vehicle %d.", AdminSpawnedVehicles[i]); SendClientMessage(playerid, COLOR_WHITE, szMessage); DestroyVehicle(carid2); AdminSpawnedVehicles[i]--; systemVariables[vehicleCounts][2]--; format(deez22, sizeof(deez22), "AdmCmd: %s has used /spawncar.",GetName(playerid)); submitToHelpersAndAdmins(deez22, COLOR_HOTORANGE); return 1; } else return SendClientMessage(playerid, COLOR_GREY, "The car ID you have entered is invalid."); } } else return SendClientMessage(playerid, COLOR_WHITE, AdminOnly); return 1; }
Use y_iterate.
https://sampforum.blast.hk/showthread.php?tid=571159 You basically can make a list with it where you can add or remove stuff to it. |
Would you mind explaining how? I have no idea how this works.
|
new
Iterator:SpawnedVehicles<MAX_VEHICLES>;
Iter_Init(SpawnedVehicles); //this in ongamemodeinit.
Am on mobile do that's hard..
First do this to create the iterator: PHP код:
Again, i am on mobile so i can't provide a full working example. |
#include <YSI_Data\y_iterate> //Include the library.
new Iterator:AdminSpawnedVehicles<MAX_VEHICLES>; //Create the iterator.
CMD:spawncar(playerid, params[])
{
if(playerVariables[playerid][pAdminLevel] >= 1)
{
if(!isnull(params))
{
new
carid = strval(params),
Float: carSpawnPos[4], // 3 for the usual dimensions, +1 for the rotation/angle.
messageString[64];
new message2[64];
if(carid < 400 || carid > 611)
return SendClientMessage(playerid, COLOR_WHITE, "Valid car IDs start at 400, and end at 611.");
if(systemVariables[vehicleCounts][0] + systemVariables[vehicleCounts][1] + systemVariables[vehicleCounts][2] < MAX_VEHICLES) {
GetPlayerPos(playerid, carSpawnPos[0], carSpawnPos[1], carSpawnPos[2]);
GetPlayerFacingAngle(playerid, carSpawnPos[3]);
new vehid = CreateVehicle(carid, carSpawnPos[0], carSpawnPos[1], carSpawnPos[2], carSpawnPos[3], -1, -1, -1); //Create the car and save its ID.
Iter_Add(AdminSpawnedVehicles, vehid); //Store the ID in the iterator.
SetVehicleNumberPlate(vehid, "ADMCAR");
LinkVehicleToInterior(vehid, GetPlayerInterior(playerid));
SetVehicleVirtualWorld(vehid, GetPlayerVirtualWorld(playerid));
PutPlayerInVehicle(playerid, vehid, 0);
switch(carid) {
case 427, 428, 432, 601, 528: SetVehicleHealth(vehid, 5000.0);
}
format(messageString, sizeof(messageString), "You have spawned a %s (vehicle ID %d).", VehicleNames[carid - 400], AdminSpawnedVehicles[vehCount]);
SendClientMessage(playerid, COLOR_WHITE, messageString);
format(message2, sizeof(message2), "AdmCmd: %s has used /spawncar.",GetName(playerid));
submitToHelpersAndAdmins(message2, COLOR_HOTORANGE);
vehCount++;
}
else
{
SendClientMessage(playerid, COLOR_GREY, "(error) 01x08");
printf("ERROR: Vehicle limit reached (MODEL %d, MAXIMUM %d, TYPE ADMIN) [01x08]", carid, MAX_VEHICLES);
}
}
else {
return SendClientMessage(playerid, COLOR_GREY, SYNTAX_MESSAGE"/spawncar [vehicleid]");
}
}
else return SendClientMessage(playerid, COLOR_WHITE, AdminOnly);
return 1;
}
CMD:vrespawn(playerid, params[]) {
new carid2, deez22[64];
if(sscanf(params, "d", carid2)) return SendClientMessage(playerid, COLOR_GREY, SYNTAX_MESSAGE"/vrespawn [car id]");
if(playerVariables[playerid][pAdminLevel] >= 1)
{
if(Iter_Contains(AdminSpawnedVehicles, carid2)) //If the ID is in the list.
{
format(szMessage, sizeof(szMessage), "You have successfully despawned vehicle %d.", AdminSpawnedVehicles[i]);
SendClientMessage(playerid, COLOR_WHITE, szMessage);
DestroyVehicle(carid2);
AdminSpawnedVehicles[i]--;
systemVariables[vehicleCounts][2]--;
format(deez22, sizeof(deez22), "AdmCmd: %s has used /spawncar.",GetName(playerid));
submitToHelpersAndAdmins(deez22, COLOR_HOTORANGE);
Iter_Remove(AdminSpawnedVehicles, carid2); //Remove the ID from list once the car is destroyed.
return 1;
}
else return SendClientMessage(playerid, COLOR_GREY, "The car ID you have entered is invalid.");
}
else return SendClientMessage(playerid, COLOR_WHITE, AdminOnly);
return 1;
}