Impound Vehicle
#1

Hi,
Below is the code i am using to impound vehicles (Just simply change the spawn location of the vehicle to inside the impound lot once it has been towed)

The problem i am having is that when i use the /impound command from inside the impound and when i am near to the vehicle i receive the 'not near vehicle' error followed by 'SERVER: Unknown command.'

I have put some comments into the code to help indicate what a couple of bits are (although should be easy to understand anyway)

Any ideas?
Thank you in advance!

pawn Код:
if(strcmp(cmd, "/impound", true) == 0)
    {
        tmp = strtok(cmdtext, idx);
        if(!strlen(tmp))
        {
            SendClientMessage(playerid, COLOR_WHITE, "USAGE: /impound VehicleID");
            SendClientMessage(playerid, COLOR_WHITE, "HINT: use /dl to see the vehicle ID");
            return 1;
        }
        if(IsPlayerConnected(playerid))
        {
            if(PlayerInfo[playerid][pFaction] != 255 && DynamicFactions[PlayerInfo[playerid][pFaction]][fType] == 1) //Is a cop
            {
                new car = strval(tmp);
//              if(IsPlayerInArea(1672.6168, -1720.5670,1643.3774, -1691.1042)) // More accurate inside impound (Why doesn't it work?)
                if(PlayerToPoint(20, playerid, 1657.9971,-1705.8356)) // Is Inside Impound
                {
                    if(PlayerToPoint(10, playerid, GetVehiclePos(car))) //Is near to vehicle
                    {
                        new Float:x,Float:y,Float:z;
                        new Float:a;
                        GetVehiclePos(car, x, y, z);
                        GetVehicleZAngle(car, a);

                        DynamicCars[car][CarX] = x;
                        DynamicCars[car][CarY] = y;
                        DynamicCars[car][CarZ] = z;
                        DynamicCars[car][CarAngle] = a;

                        DestroyVehicle(car);
                        CreateVehicle(DynamicCars[car][CarModel],DynamicCars[car][CarX],DynamicCars[car][CarY],DynamicCars[car][CarZ],DynamicCars[car][CarAngle],DynamicCars[car][CarColor1],DynamicCars[car][CarColor2], -1);
                        SaveDynamicCars();

                        SendClientMessage(playerid, COLOR_WHITE, "Vehicle Impounded.");
                    }
                    else //Not near car
                    {
                        SendClientMessage(playerid, COLOR_RED, "ERROR: You are too far from this vehicle to impound it!.");
                    }
                }
                else //Not in impound
                {
                SendClientMessage(playerid, COLOR_RED, "ERROR: You are not in the impound lot!.");
                }
            }
            else //Not a cop
            {
                SendClientMessage(playerid, COLOR_GREY, "[Error:] You are not a cop!");
            }
        }
        return 1;
    }
Reply
#2

Your mistake is simple because I assume PlayerToPoint takes 5 parameters whereas you pass only 3 to it on an instance. GetVehiclePos returns values by reference, not directly (which, for an array, is not possible in Pawn, by the way).

Also, why on EARTH do you use PlayerToPoint? This is an outdated and SLOW version of the now-native IsPlayerInRangeOfPoint function. START. USING. IT.

Also, why do you check if the player who entered the command is connected? How can a player, who does not exist, use a command in the first place?
Reply
#3

Quote:
Originally Posted by AndreT
Посмотреть сообщение
Your mistake is simple because I assume PlayerToPoint takes 5 parameters whereas you pass only 3 to it on an instance. GetVehiclePos returns values by reference, not directly (which, for an array, is not possible in Pawn, by the way).

Also, why on EARTH do you use PlayerToPoint? This is an outdated and SLOW version of the now-native IsPlayerInRangeOfPoint function. START. USING. IT.

Also, why do you check if the player who entered the command is connected? How can a player, who does not exist, use a command in the first place?
Thank you for your reply AndreT, such a simple mistake. Can't believe i didn't notice it!
Could have just suggested IsPlayerInRangeOfPoint though... Didn't have to say it in the way you did. Which is why generally i would +rep somebody, but in this case i will not be.

Thank you for your help.
Reply
#4

And another suggestion - Use Sscanf, it's much better than strtok and stuff.
Reply
#5

Thanks tsonn1, I'll keep this in mind in the future
Reply
#6

Can I give you advice?

Why you want that usual player use some debuging cmds? why you ask them to use /dl to get vehicle id?
Just use function to get closest vehicle and impound that, not some debugging /dl cmds, usual player shouldnt come across with vehicle IDs, leave it in the script, players need to see clean and nice cmds, but I know you wont get what I mean :P
Reply
#7

ikey, actually i do get what you mean. The reason i haven't done that is that the impound can become very full at times and so finding the closest vehicle wouldn't always work.
Quite a lot of servers i have been on also do it this way.
Could i also just say that just because i asked for help, doesn't mean that i don't know how to code, or that i won't know what you mean, because i do.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)