Mysql saving & loading problems + timing
#1

First problem is that, when I change data @ database, like money, score and licenes.. When I go online, it can't read money ( " pRaha " ). But when I use /raha to get money, it gives me some and saves it on exit.. So basically it just can't read " raha " row from database.

Seconds problem is that, I log in and it can load my Score, but when I leave the server it turns my Score to 0 @ database. ( " pSkoor " ).

And third.. I have part of the script that should read played time, but the seconds don't run right.. It counts less than there actually should be.. =/

Hope someone could help :S

pawn Код:
// This is a comment
// uncomment the line below if you want to write a filterscript
//#define FILTERSCRIPT

#include <a_samp>
#include <sscanf2>
#include <a_mysql>
#include <zcmd>
#include                <foreach>

#define                 COLOR_WHITE                             0xFFFFFFAA
#define                 THREAD_LOE_ANDMED
#define                 MAX_TIMERS                              (5)
#define                 INTERIOR_WEATHER_ID                     (1)
#define                 MAX_WEATHER_POINTS                      (9)

#define ColorClassTruckDriver       0xFF8000FF // Orange
#define ColorClassBusDriver         0x80FFFFFF // Light blue
#define ColorClassPilot             0x008080FF // Dark blue
#define ColorClassPolice            0x0000FFFF // Blue
#define ColorClassCourier           0xFF0080FF // Pink
#define ColorClassAssistance        0x80FF00FF // Dark green
#define ColorClassRoadWorker        0xFFFF80FF // Light yellow

#if defined FILTERSCRIPT

public OnFilterScriptInit()
{
    print("\n--------------------------------------");
    print(" Blank Filterscript by your name here");
    print("--------------------------------------\n");
    return 1;
}

public OnFilterScriptExit()
{
    return 1;
}

#else

main()
{
    print("\n----------------------------------");
    print(" Blank Gamemode by your name here");
    print("----------------------------------\n");
}

enum playerEnum {
    pPassword,
    pRaha,
    pSkoor,
    pLogged,
    ppiloot,
    ppolitsei,
    pConnectedSeconds,
    pPlayingHours,
    pSeconds,
    pClass,
}

#endif

new andmed[MAX_PLAYERS][playerEnum];

new szMessage[128];

new scriptTimers[MAX_TIMERS];
new weatherVariables[2];
new validWeatherIDs[17] = { 1, 2, 3, 4, 5, 6, 7, 9, 10, 11, 12, 13, 14, 15, 17, 18, 20 };
new gTime[3];

forward                 globalPlayerLoop();

public OnGameModeInit()
{
    mysql_connect("localhost", "root", "mysqlscript", "");

    scriptTimers[0] = SetTimer("globalPlayerLoop", 1000, true);

    weatherVariables[0] = validWeatherIDs[random(sizeof(validWeatherIDs))];
    SetWeather(weatherVariables[0]);

    // Don't use these lines if it's a filterscript
    SetGameModeText("Blank Script");
    AddPlayerClass(0, 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 0, 0, 0, 0);
    return 1;
}

public OnGameModeExit()
{
    new
        x;

    while(x < MAX_TIMERS) {
        KillTimer(scriptTimers[x]);
        x++;
    }
    return 1;
}

public OnPlayerRequestClass(playerid, classid)
{
    return 1;
}

public OnPlayerConnect(playerid)
{
    TogglePlayerSpectating(playerid, true);

    SetPlayerColor(playerid, COLOR_WHITE);
    nulliandmed(playerid);

    new logi[126], Name[MAX_PLAYER_NAME];

    GetPlayerName(playerid, Name, sizeof(Name));

    mysql_real_escape_string(Name, Name);

    format(logi, sizeof(logi), "SELECT * FROM kasutajad WHERE nimi = '%s'", Name);
    mysql_query(logi);
    mysql_store_result();

    if(mysql_num_rows() != 0)
    {
        SendClientMessage(playerid, -1, "See kasutaja on juba registreeritud");
        ShowPlayerDialog(playerid, 0, DIALOG_STYLE_INPUT, "Logimine", "Palun logi sisse kasutades enda parooli", "Logi", "Keeldu");
    }
    else
    {
        ShowPlayerDialog(playerid, 1, DIALOG_STYLE_INPUT, "Registreeri", "Palun sisesta parool enda uuele kasutajale", "Registreeri", "Keeldu");
    }

    return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
    if(andmed[playerid][pLogged] == 1) {

        salvestaandmed(playerid);
        andmed[playerid][pLogged] = -1;

    }
    return 1;
}

public OnPlayerSpawn(playerid)
{
    return 1;
}

public OnPlayerDeath(playerid, killerid, reason)
{
    return 1;
}

public OnVehicleSpawn(vehicleid)
{
    return 1;
}

public OnVehicleDeath(vehicleid, killerid)
{
    return 1;
}

public OnPlayerText(playerid, text[])
{
    return 1;
}

public OnPlayerCommandText(playerid, cmdtext[])
{
    if (strcmp("/mycommand", cmdtext, true, 10) == 0)
    {
        // Do something here
        return 1;
    }
    return 0;
}

public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
    return 1;
}

public OnPlayerExitVehicle(playerid, vehicleid)
{
    return 1;
}

public OnPlayerStateChange(playerid, newstate, oldstate)
{
    return 1;
}

public OnPlayerEnterCheckpoint(playerid)
{
    return 1;
}

public OnPlayerLeaveCheckpoint(playerid)
{
    return 1;
}

public OnPlayerEnterRaceCheckpoint(playerid)
{
    return 1;
}

public OnPlayerLeaveRaceCheckpoint(playerid)
{
    return 1;
}

public OnRconCommand(cmd[])
{
    return 1;
}

public OnPlayerRequestSpawn(playerid)
{
    return 1;
}

public OnObjectMoved(objectid)
{
    return 1;
}

public OnPlayerObjectMoved(playerid, objectid)
{
    return 1;
}

public OnPlayerPickUpPickup(playerid, pickupid)
{
    return 1;
}

public OnVehicleMod(playerid, vehicleid, componentid)
{
    return 1;
}

public OnVehiclePaintjob(playerid, vehicleid, paintjobid)
{
    return 1;
}

public OnVehicleRespray(playerid, vehicleid, color1, color2)
{
    return 1;
}

public OnPlayerSelectedMenuRow(playerid, row)
{
    return 1;
}

public OnPlayerExitedMenu(playerid)
{
    return 1;
}

public OnPlayerInteriorChange(playerid, newinteriorid, oldinteriorid)
{
    return 1;
}

public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    return 1;
}

public OnRconLoginAttempt(ip[], password[], success)
{
    return 1;
}

public OnPlayerUpdate(playerid)
{
    return 1;
}

public OnPlayerStreamIn(playerid, forplayerid)
{
    return 1;
}

public OnPlayerStreamOut(playerid, forplayerid)
{
    return 1;
}

public OnVehicleStreamIn(vehicleid, forplayerid)
{
    return 1;
}

public OnVehicleStreamOut(vehicleid, forplayerid)
{
    return 1;
}

public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    switch(dialogid)
    {
        case 0:
        {
            if(response)
            {
                new query[150], pName[MAX_PLAYER_NAME];
                GetPlayerName(playerid, pName, sizeof(pName));

                mysql_real_escape_string(pName, pName);

                format(query, sizeof(query), "SELECT * FROM kasutajad WHERE nimi = '%s' AND parool = '%s' LIMIT 1", pName, inputtext);
                mysql_query(query);
               
                mysql_store_result();

                if(mysql_num_rows() == 1)
                {
                    SendClientMessage(playerid, -1, "Sa oled edukalt sisse logitud!");
                    TogglePlayerSpectating(playerid, false);
                    andmed[playerid][pLogged] = 1;
                    laeandmed(playerid);
                    ShowPlayerDialog(playerid, 2, DIALOG_STYLE_LIST, "Amet", "Pitsapoiss\nKuller\nBussijuht\nRekkamees\nPiloot\nPolitseinik", "Vali", "");

                }
                else
                {
                    SendClientMessage(playerid, -1, "Sa sisestasid vale parooli!");
                    ShowPlayerDialog(playerid, 0, DIALOG_STYLE_INPUT, "Logimine", "Palun logi sisse kasutades enda parooli", "Logi", "Keeldu");

                }
            }
            else
            {
                Kick(playerid);
            }
        }
        case 1:
        {
            if(response)
            {
                new regi[256], pName[MAX_PLAYER_NAME];
                GetPlayerName(playerid, pName, sizeof(pName));

                format(regi, sizeof(regi), "INSERT INTO kasutajad (nimi, parool, registreerus) VALUES('%s', '%s', NOW())", pName, inputtext);
                mysql_query(regi);
                mysql_store_result();

                SendClientMessage(playerid, -1, "Sinu kasutaja on nььd registreeritud!");

                mysql_free_result();

                ShowPlayerDialog(playerid, 0, DIALOG_STYLE_INPUT, "Logimine", "Palun logi sisse kasutades enda parooli", "Logi", "Keeldu");
            }
            else
            {
                Kick(playerid);
            }
        }
        case 2:
        {
            switch(listitem)
            {
                case 0:
                {
                    SendClientMessage(playerid, -1, "Asusid tццle pitsapoisina!");
                    andmed[playerid][pClass] = 1;
                    SetPlayerColor(playerid, ColorClassRoadWorker);
                    SetSpawnInfo(playerid, 1, 293, 192.3013, -218.8836, 1.5781, 321.2913, 0, 0, 0, 0, 0, 0);
                    SpawnPlayer(playerid);
                }
                case 1:
                {
                    SendClientMessage(playerid, -1, "Asusid tццle kullerina!");
                    andmed[playerid][pClass] = 2;
                    SetPlayerColor(playerid, ColorClassCourier);
                    SetSpawnInfo(playerid, 1, 294, 1, 2, 3, 1, 0, 0, 0, 0, 0, 0);
                    SpawnPlayer(playerid);
                }
                case 2:
                {
                    SendClientMessage(playerid, -1, "Asusid tццle bussijuhina!");
                    andmed[playerid][pClass] = 3;
                    SetPlayerColor(playerid, ColorClassBusDriver);
                    SetSpawnInfo(playerid, 1, 295, 1, 2, 3, 1, 0, 0, 0, 0, 0, 0);
                    SpawnPlayer(playerid);
                }
                case 3:
                {
                    SendClientMessage(playerid, -1, "Asusid tццle rekkamehena!");
                    andmed[playerid][pClass] = 4;
                    SetPlayerColor(playerid, ColorClassTruckDriver);
                    SetSpawnInfo(playerid, 1, 295, 1, 2, 3, 1, 0, 0, 0, 0, 0, 0);
                    SpawnPlayer(playerid);
                }
                case 4:
                {
                    if(andmed[playerid][ppiloot] != 1)
                    {
                        SendClientMessage(playerid, -1, "Sul pole veel piloodi litsentsi! Info saamiseks vali mхni teine tцц ja uuri /abi");
                        ShowPlayerDialog(playerid, 2, DIALOG_STYLE_LIST, "Amet", "Pitsapoiss\nKuller\nBussijuht\nRekkamees\nPiloot\nPolitseinik", "Vali", "");
                    }
                    else
                    {
                        SendClientMessage(playerid, -1, "Asusid tццle piloodina!");
                        andmed[playerid][pClass] = 5;
                        SetPlayerColor(playerid, ColorClassPilot);
                        SetSpawnInfo(playerid, 1, 295, 1, 2, 3, 1, 0, 0, 0, 0, 0, 0);
                        SpawnPlayer(playerid);
                    }
                }
                case 5:
                {
                    if(andmed[playerid][ppolitsei] != 1)
                    {
                        SendClientMessage(playerid, -1, "Sul pole veel politsei litsentsi! Info saamiseks vali mхni teine tцц ja uuri /abi");
                        ShowPlayerDialog(playerid, 2, DIALOG_STYLE_LIST, "Amet", "Pitsapoiss\nKuller\nBussijuht\nRekkamees\nPiloot\nPolitseinik", "Vali", "");
                    }
                    else
                    {
                        SendClientMessage(playerid, -1, "Asusid tццle politeinikuna!");
                        andmed[playerid][pClass] = 6;
                        SetPlayerColor(playerid, ColorClassPolice);
                        SetSpawnInfo(playerid, 1, 295, 1, 2, 3, 1, 0, 0, 0, 0, 0, 0);
                        SpawnPlayer(playerid);
                    }
                }
            }
        }
    }

    return 1;
}

public OnPlayerClickPlayer(playerid, clickedplayerid, source)
{
    return 1;
}

public globalPlayerLoop() {
    gettime(gTime[0], gTime[1], gTime[2]);

    if(gTime[1] >= 59 && gTime[2] >= 59) {

        weatherVariables[1] += random(3) + 1; // Weather changes aren't regular.

        SetWorldTime(gTime[0]); // Set the world time to keep the worldtime variable updated (and ensure it syncs instantly for connecting players).

        if(weatherVariables[1] >= MAX_WEATHER_POINTS) {
            weatherVariables[0] = validWeatherIDs[random(sizeof(validWeatherIDs))];
            foreach(Player, i) {
                if(!GetPlayerInterior(i)) {
                    SetPlayerWeather(i, weatherVariables[0]);
                }
                else SetPlayerWeather(i, INTERIOR_WEATHER_ID);
            }
            weatherVariables[1] = 0;
        }
    }

    /* ------------------------------------------------------ */

    foreach(Player, x) {

        andmed[x][pConnectedSeconds] += 1;

        if(gTime[2] >= 59) syncPlayerTime(x);

        if(andmed[x][pLogged] == 1) {
            andmed[x][pSeconds]++;

            if(andmed[x][pSeconds] >= 3600) {

                    andmed[x][pSeconds] = 0;
                    andmed[x][pPlayingHours]++;
            }
           
            if(GetPlayerMoney(x) != andmed[x][pRaha]) {
                ResetPlayerMoney(x);
                GivePlayerMoney(x, andmed[x][pRaha]);
            }
        }
    }
   
    return true;
}

stock unixTimeConvert(timestamp, compare = -1) {
    if(compare == -1)
        compare = gettime();

    new
        n,
        Float:d = (timestamp > compare) ? timestamp - compare : compare - timestamp,
        returnstr[32];

    if (d < 60) {
        format(returnstr, sizeof(returnstr), "< 1 minute");
        return returnstr;
    } else if (d < 3600) { // 3600 = 1 hour
        n = floatround(floatdiv(d, 60.0), floatround_floor);
        format(returnstr, sizeof(returnstr), "minute");
    } else if (d < 86400) { // 86400 = 1 day
        n = floatround(floatdiv(d, 3600.0), floatround_floor);
        format(returnstr, sizeof(returnstr), "hour");
    } else if (d < 2592000) { // 2592000 = 1 month
        n = floatround(floatdiv(d, 86400.0), floatround_floor);
        format(returnstr, sizeof(returnstr), "day");
    } else if (d < 31536000) { // 31536000 = 1 year
        n = floatround(floatdiv(d, 2592000.0), floatround_floor);
        format(returnstr, sizeof(returnstr), "month");
    } else {
        n = floatround(floatdiv(d, 31536000.0), floatround_floor);
        format(returnstr, sizeof(returnstr), "year");
    }

    if (n == 1) {
        format(returnstr, sizeof(returnstr), "1 %s", returnstr);
    } else {
        format(returnstr, sizeof(returnstr), "%d %ss", n, returnstr);
    }
    return returnstr;
}

stock nulliandmed(const playerid)
{
    andmed[playerid][pRaha] = 0;
    andmed[playerid][pSkoor] = 0;

    andmed[playerid][pLogged] = 0;

    andmed[playerid][ppiloot] = 0;
    andmed[playerid][ppolitsei] = 0;

    andmed[playerid][pSeconds] = 0;
    andmed[playerid][pConnectedSeconds] = 0;
    andmed[playerid][pPlayingHours] = 0;

    andmed[playerid][pClass] = 0;

    return true;
}

stock laeandmed(playerid)
{
    new query[300], pname[24], savingstring[20];
    GetPlayerName(playerid, pname, 24);
    format(query, sizeof(query), "SELECT raha, skoor, piloot, politsei, playerHours, playerSeconds FROM kasutajad WHERE nimi = '%s'", pname);
    mysql_query(query);
    while(mysql_fetch_row_format(query,"|"))
    {
        mysql_fetch_field_row(savingstring, "raha"); GivePlayerMoney(playerid, strval(savingstring));
        mysql_fetch_field_row(savingstring, "skoor"); SetPlayerScore(playerid, strval(savingstring));
        mysql_fetch_field_row(savingstring, "piloot"); andmed[playerid][ppiloot] = strval(savingstring);
        mysql_fetch_field_row(savingstring, "politsei"); andmed[playerid][ppolitsei] = strval(savingstring);
        mysql_fetch_field_row(savingstring, "playerHours"); andmed[playerid][pPlayingHours] = strval(savingstring);
        mysql_fetch_field_row(savingstring, "playerSeconds"); andmed[playerid][pSeconds] = strval(savingstring);

    }
    mysql_store_result();
    mysql_free_result();
    return 1;
}

stock salvestaandmed(const playerid)
{
    new saveQuery[1000];
    new Name[MAX_PLAYER_NAME];

    GetPlayerName(playerid, Name, sizeof(Name));


    format(saveQuery, sizeof(saveQuery), "UPDATE kasutajad SET raha = '%d', skoor = '%d', playerSeconds = '%d', playerHours = '%d' WHERE nimi = '%s'",

    andmed[playerid][pRaha],
    andmed[playerid][pSkoor],
    andmed[playerid][pSeconds],
    andmed[playerid][pPlayingHours],
    Name);

    mysql_query(saveQuery);
    mysql_store_result();
   
    mysql_free_result();

    return 1;
}

stock syncPlayerTime(const playerid) {
    if(!GetPlayerInterior(playerid)) {
        SetPlayerWeather(playerid, weatherVariables[0]);
    }
    else SetPlayerWeather(playerid, INTERIOR_WEATHER_ID);
    return SetPlayerTime(playerid, gTime[0], gTime[1]);
}

RewardPlayer(playerid, Money, Points)
{
    // Add the given amount of money to the player's account
    andmed[playerid][pRaha] = andmed[playerid][pRaha] + Money;
    // Add the given amount of scorepoints to the player's account
    andmed[playerid][pSkoor] = andmed[playerid][pSkoor] + Points;
}

//============================================================================//
//                                  Player Commands                           //
//============================================================================//

CMD:statistika(playerid, params[])
{
    format(szMessage, sizeof(szMessage), "Litsentsid | Piloot: %d | Politsei: %d\nRaha: %d | Sekundeid: %d | Tunde: %d", andmed[playerid][ppiloot], andmed[playerid][ppolitsei], andmed[playerid][pRaha], andmed[playerid][pSeconds], andmed[playerid][pPlayingHours]);
    SendClientMessage(playerid, -1, szMessage);
   
    return 1;
}

CMD:raha(playerid, params[])
{
    new Amount, Msg[128];

    if (sscanf(params, "i", Amount)) SendClientMessage(playerid, 0xFF0000AA, "Kasuta: \"/raha <Summa>\"");
    else
    {
        // Check if the player gave himself too much at once
        if (Amount > 1000000)
        {
            // Inform the player and quit the command
            SendClientMessage(playerid, 0xFF0000AA, "Sa ei saa panna endale raha korraga ьle 10m korraga");
            return 1;
        }

        // Reward the player (give cash and points)
        RewardPlayer(playerid, Amount, 0);
        format(Msg, 128, "Sa kandsid endale $%i", Amount);
        SendClientMessage(playerid, 0x00FF00AA, Msg);
    }


    return 1;
}
Full GM + SQL file in case someone needs to help.
http://www.upload.ee/files/3332327/Mysql.rar.html
Reply
#2

I had fixxed your gamemode and even make some little comments



PHP код:
#include <a_samp>
#include <sscanf2>
#include <a_mysql>
#include <zcmd>
#include <foreach>
#define                 COLOR_WHITE                             0xFFFFFFAA
#define                 THREAD_LOE_ANDMED
#define                 MAX_TIMERS                              (5)
#define                 INTERIOR_WEATHER_ID                     (1)
#define                 MAX_WEATHER_POINTS                      (9)
#define ColorClassTruckDriver       0xFF8000FF // Orange
#define ColorClassBusDriver         0x80FFFFFF // Light blue
#define ColorClassPilot             0x008080FF // Dark blue
#define ColorClassPolice            0x0000FFFF // Blue
#define ColorClassCourier           0xFF0080FF // Pink
#define ColorClassAssistance        0x80FF00FF // Dark green
#define ColorClassRoadWorker        0xFFFF80FF // Light yellow
main(){}
enum playerEnum {
    
pPassword,
    
pRaha,
    
pSkoor,
    
pLogged,
    
ppiloot,
    
ppolitsei,
    
pConnectedSeconds,
    
pPlayingHours,
    
pSeconds,
    
pClass,
}
new 
andmed[MAX_PLAYERS][playerEnum];
new 
szMessage[128];
new 
scriptTimers[MAX_TIMERS];
new 
weatherVariables[2];
new 
validWeatherIDs[17] = { 12345679101112131415171820 };
new 
gTime[3];
forward                 globalPlayerLoop();
@
Get_Player_Time_On_Server(playerid);
public 
OnGameModeInit()
{
    
mysql_debug(true);
    
mysql_connect("localhost""root""test""");
    
scriptTimers[0] = SetTimer("globalPlayerLoop"1000true);
    
weatherVariables[0] = validWeatherIDs[random(sizeof(validWeatherIDs))];
    
SetWeather(weatherVariables[0]);
    
SetGameModeText("Blank Script");
    
AddPlayerClass(01958.37831343.157215.3746269.1425000000);
    return 
1;
}
public 
OnGameModeExit()
{
    new
        
x;
    while(
MAX_TIMERS) {
        
KillTimer(scriptTimers[x]);
        
x++;
    }
    return 
1;
}
public 
OnPlayerRequestClass(playeridclassid)
{
    return 
1;
}
public 
OnPlayerConnect(playerid)
{
    
TogglePlayerSpectating(playeridtrue);
    
SetPlayerColor(playeridCOLOR_WHITE);
    
nulliandmed(playerid);
    new 
logi[126], Name[MAX_PLAYER_NAME];
    
GetPlayerName(playeridNamesizeof(Name));
    
mysql_real_escape_string(NameName);
    
format(logisizeof(logi), "SELECT 1 FROM kasutajad WHERE nimi = '%s' LIMIT 1"Name);
    
mysql_query(logi);
    
mysql_store_result();
    if(
mysql_num_rows() != 0)
    {
        
SendClientMessage(playerid, -1"See kasutaja on juba registreeritud");
        
ShowPlayerDialog(playerid0DIALOG_STYLE_INPUT"Logimine""Palun logi sisse kasutades enda parooli""Logi""Keeldu");
    }
    else
    {
        
ShowPlayerDialog(playerid1DIALOG_STYLE_INPUT"Registreeri""Palun sisesta parool enda uuele kasutajale""Registreeri""Keeldu");
    }
    return 
1;
}
public 
OnPlayerDisconnect(playeridreason)
{
    if(
andmed[playerid][pLogged] == 1) {
        
salvestaandmed(playerid);
        
andmed[playerid][pLogged] = -1;
    }
    return 
1;
}
public 
OnPlayerSpawn(playerid)
{
    return 
1;
}
public 
OnPlayerDeath(playeridkilleridreason)
{
    return 
1;
}
public 
OnVehicleSpawn(vehicleid)
{
    return 
1;
}
public 
OnVehicleDeath(vehicleidkillerid)
{
    return 
1;
}
public 
OnPlayerText(playeridtext[])
{
    return 
1;
}
public 
OnPlayerCommandText(playeridcmdtext[])
{
    if (
strcmp("/mycommand"cmdtexttrue10) == 0)
    {
        
// Do something here
        
return 1;
    }
    return 
0;
}
public 
OnPlayerEnterVehicle(playeridvehicleidispassenger)
{
    return 
1;
}
public 
OnPlayerExitVehicle(playeridvehicleid)
{
    return 
1;
}
public 
OnPlayerStateChange(playeridnewstateoldstate)
{
    return 
1;
}
public 
OnPlayerEnterCheckpoint(playerid)
{
    return 
1;
}
public 
OnPlayerLeaveCheckpoint(playerid)
{
    return 
1;
}
public 
OnPlayerEnterRaceCheckpoint(playerid)
{
    return 
1;
}
public 
OnPlayerLeaveRaceCheckpoint(playerid)
{
    return 
1;
}
public 
OnRconCommand(cmd[])
{
    return 
1;
}
public 
OnPlayerRequestSpawn(playerid)
{
    return 
1;
}
public 
OnObjectMoved(objectid)
{
    return 
1;
}
public 
OnPlayerObjectMoved(playeridobjectid)
{
    return 
1;
}
public 
OnPlayerPickUpPickup(playeridpickupid)
{
    return 
1;
}
public 
OnVehicleMod(playeridvehicleidcomponentid)
{
    return 
1;
}
public 
OnVehiclePaintjob(playeridvehicleidpaintjobid)
{
    return 
1;
}
public 
OnVehicleRespray(playeridvehicleidcolor1color2)
{
    return 
1;
}
public 
OnPlayerSelectedMenuRow(playeridrow)
{
    return 
1;
}
public 
OnPlayerExitedMenu(playerid)
{
    return 
1;
}
public 
OnPlayerInteriorChange(playeridnewinterioridoldinteriorid)
{
    return 
1;
}
public 
OnPlayerKeyStateChange(playeridnewkeysoldkeys)
{
    return 
1;
}
public 
OnRconLoginAttempt(ip[], password[], success)
{
    return 
1;
}
public 
OnPlayerUpdate(playerid)
{
    return 
1;
}
public 
OnPlayerStreamIn(playeridforplayerid)
{
    return 
1;
}
public 
OnPlayerStreamOut(playeridforplayerid)
{
    return 
1;
}
public 
OnVehicleStreamIn(vehicleidforplayerid)
{
    return 
1;
}
public 
OnVehicleStreamOut(vehicleidforplayerid)
{
    return 
1;
}
public 
OnDialogResponse(playeriddialogidresponselistiteminputtext[])
{
    switch(
dialogid)
    {
        case 
0:
        {
            if(
response)
            {
                new 
query[150], pName[MAX_PLAYER_NAME];
                
GetPlayerName(playeridpNamesizeof(pName));
                
mysql_real_escape_string(pNamepName);
                
format(querysizeof(query), "SELECT * FROM kasutajad WHERE nimi = '%s' AND parool = '%s' LIMIT 1"pNameinputtext);
                
mysql_query(query);
                
                
mysql_store_result();
                if(
mysql_num_rows() == 1)
                {
                    
SendClientMessage(playerid, -1"Sa oled edukalt sisse logitud!");
                    
TogglePlayerSpectating(playeridfalse);
                    
andmed[playerid][pLogged] = 1;
                    
laeandmed(playerid);
                    
ShowPlayerDialog(playerid2DIALOG_STYLE_LIST"Amet""Pitsapoiss\nKuller\nBussijuht\nRekkamees\nPiloot\nPolitseinik""Vali""");
                }
                else
                {
                    
SendClientMessage(playerid, -1"Sa sisestasid vale parooli!");
                    
ShowPlayerDialog(playerid0DIALOG_STYLE_INPUT"Logimine""Palun logi sisse kasutades enda parooli""Logi""Keeldu");
                }
            }
            else
            {
                
Kick(playerid);
            }
        }
        case 
1:
        {
            if(
response)
            {
                new 
regi[256], pName[MAX_PLAYER_NAME];
                
GetPlayerName(playeridpNamesizeof(pName));
                
format(regisizeof(regi), "INSERT INTO kasutajad (nimi, parool, registreerus) VALUES('%s', '%s', NOW())"pNameinputtext);
                
mysql_query(regi);
                
mysql_store_result();
                
SendClientMessage(playerid, -1"Sinu kasutaja on nььd registreeritud!");
                
mysql_free_result();
                
ShowPlayerDialog(playerid0DIALOG_STYLE_INPUT"Logimine""Palun logi sisse kasutades enda parooli""Logi""Keeldu");
            }
            else
            {
                
Kick(playerid);
            }
        }
        case 
2:
        {
            switch(
listitem)
            {
                case 
0:
                {
                    
SendClientMessage(playerid, -1"Asusid tццle pitsapoisina!");
                    
andmed[playerid][pClass] = 1;
                    
SetPlayerColor(playeridColorClassRoadWorker);
                    
SetSpawnInfo(playerid1293192.3013, -218.88361.5781321.2913000000);
                    
SpawnPlayer(playerid);
                }
                case 
1:
                {
                    
SendClientMessage(playerid, -1"Asusid tццle kullerina!");
                    
andmed[playerid][pClass] = 2;
                    
SetPlayerColor(playeridColorClassCourier);
                    
SetSpawnInfo(playerid12941231000000);
                    
SpawnPlayer(playerid);
                }
                case 
2:
                {
                    
SendClientMessage(playerid, -1"Asusid tццle bussijuhina!");
                    
andmed[playerid][pClass] = 3;
                    
SetPlayerColor(playeridColorClassBusDriver);
                    
SetSpawnInfo(playerid12951231000000);
                    
SpawnPlayer(playerid);
                }
                case 
3:
                {
                    
SendClientMessage(playerid, -1"Asusid tццle rekkamehena!");
                    
andmed[playerid][pClass] = 4;
                    
SetPlayerColor(playeridColorClassTruckDriver);
                    
SetSpawnInfo(playerid12951231000000);
                    
SpawnPlayer(playerid);
                }
                case 
4:
                {
                    if(
andmed[playerid][ppiloot] != 1)
                    {
                        
SendClientMessage(playerid, -1"Sul pole veel piloodi litsentsi! Info saamiseks vali mхni teine tцц ja uuri /abi");
                        
ShowPlayerDialog(playerid2DIALOG_STYLE_LIST"Amet""Pitsapoiss\nKuller\nBussijuht\nRekkamees\nPiloot\nPolitseinik""Vali""");
                    }
                    else
                    {
                        
SendClientMessage(playerid, -1"Asusid tццle piloodina!");
                        
andmed[playerid][pClass] = 5;
                        
SetPlayerColor(playeridColorClassPilot);
                        
SetSpawnInfo(playerid12951231000000);
                        
SpawnPlayer(playerid);
                    }
                }
                case 
5:
                {
                    if(
andmed[playerid][ppolitsei] != 1)
                    {
                        
SendClientMessage(playerid, -1"Sul pole veel politsei litsentsi! Info saamiseks vali mхni teine tцц ja uuri /abi");
                        
ShowPlayerDialog(playerid2DIALOG_STYLE_LIST"Amet""Pitsapoiss\nKuller\nBussijuht\nRekkamees\nPiloot\nPolitseinik""Vali""");
                    }
                    else
                    {
                        
SendClientMessage(playerid, -1"Asusid tццle politeinikuna!");
                        
andmed[playerid][pClass] = 6;
                        
SetPlayerColor(playeridColorClassPolice);
                        
SetSpawnInfo(playerid12951231000000);
                        
SpawnPlayer(playerid);
                    }
                }
            }
        }
    }
    return 
1;
}
public 
OnPlayerClickPlayer(playeridclickedplayeridsource)
{
    return 
1;
}
public 
globalPlayerLoop() {
    
gettime(gTime[0], gTime[1], gTime[2]);
    if(
gTime[1] >= 59 && gTime[2] >= 59) {
        
weatherVariables[1] += random(3) + 1// Weather changes aren't regular.
        
SetWorldTime(gTime[0]); // Set the world time to keep the worldtime variable updated (and ensure it syncs instantly for connecting players).
        
if(weatherVariables[1] >= MAX_WEATHER_POINTS) {
            
weatherVariables[0] = validWeatherIDs[random(sizeof(validWeatherIDs))];
            foreach(
Playeri) {
                if(!
GetPlayerInterior(i)) {
                    
SetPlayerWeather(iweatherVariables[0]);
                }
                else 
SetPlayerWeather(iINTERIOR_WEATHER_ID);
            }
            
weatherVariables[1] = 0;
        }
    }
    
/* ------------------------------------------------------ */
    
foreach(Playerx) {
        if(
gTime[2] >= 59syncPlayerTime(x);
        if(
andmed[x][pLogged] == 1) {
            if(
GetPlayerMoney(x) != andmed[x][pRaha]) {
                
ResetPlayerMoney(x);
                
GivePlayerMoney(xandmed[x][pRaha]);
            }
        }
    }
    
    return 
true;
}
stock unixTimeConvert(timestampcompare = -1) {
    if(
compare == -1)
        
compare gettime();
    new
        
n,
        
Float:= (timestamp compare) ? timestamp compare compare timestamp,
        
returnstr[32];
    if (
60) {
        
format(returnstrsizeof(returnstr), "< 1 minute");
        return 
returnstr;
    } else if (
3600) { // 3600 = 1 hour
        
floatround(floatdiv(d60.0), floatround_floor);
        
format(returnstrsizeof(returnstr), "minute");
    } else if (
86400) { // 86400 = 1 day
        
floatround(floatdiv(d3600.0), floatround_floor);
        
format(returnstrsizeof(returnstr), "hour");
    } else if (
2592000) { // 2592000 = 1 month
        
floatround(floatdiv(d86400.0), floatround_floor);
        
format(returnstrsizeof(returnstr), "day");
    } else if (
31536000) { // 31536000 = 1 year
        
floatround(floatdiv(d2592000.0), floatround_floor);
        
format(returnstrsizeof(returnstr), "month");
    } else {
        
floatround(floatdiv(d31536000.0), floatround_floor);
        
format(returnstrsizeof(returnstr), "year");
    }
    
format(returnstr32, ((!= 1)?("%d %ss"):("1 %s")), returnstr);  // you can use even their the ternary operator
    
return returnstr;
}
@
Get_Player_Time_On_Server(playerid){
    new 
Time = (andmed[playerid][pSeconds] +(gettime()-andmed[playerid][pConnectedSeconds]));
    
andmed[playerid][pPlayingHours] += (Time/3600);
    
andmed[playerid][pSeconds] = Time 3600;
    return 
1;
}
stock nulliandmed(playerid)
{
    new 
i;
    for(; 
playerEnum:playerEnum; ++iandmed[playerid][playerEnum:i] = 0;  //this way to reset the variabel in the enum is easyier
    
return true;
}
stock laeandmed(playerid)
{
    new 
query[300], pname[24];
    
GetPlayerName(playeridpname24);
    
format(querysizeof(query), "SELECT raha, skoor, piloot, politsei, playerHours, playerSeconds FROM kasutajad WHERE nimi = '%s' LIMIT 1"pname);
    
mysql_query(query);
    
mysql_store_result();
    
mysql_fetch_row_format(query,"|");
    
sscanf(query,"p<|>dddddd",andmed[playerid][pRaha],andmed[playerid][pSkoor],andmed[playerid][ppiloot],andmed[playerid][ppolitsei],andmed[playerid][pPlayingHours],andmed[playerid][pSeconds]);
    
GivePlayerMoney(playeridandmed[playerid][pRaha]);
    
SetPlayerScore(playeridandmed[playerid][pSkoor]);
    
andmed[playerid][pConnectedSeconds] = gettime();
    
mysql_free_result(); // changed loading this way is fast than your old one and please use if you have static numbers use them it`s faster  to get the right size
    
return 1;
}
stock salvestaandmed(const playerid)
{
    new 
saveQuery[400];
    new 
Name[MAX_PLAYER_NAME];
    
GetPlayerName(playeridNamesizeof(Name));
    @
Get_Player_Time_On_Server(playerid);
    
format(saveQuerysizeof(saveQuery), "UPDATE kasutajad SET raha = '%d', skoor = '%d', playerSeconds = '%d', playerHours = '%d' WHERE nimi = '%s'",
    
andmed[playerid][pRaha],
    
andmed[playerid][pSkoor],
    
andmed[playerid][pSeconds],
    
andmed[playerid][pPlayingHours],
    
Name);
    
mysql_query(saveQuery); //changed you don`t need to clear the memory which is in used by storing results
    
return 1;
}
stock syncPlayerTime(const playerid) {
    if(!
GetPlayerInterior(playerid)) {
        
SetPlayerWeather(playeridweatherVariables[0]);
    }
    else 
SetPlayerWeather(playeridINTERIOR_WEATHER_ID);
    return 
SetPlayerTime(playeridgTime[0], gTime[1]);
}
RewardPlayer(playeridMoneyPoints)
{
    
// Add the given amount of money to the player's account
    
andmed[playerid][pRaha] = andmed[playerid][pRaha] + Money;
    
// Add the given amount of scorepoints to the player's account
    
andmed[playerid][pSkoor] = andmed[playerid][pSkoor] + Points;
}
//============================================================================//
//                                  Player Commands                           //
//============================================================================//
CMD:statistika(playeridparams[])
{
    @
Get_Player_Time_On_Server(playerid);
    
format(szMessagesizeof(szMessage), "Litsentsid | Piloot: %d | Politsei: %d\nRaha: %d | Sekundeid: %d | Tunde: %d"andmed[playerid][ppiloot], andmed[playerid][ppolitsei], andmed[playerid][pRaha], andmed[playerid][pSeconds], andmed[playerid][pPlayingHours]);
    
SendClientMessage(playerid, -1szMessage);
    return 
1;
}
CMD:raha(playeridparams[])
{
    new 
AmountMsg[128];
    if (
sscanf(params"i"Amount)) SendClientMessage(playerid0xFF0000AA"Kasuta: \"/raha <Summa>\"");
    else
    {
        
// Check if the player gave himself too much at once
        
if (Amount 1000000)
        {
            
// Inform the player and quit the command
            
SendClientMessage(playerid0xFF0000AA"Sa ei saa panna endale raha korraga ьle 10m korraga");
            return 
1;
        }
        
// Reward the player (give cash and points)
        
RewardPlayer(playeridAmount0);
        
format(Msg128"Sa kandsid endale $%i"Amount);
        
SendClientMessage(playerid0x00FF00AAMsg);
    }
    return 
1;

Reply
#3

I tried your code, complied nicely, but when I go to server it always say's that user exists and asks to log in, even if it doesn't. So pretty much it messed up login/register & password checking part of script.. Tried to figure it out, but it wont work =/
Reply
#4

Still need help
Reply
#5

Still no solution Help please.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)