Removing unoccupied vehicles
#1

Hello there. I made this little something for my server. When you write /nrg it create a nrg for admins ... anyway I also wanted to make a /destryoveh command to delete all the vehicles created by admins and only those CREATED BY ADMINS ... everything was fine but it also deletes the vehicles occupied and I don't want that ... anyone could check the destroy command and fix that? Thank you.

[What I want]: When I type /destroyveh I want to delete all the unoccupied vehicles made by admins.

pawn Код:
YCMD:nrg(playerid, params[], help)
{
    new aName[MAX_PLAYER_NAME], str[100];
    if (help) return SendClientMessage(playerid, 0x808080FF, "/heal este folosit pentru a da viata unui player, necesita truse de prim ajutor.");
    if(!PlayerInfo[playerid][pAdmin] && !IsPlayerAdmin(playerid)) return SendClientMessage(playerid, COLOR_RED, "Nu esti admin");
    GetPlayerName(playerid, aName, sizeof(aName));
    GetPlayerPos(playerid,PlayerInfo[playerid][pPosx], PlayerInfo[playerid][pPosy], PlayerInfo[playerid][pPosz]);
    gAdminVehID[gVehicleCounter] = CreateVehicle(522, PlayerInfo[playerid][pPosx], PlayerInfo[playerid][pPosy], PlayerInfo[playerid][pPosz], 0, 0,0,60000);
    gVehicleCounter++;
    for (new i = 0; i < MAX_PLAYERS; i++)
    {
        if (IsPlayerConnected(i))
        {
            new zName[MAX_PLAYER_NAME], pFile[256];
            GetPlayerName(i, zName, sizeof(zName));
            format(pFile, sizeof(pFile), "Users\%s.ini", zName);
            if (IsPlayerAdmin(i) || PlayerInfo[i][pAdmin] > 0)
            {
                format(str, sizeof(str), "Adminul %s a creat un NRG personal.", aName);
                SendClientMessage(i, COLOR_RED, str);
            }
        }
    }
    return 1;
}

YCMD:destroyveh(playerid, params[], help)
{
    new aName[MAX_PLAYER_NAME], str[100];
    if (help) return SendClientMessage(playerid, 0x808080FF, "/heal este folosit pentru a da viata unui player, necesita truse de prim ajutor.");
    if(!PlayerInfo[playerid][pAdmin] && !IsPlayerAdmin(playerid)) return SendClientMessage(playerid, COLOR_RED, "Nu esti admin");
    GetPlayerName(playerid, aName, sizeof(aName));

    for(new i; i < gVehicleCounter; i++)
    {
        for (new u = 0; u < MAX_PLAYERS; u++)
            {
                if(!IsPlayerInVehicle(u, gAdminVehID[i]))
                {
                    DestroyVehicle(gAdminVehID[i]);
                }
            }
    }
   
    gVehicleCounter = 0;
   
    for (new i = 0; i < MAX_PLAYERS; i++)
    {
        if (IsPlayerConnected(i))
        {
            new zName[MAX_PLAYER_NAME], pFile[256];
            GetPlayerName(i, zName, sizeof(zName));
            format(pFile, sizeof(pFile), "Users\%s.ini", zName);
            if (IsPlayerAdmin(i) || PlayerInfo[i][pAdmin] > 0)
            {
                format(str, sizeof(str), "Vehiculele create de admini au fost sterse de %s.", aName);
                SendClientMessage(i, COLOR_RED, str);
            }
        }
    }
    return 1;
}
Reply
#2

Bump?
Reply
#3

Bump for the last time ...
Reply
#4

I know that thing have this on my server and dosent delete occupied vehicles, but can u wait till tomoowr until I post that code as am on ipad
Reply
#5

Maybe?
pawn Код:
YCMD:destroyveh(playerid, params[], help)
{
    new aName[MAX_PLAYER_NAME], str[100];
    if (help) return SendClientMessage(playerid, 0x808080FF, "/heal este folosit pentru a da viata unui player, necesita truse de prim ajutor.");
    if(!PlayerInfo[playerid][pAdmin] && !IsPlayerAdmin(playerid)) return SendClientMessage(playerid, COLOR_RED, "Nu esti admin");
    GetPlayerName(playerid, aName, sizeof(aName));

    for(new i = 0; i < gVehicleCounter; i++)
    {
                if(!IsPlayerInVehicle(-1, i))
                {
                    DestroyVehicle(gAdminVehID[i]);
                }
    }
   
    gVehicleCounter = 0;
   
    for (new i = 0; i < MAX_PLAYERS; i++)
    {
        if (IsPlayerConnected(i))
        {
            new zName[MAX_PLAYER_NAME], pFile[256];
            GetPlayerName(i, zName, sizeof(zName));
            format(pFile, sizeof(pFile), "Users\%s.ini", zName);
            if (IsPlayerAdmin(i) || PlayerInfo[i][pAdmin] > 0)
            {
                format(str, sizeof(str), "Vehiculele create de admini au fost sterse de %s.", aName);
                SendClientMessage(i, COLOR_RED, str);
            }
        }
    }
    return 1;
}
Reply
#6

Quote:
Originally Posted by Matess
Посмотреть сообщение
Maybe?
pawn Код:
YCMD:destroyveh(playerid, params[], help)
{
    new aName[MAX_PLAYER_NAME], str[100];
    if (help) return SendClientMessage(playerid, 0x808080FF, "/heal este folosit pentru a da viata unui player, necesita truse de prim ajutor.");
    if(!PlayerInfo[playerid][pAdmin] && !IsPlayerAdmin(playerid)) return SendClientMessage(playerid, COLOR_RED, "Nu esti admin");
    GetPlayerName(playerid, aName, sizeof(aName));

    for(new i = 0; i < gVehicleCounter; i++)
    {
                if(!IsPlayerInVehicle(-1, i))
                {
                    DestroyVehicle(gAdminVehID[i]);
                }
    }
   
    gVehicleCounter = 0;
   
    for (new i = 0; i < MAX_PLAYERS; i++)
    {
        if (IsPlayerConnected(i))
        {
            new zName[MAX_PLAYER_NAME], pFile[256];
            GetPlayerName(i, zName, sizeof(zName));
            format(pFile, sizeof(pFile), "Users\%s.ini", zName);
            if (IsPlayerAdmin(i) || PlayerInfo[i][pAdmin] > 0)
            {
                format(str, sizeof(str), "Vehiculele create de admini au fost sterse de %s.", aName);
                SendClientMessage(i, COLOR_RED, str);
            }
        }
    }
    return 1;
}
Still deleting all the vehicles, even the occupied ones ...
Reply
#7

I really hope this works :S

pawn Код:
YCMD:nrg(playerid, params[], help)
{
    if(help) return SendClientMessage(playerid, 0x808080FF, "/heal este folosit pentru a da viata unui player, necesita truse de prim ajutor.");
    if(!PlayerInfo[playerid][pAdmin] && !IsPlayerAdmin(playerid)) return SendClientMessage(playerid, COLOR_RED, "Nu esti admin");
    new aName[MAX_PLAYER_NAME], str[60], Float:vehangle;
    GetPlayerName(playerid, aName, sizeof(aName));
    GetPlayerPos(playerid, PlayerInfo[playerid][pPosx], PlayerInfo[playerid][pPosy], PlayerInfo[playerid][pPosz]);
    GetPlayerFacingAngle(playerid, vehangle);
    gVehicleCounter++;
    gAdminVehID[gVehicleCounter] = CreateVehicle(522, PlayerInfo[playerid][pPosx], PlayerInfo[playerid][pPosy], PlayerInfo[playerid][pPosz], vehangle, 0, 0, 60000);
    format(str, sizeof(str), "Adminul %s a creat un NRG personal.", aName);
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(!IsPlayerConnected(i)) continue;
        if(!IsPlayerAdmin(i) && !PlayerInfo[i][pAdmin]) continue;
        SendClientMessage(i, COLOR_RED, str);
    }
    return 1;
}

YCMD:destroyveh(playerid, params[], help)
{
    if(help) return SendClientMessage(playerid, 0x808080FF, "/heal este folosit pentru a da viata unui player, necesita truse de prim ajutor.");
    if(!PlayerInfo[playerid][pAdmin] && !IsPlayerAdmin(playerid)) return SendClientMessage(playerid, COLOR_RED, "Nu esti admin");
    new aName[MAX_PLAYER_NAME], str[75];
    GetPlayerName(playerid, aName, sizeof(aName));
    format(str, sizeof(str), "Vehiculele create de admini au fost sterse de %s.", aName);
    new bool:DestroyVeh[MAX_VEHICLES] = true;
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(!IsPlayerConnected(i)) continue;
        if(IsPlayerAdmin(i) || PlayerInfo[i][pAdmin] > 0) SendClientMessage(i, COLOR_RED, str);
        for(new u = 1; u < gVehicleCounter; u++)
        {
            if(!DestroyVeh[gAdminVehID[u]]) continue;
            if(!IsPlayerInVehicle(i, gAdminVehID[u])) DestroyVeh[gAdminVehID[u]] = true;
        }
    }
    new counter = gVehicleCounter;
    for(new v = 1; v < gVehicleCounter; v++)
    {
        if(!DestroyVeh[gAdminVehID[v]])
        {
            if(!IsValidVehicle(gAdminVehID[(v - 1)]))
            {
                gAdminVehID[(v - 1)] = gAdminVehID[v];
                gAdminVehID[v] = INVALID_VEHICLE_ID;
            }
        }
        else
        {
            if(IsValidVehicle(gAdminVehID[v])) DestroyVehicle(gAdminVehID[v]);
            gAdminVehID[v] = INVALID_VEHICLE_ID;
            counter--;
        }
    }
    gVehicleCounter = counter;
    return 1;
}
NOTE: YOU NEED TO ADD THIS UNDER YOUR INCLUDES!!
pawn Код:
native IsValidVehicle(vehicleid);
Example:
pawn Код:
#include <a_samp>
#include <YSI\y_commands>
#include <YSI\y_master>
native IsValidVehicle(vehicleid);
Reply
#8

You can check if a vehicle is valid or not by using GetVehicleModel, it will return 0 if the vehicle is not created.
Reply
#9

I know, but I like using IsValidVehicle, it makes more sense to me
Reply
#10

Quote:
Originally Posted by BenzoAMG
Посмотреть сообщение
I really hope this works :S

pawn Код:
YCMD:nrg(playerid, params[], help)
{
    if(help) return SendClientMessage(playerid, 0x808080FF, "/heal este folosit pentru a da viata unui player, necesita truse de prim ajutor.");
    if(!PlayerInfo[playerid][pAdmin] && !IsPlayerAdmin(playerid)) return SendClientMessage(playerid, COLOR_RED, "Nu esti admin");
    new aName[MAX_PLAYER_NAME], str[60], Float:vehangle;
    GetPlayerName(playerid, aName, sizeof(aName));
    GetPlayerPos(playerid, PlayerInfo[playerid][pPosx], PlayerInfo[playerid][pPosy], PlayerInfo[playerid][pPosz]);
    GetPlayerFacingAngle(playerid, vehangle);
    gVehicleCounter++;
    gAdminVehID[gVehicleCounter] = CreateVehicle(522, PlayerInfo[playerid][pPosx], PlayerInfo[playerid][pPosy], PlayerInfo[playerid][pPosz], vehangle, 0, 0, 60000);
    format(str, sizeof(str), "Adminul %s a creat un NRG personal.", aName);
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(!IsPlayerConnected(i)) continue;
        if(!IsPlayerAdmin(i) && !PlayerInfo[i][pAdmin]) continue;
        SendClientMessage(i, COLOR_RED, str);
    }
    return 1;
}

YCMD:destroyveh(playerid, params[], help)
{
    if(help) return SendClientMessage(playerid, 0x808080FF, "/heal este folosit pentru a da viata unui player, necesita truse de prim ajutor.");
    if(!PlayerInfo[playerid][pAdmin] && !IsPlayerAdmin(playerid)) return SendClientMessage(playerid, COLOR_RED, "Nu esti admin");
    new aName[MAX_PLAYER_NAME], str[75];
    GetPlayerName(playerid, aName, sizeof(aName));
    format(str, sizeof(str), "Vehiculele create de admini au fost sterse de %s.", aName);
    new bool:DestroyVeh[MAX_VEHICLES] = true;
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(!IsPlayerConnected(i)) continue;
        if(IsPlayerAdmin(i) || PlayerInfo[i][pAdmin] > 0) SendClientMessage(i, COLOR_RED, str);
        for(new u = 1; u < gVehicleCounter; u++)
        {
            if(!DestroyVeh[gAdminVehID[u]]) continue;
            if(!IsPlayerInVehicle(i, gAdminVehID[u])) DestroyVeh[gAdminVehID[u]] = true;
        }
    }
    new counter = gVehicleCounter;
    for(new v = 1; v < gVehicleCounter; v++)
    {
        if(!DestroyVeh[gAdminVehID[v]])
        {
            if(!IsValidVehicle(gAdminVehID[(v - 1)]))
            {
                gAdminVehID[(v - 1)] = gAdminVehID[v];
                gAdminVehID[v] = INVALID_VEHICLE_ID;
            }
        }
        else
        {
            if(IsValidVehicle(gAdminVehID[v])) DestroyVehicle(gAdminVehID[v]);
            gAdminVehID[v] = INVALID_VEHICLE_ID;
            counter--;
        }
    }
    gVehicleCounter = counter;
    return 1;
}
NOTE: YOU NEED TO ADD THIS UNDER YOUR INCLUDES!!
pawn Код:
native IsValidVehicle(vehicleid);
Example:
pawn Код:
#include <a_samp>
#include <YSI\y_commands>
#include <YSI\y_master>
native IsValidVehicle(vehicleid);
I was so sure this will work ... but now it doesn't deletes any vehicle. Damn, I hate this code
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)