Jump to content
  • 0

Iter_Remove


TheGodfather

Question

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;
}

Link to comment
Share on other sites

6 answers to this question

Recommended Posts

  • 0
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;
}

Link to comment
Share on other sites

  • 0
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

Link to comment
Share on other sites

  • 0

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

Link to comment
Share on other sites

  • 0
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

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • 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.