23.05.2013, 19:30
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
Full GM + SQL file in case someone needs to help.
http://www.upload.ee/files/3332327/Mysql.rar.html
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;
}
http://www.upload.ee/files/3332327/Mysql.rar.html