SQL -> Vehicle saving
#1

PHP код:
stock SaveCar(playerid)
{
    new 
tr playerCar1[playerid],
        
EngineLightsAlarmDoorsBonnetBootObjective;
    static 
Float:lastPosition[4], Float:bukles;
    
GetVehiclePos(trlastPosition[0], lastPosition[1], lastPosition[2]);
    
GetVehicleZAngle(trlastPosition[3]);
    
GetVehicleParamsEx (trEngineLightsAlarmDoorsBonnetBootObjective);
    
GetVehicleHealth(trbukles);
    if ( 
playerCar1 playerid ] != -)
    {
        
format(g_szBuffersizeof g_szBuffer
        
"UPDATE "MySQL_VEHICLE_TABLE" SET \
    \
            uzraktas = %i, \
            degalai = %f, \
            statusas = %i, \
            variklis = %i, \
            bukle = %f, \
            numeriai = %s, \
            rida = %f, \
            posX = %f, \
            posY = %f, \
            posZ = %f, \
            posA = %f, \
            technikine = %i, \
            techlaikas = %i \
    \
        WHERE savininkas = %s"
,
        
masinatr ][ lock ],
        
masinatr ][ Gas ],
        
masinatr ][ status ],
        
Engine,
        
bukles,
        
masinatr ][vehNumber],
        
masinatr ][ vehRida ],
        
lastPosition[0],
        
lastPosition[1],
        
lastPosition[2],
        
lastPosition[3],
        
masinatr ][ vehTech ],
        
masinatr ][ vehTechtime ],
        
getPlayerName(playerid));
        
sql_query(sqlg_szBufferQUERY_THREADED);
        
printf("%s transportas isaugotas ( %f , %f, %f, %f )"getPlayerName(playerid),lastPosition[0], lastPosition[1], lastPosition[2], lastPosition[3]);
    }
    
DestroyVehicle(tr);

printf:
PHP код:
[07:52:43Iam_Satan transportas isaugotas ( -2048.752929 307.54745440.62011349.947959 
SQL LOG
PHP код:
[21:24:36][debugNatives::sql_queryScheduling statement (stmt->id 16stmt->query UPDATE vehicles SET uzraktas 0degalai 40.000000statusas 0variklis 1bukle 789.740234numeriai NEREGISTRUOTArida 0.000000posX = -2276.572265posY 365.594726posZ 33.922851posA 229.472518technikine 0techlaikas 0 WHERE savininkas Iam_Satanstmt->callback = ) for execution...
[
21:24:36][debugSQL_Worker[1]: Executing query (stmt->id 16stmt->query UPDATE vehicles SET uzraktas 0degalai 40.000000statusas 0variklis 1bukle 789.740234numeriai NEREGISTRUOTArida 0.000000posX = -2276.572265posY 365.594726posZ 33.922851posA 229.472518technikine 0techlaikas 0 WHERE savininkas Iam_Satan)... 
But in dB nothing changes..:
Reply
#2

any one?
Reply
#3

Код:
WHERE savininkas = 'Iam_Satan'
You need quotes there. What plugin is this anyway? It sends debug information on anything, but errors? And if I may give you a hint, don't use player names as a key.
Reply
#4

So what should I instead playername?
Reply
#5

Quote:
Originally Posted by Vince
Посмотреть сообщение
Код:
WHERE savininkas = 'Iam_Satan'
You need quotes there. What plugin is this anyway? It sends debug information on anything, but errors? And if I may give you a hint, don't use player names as a key.
That didin't worked with ''
Reply
#6

@Vince,
https://github.com/udan11/samp-plugin-sql
https://sampforum.blast.hk/showthread.php?tid=429464
Quote:
Originally Posted by bogushas
Посмотреть сообщение
So what should I instead playername?
Player id

I don't see what else could be the fault, my only guess would be wrong database.
Reply
#7

Quote:
Originally Posted by bogushas
Посмотреть сообщение
So what should I instead playername?
Every player should have a unique ID in the database.
An ID is just an integer variable, usually that column is set to auto_increment and Primary Key.
Integers are alot faster to search for compared to a string.

For owned vehicles, you should store the player's ID as set in MySQL.

You would get in trouble if you allow a /changename command, which would allow the player to change his name.
Then you would not only need to update his name in your playerdata table, but in the owned vehicles table as well.

When you use his ID, you can change his name all the time, as everything is connected to his ID, which never changes.
Reply
#8

Mmm.. I have these 2 stocks:
PHP код:
stock getPlayerSqlID(pid) return player[pid][pSqlID];
stock setPlayerSqlID(pididplayer[pid][pSqlID] = id
I use it here:
PHP код:
stock playerExist(pid)
{
    new const 
Result:sql_query(sql,
        
f("SELECT id FROM "MySQL_PLAYERS_TABLE" WHERE pName = '%s'"getPlayerName(pid)),
        
QUERY_CACHED
    
);
    if(
sql_num_rows(r))
    {
        
setPlayerSqlID(pidsql_get_field_assoc_int(r"id"));
        return 
true;
    
    } else {
        return 
false;
    }

PHP код:
stock registerPlayer(pid)
{
    
inline register(iddidresponselistitemstring:inputtext[])
    {
        
#pragma unused id, did, listitem
        
if(response)
        {
            if(
isnull(inputtext))
            {
                
registerPlayer(pid);
            
            } else {
                new 
pw[130];
                
WP_Hash(pwsizeof pwinputtext);
                new const 
Result:sql_query(sql,
                    
f("INSERT INTO "MySQL_PLAYERS_TABLE" (pName, pPw) VALUES ('%s', '%s')"getPlayerName(pid), pw),
                    
QUERY_NONE // none naudoti, kada reikia palaukti kol duomenys bus įraљyti į mysql
                
);
                
setPlayerSqlID(pidsql_insert_id(r));
                
set.fPrisijunge[pid] = true;
                
OnPlayerRegister(pid);
            }
        } else {
            
Kick(pid);
        }
    }
    
showDialog(pidusing inline registerDIALOG_STYLE_INPUT"{FFC13B}•{ffffff} REGISTRACIJA""Įvesk naują slaptaћodį:""Jungtis""");

So how should I place this SQL it to vehicle id?
On Player buys vehicle:
PHP код:
YCMD:pirkti(playeridparams[], help)
{
    if(
playerCar1 playerid ] != -1) return SendError(playerid"jūs jau turite transportą !");
    
printf("lol1");
    if( 
vehSelectedplayerid ] == sportCars ) return 0;
    
printf("lol2");
    if( 
soldCarsvehSelected playerid ] ][ soldPrice ] > getPlayerMoneyplayerid ) ) return SendErrorplayerid"Neuћtenka pinigų transportui!" )   ;
    
givePlayerMoney(playerid, -soldCarsvehSelected playerid ] ][ soldPrice ]);
    
printf("lol3");
    
playerCar1 playerid ] = CreateVehicle soldCarsvehSelectedplayerid ]][ soldModel ], -1979.8074,270.152190,0000ChosenColor[playerid], ChosenColor[playerid], -) ;
    
format masina playerCar1 playerid ] ] [ vehOwner ] , 50 "%s" getPlayerName playerid ) ) ;
    for ( new 
tune 0tune 13tune++ ) masina playerCar1 playerid ] ] [ vehTune ] [ tune ] = 0;
    for ( new 
color 0color 2color++ ) masina playerCar1 playerid ] ] [ vehColor ] [ color ] = ChosenColor[playerid];
    
masina playerCar1 playerid ] ] [ vehPaintjob ] = -1;
    
masina playerCar1 playerid ] ] [ lock ] = true;
    
masina playerCar1 playerid ] ] [ vehRida ] = 0.0;
    
masina playerCar1 playerid ] ] [ Gas ] = 40;
    
masina playerCar1 playerid ] ] [ vehLastPos ] [ ] = -1979.8074;
    
masina playerCar1 playerid ] ] [ vehLastPos ] [ ] = 270.1521 ;
    
masina playerCar1 playerid ] ] [ vehLastPos ] [ ] = 35.0415 ;
    
masina playerCar1 playerid ] ] [ vehLastPos ] [ ] = 90.0000 ;
    
masina playerCar1 playerid ] ] [ vehModel ] = soldCarsvehSelectedplayerid ]][ soldModel ];
    
masina playerCar1 playerid ] ] [ vehOwned ] = true;
    
SetVehicleParamsEx playerCar1 playerid ], falsefalsefalsefalsefalsefalsefalse ) ;
    new 
query 200 ];
    
format query sizeof query ) , "NEREGISTRUOTA") ;
    
SetVehicleNumberPlate playerCar1 playerid ] , query) ;
    
format masina playerCar1 playerid ] ] [ vehNumber ] , 21 "%s" query ) ;
    
format(g_szBuffersizeof g_szBuffer
    
"INSERT INTO "MySQL_VEHICLE_TABLE" \
    \
        (savininkas, \
        modelis, \
        posX, \
        posY, \
        posZ, \
        posA, \
        spalva1, \
        spalva2, \
        kaina, \
        degalai, \
        numeriai) \
    \
        VALUES \
        ('%s', '%i', '%f', '%f', '%f', '%f', '%i', '%i', '%i', '%f', '%s')"
, \ 
    
masinaplayerCar1 playerid ] ][ vehOwner ],
    
masinaplayerCar1 playerid ] ][ vehModel ], 
    
masinaplayerCar1 playerid ] ][ vehLastPos ][0],
    
masinaplayerCar1 playerid ] ][ vehLastPos ][1], 
    
masinaplayerCar1 playerid ] ][ vehLastPos ][2],
    
masinaplayerCar1 playerid ] ][ vehLastPos ][3],
    
ChosenColor[playerid],
     
ChosenColor[playerid],
    
masinaplayerCar1 playerid ] ][ vehKaina ], 
    
masinaplayerCar1 playerid ] ][ Gas ], 
    
masinaplayerCar1 playerid ] ][ vehNumber ]);
    
sql_query(sqlg_szBufferQUERY_THREADED);
    
format query sizeof query ) , "Nusipirkote transportą ( {f86000}%s{ffffff} ), kurio numeriai ( {f86000}%s{ffffff} ) !" aVehicleNames masina playerCar1 playerid ] ] [ vehModel ] - 400 ], masina[playerCar1[playerid]][vehNumber] ) ;
    
SendClientMessage(playerid,-1,query);
    
CancelSelectTextDraw(playerid);
    
SetPlayerVirtualWorld(playerid0);
    
//SendClientMessage(playerid, 0xFFFFFFAA, "isejai is car shopo :).");
    
hideCarShop(playerid);
    
DestroyVehiclepreVehplayerid ] )    ;
    
SetCameraBehindPlayerplayerid );
    
TogglePlayerControllableplayerid) ;
    return 
1;

Still it no sense, the info should save by name...
Reply


Forum Jump:


Users browsing this thread: