/lastdriver help
#1

I've been trying to make a /lastdriver command though all it says is this:

"The last driver of this FBI Rancher was "

Here's my codes:

pawn Код:
command(lastdriver, playerid, params[])
    {
        new vehicleid;
        if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
        {
            new query[500], data_value[50], name[24], string[500];
            format(query, sizeof(query), "SELECT * FROM `vehicles` WHERE `LastDriver` = '%s' AND `VehicleID` = sha1('%s')", vehicleid);
            mysql_query(query);
            mysql_store_result();
           
            while(mysql_retrieve_row())
            {
                mysql_fetch_field_row(data_value, "LastDriver"); format(name, sizeof(name), "%s", data_value);
            }
            format(string, sizeof(string), "The last driver of this %s was {FF0000}%s{FFFFFF}", GetVehicleName(GetPlayerVehicleID(playerid)), name);
            SendClientMessage(playerid, WHITE, string);
            mysql_free_result();
        }
        else return SCM(playerid, WHITE, "You are not in a vehicle.");
        return 1;
    }
pawn Код:
if(newstate == PLAYER_STATE_ONFOOT && oldstate == PLAYER_STATE_DRIVER)
        {
            new query[512], vehicleid2;
            format(query, sizeof(query), "UPDATE `vehicles` SET `LastDriver`=%s WHERE `VehicleID`=%d", pName(playerid), vehicleid2);
            mysql_query(query);
            mysql_free_result();
        }
p.s Merry XMAS!
Reply
#2

Try this

pawn Код:
if(newstate == PLAYER_STATE_DRIVER)
        {
            new query[512], vehicleid2;
            format(query, sizeof(query), "UPDATE `vehicles` SET `LastDriver`=%s WHERE `VehicleID`=%d", pName(playerid), vehicleid2);
            mysql_query(query);
        }
And in

pawn Код:
format(query, sizeof(query), "SELECT * FROM `vehicles` WHERE `LastDriver` = '%s' AND `VehicleID` = sha1('%s')", vehicleid);
            mysql_query(query);
use "SELECT `LastDriver` FROM ....

So you can use more simple

mysql_fetch_row(name);
format(string, sizeof(string), "The last driver of this %s was {FF0000}%s{FFFFFF}", GetVehicleName(GetPlayerVehicleID(playerid)), name);
Reply
#3

I'll try it
Reply
#4

Still not working.
Reply
#5

But why to use mysql?

Just use

new LastDriver[MAX_VEHICLES];


OnPlayersStateChange()..


if( newstate == DRIVER) { LastDriver[GetPlayerVehicleID(playerid)] = playerid;
Reply
#6

what about it, isn't working?
Reply
#7

It doesnt show the name of the last driver.
Reply
#8

pawn Код:
if(newstate == PLAYER_STATE_ONFOOT && oldstate == PLAYER_STATE_DRIVER)
{
    new query[512],vehicleid2;
    vehicleid2 = vSQLID[vehicleid]; // Wherever you store the SQL ID
    format(query,sizeof(query),"UPDATE `vehicles` SET `LastDriver` = '%s' WHERE `VehicleID` = '%d'",pName(playerid),vehicleid2);
    mysql_query(query);
    mysql_free_result();
}
You didn't wrap the value with apostrophes ( ' ) nor are you giving vehicleid2 an ID (0). This should work.
Reply
#9

Something like:

pawn Код:
new lastDriver[MAX_VEHICLES] = {INVALID_PLAYER_ID,..};

if(newstate == PLAYER_STATE_ONFOOT && oldstate == PLAYER_STATE_DRIVER)
{
    lastDriver[vehicleid] = playerid;
}

// onVehicleDeath
lastDriver[vehicleid] = INVALID_PLAYER_ID;

command(lastdriver, playerid, params[])
{
    if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
    {
        new name[24], string[500]; GetPlayerName(lastDriver[GetPlayerVehicleID(playerid)],name,sizeof(name));
        format(string, sizeof(string), "The last driver of this %s was {FF0000}%s{FFFFFF}", GetVehicleName(GetPlayerVehicleID(playerid)), (isnull(name) ? "Unknown" : name));
        SendClientMessage(playerid, WHITE, string);
    }
    else return SCM(playerid, WHITE, "You are not in a vehicle.");
    return 1;
}
Reply
#10

Quote:
Originally Posted by ikey07
Посмотреть сообщение
But why to use mysql?

Just use

new LastDriver[MAX_VEHICLES];


OnPlayersStateChange()..


if( newstate == DRIVER) { LastDriver[GetPlayerVehicleID(playerid)] = playerid;
Could you please explain some more, like builidng a full command for an example?
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)