PDA

View Full Version : settime


ivndosos
25/02/2018, 11:15 AM
For some reason it only sets my time to 0?


CMD:settime(playerid, params[])
{
if(connected[playerid] == true) return GameTextForPlayer(playerid, "~r~Spawn First", 5000, 5);
{
new str[256], time[256];
if(sscanf(params, "i", time)) return SendClientMessage(playerid, -1, "{c3c3c3}(INFO) /settime [time]");
new h = strval(time);
if(h < 0 || h > 50)
{
SendClientMessage(playerid, -1, "{c3c3c3}(INFO) /settime [time]");
return 1;
}
SetPlayerTime(playerid, h, h);
format(str, sizeof(str), "{c3c3c3}{INFO) You have set your time to %d", h);
SendClientMessage(playerid, -1, str);

}
return 1;
}

jasperschellekens
25/02/2018, 11:19 AM
For some reason it only sets my time to 0?

How is that a problem? You have set it to be for you only. SetPlayerTime(playerid, h, h);
If you want it to be for all players, loop trough players:

for(new i=0; i < MAX_PLAYERS; i++)
{
if(IsPlayerConnectedEx(i))
{
SetPlayerTime(i, h, h);
}
}

ivndosos
25/02/2018, 11:33 AM
not for all players

RogueDrifter
25/02/2018, 11:37 AM
Because you're setting the time using h (using strval of the variable) when you need to use time (value of the variable using sscanf).
Briefly, this:

SetPlayerTime(playerid, h, h);

Should be like this:

SetPlayerTime(playerid, time, time);

BalkanEliteRP
25/02/2018, 11:38 AM
try this

CMD:settime(playerid, params[])
{
if(connected[playerid] == true) return GameTextForPlayer(playerid, "~r~Spawn First", 5000, 5);
new str[50], time;
if(sscanf(params, "i", time)) return SendClientMessage(playerid, -1, "{c3c3c3}(INFO) /settime [time]");
if(time < 0 || time > 50)
{
SendClientMessage(playerid, -1, "{c3c3c3}(INFO) /settime [time]");
return 1;
}
SetPlayerTime(playerid, time, time);
format(str, sizeof(str), "{c3c3c3}{INFO) You have set your time to %d", time);
SendClientMessage(playerid, -1, str);
return 1;
}

RedFusion
25/02/2018, 11:40 AM
This is how i'd solve it:


CMD:settime(playerid, params[]) {
new h, m;
if( sscanf(params, "p<:>ii", h, m) ) {
return SendClientMessage(playerid, 0xFF0000FF, "USAGE: /settime hh:mm"), 1;
}

if( h < 0 || h >= 24 || m < 0 || m >= 60 ) {
return SendClientMessage(playerid, 0xFF0000FF, "ERROR: You did not enter valid time values!"), 1;
}

SetPlayerTime(playerid, h, m);

new msg[144+1];
format(msg, sizeof msg, "You have set the time to %02i:%02i", h, m);
SendClientMessage(playerid, 0x00FF00FF, msg);
return 1;
}

Dayrion
25/02/2018, 12:02 PM
This is how i'd solve it:


...

SetWorldTime(h);
for(new i, max_playerid = GetPlayerPoolSize(); i <= max_playerid; i ++) {
if( IsPlayerConnected(i) ) {
SetPlayerTime(i, h, m);
}
}

new msg[144+1];
format(msg, sizeof msg, "You have set the time to %02i:%02i", h, m);
SendClientMessage(playerid, 0x00FF00FF, msg);
return 1;
}


Should be:
SetWorldTime(h);

new msg[39];
format(msg, sizeof msg, "You have set the time to %02i:%02i", h, m);
SendClientMessage(playerid, 0x00FF00FF, msg);
Also, mention to the author's post he can do "23:47" to set the world time.
Plus, check if it's valid hour/minute isn't useful since the pawn native already do it. Saying that for every code presented here.

RxErT
25/02/2018, 04:22 PM
Changing all players's time: (ADMIN)
CMD:changetime(playerid, params[])
{
if(IsPlayerAdmin(playerid))
{
new time, string[128];
if(sscanf(params, "i", time)) return SendClientMessage(playerid, 0xf8f8f8fff, "Syntax: {f00f00}/changetime <0 - 23>");
if(time < 0 || time > 23) return SendClientMessage(playerid, 0xf8f8f8fff, "ERROR: {FFFFFF}Invalid time! <0 - 23>");
for(new i = 0; i <= MAX_PLAYERS; i++)
{
SetPlayerTime(i,time);
format(string, sizeof(string), "{} {f00f00}an admin has changed the time to %d!",time);
SendClientMessage(i, 0xf8f8f8fff, string);
}
}
else
{
SendClientMessage(playerid,0xf8f8f8fff,"ERROR: {f00f00}You are not allowed to use this command!");
}
return 1;
}

Changing player's time:

CMD:changemytime(playerid, params[])
{
new timee, string[128];
if(sscanf(params, "i", timee)) return SendClientMessage(playerid, 0xf8f8f8fff, "Syntax: {f00f00}/changemytime <0 - 23>");
if(timee < 0 || timee > 23) return SendClientMessage(playerid, 0xf8f8f8fff, "ERROR: {FFFFFF}Invalid Time <0 - 23>.");
format(string, sizeof(string), "{ff0ff0}Your time has changed to %d!",timee);
SendClientMessage(playerid, 0xf8f8f8fff, string);
SetPlayerTime(playerid, timee, 0);
return 1;
}

jasperschellekens
25/02/2018, 06:42 PM
not for all players

Oops.. reading error. my fault

ivndosos
26/02/2018, 07:17 AM
Why doesn't it change my weather? Nothing happens, btw settime works thanks!


CMD:setweather(playerid, params[])
{
if(connected[playerid] == true) return GameTextForPlayer(playerid, "~r~Spawn First", 5000, 5);
{
new str[50], weather;
if(sscanf(params, "i", weather)) return SendClientMessage(playerid, -1, "{c3c3c3}(INFO) /setweather [weather]");

if(weather < 0 || weather > 50)
{
SendClientMessage(playerid, -1, "{c3c3c3}(INFO) /setweather [weather]");
return 1;
}
SetPlayerWeather(playerid, weather);
format(str, sizeof(str), "{c3c3c3}{INFO) You have set your weather to %d", weather);
SendClientMessage(playerid, -1, str);

}
return 1;
}

andrejc999
26/02/2018, 07:22 AM
What's the point of returning the message "spawn first" if the variable connected is true?

remove return gametextforplayer and put it down, something like:

if(connected...)
{
...
}
else
{
return GameTextForPlayer(...);
}

ivndosos
26/02/2018, 08:26 AM
What's the point of returning the message "spawn first" if the variable connected is true?

remove return gametextforplayer and put it down, something like:

if(connected...)
{
...
}
else
{
return GameTextForPlayer(...);
}

thats not the issue, each and every cmd has it, its if played didnt spawn he cant type cmds

RxErT
26/02/2018, 12:56 PM
For all players: (ADMIN)
CMD:changeweather(playerid, params[])
{
if(IsPlayerAdmin(playerid))
{
new weather, string[128];
if(sscanf(params, "i", weather)) return SendClientMessage(playerid, 0xf8f8f8fff, "Syntax: {f00f00}/changeweather <0 - 45>");
if(weather < 0 || weather > 45) return SendClientMessage(playerid, 0xf8f8f8fff, "ERROR: {FFFFFF}Invalid Weather! <0 - 45>");
for(new i = 0; i <= MAX_PLAYERS; i++)
{
SetPlayerWeather(i,weather);
format(string, sizeof(string), "{} {f00f00}an admin has changed the weather to %d!",weather);
SendClientMessage(i, 0xf8f8f8fff, string);
}
}
else
{
SendClientMessage(playerid,0xf8f8f8fff,"ERROR: {f00f00}You are not allowed to use this command!");
}
return 1;
}


For player who types it:
CMD:myweather(playerid, params[])
{
new weather, string[128];
if(sscanf(params, "i", weather)) return SendClientMessage(playerid, 0xf8f8f8fff, "Syntax: {f00f00}/myweather <0 - 45>");
if(weather < 0 || weather > 45) return SendClientMessage(playerid, 0xf8f8f8fff, "ERROR: {FFFFFF}Invalid Weather! <0 - 45>");
SetPlayerWeather(playerid, weather);
format(string, sizeof(string), "{} {f00f00}Your weather has changed the to %d!",weather);
SendClientMessage(playerid , 0xf8f8f8fff, string);
return 1;
}