SA-MP Forums Archive
/lastdriver help - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: /lastdriver help (/showthread.php?tid=482302)



/lastdriver help - Mitchy - 20.12.2013

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!


Re: /lastdriver help - ikey07 - 20.12.2013

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);


Re: /lastdriver help - Mitchy - 20.12.2013

I'll try it


Re: /lastdriver help - Mitchy - 20.12.2013

Still not working.


Re: /lastdriver help - ikey07 - 20.12.2013

But why to use mysql?

Just use

new LastDriver[MAX_VEHICLES];


OnPlayersStateChange()..


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


Re: /lastdriver help - cessil - 20.12.2013

what about it, isn't working?


Re: /lastdriver help - Mitchy - 20.12.2013

It doesnt show the name of the last driver.


Re: /lastdriver help - tyler12 - 20.12.2013

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.


Re: /lastdriver help - tyler12 - 20.12.2013

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;
}



Re: /lastdriver help - DemME - 20.12.2013

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?