Vehicle Change on the Spot
#1

I want to create a command where I can change the car on the spot. Meaning lets say I have a sultan, and I want to change it to an infernus, all I would have to do is type /changev [carid] and the car would change to the infernus at that spot. So how can I create this?
Reply
#2

pawn Код:
//let code be called when typed /changev
//let id == parameter entered after /changev
//let id be an integer between 400 and 611
//let player be in a vehicle and driver of said vehicle
new cid = GetPlayerVehicleID(playerid);
new Float:x, Float:y, Float:z, Float:a,
Float:vX, Float:vY, Float:vZ;
GetVehiclePos(cid, x, y, z);
GetVehicleZAngle(cid, a);
DestroyVehicle(cid);
new nid = CreateVehicle(id, x, y, z, a, -1, -1, -1);
PutPlayerInVehicle(playerid, nid, 0);
SetVehicleVelocity(nid, vX, vY, vZ);
Reply
#3

Quote:
Originally Posted by Daren_Jacobson
Посмотреть сообщение
pawn Код:
//let code be called when typed /changev
//let id == parameter entered after /changev
//let id be an integer between 400 and 611
//let player be in a vehicle and driver of said vehicle
new cid = GetPlayerVehicleID(playerid);
new Float:x, Float:y, Float:z, Float:a,
Float:vX, Float:vY, Float:vZ;
GetVehiclePos(cid, x, y, z);
GetVehicleZAngle(cid, a);
DestroyVehicle(cid);
new nid = CreateVehicle(id, x, y, z, a, -1, -1, -1);
PutPlayerInVehicle(playerid, nid, 0);
SetVehicleVelocity(nid, vX, vY, vZ);
Thanks, but I'm still fairly new to pawno, so could you maybe give me the whole command? I would really appreciate it.
Reply
#4

Can somebody please help me out with this? Heres the code that I'm using right now:

pawn Код:
if(strcmp(cmd, "/vch", true) == 0)
    {
        if(IsPlayerConnected(playerid))
        {
            if (PlayerInfo[playerid][pAdmin] <= 2)
            {
                SendClientMessage(playerid, COLOR_RED, " [ERROR:] You are not authorized to use that command!");
                return 1;
            }
            tmp = strtok(cmdtext, idx);
            if(!strlen(tmp))
            {
                SendClientMessage(playerid, COLOR_LIGHTBLUE, "USAGE: /vch [carid]");
                return 1;
            }
            new id;
            if(id < 1 || id > 611)
            {
            SendClientMessage(playerid, COLOR_RED, " [ERROR:] Vehicle Number can't be below 400 or above 611!");
            return 1;
            }
            tmp = strtok(cmdtext, idx);
            if(!strlen(tmp))
            {
                SendClientMessage(playerid, COLOR_LIGHTBLUE, "USAGE: /vch [carid]");
                return 1;
            }
            new cid = GetPlayerVehicleID(playerid);
            new Float:x, Float:y, Float:z, Float:a,
            Float:vX, Float:vY, Float:vZ;
            GetVehiclePos(cid, x, y, z);
            GetVehicleZAngle(cid, a);
            DestroyVehicle(cid);
            new nid = CreateVehicle(id, x, y, z, a, -1, -1, -1);
            PutPlayerInVehicle(playerid, nid, 0);
            SetVehicleVelocity(nid, vX, vY, vZ);
            format(string, sizeof(string), "[SERVER:] Your vehicle has been successfully changed. Vehicle ID:%d", nid);
            SendClientMessage(playerid, COLOR_GREEN, string);
        }
        return 1;
    }
It compiles fine, but when I do the command in game, the car just disappears. I do get the whole "Your vehicle has been changed" thing, but the vehicle just disappears. So can somebody please tell me what I'm doing wrong here, and how I can fix it.
Reply
#5

pawn Код:
if(strcmp(cmd, "/vch", true) == 0)
    {
        if(IsPlayerConnected(playerid))
        {
            if (PlayerInfo[playerid][pAdmin] <= 2)
            {
                SendClientMessage(playerid, COLOR_RED, " [ERROR:] You are not authorized to use that command!");
                return 1;
            }
            tmp = strtok(cmdtext, idx);
            if(!strlen(tmp))
            {
                SendClientMessage(playerid, COLOR_LIGHTBLUE, "USAGE: /vch [carid]");
                return 1;
            }
            new id;
            if(id < 1 || id > 611)
            {
            SendClientMessage(playerid, COLOR_RED, " [ERROR:] Vehicle Number can't be below 400 or above 611!");
            return 1;
            }
            tmp = strtok(cmdtext, idx);
            if(!strlen(tmp))
            {
                SendClientMessage(playerid, COLOR_LIGHTBLUE, "USAGE: /vch [carid]");
                return 1;
            }
            new cid = GetPlayerVehicleID(playerid);
            new Float:x, Float:y, Float:z, Float:a,
            Float:vX, Float:vY, Float:vZ;
            GetVehiclePos(cid, x, y, z);
            GetVehicleZAngle(cid, a);
            DestroyVehicle(cid);
            new nid
            nid = CreateVehicle(id, x, y, z, a, -1, -1, -1);
            PutPlayerInVehicle(playerid, nid, 0);
            SetVehicleVelocity(nid, vX, vY, vZ);
            format(string, sizeof(string), "[SERVER:] Your vehicle has been successfully changed. Vehicle ID:%d", nid);
            SendClientMessage(playerid, COLOR_GREEN, string);
        }
        return 1;
    }
Reply
#6

at Playboy, he forgot at new nid the ;
pawn Код:
new nid;
Reply
#7

DestroyVehicle doesn't work if you're inside the vehid. Better use it like this:
pawn Код:
if(strcmp(cmd, "/vch", true) == 0)
    {
        if(IsPlayerConnected(playerid))
        {
            if (PlayerInfo[playerid][pAdmin] <= 2)
            {
                SendClientMessage(playerid, COLOR_RED, " [ERROR:] You are not authorized to use that command!");
                return 1;
            }
            if(!IsPlayerInAnyVehicle(playerid))
            {
                 SendClientMessage(playerid, COLOR_RED, " [ERROR:] You have to be in a vehicle to use this command!");
                 return 1;
            }
            tmp = strtok(cmdtext, idx);
            if(!strlen(tmp))
            {
                SendClientMessage(playerid, COLOR_LIGHTBLUE, "USAGE: /vch [carid]");
                return 1;
            }
            new id;
            if(id < 1 || id > 611)
            {
            SendClientMessage(playerid, COLOR_RED, " [ERROR:] Vehicle Number can't be below 400 or above 611!");
            return 1;
            }
            tmp = strtok(cmdtext, idx);
            if(!strlen(tmp))
            {
                SendClientMessage(playerid, COLOR_LIGHTBLUE, "USAGE: /vch [carid]");
                return 1;
            }
            new cid = GetPlayerVehicleID(playerid);
            new Float:x, Float:y, Float:z, Float:a,
            Float:vX, Float:vY, Float:vZ;
            GetVehiclePos(cid, x, y, z);
            GetVehicleZAngle(cid, a);
            SetPlayerPos(playerid,x,y,z+2);
            DestroyVehicle(cid);
            new nid
            nid = CreateVehicle(id, x, y, z, a, -1, -1, -1);
            PutPlayerInVehicle(playerid, nid, 0);
            SetVehicleVelocity(nid, vX, vY, vZ);
            format(string, sizeof(string), "[SERVER:] Your vehicle has been successfully changed. Vehicle ID:%d", nid);
            SendClientMessage(playerid, COLOR_GREEN, string);
        }
        return 1;
    }
Reply
#8

Thanks! It worked
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)