saving player time and weather -
severance - 15.08.2018
Ok well everything works but I don't know how to load players weather and time once they log in.
Код:
SetPlayerTime(playerid, pInfo[playerid][Time]);
SetPlayerWeather(playerid, pInfo[playerid][Weather]);
Looks like this doesn't work ?
Re: saving player time and weather -
OMonger - 15.08.2018
Have you set the players weather previously? To load it you could use:
PHP код:
pInfo[playerid][Time] = SetPlayerTime(playerid, 1);
on the command you set it and then use:
PHP код:
SetPlayerTime(playerid, pInfo[playerid][Time]);
when you are trying to reload it? Let me know
Q
Re: saving player time and weather -
severance - 15.08.2018
Yeah everything is set, but I get a warning from your code, which is
Код:
warning 202: number of arguments does not match definition
line:
Код:
pInfo[playerid][Time] = SetPlayerTime(playerid, 1);
EDIT: the command is working fine. Just take a look if you need to know whats happening there
Код:
CMD:settime(playerid, params[])
{
if(connected[playerid] == true) return GameTextForPlayer(playerid, "~r~Spawn First", 5000, 5);
new str[50], time, query[250];
if(sscanf(params, "i", time)) return SendClientMessage(playerid, -1, "{c3c3c3}/settime [time]");
if(time < 0 || time > 50)
{
SendClientMessage(playerid, -1, "{c3c3c3}/settime [time]");
return 1;
}
SetPlayerTime(playerid, time, time);
format(str, sizeof(str), "{c3c3c3}(time) Time set to %d", time);
SendClientMessage(playerid, -1, str);
mysql_format(g_SQL, query, sizeof query, "UPDATE `players` SET `time` = %d WHERE `id` = %d LIMIT 1", time, pInfo[playerid][ID]);
mysql_tquery(g_SQL, query);
return 1;
}
I only need to load the players time which is now stored into my MySQL database throught phpymyadmin using r41-2 version.
Re: saving player time and weather -
OMonger - 15.08.2018
I see.
What you need to do is load the time again, so:
PHP код:
stock LoadTime(playerid)
{
//if(pInfo[playerid][LoggedIn] == 1)
{
new string[100];
cache_get_value("time",pInfo[playerid][Time]); // cache get value will get the value from the mysql, loading it as a cache
SetPlayerTime(playerid,pInfo[playerid][Time], 0); //this then sets Time from the bit above. You can do the same with the weather, just add this:
/*cache_get_value("weather",pInfo[playerid][Weather]);
SetPlayerWeather(playerid,pInfo[playerid][Weather]);
*/
return 1;
}
}
And then once they are logged in properly, put: "LoadTime(playerid);" under that function. Let me know if it works. Sorry about indentation, on my phone
Re: saving player time and weather -
severance - 15.08.2018
Unfortunately, even this doesn't work.
Код:
SetPlayerTime(playerid,pInfo[playerid][Time], 0);
Is the issue, it sets my time to 0:00 and not the one I saved with /settime.
Re: saving player time and weather -
OMonger - 15.08.2018
Also: I've noticed you're saving SetPlayerTime as the same string. You need to create another "new" called: new time2 and place it like this:
PHP код:
CMD:settime(playerid, params[])
{
if(connected[playerid] == true) return GameTextForPlayer(playerid, "~r~Spawn First", 5000, 5);
new str[50], time, time2, query[250];
if(sscanf(params, "ii", time)) return SendClientMessage(playerid, -1, "{c3c3c3}/settime [hours] [mins]");
if(time < 0 || time > 50)
{
SendClientMessage(playerid, -1, "{c3c3c3}/settime [hours][mins]");
return 1;
}
SetPlayerTime(playerid, time, time2);
format(str, sizeof(str), "{c3c3c3}(time) Time set to %d:%d",time,time2);
SendClientMessage(playerid, -1, str);
mysql_format(g_SQL, query, sizeof query, "UPDATE `players` SET `time` = %d, `time2`WHERE `id` = %d LIMIT 1", pInfo[playerid][Time], time2, pInfo[playerid][ID]);
mysql_tquery(g_SQL, query);
return 1;
}
Let me know if it works. Try it with the stock I gave above.
Re: saving player time and weather -
severance - 16.08.2018
Doesn't work, tried to create another table in MySQL database such as time and time2, still don't load my time. Even tho, it saves correctly on my database from phpmyadmin, I can see the exact same time saved. But struggle on loading it.
This is the command:
PHP код:
CMD:settime(playerid, params[])
{
if(connected[playerid] == true) return GameTextForPlayer(playerid, "~r~Spawn First", 5000, 5);
new str[50], time, query[250];
if(sscanf(params, "i", time)) return SendClientMessage(playerid, -1, "{c3c3c3}/settime [time]");
if(time < 0 || time > 50)
{
SendClientMessage(playerid, -1, "{c3c3c3}/settime [time]");
return 1;
}
SetPlayerTime(playerid, time, time);
format(str, sizeof(str), "{c3c3c3}(time) Time set to %d", time);
SendClientMessage(playerid, -1, str);
mysql_format(g_SQL, query, sizeof query, "UPDATE `players` SET `time` = '%d' WHERE `id` = '%d' LIMIT 1", time, pInfo[playerid][ID]);
mysql_tquery(g_SQL, query);
mysql_format(g_SQL, query, sizeof query, "UPDATE `players` SET `time2` = '0' WHERE `id` = '%d' LIMIT 1", time, pInfo[playerid][ID]);
mysql_tquery(g_SQL, query);
return 1;
}
I made time2 = minutes to set it to 0, because I don't care about minutes. I want to make it simply as that, no need to add additional numbers while changing own time.
PHP код:
stock LoadTime(playerid){
cache_get_value_int(0, "time", pInfo[playerid][Time]);
cache_get_value_int(0, "time2", pInfo[playerid][Time2]);
SetPlayerTime(playerid,pInfo[playerid][Time], pInfo[playerid][Time2]);
return 1;}
Something wrong there...