Entrance save
#1

I have this business system.
I want to add that if I use /enter, my name will be saved in a MySQL table.
And if I use /lastentered, then it will show me the last 5 that entered.
I have no idea how to make it so far, asking for your help.
No need for the script lines themselves, maybe the idea and a small example.
Thanks in advance.
Reply
#2

Make a new table in the database called 'bussiness_visits' with the columns you need (id, name and time/hour). When a player uses the command, check that he really entered a bussiness and if so, make a insert to the table with his name and getdate() or gettime() to get when he entered.

After that, for the /lastentered command, make a simple select like "SELECT name, hour FROM bussiness_visits ORDER BY id DESC LIMIT 5" and send the message to the player.
Reply
#3

I'm totally confused about sending the message, this is what I've got so far:
pawn Код:
CMD:lastentered(playerid,params[])
{
    new faction = PlayerInfo[playerid][pFaction];
    if(faction != LSPD) return SCM(playerid, COLOR_SALMON, "Invalid faction.");
    format(query, sizeof(query), "SELECT name, timedate FROM biz_visits ORDER BY id DESC LIMIT 5");
    mysql_function_query(dbHandle, query, true, "", "");

}
Reply
#4

Something like this:

pawn Код:
CMD:lastentered(playerid,params[])
{
    new faction = PlayerInfo[playerid][pFaction];
    if(faction != LSPD) return SCM(playerid, COLOR_SALMON, "Invalid faction.");
    format(query, sizeof(query), "SELECT name, timedate FROM biz_visits ORDER BY id DESC LIMIT 5");
    mysql_function_query(dbHandle, query, true, "OnQueryFinished", "d", playerid);
}

forward OnQueryFinished(playerid);
public OnQueryFinished(playerid)
{
    new rows, fields, name[MAX_PLAYER_NAME], date[16];
    cache_get_data(rows, fields);
    SCM(playerid, COLOR_SALMON, "_________Entered people:_________");
    for(new p = 0; p < rows; p++)
    {
        cache_get_field_content(p, "name", name);
        cache_get_field_content(p, "timedate", date);
        format(string, sizeof(string), "%d. %s entered at %s.", p+1, name, date);
        SCM(playerid, COLOR_WHITE, string);
    }
    return 1;
}
Reply
#5

Why did I format the query? derp.
Does it need to be formatted? I do not use any %s or %d or whatever.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)