[HELP]Split a string
#1

I do a system to save only the objects attached to the player that I would save all the 9 fields of '"SetPlayerAttachedObject" in one field of mysql instead of create 9.
Else is needed to use sscanf, but I do not understand how to use it to split a string.

well now I have made ​​the function to insert values ​​in database
PHP код:
stock SavePlayerObject(playeridindexmodelidboneidFloat:fOffsetXFloat:fOffsetYFloat:fOffsetZFloat:fRotXFloat:fRotYFloat:fRotZFloat:fScaleXFloat:fScaleYFloat:fScaleZ)
{
    new 
string[500];
    switch(
index)
    {
        case 
SLOT_TESTA:
        {
            
format(string,sizeof(string),"%d,%d,%.2f,%.2f,%.2f,%.2f,%.2f,%.2f,%.2f,%.2f,%.2f",modelidboneidFloat:fOffsetXFloat:fOffsetYFloat:fOffsetZFloat:fRotXFloat:fRotYFloat:fRotZFloat:fScaleXFloat:fScaleYFloat:fScaleZ);
            
MySQLUpdatePlayerStr(queryPlayerInfo[playerid][pSQLID], "OggettoTesta",string);
        }
        case 
SLOT_BOCCA:
        {
            
format(string,sizeof(string),"%d,%d,%.2f,%.2f,%.2f,%.2f,%.2f,%.2f,%.2f,%.2f,%.2f",modelidboneidFloat:fOffsetXFloat:fOffsetYFloat:fOffsetZFloat:fRotXFloat:fRotYFloat:fRotZFloat:fScaleXFloat:fScaleYFloat:fScaleZ);
            
MySQLUpdatePlayerStr(queryPlayerInfo[playerid][pSQLID], "OggettoBocca",string);
        }
        case 
SLOT_OCCHI:
        {
            
format(string,sizeof(string),"%d,%d,%.2f,%.2f,%.2f,%.2f,%.2f,%.2f,%.2f,%.2f,%.2f",modelidboneidFloat:fOffsetXFloat:fOffsetYFloat:fOffsetZFloat:fRotXFloat:fRotYFloat:fRotZFloat:fScaleXFloat:fScaleYFloat:fScaleZ);
            
MySQLUpdatePlayerStr(queryPlayerInfo[playerid][pSQLID], "OggettoOcchi",string);
        }
    }

PHP код:
stock LoadPlayerObject(playerid)
{
    new 
indexmodelidboneidFloat:fOffsetXFloat:fOffsetYFloat:fOffsetZFloat:fRotXFloat:fRotYFloat:fRotZFloat:fScaleXFloat:fScaleYFloat:fScaleZ;
    
//the string with all values it's PlayerInfo[playerid][pOggTesta]
    
SetPlayerAttachedObject(playeridindexmodelidboneidFloat:fOffsetXFloat:fOffsetYFloat:fOffsetZFloat:fRotXFloat:fRotYFloat:fRotZFloat:fScaleXFloat:fScaleYFloat:fScaleZ);

I do not know how to separate the various fields separated by a comma and assign to each variable and mostly how to convert the string into a numeric variable
Reply
#2

Use

pawn Код:
mysql_fetch_row(variableName);
after storing the result after your select and then

pawn Код:
sscanf(variableName, "p<|>ddfffffffff", all variables here, variable2, variable3, etc);
Reply
#3

Quote:
Originally Posted by SuperViper
Посмотреть сообщение
pawn Код:
sscanf(variableName, "p<|>ddfffffffff", all variables here, variable2, variable3, etc);
i change <|> to <,> right ?
Reply
#4

Nope, when you use

pawn Код:
mysql_fetch_row();
it seperates all of the columns with a '|'.
Reply
#5

Quote:
Originally Posted by SuperViper
Посмотреть сообщение
Nope, when you use

pawn Код:
mysql_fetch_row();
it seperates all of the columns with a '|'.
no you didn't understand

"PlayerInfo[playerid][pOggTesta]" already contains all variable in form of string because i've already set it whit all other PlayerInfo variables

Now for exemple PlayerInfo[playerid][pOggTesta] contains this string "1,1345,6,0.00,0.00,0.00,0.00,0.00,0.00,1.00,1.00, 1.00"

how do I separate the string??
Reply
#6

In that case, yes, change it to p<,>.
Reply
#7

ok tanks works fine
Reply
#8

sorry for double post but i test and will wont work i try this
PHP код:
stock LoadPlayerObject(playerid)
{
    new 
modelidboneidFloat:fOffsetXFloat:fOffsetYFloat:fOffsetZFloat:fRotXFloat:fRotYFloat:fRotZFloat:fScaleXFloat:fScaleYFloat:fScaleZ;
    
sscanf(PlayerInfo[playerid][pOggTesta], "p<,>ddfffffffff",modelid,boneid,fOffsetX,fOffsetY,fOffsetZ,fRotX,fRotY,fRotZ,fScaleX,fScaleY,fScaleZ);
    if(
modelid != -1)
    {
        new 
string[60];
        
SetPlayerAttachedObject(playeridSLOT_TESTAmodelidboneidfOffsetXfOffsetYfOffsetZfRotXfRotYfRotZfScaleXfScaleYfScaleZ);
        
format(string,sizeof(string),"%d,%d,%.2f,%.2f,%.2f,%.2f,%.2f,%.2f,%.2f,%.2f,%.2f",modelid,boneid,fOffsetX,fOffsetY,fOffsetZ,fRotX,fRotY,fRotZ,fScaleX,fScaleY,fScaleZ);
        
SendClientMessage(playerid,COLOR_WHITE,string);
    }
    
sscanf(PlayerInfo[playerid][pOggBocca], "p<,>ddfffffffff",modelid,boneid,fOffsetX,fOffsetY,fOffsetZ,fRotX,fRotY,fRotZ,fScaleX,fScaleY,fScaleZ);
    if(
modelid != -1)
    {
        new 
string[60];
        
SetPlayerAttachedObject(playeridSLOT_BOCCAmodelidboneidfOffsetXfOffsetYfOffsetZfRotXfRotYfRotZfScaleXfScaleYfScaleZ);
        
format(string,sizeof(string),"%d,%d,%.2f,%.2f,%.2f,%.2f,%.2f,%.2f,%.2f,%.2f,%.2f",modelid,boneid,fOffsetX,fOffsetY,fOffsetZ,fRotX,fRotY,fRotZ,fScaleX,fScaleY,fScaleZ);
        
SendClientMessage(playerid,COLOR_WHITE,string);
    }
    
sscanf(PlayerInfo[playerid][pOggOcchi], "p<,>ddfffffffff"modelid,boneid,fOffsetX,fOffsetY,fOffsetZ,fRotX,fRotY,fRotZ,fScaleX,fScaleY,fScaleZ);
    if(
modelid != -1)
    {
        new 
string[60];
        
SetPlayerAttachedObject(playeridSLOT_OCCHImodelidboneidfOffsetXfOffsetYfOffsetZfRotXfRotYfRotZfScaleXfScaleYfScaleZ);
        
format(string,sizeof(string),"%d,%d,%.2f,%.2f,%.2f,%.2f,%.2f,%.2f,%.2f,%.2f,%.2f",modelid,boneid,fOffsetX,fOffsetY,fOffsetZ,fRotX,fRotY,fRotZ,fScaleX,fScaleY,fScaleZ);
        
SendClientMessage(playerid,COLOR_WHITE,string);
    }

And in Game it return

PHP код:
[19:37:060,0,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00
[19:37:060,0,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00
[19:37:060,0,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00 
The values isn't setted to variables D: why??
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)