SA-MP Forums Archive
[HELP]Split a string - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: [HELP]Split a string (/showthread.php?tid=337224)



[HELP]Split a string [SSCANF PROBLEM] - xX_Simon_Xx - 25.04.2012

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


Re: Save an attached player object in one Mysql field - SuperViper - 25.04.2012

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);



Re: Save an attached player object in one Mysql field - xX_Simon_Xx - 25.04.2012

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


Re: [HELP]Split a string - SuperViper - 25.04.2012

Nope, when you use

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


Re: [HELP]Split a string - xX_Simon_Xx - 25.04.2012

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??


Re: [HELP]Split a string - SuperViper - 25.04.2012

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


Re: [HELP]Split a string - xX_Simon_Xx - 25.04.2012

ok tanks works fine


Re: [HELP]Split a string - xX_Simon_Xx - 25.04.2012

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??