/admin and /msg not working
#1

So, i'm working on an (/admin) command so they can message an admin about something and I've made a (/msg) command to message them back with an answer for example.

It isn't working, just gives an error that the command doesn't exist, here are the commands:
pawn Код:
CMD:msg(playerid, params[])
{
    new id, str1[128], str2[128], message, adminmsg[128];
    if(pInfo[playerid][pAdmin] < 1) return 0;
    if(sscanf(params,"us[128]",id,message)) return SCM(playerid, COLOR_WHITE,"Syntax: /msg [playerid/partofname] [message]");
    format(str1, sizeof(str1), "%s", params);
    format(str2, sizeof(str2), "{FF0000}Message From Admin:{FFFFFF}%s(%d)", PlayerName(playerid), playerid);
    ShowPlayerDialog(playerid, anotice, DIALOG_STYLE_MSGBOX, str2,str1,"Close","");
    format(adminmsg, sizeof(adminmsg), "{1B8AE4}%s(%d){FFFFFF} messaged {1B8AE4}%s(%d){FFFFFF}: %s", PlayerName(playerid), playerid, PlayerName(id), id, message);
    SendMessageToAdmins(-1, adminmsg);
    return 1;
}

CMD:admin(playerid, params[])
{
    new message, adminmsg[128];
    if(sscanf(params,"s[128]",message)) return SCM(playerid, COLOR_WHITE,"Syntax: /admin [message]");
    format(adminmsg, sizeof(adminmsg), "Message From: {1B8AE4}%s(%d){FFFFFF}: %s", PlayerName(playerid), playerid, message);
    SendMessageToAdmins(-1, adminmsg);
    SCM(playerid, -1, "Your message has been sent to all online admins.");
    return 1;
}
Reply
#2

You should always try debugging the code.

EDIT: Just noticed - you're declaring message as a integer aswell.

pawn Код:
new id, str1[128], str2[128], message[128], adminmsg[128];
pawn Код:
CMD:msg(playerid, params[])
{
    new id, str1[128], str2[128], message, adminmsg[128];
    if(pInfo[playerid][pAdmin] < 1) return 0;
    print("reached 1");
    if(sscanf(params,"us[128]",id,message)) return SCM(playerid, COLOR_WHITE,"Syntax: /msg [playerid/partofname] [message]");
    print("reached 2");
    format(str1, sizeof(str1), "%s", params); //change from params to message so it doesnt take in the ID you entered.
    print("reached 3");
    format(str2, sizeof(str2), "{FF0000}Message From Admin:{FFFFFF}%s(%d)", PlayerName(playerid), playerid);
    print("reached 4");
    ShowPlayerDialog(playerid, anotice, DIALOG_STYLE_MSGBOX, str2,str1,"Close",""); //I think you should be sending this to id btw :P
    print("reached 5");
    format(adminmsg, sizeof(adminmsg), "{1B8AE4}%s(%d){FFFFFF} messaged {1B8AE4}%s(%d){FFFFFF}: %s", PlayerName(playerid), playerid, PlayerName(id), id, message);
    print("reached 6");
    SendMessageToAdmins(-1, adminmsg);
    return 1;
}

CMD:admin(playerid, params[])
{
    new message, adminmsg[128];
    if(sscanf(params,"s[128]",message)) return SCM(playerid, COLOR_WHITE,"Syntax: /admin [message]");
    print("reached A");
    format(adminmsg, sizeof(adminmsg), "Message From: {1B8AE4}%s(%d){FFFFFF}: %s", PlayerName(playerid), playerid, message);
    print("reached B");
    SendMessageToAdmins(-1, adminmsg);
    print("reached C");
    SCM(playerid, -1, "Your message has been sent to all online admins.");
    return 1;
}
EDIT2:
You could make this work with just 2strings.
pawn Код:
CMD:msg(playerid, params[])
{
    new id, str[128],message[128];
    if(pInfo[playerid][pAdmin] < 1) return 0;
    if(sscanf(params,"us[128]",id,message)) return SCM(playerid, COLOR_WHITE,"Syntax: /msg [playerid/partofname] [message]");
    format(str, sizeof(str), "{FF0000}Message From Admin:{FFFFFF}%s(%d)", PlayerName(playerid), playerid);
    ShowPlayerDialog(id, anotice, DIALOG_STYLE_MSGBOX, str,message,"Close","");
    format(str, sizeof(str), "{1B8AE4}%s(%d){FFFFFF} messaged {1B8AE4}%s(%d){FFFFFF}: %s", PlayerName(playerid), playerid, PlayerName(id), id, message);
    //SendMessageToAdmins(-1, str);
    return 1;
}

CMD:admin(playerid, params[])
{
    new message[128], adminmsg[128];
    if(sscanf(params,"s[128]",message)) return SCM(playerid, COLOR_WHITE,"Syntax: /admin [message]");
    print("reached A");
    format(adminmsg, sizeof(adminmsg), "Message From: {1B8AE4}%s(%d){FFFFFF}: %s", PlayerName(playerid), playerid, message);
    print("reached B");
    SendMessageToAdmins(-1, adminmsg);
    print("reached C");
    SCM(playerid, -1, "Your message has been sent to all online admins.");
    return 1;
}
Reply
#3

Quote:
Originally Posted by EiresJason
Посмотреть сообщение
You should always try debugging the code.

EDIT: Just noticed - you're declaring message as a integer aswell.

pawn Код:
new id, str1[128], str2[128], message[128], adminmsg[128];
pawn Код:
CMD:msg(playerid, params[])
{
    new id, str1[128], str2[128], message, adminmsg[128];
    if(pInfo[playerid][pAdmin] < 1) return 0;
    print("reached 1");
    if(sscanf(params,"us[128]",id,message)) return SCM(playerid, COLOR_WHITE,"Syntax: /msg [playerid/partofname] [message]");
    print("reached 2");
    format(str1, sizeof(str1), "%s", params); //change from params to message so it doesnt take in the ID you entered.
    print("reached 3");
    format(str2, sizeof(str2), "{FF0000}Message From Admin:{FFFFFF}%s(%d)", PlayerName(playerid), playerid);
    print("reached 4");
    ShowPlayerDialog(playerid, anotice, DIALOG_STYLE_MSGBOX, str2,str1,"Close",""); //I think you should be sending this to id btw :P
    print("reached 5");
    format(adminmsg, sizeof(adminmsg), "{1B8AE4}%s(%d){FFFFFF} messaged {1B8AE4}%s(%d){FFFFFF}: %s", PlayerName(playerid), playerid, PlayerName(id), id, message);
    print("reached 6");
    SendMessageToAdmins(-1, adminmsg);
    return 1;
}

CMD:admin(playerid, params[])
{
    new message, adminmsg[128];
    if(sscanf(params,"s[128]",message)) return SCM(playerid, COLOR_WHITE,"Syntax: /admin [message]");
    print("reached A");
    format(adminmsg, sizeof(adminmsg), "Message From: {1B8AE4}%s(%d){FFFFFF}: %s", PlayerName(playerid), playerid, message);
    print("reached B");
    SendMessageToAdmins(-1, adminmsg);
    print("reached C");
    SCM(playerid, -1, "Your message has been sent to all online admins.");
    return 1;
}
EDIT2:
You could make this work with just 2strings.
pawn Код:
CMD:msg(playerid, params[])
{
    new id, str[128],message[128];
    if(pInfo[playerid][pAdmin] < 1) return 0;
    if(sscanf(params,"us[128]",id,message)) return SCM(playerid, COLOR_WHITE,"Syntax: /msg [playerid/partofname] [message]");
    format(str, sizeof(str), "{FF0000}Message From Admin:{FFFFFF}%s(%d)", PlayerName(playerid), playerid);
    ShowPlayerDialog(id, anotice, DIALOG_STYLE_MSGBOX, str,message,"Close","");
    format(str, sizeof(str), "{1B8AE4}%s(%d){FFFFFF} messaged {1B8AE4}%s(%d){FFFFFF}: %s", PlayerName(playerid), playerid, PlayerName(id), id, message);
    //SendMessageToAdmins(-1, str);
    return 1;
}
Still nothing, also no output in the console saying that it has reached the certain point.
EDIT: even when removing the code it still says the command does not exist.
Reply
#4

Quote:
Originally Posted by Jimmy0wns
Посмотреть сообщение
Still nothing, also no output in the console saying that it has reached the certain point.
Which snippet did you try?

The last one was without the debugging but what the code should look like when it's done.

Add in debug into the snippet after EDIT 2 and see what happens.

I threw it onto my script, changed the PlayerName(playerid) to the stock I use and remove the SendAdminMessage and it worked perfectly.
Reply
#5

Quote:
Originally Posted by EiresJason
Посмотреть сообщение
Which snippet did you try?

The last one was without the debugging but what the code should look like when it's done.

Add in debug into the snippet after EDIT 2 and see what happens.
Still nothing.
Reply
#6

Can you post the code that you're trying with now, incase I'm looking back at my code but you tried code before i edited it
Reply
#7

Quote:
Originally Posted by EiresJason
Посмотреть сообщение
Can you post the code that you're trying with now, incase I'm looking back at my code but you tried code before i edited it
pawn Код:
CMD:msg(playerid,params[])
{
    new id, str[128],message[128];
    if(pInfo[playerid][pAdmin] < 1) return 0;
    print("reached 1");
    if(sscanf(params,"us[128]",id,message)) return SCM(playerid, COLOR_WHITE,"Syntax: /msg [playerid/partofname] [message]");
    print("reached 2");
    format(str, sizeof(str), "{FF0000}Message From Admin:{FFFFFF}%s(%d)", PlayerName(playerid), playerid);
    print("reached 3");
    ShowPlayerDialog(id, anotice, DIALOG_STYLE_MSGBOX, str,message,"Close","");
    print("reached 4");
    format(str, sizeof(str), "{1B8AE4}%s(%d){FFFFFF} messaged {1B8AE4}%s(%d){FFFFFF}: %s", PlayerName(playerid), playerid, PlayerName(id), id, message);
    print("reached 5");
    SendMessageToAdmins(-1, str);
    return 1;
}

CMD:admin(playerid,params[])
{
    new message, adminmsg[128];
    if(sscanf(params,"s[128]",message)) return SCM(playerid, COLOR_WHITE,"Syntax: /admin [message]");
    print("reached A");
    format(adminmsg, sizeof(adminmsg), "Message From: {1B8AE4}%s(%d){FFFFFF}: %s", PlayerName(playerid), playerid, message);
    print("reached B");
    SendMessageToAdmins(-1, adminmsg);
    print("reached C");
    SCM(playerid, -1, "Your message has been sent to all online admins.");
    return 1;
}
Reply
#8

The only reason I can see this returning the error is that you think your pAdmin is greater than 0, but it isnt
pawn Код:
//Like here
 if(pInfo[playerid][pAdmin] < 1) return 0;
Do both commands return the error?
Reply
#9

Quote:
Originally Posted by EiresJason
Посмотреть сообщение
The only reason I can see this returning the error is that you think your pAdmin is greater than 0, but it isnt

Do both commands return the error?
Yes they do, for normal users and level 5 administrators.
Reply
#10

did you define include ZCMD?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)