/mute command
#1

PHP код:
dcmd_mute(playeridparams[])
{
    new 
pIDtimereason[128];
    if(
adminlevel==0) return SendClientMessage(playeridCOLOR_WHITE"Server: Unrecognized command, type /commands to see the commands available for you.");
    if(
adminlevel<2) return SendClientMessage(playeridCOLOR_ADMINBLUE"ERROR: This command is unavailable for your admin rank.");
    if(
sscanf(params"uds"pIDtimereason)) return SendClientMessage(playeridCOLOR_ADMINBLUE"Correct usage: /mute [name/id] [seconds] [reason]");
    if(!
IsPlayerConnected(pID)) return SendClientMessage(playeridCOLOR_ADMINBLUE"ERROR: This player is not connected.");
    if(
playerid==pID) return SendClientMessage(playeridCOLOR_ADMINBLUE"ERROR: You cannot mute yourself.");
    new 
pIDadminlevel;
    
INI_ParseFile(UserPath(pID), "LoadUser_%s", .bExtra true, .extra pID);
    
pIDadminlevelPlayerInfo[pID][pAdmin];
    if(
pIDadminlevel>0)
    {
        if(
adminlevel==10)
        {
            
muted[pID] = 1;
            new 
amalmuteclient[128], amalmuteserver[128];
            
format(amalmuteclientsizeof(amalmuteclient), "You have been muted by the Senior Admin AmalM for %d seconds (Reason: %s)."timereason);
            
SendClientMessage(pIDCOLOR_BRIGHTREDamalmuteclient);
            new 
pName[128];
            
GetPlayerName(pIDpNamesizeof(pName));
            
format(amalmuteserversizeof(amalmuteserver), "Admin-mute: %s(%d) has been muted by the Senior Admin AmalM for %d seconds (Reason: %s)."pNamepIDtimereason);
            
SendClientMessageToAll(COLOR_BRIGHTREDamalmuteserver);
            
SetTimerEx("amalmute"time*1000false"is"pIDpName);
        }
        else
        {
            
muted[pID] = 1;
            new 
muteclient[128], muteserver[128];
            
format(muteclientsizeof(muteclient), "You have been muted by an admin for %d seconds (Reason: %s)."timereason);
            
SendClientMessage(pIDCOLOR_BRIGHTREDmuteclient);
            new 
pName[128];
            
GetPlayerName(pIDpNamesizeof(pName));
            
format(muteserversizeof(muteserver), "Admin-mute: %s(%d) has been muted for %d seconds (Reason: %s)."pNamepIDtimereason);
               
SendClientMessageToAll(COLOR_BRIGHTREDmuteserver);
            
SetTimerEx("mute"time*1000false"i"pIDpName);
        }
    }
    return 
1;
}
forward amalmute(pIDpName);
public 
amalmute(pIDpName)
{
    
muted[pID] = 0;
    
SendClientMessage(pIDCOLOR_BRIGHTRED"You have been auto-unmuted.");
    new 
unmuted[128];
    
format(unmutedsizeof(unmuted), "Auto-unmute: %s(%d) has been auto-unmuted.");
    
SendClientMessageToAll(COLOR_BRIGHTREDunmuted);
    return 
1;
}
forward mute(pIDpName);
public 
mute(pIDpName)
{
    
muted[pID] = 0;
    
SendClientMessage(pIDCOLOR_BRIGHTRED"You have been auto-unmuted.");
    new 
unmuted[128];
    
format(unmutedsizeof(unmuted), "Auto-unmute: %s(%d) has been auto-unmuted.");
    
SendClientMessageToAll(COLOR_BRIGHTREDunmuted);
    return 
1;

What's the problem in this script?

I gets the error
Quote:

E:\My Server\gamemodes\SARCR.pwn(831) : error 028: invalid subscript (not an array or too many subscripts): "muted"
E:\My Server\gamemodes\SARCR.pwn(831) : warning 215: expression has no effect
E:\My Server\gamemodes\SARCR.pwn(831) : error 001: expected token: ";", but found "]"
E:\My Server\gamemodes\SARCR.pwn(831) : error 029: invalid expression, assumed zero

Someone please help me.
Reply
#2

First of all, sscanf has to go like this:
Код:
if(sscanf(params, "uds[128]", pID, time, reason))
And can you show us the code where you declared muted variable.
Reply
#3

Quote:
Originally Posted by dominik523
Посмотреть сообщение
First of all, sscanf has to go like this:
Код:
if(sscanf(params, "uds[128]", pID, time, reason))
And can you show us the code where you declared muted variable.
You mean this?
PHP код:
new muted=0
Reply
#4

Muted can only store one data, and you want to store data of every player (MAX_PLAYERS).
So you need to create an array.
Код:
new muted[MAX_PLAYERS];
// under onPlayerConnect
muted[playerid] = 0;
Reply
#5

But when I do that, I gets this error for the /me, /do and /w command.
Quote:

// /me
if (strcmp(cmdtext, "/me ", true, 4) == 0)
{
if(!cmdtext[4])return SendClientMessage(playerid, COLOR_ORANGE, "Correct Usage: /me [action]");
if(muted > 0) return SendClientMessage(playerid, COLOR_ORANGE, "You cannot use this command when you are muted.");
new actionme[128];
format (actionme, sizeof(actionme), "*%s %s", playername, cmdtext[4]);
SendLocalMessage(playerid, COLOR_PINK, 7, actionme);
return 1;
}

// /do
if (strcmp(cmdtext,"/do ", true, 4) == 0)
{
if(!cmdtext[4])return SendClientMessage(playerid, COLOR_ORANGE, "Correct Usage: /do [message]");
if(muted > 0) return SendClientMessage(playerid, COLOR_ORANGE, "You cannot use this command when you are muted.");
new actiondo[128];
format (actiondo, sizeof(actiondo), "*%s((%s))", cmdtext[4], playername);
SendLocalMessage(playerid,COLOR_PINK,7, actiondo);
return 1;
}

// /do
if (strcmp(cmdtext, "/w ", true, 3) == 0)
{
if(!cmdtext[3])return SendClientMessage(playerid, COLOR_ORANGE, "Correct Usage: /w [message]");
if(muted > 0) return SendClientMessage(playerid, COLOR_ORANGE, "You cannot use this command when you are muted.");
new wmessage[128];
format (wmessage, sizeof(wmessage), "(Local) %s(%d): %s", playername, playerid, cmdtext[3]);
SendLocalMessage(playerid, COLOR_YELLOW, 7, wmessage);
return 1;
}

These are the errors
Quote:

E:\My Server\gamemodes\SARCR.pwn(922) : error 033: array must be indexed (variable "muted")
E:\My Server\gamemodes\SARCR.pwn(933) : error 033: array must be indexed (variable "muted")
E:\My Server\gamemodes\SARCR.pwn(944) : error 033: array must be indexed (variable "muted")

So, what should I do?
Reply
#6

change all muted to muted[playerid]

use CTRL+R to replace all muted to muted[playerid]
Reply
#7

Thanks man, its all fixed, now I gets no errors.

Also here
Quote:

forward mute(pID, pName);
public mute(pID, pName)
{
muted[pID] = 0;
SendClientMessage(pID, COLOR_BRIGHTRED, "You have been auto-unmuted.");
new unmuted[128];
format(unmuted, sizeof(unmuted), "Auto-unmute: %s(%d) has been auto-unmuted.");
SendClientMessageToAll(COLOR_BRIGHTRED, unmuted);
return 1;
}

I need to put mute[playerid] or mute[pID]?

rep++;
Reply
#8

Quote:
Originally Posted by ATGOggy
Посмотреть сообщение
Thanks man, its all fixed, now I gets no errors.

Also here

I need to put mute[playerid] or mute[pID]?

rep++;
muted[pID]

EDIT: as well as in dcmd_mute command
Reply
#9

Ok, thanks to both of you and your rep++;
Reply
#10

That problem is fixed.

This is my new code:
PHP код:
// /mute[dcmd]
dcmd_mute(playeridparams[])
{
    new 
pIDtimereason[128];
    if(
adminlevel==0) return SendClientMessage(playeridCOLOR_WHITE"Server: Unrecognized command, type /commands to see the commands available for you.");
    if(
adminlevel<2) return SendClientMessage(playeridCOLOR_ADMINBLUE"ERROR: This command is unavailable for your admin rank.");
    if(
sscanf(params"uds"pIDtimereason)) return SendClientMessage(playeridCOLOR_ADMINBLUE"Correct usage: /mute [name/id] [seconds] [reason]");
    if(!
IsPlayerConnected(pID)) return SendClientMessage(playeridCOLOR_ADMINBLUE"ERROR: This player is not connected.");
    if(
playerid==pID) return SendClientMessage(playeridCOLOR_ADMINBLUE"ERROR: You cannot mute yourself.");
    new 
pIDadminlevel;
    
INI_ParseFile(UserPath(pID), "LoadUser_%s", .bExtra true, .extra pID);
    
pIDadminlevelPlayerInfo[pID][pAdmin];
    if(
pIDadminlevel>0)
    {
        if(
adminlevel==10)
        {
            
muted[pID] = 1;
            new 
amalmuteclient[128], amalmuteserver[128];
            
format(amalmuteclientsizeof(amalmuteclient), "You have been muted by the Senior Admin AmalM for %d seconds (Reason: %s)."timereason);
            
SendClientMessage(pIDCOLOR_BRIGHTREDamalmuteclient);
            new 
pName[128];
            
GetPlayerName(pIDpNamesizeof(pName));
            
format(amalmuteserversizeof(amalmuteserver), "Admin-mute: %s(%d) has been muted by the Senior Admin AmalM for %d seconds (Reason: %s)."pNamepIDtimereason);
            
SendClientMessageToAll(COLOR_BRIGHTREDamalmuteserver);
            
SetTimerEx("amalmute"time*1000false"is"pIDpName);
        }
        else
        {
            
muted[pID] = 1;
            new 
muteclient[128], muteserver[128];
            
format(muteclientsizeof(muteclient), "You have been muted by an admin for %d seconds (Reason: %s)."timereason);
            
SendClientMessage(pIDCOLOR_BRIGHTREDmuteclient);
            new 
pName[128];
            
GetPlayerName(pIDpNamesizeof(pName));
            
format(muteserversizeof(muteserver), "Admin-mute: %s(%d) has been muted for %d seconds (Reason: %s)."pNamepIDtimereason);
               
SendClientMessageToAll(COLOR_BRIGHTREDmuteserver);
            
SetTimerEx("mute"time*1000false"i"pIDpName);
        }
    }
    return 
1;
}
forward amalmute(pIDpName);
public 
amalmute(pIDpName)
{
    
muted[pID] = 0;
    
SendClientMessage(pIDCOLOR_BRIGHTRED"You have been auto-unmuted.");
    new 
unmuted[128];
    
format(unmutedsizeof(unmuted), "Auto-unmute: %s(%d) has been auto-unmuted.");
    
SendClientMessageToAll(COLOR_BRIGHTREDunmuted);
    return 
1;
}
forward mute(pIDpName);
public 
mute(pIDpName)
{
    
muted[pID] = 0;
    
SendClientMessage(pIDCOLOR_BRIGHTRED"You have been auto-unmuted.");
    new 
unmuted[128];
    
format(unmutedsizeof(unmuted), "Auto-unmute: %s(%d) has been auto-unmuted.");
    
SendClientMessageToAll(COLOR_BRIGHTREDunmuted);
    return 
1;

The problem is when I type '/mute 0 500 bye', it says me 'Correct usage: /mute [name/id] [seconds] [reason]'

Someone please help me.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)