How to delete a specific vehicle ID?
#1

Hello reader,

here I am, once again. It maybe looks I ask everything as soon as it doesn't work but I don't, I first try to solve it myself ( As I am new to PAWN I am spending quite a lot time on it so that is why you will still get to see so much questions from me ^^ ). Okay, that is just for the people who think like "Screw him, he just doesn't want to put any effort into it.".

Now, my question. I got a command to create vehicles, that all works fine, nothing wrong with it. Now the problem is, I tried to script a /deleteveh myself, and I sucseeded, for a part. I already got so far that I could delete the vehicle I am inside ( With the help of SA-MP Wiki :P ), but I planned to create a command to "/deleteveh [vehicleid]" ( Ofcourse the IG vehicle ID from /dl and not like ID 400 will delete all Landstalkers but that ID 1 will delete the first vehicle created in the server. ) but I can't get that to work.

Now I am also not sure if that is possible but I guess it is. This is the code I am currently using:
pawn Code:
CMD:deleteveh(playerid, params[])
{

    if (IsPlayerAdmin(playerid) == 0)
    {
    SendClientMessage(playerid, KLEUR_WIT, "You are not an Administrator.");
    return 1;
    }
    else if (isnull(params))
    {
    SendClientMessage(playerid, KLEUR_WIT, "{B4B5B7}USAGE: /deleteveh [vehicleid]");
    return 1;
    }
    else if (IsPlayerAdmin(playerid) == 1)
    {
    new vehicleid;
    vehicle =
    DestroyVehicle(vehicleid);
    if(!sscanf(params, "%i", vehicleid))
        {
        new string[128];
        format(string, sizeof(string), "You succesfully deleted vehicle ID: %i", vehicleid);
        return 1;
        }
    }
    return 1;
}
I need to know what I should put behind "vehicle = ......" because I think it will work then .

Best regards,
Jesse
Reply
#2

Well.. Here you go:

pawn Code:
CMD:deleteveh(playerid, params[])
{
    if(IsPlayerAdmin(playerid))
    {
        new vehicleid, string[64];
        if(!sscanf(params, "i", vehicleid))
        {
            DestroyVehicle(vehicleid);
            format(string, sizeof(string), "Vehicle ID: %d has been suceful deleted.", vehicleid);
            SendClientMessage(playerid, 0xFFFFFFFF, string)
            return 1;
        }
        else return SendClientMessage(playerid, 0xFFFFFFFFF, "Usage: /deletveh [Vehicle ID]");
    }
    else return SendClientMessage(playerid, 0xFFFFFFF, "You are not Admin.");
}
Reply
#3

You're using ZCMD oddly. You don't need if(isnull) sscanf already has a built in null checker.

pawn Code:
CMD:deleteveh(playerid, params[])
{
    new vehicle;
    if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, KLEUR_WIT, "You are not an Administrator.");
    if(sscanf(params,"i",vehicle)) return SendClientMessage(playerid, KLEUR_WIT, "{B4B5B7}USAGE: /deleteveh [vehicleid]");
    if(vehicle == INVALID_VEHICLE_ID) return SendClientMessage(playerid,KLEUR_WIT,"Vehicle not found.");
    else
    {
        DestroyVehicle(vehicle);
        new string[128];
        format(string, sizeof(string), "You succesfully deleted vehicle ID: %i", vehicle);
        SendClientMessage(playerid,KLEUR_WIT,string);
        return 1;
    }
    return 1;
}
================================================== ===================
pawn Code:
new vehicle;
Defines a variable that will hold the vehicleid.

pawn Code:
if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, KLEUR_WIT, "You are not an Administrator.");
Checks if the player is Admin. The ! is if IsPlayerAdmin returns false. So basically. If a player is not admin then send them the message.

pawn Code:
if(sscanf(params,"i",vehicle)) return SendClientMessage(playerid, KLEUR_WIT, "{B4B5B7}USAGE: /deleteveh [vehicleid]");
Checks if they left the command empty.

pawn Code:
if(vehicle == INVALID_VEHICLE_ID) return SendClientMessage(playerid,KLEUR_WIT,"Vehicle not found.");
Checks if the vehicleid they typed is not in the script.

pawn Code:
else
    {
        DestroyVehicle(vehicle);
    }
    return 1;
}
If everything else passes, then DestroyVehicle(vehicle) will the destroy the vehicle with variable they typed inside.

pawn Code:
new string[128];
        format(string, sizeof(string), "You succesfully deleted vehicle ID: %i", vehicle);
        SendClientMessage(playerid,KLEUR_WIT,string);
Formats the string and Sends the client the string as a message.
Goodluck.
Reply
#4

For the people above me.. You don't need to use sscanf if you're just using 1 parameter.
Here is a simple version for you to play around with:
pawn Code:
CMD:deleteveh(playerid, params[])
{
    if (!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, KLEUR_WIT, "You are not an Administrator.");
    else if(isnull(params)) return SendClientMessage(playerid, KLEUR_WIT, "{B4B5B7}USAGE: /deleteveh [vehicleid]");
    else
    {
        new vehicleid = strval(params);
        if(vehicleid == INVALID_VEHICLE_ID) return SendClientMessage(playerid,-1,"Not a vaild vehicle");
        DestroyVehicle(vehicleid);
        new string[128];        
        format(string, sizeof(string), "You succesfully deleted vehicle ID: %i", vehicleid);
        SendClientMessage(playerid,-1,string);
    }
    return 1;
}
Reply
#5

Quote:
Originally Posted by ricardo178
View Post
Well.. Here you go:

pawn Code:
SendClientMessage(playerid, 0xFFFFFFFF, "Vehicle id %d has been suceful deleted.", vehicleid)
Since when does SendClientMessage support floats? Use format!
Reply
#6

Quote:
Originally Posted by VincentDunn
View Post
Since when does SendClientMessage support floats? Use format!
Changed it.. My fault. Been scripting dynamic house system that actualy has a damn bug, can't actualy think good. xD
Reply
#7

pawn Code:
CMD:deleteveh(playerid, params[])
{
    new vehicleid;
    if(!IsPlayerAdmin(playerid)) SendClientMessage(playerid, KLEUR_WIT, "You are not an Administrator.");
    else if(isnull(params)) SendClientMessage(playerid, KLEUR_WIT, "{B4B5B7}USAGE: /deleteveh [vehicleid]");
    else if(!(0 < (vehicleid = strval(params)) < MAX_VEHICLES)) SendClientMessage(playerid,-1,"Not a vaild vehicle");
    {
        new string[42];
        format(string, sizeof(string), "You succesfully deleted vehicle ID: %i", vehicleid);
        SendClientMessage(playerid,-1,string);
        DestroyVehicle(vehicleid);
    }
    return 1;
}
Reply
#8

Thank you all for replying,
but for everyone who replied after Ricardo I am sorry to say his reply already helped me out ( Yes, I still read all the others and yes I will take the tips ), I just replaced some lines in my command after I had seen his and then it worked. Again, everyone thank you for your reply!

Best regards,
Jesse
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)