Jump to content
Autentificarea cu Google și Facebook nu mai este disponibilă. ×

Question

Posted

Salut, am o comanda de /spawncar si una de /despawncars, cand spawnez 2 masini de exemplu, o despawneaza pe prima dar pe a doua nu cand dau /despawncars iar in loguri am eroarea asta:

[19:24:22] [debug]
[19:24:22] [debug] Parameter count corrections:
[19:24:22] [debug]
[19:24:22] [debug] The 1st mangled argments (e.g. `<1073741823 arguments>`) below should read `<2 arguments>`
[19:24:22] [debug]
[19:24:22] [debug] Run time error 4: "Array index out of bounds"
[19:24:22] [debug] AMX backtrace:
[19:24:22] [debug] #0 0038d318 in ?? (0, 23972552, 0) from B-HOOD.amx
[19:24:22] [debug] #1 000552f4 in ?? (0, 23972504, 0) from B-HOOD.amx
[19:24:22] [debug] #2 00057e4c in ?? (0, 23972504, 0, 0, 0, 0, 8, 0, 23972504, 0, ... <1073741813 arguments>) from B-HOOD.amx
[19:24:22] [debug] #3 00022180 in public OnPlayerCommandText (0, 23972504) from B-HOOD.amx

YCMD:spawncar(playerid, params[], help) {
    if(PlayerInfo[playerid][pAdmin] < 1) return SCMM(playerid, -1, AdminOnly);
    new model, color1, color2;
    if(sscanf(params, "iii", model, color1, color2)) return SCMM(playerid,COLOR_GREY, "Syntax: {FFFFFF}/spawncar <Model> <color1> <color2>");
    if(model < 400 || model > 611) return SCMM(playerid,-1, "Invalid car ID.");
    new Float:X,Float:Y,Float:Z;
    GetPlayerPos(playerid, X,Y,Z);
    new carid = CreateVehicleEx(model, X,Y,Z, 0.0, color1, color2, -1, 0);
    Gas[carid] = 100;
    SetVehicleNumberPlate(carid, "AdmCar");
    Iter_Add(SpawnedCars, carid);
    LinkVehicleToInterior(carid, GetPlayerInterior(playerid));
    SetVehicleVirtualWorld(carid, GetPlayerVirtualWorld(playerid));
    PutPlayerInVehicleEx(playerid, carid, 0);
    new idcar = GetPlayerVehicleID(playerid), vehicle = GetVehicleModel(idcar) - 400;
    SCMf(playerid, COLOR_LIGHTGOLD, "[/spawncar] {FFFFFF}You have spawned one %s, car model: %d and car ID: %d.", aVehicleNames[vehicle], model, carid);
    return true;
}

YCMD:despawncars(playerid, params[], help) {
    if(PlayerInfo[playerid][pAdmin] < 1) return SCMM(playerid, -1, AdminOnly);
    foreach(new i : SpawnedCars)
        Iter_Remove(SpawnedCars, i), DestroyVehicle(i), SCMf(playerid, -1, "%d", i);
    new string[100];
    format(string, sizeof(string), "[/despawncars] {FFFFFF}Admin %s destroyed all spawned cars.", GetName(playerid));
    if(GetPVarInt(playerid, "Cover") == 0) SendAdminMessage(COLOR_LIGHTGOLD, string, 1);
    return true;
}

6 answers to this question

Recommended Posts

  • 0
Posted
23 minutes ago, TheGodfather said:

up

YCMD:despawncars(playerid, params[], help) {
    if(PlayerInfo[playerid][pAdmin] < 1) return SCMM(playerid, -1, AdminOnly);
    foreach(new i : SpawnedCars) {
        DestroyVehicle(i);
        Iter_Remove(SpawnedCars, i);
        SCMf(playerid, -1, "%d", i);
    }
   
    new string[100];
    format(string, sizeof(string), "[/despawncars] {FFFFFF}Admin %s destroyed all spawned cars.", GetName(playerid));
    if(GetPVarInt(playerid, "Cover") == 0) SendAdminMessage(COLOR_LIGHTGOLD, string, 1);
    return true;
}

  • 0
Posted
3 minutes ago, iSorin[] said:

YCMD:despawncars(playerid, params[], help) {
    if(PlayerInfo[playerid][pAdmin] < 1) return SCMM(playerid, -1, AdminOnly);
    foreach(new i : SpawnedCars) {
        DestroyVehicle(i);
        Iter_Remove(SpawnedCars, i);
        SCMf(playerid, -1, "%d", i);
    }
   
    new string[100];
    format(string, sizeof(string), "[/despawncars] {FFFFFF}Admin %s destroyed all spawned cars.", GetName(playerid));
    if(GetPVarInt(playerid, "Cover") == 0) SendAdminMessage(COLOR_LIGHTGOLD, string, 1);
    return true;
}

Nu merge, tot primesc aceeasi eroare si daca am 2 sau mai multe masini spawnate cu /spawncar despawneaza doar una

  • 0
Posted
Just now, TheGodfather said:

Nu merge, tot primesc aceeasi eroare si daca am 2 sau mai multe masini spawnate cu /spawncar despawneaza doar una

add pe discord qSorin_#1245

  • 0
Posted

Salut @TheGodfather,

In cazul in care nu ai rezolvat, desi ma indoiesc. Sistemul ar trebui sa functioneze in felul urmator:

new 
	Iterator: serverVehicles<MAX_VEHICLES>;

YCMD:spawncar(playerid, params[], help)
{
    new 
        carid = CreateVehicle(etc.....);
    
    Iter_Add(serverVehicles, carid);
    
    //etc..
}
      
YCMD:despawncars(playerid, params[], help)
{
    if(!Iter_Count(serverVehicles)) 
    	return SendClientMessage(playerid, -1, "No cars to despawn!");
    
    new 
      	String[100];
    
    format(String, sizeof String, "%s despawned %d vehicles.", GetName(playerid), Iter_Count(serverVehicles));
    SendClientMessageToAll(playerid, -1, String) // exemplu
      
    foreach(new i : serverVehicles) DestroyVehicle(i);
    Iter_Clear(serverVehicles);
      
    //etc..
}

Iti recomand ' Iter_Clear ', in loc de ' Iter_Remove '. Ce ai tu mai sus, pare ok, ce ti-am dat eu, e doar un exemplu, de la care poti reface sistemul.

 

Daca te-am ajutat =>

spacer.png

  • 0
Posted
31 minutes ago, shane said:

Salut @TheGodfather,

In cazul in care nu ai rezolvat, desi ma indoiesc. Sistemul ar trebui sa functioneze in felul urmator:

new 
	Iterator: serverVehicles<MAX_VEHICLES>;

YCMD:spawncar(playerid, params[], help)
{
    new 
        carid = CreateVehicle(etc.....);
    
    Iter_Add(serverVehicles, carid);
    
    //etc..
}
      
YCMD:despawncars(playerid, params[], help)
{
    if(!Iter_Count(serverVehicles)) 
    	return SendClientMessage(playerid, -1, "No cars to despawn!");
    
    new 
      	String[100];
    
    format(String, sizeof String, "%s despawned %d vehicles.", GetName(playerid), Iter_Count(serverVehicles));
    SendClientMessageToAll(playerid, -1, String) // exemplu
      
    foreach(new i : serverVehicles) DestroyVehicle(i);
    Iter_Clear(serverVehicles);
      
    //etc..
}

Iti recomand ' Iter_Clear ', in loc de ' Iter_Remove '. Ce ai tu mai sus, pare ok, ce ti-am dat eu, e doar un exemplu, de la care poti reface sistemul.

 

Salut, multumesc de reply. Am rezolvat, in loc de Iter_Remove am folosit Iter_SafeRemove. Am cautat pe internet cum functioneaza functiile de la iteratori dar nu am gasit nimic... altfel banuiesc ca nu eram nevoit sa fac postul acesta :D

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. For more details you can also review our Terms of Use and Privacy Policy.