Newbie chat help
#1

I have a /n chat script right. So, what I have so far is
Код:
[N] Karlos Says: Example
But I would like certain users to have a prefix before their name if thats possible. Like the users that are scripted as admin/moderators heres what I want it to be like.

-Examples below.

[Adminlevel] < 1) Helper = [N] Helper Karlos Says: Welcome to my server!
[Adminlevel] < 2) Moderator = [N] Moderator Karlos Says: Welcome to my server!
[Adminlevel] < 3) Admin = [N] Admin Karlos Says: Welcome to my server!
[Adminlevel] < 4) Admin = [N] Admin Karlos Says: Welcome to my server!
[Adminlevel] < 5) Admin = [N] Admin Karlos Says: Welcome to my server!

-Here's my current code

Код:
CMD:n(playerid, params[])
{
    new tmpstring[164], name[MAX_PLAYER_NAME];
        GetPlayerName(playerid, name, sizeof(name));
    if(sscanf(params, "s[128]", tmpstring))
    {
    	SendClientMessage(playerid, NEWBIE, "ERROR: Usage /n [message]");
        return 1;
    }
    else
    {
        format(tmpstring, sizeof(tmpstring), "[N] %s: %s ", name, tmpstring);
        SendClientMessageToAll(0x00E3AEFF, tmpstring);
    }
    return 1;
}
Reply
#2

You can use a set of if statements to check if the player is an admin, then use the format() to add the information in. Can you paste us another command from your script which requires admin or your variable names?

pawn Код:
MD:n(playerid, params[]) {
    new tmpstring[128], name[MAX_PLAYER_NAME];

    GetPlayerName(playerid, name, sizeof(name));
       
    if(isnull(params))
        return SendClientMessage(playerid, NEWBIE, "ERROR: Usage /n [message]");

    format(tmpstring, sizeof(tmpstring), "[N] %s: %s ", name, params);
    SendClientMessageToAll(0x00E3AEFF, tmpstring);
    return 1;
}
This code is more logical btw - when you only are dealing with one string, there's no need to use sscanf, you can just use the information directly from "params", and you can use isnull() to check if there's anything written after the command.

Also, message strings never exceed 128 characters usually. So it'd be wise to set the size to 128 as opposed to 164.
Reply
#3

Код:
CMD:n(playerid, params[])
{
new tmpstring[164], name[MAX_PLAYER_NAME];
GetPlayerName(playerid, name, sizeof(name));
if(sscanf(params, "s[128]", tmpstring))
{
SendClientMessage(playerid, NEWBIE, "ERROR: Usage /n [message]");
return 1;
}
if(Adminlevel[playerid] == 1) 
{
format(tmpstring, sizeof(tmpstring), "Helper = [N] %s: %s ", name, tmpstring);
SendClientMessageToAll(0x00E3AEFF, tmpstring);
}

if(Adminlevel[playerid] == 2) 
{
format(tmpstring, sizeof(tmpstring), "Moderator = [N] %s: %s ", name, tmpstring);
SendClientMessageToAll(0x00E3AEFF, tmpstring);
}

if(Adminlevel[playerid] >= 3) 
{
format(tmpstring, sizeof(tmpstring), "Admin = [N] %s: %s ", name, tmpstring);
SendClientMessageToAll(0x00E3AEFF, tmpstring);
}

if(Adminlevel[playerid] == 0) 
{
format(tmpstring, sizeof(tmpstring), "[N] %s: %s ", name, tmpstring);
SendClientMessageToAll(0x00E3AEFF, tmpstring);
}

return 1;
}
Reply
#4

Quote:
Originally Posted by jikesh_jus
Посмотреть сообщение
Код:
CMD:n(playerid, params[])
{
new tmpstring[164], name[MAX_PLAYER_NAME];
GetPlayerName(playerid, name, sizeof(name));
if(sscanf(params, "s[128]", tmpstring))
{
SendClientMessage(playerid, NEWBIE, "ERROR: Usage /n [message]");
return 1;
}
if(Adminlevel[playerid] == 1) 
{
format(tmpstring, sizeof(tmpstring), "Helper = [N] %s: %s ", name, tmpstring);
SendClientMessageToAll(0x00E3AEFF, tmpstring);
}

if(Adminlevel[playerid] == 2) 
{
format(tmpstring, sizeof(tmpstring), "Moderator = [N] %s: %s ", name, tmpstring);
SendClientMessageToAll(0x00E3AEFF, tmpstring);
}

if(Adminlevel[playerid] >= 3) 
{
format(tmpstring, sizeof(tmpstring), "Admin = [N] %s: %s ", name, tmpstring);
SendClientMessageToAll(0x00E3AEFF, tmpstring);
}

if(Adminlevel[playerid] == 0) 
{
format(tmpstring, sizeof(tmpstring), "[N] %s: %s ", name, tmpstring);
SendClientMessageToAll(0x00E3AEFF, tmpstring);
}

return 1;
}
Umm

Код:
D:\khubb2\Desktop\GTA_SERVER\gamemodes\Gamemode.pwn(989) : error 028: invalid subscript (not an array or too many subscripts): "Adminlevel"
D:\khubb2\Desktop\GTA_SERVER\gamemodes\Gamemode.pwn(989) : warning 215: expression has no effect
D:\khubb2\Desktop\GTA_SERVER\gamemodes\Gamemode.pwn(989) : error 001: expected token: ";", but found "]"
D:\khubb2\Desktop\GTA_SERVER\gamemodes\Gamemode.pwn(989) : error 029: invalid expression, assumed zero
D:\khubb2\Desktop\GTA_SERVER\gamemodes\Gamemode.pwn(989) : fatal error 107: too many error messages on one line

Compilation aborted.Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


4 Errors.
Reply
#5

Just replace AdminLevel[playerid] with the variable in your gamemode..
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)