mysql related question r39
#1

Hi,
i was wondering if you could make a stock like
SQL_GetInt(name[], field[])
using cache ?
like select field from `rp` where `username`=name ....
and i want to use it in the gamemode like :

Код:
if(SQL_GetInt("Someone", "Member") > 1)
{
// do something here
}
Reply
#2

No, you cannot because you must wait for the result.
Reply
#3

This is pretty important because i have this :
Код:
stock GetPlayerOFactionName(targetname[])
{
	new ttext[64];
	// if player is in a family, format family name
	if(dini_Int(targetname, "FMember") != 255)
	    format(ttext,sizeof(ttext),"%s",FamilyInfo[dini_Int(targetname, "FMember")][FamilyName]);
	// else format faction name
	else
	{
		switch(dini_Int(targetname, "Member"))
		{
			case 1: ttext = "lspd";
			case 2: ttext = "FBI";
			case 3: ttext = "RCSD";
			case 4: ttext = "LSFMD";
			case 5: ttext = "NG";
			case 6: ttext = "Senate";
			case 66413: ttext = "????";
			case 8: ttext = "Hitmen";
			case 9: ttext = "News";
			case 10: ttext = "Taxi";
			default: ttext = "None";
		}
	}
	return ttext;
}
and i want to turn it into mysql !
Reply
#4

Quote:

i want to turn it into mysql !

What i used to do way back (when mysql was still virtually impossible) was load my ini files, memorize them by storing the data in a multidimensional array in my script, and only update the ini files at set intervals and on player-leave or server-stop, this is exactly what you will need to do for your mysql.

0] Make array to store player data
1] Get player data from mysql db on player join
2] Store in player-data-array
3] Use player-data-array troughout your code as a source of player data
4] Update any player data in the array troughout your code
5] At set intervals (like every 5 minutes) save all the player-data from the array to the related mysql records
6] When a player leaves, save all the player-data from the array to the related mysql record
7] When you shut down server/gamemode, run step [5] once more to save everything again.

All in all, this is quite a big thing, way more then what i conciser "small enough to code as a reply to a question", so i would strongly suggest you start by looking at this tutorial, or this tutorial, then once you have a basic mysql based user profile system, come back here if you want more explenation about the player-data-array (both tutorials have such an array btw, they just dont go into a whole lot of detail on when you should be saving back to mysql db)
Reply
#5

Quote:
Originally Posted by bare380
Посмотреть сообщение
This is pretty important because i have this :
Код:
stock GetPlayerOFactionName(targetname[])
{
	new ttext[64];
	// if player is in a family, format family name
	if(dini_Int(targetname, "FMember") != 255)
	    format(ttext,sizeof(ttext),"%s",FamilyInfo[dini_Int(targetname, "FMember")][FamilyName]);
	// else format faction name
	else
	{
		switch(dini_Int(targetname, "Member"))
		{
			case 1: ttext = "lspd";
			case 2: ttext = "FBI";
			case 3: ttext = "RCSD";
			case 4: ttext = "LSFMD";
			case 5: ttext = "NG";
			case 6: ttext = "Senate";
			case 66413: ttext = "????";
			case 8: ttext = "Hitmen";
			case 9: ttext = "News";
			case 10: ttext = "Taxi";
			default: ttext = "None";
		}
	}
	return ttext;
}
and i want to turn it into mysql !
You're not formatting anything...
All you're doing is telling "ttext" that it's a string that contains.. "name"...

You should be..
PHP код:
new ttext[128];
format(ttextsizeof(ttext), "%s", case); 
then.. return ttext
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)