houselist
#1

hey guys i did this cmd but i want to show me only houses from players who didn't connect for 5 mins i will make it for 1 month but to test it only 5 mins

Код HTML:
CMD:houselist(playerid, params[])
{
	if(gLogged[playerid] == 0) return SendClientMessage(playerid, COLOR_ERROR, "Tu nu esti logat si nu poti sa folosesti aceasta comanda!");
	if(!IsManager(playerid)) return SendClientMessage(playerid, COLOR_ERROR, "Nu ai gradul necesar ca sa folosesti aceasta comanda!");
	new aim[1500], tstring[100];
	format(tstring, sizeof(tstring),"{FFFFFF}Lista caselor cumparate");
	new memid = 0;

	gQuery[0] = (EOS);
	mysql_format(handle, gQuery, sizeof(gQuery), "SELECT `Name`,`HouseKey`,`LastLogin` FROM `players` WHERE `HouseKey` > 0 ORDER BY `HouseKey` DESC LIMIT 100");
	new Cache:result = mysql_query (handle, gQuery);

	new iResult[64];
    new test[32], query[32], test1[32], houseOwnerLastOn;
	new coordsstring[250] = "Name\tCheia de la casa\tLast Login\n";
	for ( new i, j = cache_get_row_count ( ); i != j; ++i )
	{
		cache_get_field_content(i, "Name", iResult); format(query, 32, iResult);
		format(Selected[memid][snume],32, query);
		cache_get_field_content(i, "HouseKey", iResult); format(test, 32, iResult);
		houseOwnerLastOn = cache_get_field_content(i, "LastLogin", iResult); format(test1, 32, iResult);
        if((gettime()-houseOwnerLastOn) >= 300)
        {
			new id = GetPlayerID(Selected[memid][snume]);

			if(id != INVALID_PLAYER_ID)
			{
				format(gString, sizeof(gString), "{FFFFFF}%s\t%s\tOnline\n", query, test);
				strcat(aim, gString);
			}
			else
			{
	  			format(gString, sizeof(gString), "{FFFFFF}%s\t%s\t%s\n", query, test, test1);
	     		strcat(aim, gString);
			}
			memid ++;
		}
	}
	cache_delete(result);
    strins(aim, coordsstring, 0);
	ShowPlayerDialog(playerid,3363566,DIALOG_STYLE_TABLIST_HEADERS,tstring,aim,"Alege","Iesi");
	return 1;
}
why isn't working?
Reply
#2

Information

First of all to save memory in both the script and mysql you could have lessened the amount of queries being returned by simply adding an extra check to the query:

Код:
SELECT `Name`,`HouseKey`,`LastLogin` FROM `players` WHERE `HouseKey` > 0 AND `LastLogin` <= (NOW() - INTERVAL 60 SECOND) ORDER BY `HouseKey` DESC LIMIT 100
What did I add? I simply used a mysql function called NOW() which returns the current time, and I subtracted 60 seconds from it, of course you can change this to your own number, but make sure to change SECOND to MINUTE, HOUR, DAY, MONTH, YEAR if you need.

Solution

Your code is really hard to read and I didn't understand most of your functions or way of thinking however. This is as close as I could get to what you wanted:

Код:
for ( new i, j = cache_get_row_count( ); i != j; ++i )
{
	static 
		h_name[ 32 ],
		h_key,
		pid
	;

	cache_get_field_content( i, "Name", h_name ); // THIS FUNCTION IS USED FOR STRINGS ONLY

	h_key = cache_get_field_content_int( i, "HouseKey" ); // THIS FUNCTION IS USED FOR INTEGERS

	pid = GetPlayerID( h_name ); // Im guessing this function loops through all the players and checks if any player's name matches the one passed in?
		
	if( pid != INVALID_PLAYER_ID && IsPlayerConnected( pid ) )
	{
		format( gString, sizeof( gString ), "%s{FFFFFF}%s\t%s\tOnline\n", gString, h_name, h_key );
	}
	else
	{
		format( gString, sizeof( gString ), "%s{FFFFFF}%s\t%s\tOffline\n", gString, h_name, h_key );
	}

	memid ++;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)