[Tutorial] Mute & Unmute commands
#1

Hello here is another tutorial to help newbies make other admins commad

Mute & Unmute
first the includes
PHP Code:
#include <a_samp>
#include <zcmd>
#include <sscanf2> 
I think no need for explain here !

a color !
PHP Code:
#define COLOR_RED 0xFF0000AA 
Now for the.....
Mute !!
first we need a bool on the top of the script to check if the player muted or not
(bool is something in samp that can be set to true or false only !)
PHP Code:
new bool:muted[MAX_PLAYERS]; 
now for the command
PHP Code:
CMD:mute(playeridparams[])

Then ....
PHP Code:
new targetidminutesreason[128], string[128]; 
Here we define the targetid that will mute and reason and string
PHP Code:
if(!IsPlayerConnected(targetid)) return SendClientMessage(playeridCOLOR_RED"Player is not connected to the server"); 
Here we check if the targetid that the player wrote is connected to the server or not
PHP Code:
if(PlayerInfo[playerid][pAdmin] < 2) return SendClientMessage(playeridCOLOR_RED"Command not found on server! /help"); 
Here we check if the player is admin check it to your Variables !
PHP Code:
if(muted[targetid] == true) return SendClientMessage(playeridCOLOR_RED"Player is already muted"); 
As i said we check if the bool equal true (Means if the player is muted) Send a message and stop !
PHP Code:
if(sscanf(params,"uis[128]"targetidminutesreason)) return SendClientMessage(playeridCOLOR_RED"Mute: /mute (id) (minutes) (reason)"); 
And here we check if the player typed the command full with his params or not
PHP Code:
    format(stringsizeof(string), "Administrator %s muted %s for %d minutes: %s"PlayerName(playerid),         PlayerName(targetid), minutesreason);
    
SendClientMessageToAll(COLOR_REDstring); 
And this is for messages (Do in it what do you want !)
PHP Code:
SetTimerEx("Unmute"minutes*60000false"i"targetid); 
Here,You set a timer that we will do later and multiply the minutes that the player write with 60000 because the timer is set with millisecond and set this timer for thr targetid
PHP Code:
muted[targetid] = true
Here we set the bool true means that the player is muted !
PHP Code:
return 1;

Then end......

Now for the timer
PHP Code:
forward Unmute(playerid); 
make forward to make public (The timer)
PHP Code:
public Unmute(playerid)

The public
PHP Code:
muted[playerid] = false
Set the player mute to false (Player unmuted) after the time end.
PHP Code:
SendClientMessage(playeridCOLOR_RED"You have been unmuted automatically by server"); 
And send a message to the player after he umnuted
PHP Code:
return 1;

End of the timer.

And now for.....
Unmute !!
PHP Code:
CMD:unmute(playeridparams[])

The command.....
PHP Code:
new targetidstring[128];
    if(!
IsPlayerConnected(targetid)) return SendClientMessage(playeridCOLOR_RED"Player is not connected to the server");
    if(
PlayerInfo[playerid][pAdmin] < 2) return SendClientMessage(playeridCOLOR_RED"Command not found on server! /help");
    if(
sscanf(params"u"targetid)) return SendClientMessage(playeridCOLOR_RED"Cancel player mute: /unmute (id)");
    
format(stringsizeof(string), "Your mute has been canceled by administrator %s"PlayerName(playerid));
    
SendClientMessage(targetidCOLOR_REDstring);
    
format(stringsizeof(string), "Administrator %s has canceled %s's mute"PlayerName(playerid), PlayerName(targetid));
    
SendToAdmins(COLOR_REDstring); 
All these as i explained before (I am lazy :P !)
PHP Code:
KillTimer(Unmute(playerid)); 
The timer will killed because we will stop it and will unmute the player
PHP Code:
muted[targetid] = false
Set the player mute to false (Unmuted !)
PHP Code:
return 1;

End of the command..

End of the tutorial and this is for newbies because sure there are some people who are still learning

Basic code by : Axey (I was having exams -_-)
Edited by : Me (After i finished )

Hope it will help you .
Ahmed_Nezoo
Reply
#2

Nice! + rep
Reply
#3

Thanks
Reply
#4

Quote:

C:\Users\Antix\Desktop\MyServer\filterscripts\mute .pwn(59) : error 017: undefined symbol "PlayerName"

Can you tell me what to do?
Reply
#5

Quote:
Originally Posted by antixgaming
View Post
Can you tell me what to do?
Code:
PlayerName(playerid)
{
 new name[MAX_PLAYER_NAME];
 GetPlayerName(playerid, name, MAX_PLAYER_NAME);
 return name;
}
maybe this help u
Reply
#6

nezo you must killtimer on public unmute, otherwise timer wont make u unmute

EDIT: like

Code:
forward Unmute(playerid);
public Unmute(playerid)
{
muted[playerid] = false; 
KillTimer(Unmute(playerid));
SendClientMessage(playerid, color, "Server unmuted you automatically");
return 1;
}
Reply
#7

You are missing a callback, all that part of the tutorial is I just creating the commands. It does mute the player from the chat without OnPlayerText.
Reply
#8

you must add OnPlayerText
because if you are muted then you can chat if you didnot added the code on callback OnPlayerText
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)