How to complete this command?
#1

Hey all!

I am makin' a "warn-command" in ZCMD, but don't really know how to continue, and also don't know if it's right until now, I am a newbie!

PHP код:
    CMD:warn(playeridparams[])
    {
        if(
PlayerInfo[playerid][pAdmin] >= 3)
        {
            for(new 
0MAX_WARNINGSi++)
            new 
playernamestring[128];
            new 
adminnamestring[128];
                                       new 
reasonstring[128];
            
GetPlayername(playeridplayernameadminnamesizeof(playername,adminname));
            
format(string,sizeof(string), "Administrator "%s" has given "%s" a warning: 
For example, I dunno how t complete this string for the reason and also, how to set the limit in the loop to 3 warnings, cause after the 3rd the player should get kicked!!
Reply
#2

concept: ok. idea: ok. started to script: fail.
why? you cannot expect to script 100000 lines, press compile, and get the most awesome server. 1 step after 1, thats the magic trick. regardless WHAT you are doing (script a simple command in this case), start it like:
pawn Код:
CMD:warn(playerid,params[])
{
SendClientMessage(playerid,0xffffffff,"warning command works.");
return 1;
}
thats it. compile. if it gives any erors, smash your pc into pieces.. if it compiles those few lines, feel free to go on.
ok, now adding the admin level wont hurt:
pawn Код:
CMD:warn(playerid,params[])
{
if(PlayerInfo[playerid][pAdmin] >= 3)
{
SendClientMessage(playerid,0xffffffff,"warning command works.");
}
return 1;
}
indentation is our friend, so press the TAB key sometimes - nobody can read a worm:
pawn Код:
CMD:warn(playerid,params[])
{
    if(PlayerInfo[playerid][pAdmin] >= 3)
    {
        SendClientMessage(playerid,0xffffffff,"warning command works.");
    }
    return 1;
}
..already looks better. non-admins fail by reading that text now, but the next choice below looks beter anyways
pawn Код:
CMD:warn(playerid,params[])
{
    if(PlayerInfo[playerid][pAdmin] >= 3)
    {
        SendClientMessage(playerid,0xffffffff,"warning command works.");
    }
    else
    {
        SendClientMessage(playerid,0xffffffff,"you are not admin.");
    }
    return 1;
}
or
pawn Код:
CMD:warn(playerid,params[])
{
    if(PlayerInfo[playerid][pAdmin] >= 3)
    {
        SendClientMessage(playerid,0xffffffff,"warning command works.");
        return 1;
    }
    SendClientMessage(playerid,0xffffffff,"you are not admin.");
    return 1;
}
.. where last option looks neater. now lets include the warning count, assuming that its called PlayerInfo[playerid][warnings]...
now i strongly suggest you to download the sscanf2 2.5 plugin, you wont be able to continue from nowon without it.
pawn Код:
CMD:warn(playerid,params[])
{
    if(PlayerInfo[playerid][pAdmin] >= 3)
    {
        new TargetID,TargetName[MAX_PLAYER_NAME],AdminName[MAX_PLAYER_NAME];
        if(!sscanf2(params,"u",TargetID))
        {
            PlayerInfo[TargetID][warnings]++;
            GetPlayerName(playerid,AdminName,sizeof(AdminName));
            GetPlayerName(TargetID,TargetName,sizeof(TargetName));
            new string[128];
            format(string,sizeof(string),"(%d)%s gave (%d)%s Warning #%d.",playerid,AdminName,TargetID,TargetName,PlayerInfo[TargetID][warnings]);
            SendClientMessageToAll(0xffffffff,string);
            if(PlayerInfo[TargetID][warnings]>2)
            {
                SendClientMessageToAll(0xffffffff,"...and kicked him.");
                Kick(TargetID);
            }
        }
        return 1;
    }
    SendClientMessage(playerid,0xffffffff,"you are not admin.");
    return 1;
}
not tested, typed it in a hurry
Reply
#3

You're completely right, I should do everything step by step!
Compiled it now, and got 4 errors:

Код:
D:\Program Files\GTA San Andreas\eigener SAMP\gamemodes\deathmatch.pwn(385) : error 017: undefined symbol "sscanf2"
D:\Program Files\GTA San Andreas\eigener SAMP\gamemodes\deathmatch.pwn(387) : error 017: undefined symbol "warnings"
D:\Program Files\GTA San Andreas\eigener SAMP\gamemodes\deathmatch.pwn(391) : error 017: undefined symbol "warnings"
D:\Program Files\GTA San Andreas\eigener SAMP\gamemodes\deathmatch.pwn(393) : error 017: undefined symbol "warnings"
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


4 Errors.
Downloaded the new sscanf plugin and included it already....

PHP код:
#include <sscanf2> 
Reply
#4

If your includes are at the top of your script (which I'm assuming), then why do you have sscanf2 written on line 385?
Reply
#5

Quote:
Originally Posted by Mosslah
Посмотреть сообщение
If your includes are at the top of your script (which I'm assuming), then why do you have sscanf2 written on line 385?
pawn Код:
if(!sscanf2(params,"u",TargetID))
he has missing the function of sscanf2.
Reply
#6

Huh, it's written there! :O
What should I do now? They're all "undefined symbols".... ><
Reply
#7

Make sure you have sscanf2.inc at your_server\pawno\includes\Here!
pawn Код:
// At The Top  
#include < a_samp >
#include < zcmd >
#include < sscanf2 >
// Rest
#define MAX_WARNINGS 3
new
    Warnings[ MAX_PLAYERS ];

CMD:warn( playerid, params[ ] )
{
    if( PlayerInfo[ playerid ][ pAdmin ] >= 3 ) return SendClientMessage( playerid, -1, "You are not Admin" );
    new
        playername[ MAX_PLAYER_NAME ], adminname[ MAX_PLAYER_NAME ],
        id, reason[ 64 ], string[ 128 ];

    if( sscanf( params, "rs[64]", id, reason ) ) return SendClientMessage( playerid, -1, "Usage: /warn [ID/Part Of Name] [Reason]" );

    GetPlayerName( playerid, playername, sizeof( playername ) );
    GetPlayerName( playerid, playername, sizeof( playername ) );
    Warnings[ id ] ++;
    format( string, sizeof( string ), "Administrator \"%s\" has given \"%s\" a warning: %i/%i", adminname, playername, Warnings[ id ], MAX_WARNINGS );
    SendClientMessageToAll( -1, string );
    if( Warnings[ id ] > 2 ) {
        Kick( id );
    }
    return 1;
}
Reply
#8

There are no problems when I compile, but when I wanna /warn, then there is written "You are not admin"!

This is the file from my registersystem:

Password=XXXXXXXXXXXXXX
Cash=0
Admin=10
Score=0
FirstTime=0
Skin=175


Maybe there are problems there? I also can't do it when I am logged in as RCON!
Reply
#9

Sorry my mistake! Replace
pawn Код:
if( PlayerInfo[ playerid ][ pAdmin ] >= 3 ) return SendClientMessage( playerid, -1, "You are not Admin" );
To
pawn Код:
if( PlayerInfo[ playerid ][ pAdmin ] < 3 ) return SendClientMessage( playerid, -1, "You are not Admin" );
Reply
#10

Quote:
Originally Posted by Babul
Посмотреть сообщение
concept: ok. idea: ok. started to script: fail.
why? you cannot expect to script 100000 lines, press compile, and get the most awesome server. 1 step after 1, thats the magic trick. regardless WHAT you are doing (script a simple command in this case), start it like:
pawn Код:
CMD:warn(playerid,params[])
{
SendClientMessage(playerid,0xffffffff,"warning command works.");
return 1;
}
thats it. compile. if it gives any erors, smash your pc into pieces.. if it compiles those few lines, feel free to go on.
ok, now adding the admin level wont hurt:
pawn Код:
CMD:warn(playerid,params[])
{
if(PlayerInfo[playerid][pAdmin] >= 3)
{
SendClientMessage(playerid,0xffffffff,"warning command works.");
}
return 1;
}
indentation is our friend, so press the TAB key sometimes - nobody can read a worm:
pawn Код:
CMD:warn(playerid,params[])
{
    if(PlayerInfo[playerid][pAdmin] >= 3)
    {
        SendClientMessage(playerid,0xffffffff,"warning command works.");
    }
    return 1;
}
..already looks better. non-admins fail by reading that text now, but the next choice below looks beter anyways
pawn Код:
CMD:warn(playerid,params[])
{
    if(PlayerInfo[playerid][pAdmin] >= 3)
    {
        SendClientMessage(playerid,0xffffffff,"warning command works.");
    }
    else
    {
        SendClientMessage(playerid,0xffffffff,"you are not admin.");
    }
    return 1;
}
or
pawn Код:
CMD:warn(playerid,params[])
{
    if(PlayerInfo[playerid][pAdmin] >= 3)
    {
        SendClientMessage(playerid,0xffffffff,"warning command works.");
        return 1;
    }
    SendClientMessage(playerid,0xffffffff,"you are not admin.");
    return 1;
}
.. where last option looks neater. now lets include the warning count, assuming that its called PlayerInfo[playerid][warnings]...
now i strongly suggest you to download the sscanf2 2.5 plugin, you wont be able to continue from nowon without it.
pawn Код:
CMD:warn(playerid,params[])
{
    if(PlayerInfo[playerid][pAdmin] >= 3)
    {
        new TargetID,TargetName[MAX_PLAYER_NAME],AdminName[MAX_PLAYER_NAME];
        if(!sscanf2(params,"u",TargetID))
        {
            PlayerInfo[TargetID][warnings]++;
            GetPlayerName(playerid,AdminName,sizeof(AdminName));
            GetPlayerName(TargetID,TargetName,sizeof(TargetName));
            new string[128];
            format(string,sizeof(string),"(%d)%s gave (%d)%s Warning #%d.",playerid,AdminName,TargetID,TargetName,PlayerInfo[TargetID][warnings]);
            SendClientMessageToAll(0xffffffff,string);
            if(PlayerInfo[TargetID][warnings]>2)
            {
                SendClientMessageToAll(0xffffffff,"...and kicked him.");
                Kick(TargetID);
            }
        }
        return 1;
    }
    SendClientMessage(playerid,0xffffffff,"you are not admin.");
    return 1;
}
not tested, typed it in a hurry
Its a shame no one has put this in the Tutorial section. It would cut down on almost half these posts.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)