Using cache_get_row_float and other questions
#1

1.
Код:
    cache_get_row(0, 0, strr); pData[playerid][ID] = strval(strr);
    cache_get_row(0, 4, strr); pData[playerid][Level] = strval(strr);
    cache_get_row(0, 5, strr); pData[playerid][Colour] = strval(strr);
    cache_get_row(0, 6, strr); pData[playerid][RegTime] = strval(strr);
    cache_get_row(0, 7, strr); pData[playerid][OnlineTime] = strval(strr);
    cache_get_row(0, 8, strr); pData[playerid][Score] = strval(strr);
    cache_get_row(0, 9, strr); pData[playerid][Money] = strval(strr);
    
    pData[playerid][pX] = cache_get_row_float(0, 10);
    pData[playerid][pY] = cache_get_row_float(0, 11);
    pData[playerid][pZ] = cache_get_row_float(0, 12);
Are those correct? Anything off or missing?

2. How would I make a player spawn, wherein the data would be taken from the MySQL database? Should it be in :-
  • Under the same stock (stock which contains code being executed after player logs in after password check)?
or
  • Under OnPlayerSpawn or any other callback?
Thanks.
Reply
#2

Код:
<parallx> what's the difference between cache_get_row_float and cache_get_field_content_float?
Cache_get_row_float means it load player float with row id and in cache_get_field_content_float it load player float with row name

example

Код:
pData[playerid][pX] = cache_get_row_float(0, 10); // row number is 10 its an example
Cache_get_field_content_float and it doesnt matter if px row is 10 or 12
Код:
 pData[playerid][pX] = cache_get_field_content_float(0,"px");
Код:
public OnPlayerSpawn(playerid)
{

    SetPlayerPos(playerid, pData[playerid][pX], pData[playerid][pY], pData[playerid][pZ]);
    return 1;
}
Reply
#3

Quote:
Originally Posted by Parallax
Посмотреть сообщение
1.
Код:
    cache_get_row(0, 0, strr); pData[playerid][ID] = strval(strr);
    cache_get_row(0, 4, strr); pData[playerid][Level] = strval(strr);
    cache_get_row(0, 5, strr); pData[playerid][Colour] = strval(strr);
    cache_get_row(0, 6, strr); pData[playerid][RegTime] = strval(strr);
    cache_get_row(0, 7, strr); pData[playerid][OnlineTime] = strval(strr);
    cache_get_row(0, 8, strr); pData[playerid][Score] = strval(strr);
    cache_get_row(0, 9, strr); pData[playerid][Money] = strval(strr);
    
    pData[playerid][pX] = cache_get_row_float(0, 10);
    pData[playerid][pY] = cache_get_row_float(0, 11);
    pData[playerid][pZ] = cache_get_row_float(0, 12);
Are those correct? Anything off or missing?

2. How would I make a player spawn, wherein the data would be taken from the MySQL database? Should it be in :-
  • Under the same stock (stock which contains code being executed after player logs in after password check)?
or
  • Under OnPlayerSpawn or any other callback?
Thanks.
You should use cache_get_row_int or cache_get_field_content_int to get integer from MySQL.
Код:
pData[playerid][ID] = cache_get_row_int(0, 0);
pData[playerid][Level] = cache_get_row_int(0, 4);
pData[playerid][Colour] = cache_get_row_int(0, 5);
pData[playerid][RegTime] = cache_get_row_int(0, 6);
pData[playerid][OnlineTime] = cache_get_row_int(0, 7);
pData[playerid][Score] = cache_get_row_int(0, 8);
pData[playerid][Money] = cache_get_row_int(0, 9);
If you save it as integer in MySQL database, you should.
Reply
#4

1. cache_get_row_int and cache_get_row_float are slightly faster than using cache_get_row and strval/floatstr.

Also cache_get_row and cache_get_row_* functions are faster than using cache_get_field_content and cache_get_field_content_* functions.

2. After loading and storing the data to variables, you can use SetSpawnInfo to change the spawn position with the coordinates you loaded.
Reply
#5

Quote:
Originally Posted by JeaSon
Посмотреть сообщение
-snip-
Someone did notice my IRC help msg, thanks man!

Quote:
Originally Posted by Awdratai
Посмотреть сообщение
-snip-
Ah, thanks for the restructuring!

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
-snip-
Where should I put the SetSpawnInfo code? On OnPlayerSpawn or?
Reply
#6

In the public function you assign the data to the player's variables.

pawn Код:
// assigning..
...
pData[playerid][pX] = cache_get_row_float(0, 10);
pData[playerid][pY] = cache_get_row_float(0, 11);
pData[playerid][pZ] = cache_get_row_float(0, 12);

SetSpawnInfo(playerid, ..., pData[playerid][pX], pData[playerid][pY], pData[playerid][pZ], ...);
SpawnPlayer(playerid);
Reply
#7

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
In the public function you assign the data to the player's variables.

pawn Код:
// assigning..
...
pData[playerid][pX] = cache_get_row_float(0, 10);
pData[playerid][pY] = cache_get_row_float(0, 11);
pData[playerid][pZ] = cache_get_row_float(0, 12);

SetSpawnInfo(playerid, ..., pData[playerid][pX], pData[playerid][pY], pData[playerid][pZ], ...);
SpawnPlayer(playerid);
That did the trick! Thanks!
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)