Command /acar doesn't seem to work well.
#1

So I've made this:
pawn Код:
CMD:acar(playerid, params[])
{
    new string[128], park[30];
    if(PlayerInfo[playerid][pAdmin] < 5) return SendClientMessage(playerid, COLOR_REDD, "[ERROR] You do not have the right's to use this command!");
    if(sscanf(params, "s[128]", string)) return SendClientMessage(playerid, COLOR_LGREEN, "[USAGE]{ffffff} /acar [park/etc/etc]");
    format(park, sizeof(park), "park");
    if(strcmp(park, string, true, strlen(park)))
    {
        new vehicle, Float:x, Float:y, Float:z, Float:angle;
        vehicle = GetPlayerVehicleID(playerid);
        GetPlayerPos(playerid, x, y, z);
        GetPlayerFacingAngle(playerid, angle);
        VehicleInfo[vehicle][vX] = x;
        VehicleInfo[vehicle][vY] = y;
        VehicleInfo[vehicle][vZ] = z;
        VehicleInfo[vehicle][vA] = angle;
        SaveVehicle(vehicle);
        {
            LoadVehicle(vehicle);
        }
        SetPlayerPos(playerid, x, y, z+3);
        SendClientMessage(playerid, COLOR_LGREEN, "[Acar]{ffffff} Vehicle parked!");
    }
    return 1;
}
And it doesn't seem to work, and I honestly don't know how to make like /acar help/park/whatever, so anyone could help me out?
Reply
#2

pawn Код:
CMD:acar(playerid, params[])
{
    if (PlayerInfo[playerid][pAdmin] < 5) return SendClientMessage(playerid, COLOR_REDD, "[ERROR] You do not have the right's to use this command!");
    if (isnull(params)) return SendClientMessage(playerid, COLOR_LGREEN, "[USAGE]{ffffff} /acar [park/etc/etc]");
    if (strcmp(params, "help", true))
    {
        // code for "/acar help"
    }
    else if (strcmp(params, "park", true))
    {
        // code for "/acar park"
    }
    else SendClientMessage(playerid, COLOR_LGREEN, "Use: help/park etc..");
    return 1;
}
By the way I don't get why you save and then load the vehicle together but anyways if you want to do that then you don't need the brackets so this:
pawn Код:
SaveVehicle(vehicle);
{
    LoadVehicle(vehicle);
}
becomes:
pawn Код:
SaveVehicle(vehicle);
LoadVehicle(vehicle);
Reply
#3

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
pawn Код:
CMD:acar(playerid, params[])
{
    if (PlayerInfo[playerid][pAdmin] < 5) return SendClientMessage(playerid, COLOR_REDD, "[ERROR] You do not have the right's to use this command!");
    if (isnull(params)) return SendClientMessage(playerid, COLOR_LGREEN, "[USAGE]{ffffff} /acar [park/etc/etc]");
    if (strcmp(params, "help", true))
    {
        // code for "/acar help"
    }
    else if (strcmp(params, "park", true))
    {
        // code for "/acar park"
    }
    else SendClientMessage(playerid, COLOR_LGREEN, "Use: help/park etc..");
    return 1;
}
By the way I don't get why you save and then load the vehicle together but anyways if you want to do that then you don't need the brackets so this:
pawn Код:
SaveVehicle(vehicle);
{
    LoadVehicle(vehicle);
}
becomes:
pawn Код:
SaveVehicle(vehicle);
LoadVehicle(vehicle);
Wow man, thanks a lot! And yeah, I wanted to make a timer for the load.
Reply
#4

pawn Код:
if (!strcmp(params, "help", true))
    {
        // code for "/acar help"
    }
    else if (!strcmp(params, "park", true))
Reply
#5

Quote:
Originally Posted by BenzoAMG
Посмотреть сообщение
pawn Код:
if (!strcmp(params, "help", true))
    {
        // code for "/acar help"
    }
    else if (!strcmp(params, "park", true))
doesn't that !strmcp stands for that it's not?
Like:
if (!strcmp(params, "help", true)) stands for: If it isn't "help" .
Reply
#6

Now i got this:
pawn Код:
CMD:acar(playerid, params[])
{
    if (PlayerInfo[playerid][pAdmin] < 5) return SendClientMessage(playerid, COLOR_REDD, "[ERROR] You do not have the right's to use this command!");
    if (isnull(params)) return SendClientMessage(playerid, COLOR_LGREEN, "[USAGE]{ffffff} /acar [park/help/etc]");
    if (!strcmp(params, "help", true))
    {
        SendClientMessage(playerid, COLOR_LGREEN, "/acar help {ffffff}- List of /acar commands");
        SendClientMessage(playerid, COLOR_LGREEN, "/acar park {ffffff}- Park the vehicle you are in!");
    }
    else if (!strcmp(params, "park", true))
    {
        new vehicle, Float:x, Float:y, Float:z, Float:angle;
        vehicle = GetPlayerVehicleID(playerid);
        GetPlayerPos(playerid, x, y, z);
        GetPlayerFacingAngle(playerid, angle);
        VehicleInfo[vehicle][vX] = x;
        VehicleInfo[vehicle][vY] = y;
        VehicleInfo[vehicle][vZ] = z;
        VehicleInfo[vehicle][vA] = angle;
        SaveVehicle(vehicle);
        SetTimerEx("loadcar", 1000, false, "i", vehicle);
        SetPlayerPos(playerid, x, y, z+3);
        SendClientMessage(playerid, COLOR_LGREEN, "[Acar]{ffffff} Vehicle parked!");
    }
    else SendClientMessage(playerid, COLOR_LGREEN, "Use:{ffffff} /acar help for more info!");
    return 1;
}
And the timer:
pawn Код:
forward loadcar(i);
public loadcar(i)
{
    SetVehicleToRespawn(i);
}
Yet, it doesn't seem to park the vehicle yet.
Reply
#7

Sorry about that, BenzoAMG is correct. When the 2 strings are the same, it returns 0.

Anyways, you should make sure that you're in a car because GetPlayerVehicleID will return 0 and that's not a valid vehicleid; thus it will never respawn it.

Also respawning the vehicle will set it to the coordinates it was first created not in a specific place you want (for that use SetVehiclePos).
Reply
#8

I changed the timer to:
pawn Код:
forward loadcar(i);
public loadcar(i)
{
    SetVehiclePos(i, VehicleInfo[i][vX], VehicleInfo[i][vY], VehicleInfo[i][vZ]);
}
Yet, it didn't work. If this isn't what you ment, mind giving an example?
I did /respawncars and it just went back to his old position.
Reply
#9

If the coordinates has been stored to the array (and the correct index) then it should've set the vehicle's position.

When you respawn vehicles, they go back to the place where they were created. I also added a check about being driver to use the command. Do some debugging:
pawn Код:
CMD:acar(playerid, params[])
{
    if (PlayerInfo[playerid][pAdmin] < 5) return SendClientMessage(playerid, COLOR_REDD, "[ERROR] You do not have the right's to use this command!");
    if (isnull(params)) return SendClientMessage(playerid, COLOR_LGREEN, "[USAGE]{ffffff} /acar [park/help/etc]");
    if (!strcmp(params, "help", true))
    {
        SendClientMessage(playerid, COLOR_LGREEN, "/acar help {ffffff}- List of /acar commands");
        SendClientMessage(playerid, COLOR_LGREEN, "/acar park {ffffff}- Park the vehicle you are in!");
    }
    else if (!strcmp(params, "park", true))
    {
        if (GetPlayerState(playerid) != PLAYER_STATE_DRIVER) return SendClientMessage(playerid, COLOR_REDD, "You need to be driver");
        new vehicle, Float:x, Float:y, Float:z, Float:angle;
        vehicle = GetPlayerVehicleID(playerid);
        GetPlayerPos(playerid, x, y, z);
        GetPlayerFacingAngle(playerid, angle);
        VehicleInfo[vehicle][vX] = x;
        VehicleInfo[vehicle][vY] = y;
        VehicleInfo[vehicle][vZ] = z;
        VehicleInfo[vehicle][vA] = angle;
        printf("park -> vehicle: %i | X: %f | Y: %f | Z: %f | A: %f", vehicle, x, y, z, angle);
        SaveVehicle(vehicle);
        SetTimerEx("loadcar", 1000, false, "i", vehicle);
        SetPlayerPos(playerid, x, y, z+3);
        SendClientMessage(playerid, COLOR_LGREEN, "[Acar]{ffffff} Vehicle parked!");
    }
    else SendClientMessage(playerid, COLOR_LGREEN, "Use:{ffffff} /acar help for more info!");
    return 1;
}
and
pawn Код:
forward loadcar(i);
public loadcar(i)
{
    printf("loadcar -> vehicle: %i | X: %f | Y: %f | Z: %f", i, VehicleInfo[i][vX], VehicleInfo[i][vY], VehicleInfo[i][vZ]);
    SetVehiclePos(i, VehicleInfo[i][vX], VehicleInfo[i][vY], VehicleInfo[i][vZ]);
}
Do they both print the same coordinates and vehicleid?
Reply
#10

They both gave the same coordinates, yet I might found the issue.
Vehicle data file:
pawn Код:
Model = 560
vX = 1706.440307
vY = 1434.831298
vZ = 10.336604
Color1 = 1
Color2 = 1
Respawn = -1
Owner = Marco_Baccalieri
FactionCar = 0
NoobCar = 0
[data]
Model = 560
vX = 1695.949584
vY = 1442.413696
vZ = 10.762247
vA = 242.479843
Color1 = 1
Color2 = 1
Respawn = -1
Owner = Marco_Baccalieri
FactionCar = 0
NoobCar = 0
I'll try to fix this, and then tell you if it worked or not.
Edit: Didn't seem to work, the coordinates are both the same and the carfile seems unharmed, yet the car doesn't spawn at those coordinates. I use this timer to respawn the vehicles: (also, the angle doesn't seem to save)

pawn Код:
forward RespawnTimer();
public RespawnTimer()
{
    new bool:VehicleUsed[MAX_VEHICLES] = false;
    foreach(Character, i)//for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(IsPlayerInAnyVehicle(i)) VehicleUsed[GetPlayerVehicleID(i)] = true;
    }
    for(new i = 1; i < MAX_VEHICLES; i++)
    {
        if(VehicleUsed[i] == false)
        SetVehiclePos(i, VehicleInfo[i][vX], VehicleInfo[i][vY], VehicleInfo[i][vZ]);
        SetVehicleZAngle(i, VehicleInfo[i][vA]);
    }
    new string[128];
    format(string, sizeof(string), "[ADMIN]{FCF507} All unused vehicle's have been respawned.");
    SendClientMessageToAll(COLOR_AMESSAGE, string);
}
edit2: The angle problem got fixed, made a mistake in the savecar function.
edit3: Fixed the respawn, seems like it's working, also SetVehicleZAngle seems to be acting weird, as he flips the car 180 degrees at respawn.
Reply


Forum Jump:


Users browsing this thread: 4 Guest(s)