• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Pawn] Timer
#1
Im trying to make /mute command, but i dont know how to set timer which is equal to time which i set in command and when this timer ends it sets to player stats Muted = 0



Code:
CMD:mute(playerid, params[])

{

if (!IsPlayerAdmin(playerid) || PlayerInfo [playerid] [pAdmin] < 1) return SendClientMessage(playerid, COLOR_SERVER, "[BC:RP] {FFFFFF}Niste admin.");

if (IsPlayerAdmin(playerid) || PlayerInfo [playerid] [pAdmin] > 0)

{

new id, reason[128], str[128], string[256], pName[MAX_PLAYER_NAME], pMutedName[MAX_PLAYER_NAME], time;

if(sscanf(params, "uis", id, time, reason)) return SendClientMessage(playerid, COLOR_SERVER, "[Usage]: {FFFFFF}/mute [ID/Ime] [Vrijeme] [Razlog]") ;

else if (time < 0 || time > 1000) return SendClientMessage(playerid, COLOR_SERVER, "[Usage]: Vrijeme ne moze biti manje od 0 (skidanje mute-a) i vece od 1000. ");

else if (time == 0) return SendClientMessage(playerid, -1, "Admin vam je skinuo mute.");

GetPlayerName(playerid, pName, sizeof(pName));

GetPlayerName(id, pMutedName, sizeof(pMutedName));

format(str, sizeof(str), "{FF0000}Utisani ste od strane admina {FFFFFF}%s {FF0000} na {FFFFFF}%d {FF0000}minuta. Razlog: {FFFFFF}%s.", pName, time, reason);

SendClientMessage(id, -1, str);

format(string, sizeof(string), "{FF0000}[Mute]: Admin {FFFFFF}%s {FF0000}je utisao igraca {FFFFFF}%s {FF0000}na {FFFFFF}%d {FF0000}minuta. Razlog: {FFFFFF}%s", pName, pMutedName, time, reason);

foreach(Player, i)

if(PlayerInfo [i] [pStaff] == 1)

{

SendClientMessage(i, -1, string);

}

PlayerInfo [id] [pMuted] = time;

PlayerInfo [id] [pMutedReason] = reason;

SetTimerEx("mutetime", time*1000, false, "d", id);





}

return 1;

}
  Reply
#2
Set a timer with 1 second interval?on OnGameModeInit() then decrease player mute time.



Code:
public OneSecondPlayerTimer() {

? ? foreach(new i: Player) {

? ? ? ? PlayerMuteCheck(i);

? ? }

}



PlayerMuteCheck(playerid) {

? ? if(PlayerInfo [playerid] [pMuted] == 1) {

? ? ? ? PlayerInfo [playerid] [pMuted]--;

? ? ? ? SendClientMessage(playerid, -1, "Mute time expired.");

? ? }



? ? if(PlayerInfo [playerid] [pMuted] > 1) PlayerInfo [playerid] [pMuted]--;

}



Also if you want check player is muted you just need check the?PlayerInfo[playerid][pMuted] is not 0.
Code:
IsPlayerMuted(playerid) {

? ? if(PlayerInfo[playerid][pMuted] == 0) return 0;



? ? return 1;

}
  Reply
#3
(2021-07-30, 10:19 PM)Radical Wrote: Set a timer with 1 second interval?on OnGameModeInit() then decrease player mute time.

Code:
public OneSecondPlayerTimer() {
? ? foreach(new i: Player) {
? ? ? ? PlayerMuteCheck(i);
? ? }
}

PlayerMuteCheck(playerid) {
? ? if(PlayerInfo [playerid] [pMuted] == 1) {
? ? ? ? PlayerInfo [playerid] [pMuted]--;
? ? ? ? SendClientMessage(playerid, -1, "Mute time expired.");
? ? }

? ? if(PlayerInfo [playerid] [pMuted] > 1) PlayerInfo [playerid] [pMuted]--;
}

Also if you want check player is muted you just need check the?PlayerInfo[playerid][pMuted] is not 0.
Code:
IsPlayerMuted(playerid) {
? ? if(PlayerInfo[playerid][pMuted] == 0) return 0;

? ? return 1;
}
One simple question: why.

Here's the solution:
https://ideone.com/N0ciwe
Using Pawn.CMD?

If you're doing so, this is the very first sign that you absolutely shouldn't utilize your all powerful P-Code knowledge in any of the scripting discussion topics.
  Reply
#4
(2021-07-31, 12:48 AM)Pinch Wrote: One simple question: why.



Here's the solution:

https://ideone.com/N0ciwe



I just gived him a solution.

But I forgot to using gettime().

IS OK NOW?
  Reply
#5
(2021-07-31, 12:48 AM)Pinch Wrote:
(2021-07-30, 10:19 PM)Radical Wrote: Set a timer with 1 second interval?on OnGameModeInit() then decrease player mute time.

Code:
public OneSecondPlayerTimer() {
? ? foreach(new i: Player) {
? ? ? ? PlayerMuteCheck(i);
? ? }
}

PlayerMuteCheck(playerid) {
? ? if(PlayerInfo [playerid] [pMuted] == 1) {
? ? ? ? PlayerInfo [playerid] [pMuted]--;
? ? ? ? SendClientMessage(playerid, -1, "Mute time expired.");
? ? }

? ? if(PlayerInfo [playerid] [pMuted] > 1) PlayerInfo [playerid] [pMuted]--;
}

Also if you want check player is muted you just need check the?PlayerInfo[playerid][pMuted] is not 0.
Code:
IsPlayerMuted(playerid) {
? ? if(PlayerInfo[playerid][pMuted] == 0) return 0;

? ? return 1;
}
One simple question: why.

Here's the solution:
https://ideone.com/N0ciwe

thank you bro, but player is always muted until someone unmute him.. im asking how to set timer which is equal to time in command and when this timer ends pMute sets to 0 and he can speak, use commands..
  Reply
#6
(2021-07-31, 09:56 AM)njoBe_ Wrote:
(2021-07-31, 12:48 AM)Pinch Wrote:
(2021-07-30, 10:19 PM)Radical Wrote: Set a timer with 1 second interval?on OnGameModeInit() then decrease player mute time.



Code:
public OneSecondPlayerTimer() {

? ? foreach(new i: Player) {

? ? ? ? PlayerMuteCheck(i);

? ? }

}



PlayerMuteCheck(playerid) {

? ? if(PlayerInfo [playerid] [pMuted] == 1) {

? ? ? ? PlayerInfo [playerid] [pMuted]--;

? ? ? ? SendClientMessage(playerid, -1, "Mute time expired.");

? ? }



? ? if(PlayerInfo [playerid] [pMuted] > 1) PlayerInfo [playerid] [pMuted]--;

}



Also if you want check player is muted you just need check the?PlayerInfo[playerid][pMuted] is not 0.
Code:
IsPlayerMuted(playerid) {

? ? if(PlayerInfo[playerid][pMuted] == 0) return 0;



? ? return 1;

}

One simple question: why.



Here's the solution:

https://ideone.com/N0ciwe



thank you bro, but player is always muted until someone unmute him.. im asking how to set timer which is equal to time in command and when this timer ends pMute sets to 0 and he can speak, use commands..

Bukvalno sam ti dao komandu invalidu
Using Pawn.CMD?

If you're doing so, this is the very first sign that you absolutely shouldn't utilize your all powerful P-Code knowledge in any of the scripting discussion topics.
  Reply
#7
(2021-07-31, 12:48 AM)Pinch Wrote:
(2021-07-30, 10:19 PM)Radical Wrote: Set a timer with 1 second interval?on OnGameModeInit() then decrease player mute time.



Code:
public OneSecondPlayerTimer() {

? ? foreach(new i: Player) {

? ? ? ? PlayerMuteCheck(i);

? ? }

}



PlayerMuteCheck(playerid) {

? ? if(PlayerInfo [playerid] [pMuted] == 1) {

? ? ? ? PlayerInfo [playerid] [pMuted]--;

? ? ? ? SendClientMessage(playerid, -1, "Mute time expired.");

? ? }



? ? if(PlayerInfo [playerid] [pMuted] > 1) PlayerInfo [playerid] [pMuted]--;

}



Also if you want check player is muted you just need check the?PlayerInfo[playerid][pMuted] is not 0.
Code:
IsPlayerMuted(playerid) {

? ? if(PlayerInfo[playerid][pMuted] == 0) return 0;



? ? return 1;

}

One simple question: why.



Here's the solution:

https://ideone.com/N0ciwe



Using gettime() Mute may expire while user is simply offline. Maybe to get full potential of punishment he wants for user to be online to serve his punishment.

Still it is definetly possible and better way to do with gettime(), you just need 1 more variable to save distance on disconnect.
  Reply


Forum Jump: