Can't get this to work for the life of me
#1

I just don't see why this command does not work, as far as I can see it is completely correct and I see no reason why it should not work. When the player types /towcar and an ID of a vehicle he owns, it returns the error message "You cannot respawn a car you do not own." It does the same when you type in the ID of a vehicle you do not own.

Here is the command...
PHP код:
CMD:towcar(playeridparams[])
{
    new 
vehicleid;
    if (
sscanf(params"d"vehicleid))
        return 
SendSyntaxMessage(playerid"/towcar [id]");
    if (!
Car_IsOwner(playeridvehicleid))
        return 
SendErrorMessage(playerid"You cannot respawn a car that you do not own.");
    
RespawnVehicle(vehicleid);
    
SendServerMessage(playerid"You have respawned your vehicle [ID: %d]."vehicleid);
    
GiveMoney(playerid, -500);
    return 
1;

And here is the Car_IsOwner function...
PHP код:
Car_IsOwner(playeridcarid)
{
    if (!
PlayerData[playerid][pLogged] || PlayerData[playerid][pID] == -1)
        return 
0;
    if ((
CarData[carid][carExists] && CarData[carid][carOwner] != 0) && CarData[carid][carOwner] == PlayerData[playerid][pID])
        return 
1;
    return 
0;

Car_IsOwner is used in other commands without issue, for example...
PHP код:
CMD:uselock(playeridparams[])
{
    new 
id Car_GetID(GetPlayerVehicleID(playerid));
    if (!
IsEngineVehicle(id))
        return 
SendErrorMessage(playerid"You cannot use an Advanced Lock on this vehicle.");
    if (!
Car_IsOwner(playeridid))
        return 
SendErrorMessage(playerid"You do not own this vehicle.");
    if (
GetPlayerState(playerid) != PLAYER_STATE_DRIVER)
        return 
SendErrorMessage(playerid"You can't do this as you're not the driver.");
    if (
CarData[id][carLockType] == 1)
        return 
SendErrorMessage(playerid"This vehicle is already fitted with an Advanced Lock.");
    if (!
Inventory_HasItem(playerid"Advanced Lock"))
        return 
SendErrorMessage(playerid"You do not have an Advanced Lock.");
    
SendServerMessage(playerid"You have used an Advanced Lock on your %s."ReturnVehicleModelName(CarData[id][carModel]));
    
Inventory_Remove(playerid"Advanced Lock");
    
CarData[id][carLockType] = 1;
    
Car_Save(id);
    return 
1;

It works fine in that command, you can only /uselock on a vehicle you own... so why not for the /towcar command?

I have also tried replacing "Car_IsOwner" with "CarData[carid][carOwner] != PlayerData[playerid][pID]" to no avail.
Reply
#2

Try:
PHP код:
SetVehicleToRespawn(vehicleid); 
Reply
#3

Quote:
Originally Posted by runcis
Посмотреть сообщение
Try:
PHP код:
SetVehicleToRespawn(vehicleid); 
That's not the problem, it is returning the error message "You cannot respawn a car that you do not own", it does't even reach the RespawnVehicle part of the code because it returns the error.
Reply
#4

PHP код:
CMD:towcar(playeridparams[])
{
    new 
vehicleid;

    if (
sscanf(params"d"vehicleid))
        return 
SendSyntaxMessage(playerid"/towcar [veh]");

    if (
vehicleid || vehicleid MAX_VEHICLES || !IsValidVehicle(vehicleid))
        return 
SendErrorMessage(playerid"You have specified an invalid vehicle ID.");

    if (
Car_IsOwner(playeridvehicleid)) {
        
RespawnVehicle(vehicleid);
        
Car_Save(vehicleid);
        
SendServerMessage(playerid"You have respawned vehicle ID: %d."vehicleid);
        
GiveMoney(playerid, -500);
    } else {
        
SendErrorMessage(playerid"You cannot respawn a car that you do not own."); 
    }
    return 
1;

I was just thinking of "How can player even know his car's id?".
Reply
#5

You are not getting the vehicle's ID dude you just defined it.

Look at /uselock you'll see on top new id= and so on.

EDIT*

Quote:

new id = Car_GetID(GetPlayerVehicleID(playerid));

Chnage id to vehicleid and add it on top of your tow command and make sure to read the full command, I am on tablet sorry.
Reply
#6

Quote:
Originally Posted by Bingo
Посмотреть сообщение
You are not getting the vehicle's ID dude you just defined it.

Look at /uselock you'll see on top new id= and so on.
And what about sscanf?

Like cmd gives the vehicle's id. /towcar [VEHICLEID],
so, command works with id that's given.

And you probably right.

-------

Probably cmd won't work, because you have static vehicles too, like police n shit, well, I guess when you enter car's id, you entered the id of mysql cars list.

Try:
PHP код:
CMD:towcar(playeridparams[])
{
    new 
vehicleid;
    if (
sscanf(params"d"vehicleid))
        return 
SendSyntaxMessage(playerid"/towcar [veh]");
        
    if (
vehicleid || vehicleid MAX_VEHICLES || !IsValidVehicle(vehicleid))
        return 
SendErrorMessage(playerid"You have specified an invalid vehicle ID.");
    
id Car_GetID(vehicleid);
        
    if (
Car_IsOwner(playeridid)) {
        
RespawnVehicle(id);
        
Car_Save(id);
        
SendServerMessage(playerid"You have respawned vehicle ID: %d."id);
        
GiveMoney(playerid, -500);
    } else {
        
SendErrorMessage(playerid"You cannot respawn a car that you do not own."); 
    }
    return 
1;

Reply
#7

Quote:
Originally Posted by Bingo
Посмотреть сообщение
You are not getting the vehicle's ID dude you just defined it.

Look at /uselock you'll see on top new id= and so on.

EDIT*



Chnage id to vehicleid and add it on top of your tow command and make sure to read the full command, I am on tablet sorry.
The purpose of the command is to respawn your car if you lose it/it gets stolen and abandoned so Car_GetID(GetPlayerVehicleID(playerid)) would not work, as the player would not be physically inside the vehicle.
Reply
#8

Quote:
Originally Posted by runcis
Посмотреть сообщение
And what about sscanf?

Like cmd gives the vehicle's id. /towcar [VEHICLEID],
so, command works with id that's given.

And you probably right.

-------

Probably cmd won't work, because you have static vehicles too, like police n shit, well, I guess when you enter car's id, you entered the id of mysql cars list.

Try:
PHP код:
CMD:towcar(playeridparams[])
{
    new 
vehicleid;
    if (
sscanf(params"d"vehicleid))
        return 
SendSyntaxMessage(playerid"/towcar [veh]");
        
    if (
vehicleid || vehicleid MAX_VEHICLES || !IsValidVehicle(vehicleid))
        return 
SendErrorMessage(playerid"You have specified an invalid vehicle ID.");
    
id Car_GetID(vehicleid);
        
    if (
Car_IsOwner(playeridid)) {
        
RespawnVehicle(id);
        
Car_Save(id);
        
SendServerMessage(playerid"You have respawned vehicle ID: %d."id);
        
GiveMoney(playerid, -500);
    } else {
        
SendErrorMessage(playerid"You cannot respawn a car that you do not own."); 
    }
    return 
1;

The fact there are static vehicles should not effect the command, this command is basically a clone of the /respawncar [id] command except on /towcar it checks that the player owns the vehicle.

I will try your solution
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)