SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 24/09/2019, 07:10 PM   #1
sean0uk0
Little Clucker
 
Join Date: May 2010
Posts: 7
Reputation: 0
Default sqlite multiple results

Hey I'm still learning scripting and have got stuck on how to get the top 5 results for race records, it's done by race id eg. /racerec 1


Code:
CMD:racerec(playerid, params[])
{
    new msg[128], DBResult: result, id, racename[50], validraceid;
    if (sscanf(params, "i", id)) return SendClientMessage(playerid, 0xFFFF00FF, "Usage: /racerec (raceid)");
    if (sscanf(params, "i", id)) id = strval(msg);
	{
        new str[2048];
        for (new i = 1; i < MAX_RACES; i++)
        {
            format(msg, sizeof(msg), "SELECT * FROM `Races` WHERE `id` = %d", id);
			result = db_query(Database, msg);
			if (db_num_rows(result) == 0) { db_free_result(result); return SendClientMessage(playerid, 0xFFFF00FF, "Invalid race id"); }
			//db_get_field_assoc(result, "id", msg, sizeof(msg));

			db_get_field_assoc(result, "name", racename, sizeof(racename));
            validraceid = 0;
            if (!db_num_rows(result)) validraceid = 0;
            else validraceid = 1;
            db_free_result(result);
            if (!validraceid) continue;
            format(str, sizeof(str), "SELECT * FROM `Racerecords` WHERE `raceid` = %d ORDER BY `time` ", id);
			result = db_query(Database, str);

			if (db_num_rows(result))
			{

			    new h, m, s, Float:ftime, ruserid;
   				db_get_field_assoc(result, "userid", str, sizeof(str));
			    ruserid = strval(str);
			    db_get_field_assoc(result, "time", str, sizeof(str));
			    ftime = floatstr(str);
       			secs2hms(floatround(ftime, floatround_tozero), h, m, s);
				ftime = ftime - floatround(ftime, floatround_tozero);
                format(msg, sizeof(msg), "Current record for \t%s top is %d:%02.2f set by %s.",  racename, m, s+ftime, GetNameFromUserID(ruserid)); 
            }
			else format(msg, sizeof(msg), "There is no record set for this race yet.");  
            SendClientMessage(playerid, 0xFFFF00FF, msg);
			db_free_result(result);

            format(str, sizeof(str), "SELECT * FROM `Racerecords` WHERE `raceid` = %d AND `userid` = %d", id, userid[playerid]);
            result = db_query(Database, str);
            if (db_num_rows(result) != 0)
            {
                new Float:ftime, h, m, s;
                db_get_field_assoc(result, "time", str, sizeof(str));
                ftime = floatstr(str);
                secs2hms(floatround(ftime, floatround_tozero), h, m, s);
                ftime = ftime - floatround(ftime, floatround_tozero);
                format(str, sizeof(str), "Your current personal record is %d:%02.2f.", m, s+ftime);
                SendClientMessage(playerid, 0xFFFF00FF, str);
            }
            db_free_result(result);
            return 1;

        }


    }
    return 1;
}
I have no idea how to do it at all, any help please?
sean0uk0 is offline   Reply With Quote
Old 26/09/2019, 05:48 AM   #2
SiaReyes
Huge Clucker
 
SiaReyes's Avatar
 
Join Date: Mar 2019
Location: Coordinates X,Y,Z
Posts: 328
Reputation: 22
Default Re: sqlite multiple results

This is what i used to list out top 3,
Maybe try editing this code to your favour!
Code:
    new
        DBResult:result,
        racems,
        name[30],
        rstring[512];
    new racemin, racesec;
    format(query,sizeof(query),"SELECT RACER_NAME, TIME_RECORD FROM RACE_TIME WHERE RACE_ID = (SELECT RACE_ID FROM RACES WHERE RACE_NAME = '%q') ORDER BY TIME_RECORD LIMIT 3", RaceName);
    result = db_query( Database, query );
    if(db_num_rows(result))
    {
	    for (new a,b = db_num_rows(result); a != b; a++, db_next_row(result))
	    {
	        db_get_field_assoc(result, "RACER_NAME", name, sizeof(name));
	        racems = db_get_field_assoc_int(result, "TIME_RECORD");
	        racemin = racems / 60000;
	        racems = racems - (racemin * 60000);
	        racesec = racems / 1000;
	        racems = racems - (racesec * 1000);
			if(racemin == 0) format(rstring,sizeof(rstring),"{FFE600}%i.{0BDDC4} %s {FFE600}- {F0F0F0}%02d.%03d\n",a + 1, name, racesec, racems);
			else format(rstring,sizeof(rstring),"{FFE600}%i.{0BDDC4} %s {FFE600}- {F0F0F0}%d:%02d.%03d\n",a + 1, name, racemin, racesec, racems);
            SendClientMessage(playerid, COLOR_WHITE, rstring);
	    }
	}
    else SendClientMessage(playerid,COLOR_YELLOW, "{6EF83C} No race records available");
    db_free_result(result);
__________________
Offshowtime Fuck It!

Quote:
Originally Posted by Toroi View Post
blackmail people that join your server using their ip address as hostage

or get a job and play sa-mp for fun
SiaReyes is offline   Reply With Quote
Old 26/09/2019, 09:17 AM   #3
sean0uk0
Little Clucker
 
Join Date: May 2010
Posts: 7
Reputation: 0
Default Re: sqlite multiple results

Worked a treat, thank you! Rep+
sean0uk0 is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Question about SQLite's multiple connections Joey^ Scripting Help 1 04/01/2014 03:36 AM
SQLite - Create multiple tables in db u3games Server Support 8 13/04/2013 02:26 PM
SQLite results question xXShadowXx Scripting Help 3 17/03/2013 10:32 PM
help: multiple results for vehicle found NewbieScripter Scripting Help 1 18/09/2012 05:55 PM
MySQL or SQLite - Multiple servers [L3th4l] Scripting Help 6 26/11/2011 09:00 PM


All times are GMT. The time now is 01:14 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.