Some /set commands
#1

Can someone give me a example like /setweather, /setallweather, /sethp (health) please, Zcmd and sscanf
Reply
#2

pawn Код:
CMD:setweather( playerid, params[ ] )
{
    new Player, Weather;
    if ( sscanf( params, "ui", Player, Weather ) ) return SendClientMessage( playerid, 0x20FF20FF, "USAGE: /setweather "GREY"<id> <weather id>");
    else
    {
        if ( Player == ( 0xFFFF ) )  return SendClientMessage( playerid, 0xFF2020FF, "Player not connected!");

        SetPlayerWeather( Player, Weather );

        new Str[ 256 ];
        if ( Player != playerid )
        {
            format( Str, sizeof (Str), "You set %s's weather to %d", Name( Player ), Weather );
            SendClientMessage( playerid, 0xC3C3C3FF, Str );
            format( Str, sizeof (Str), "Admin %s set your weather to %d", Name( playerid), Weather );
            SendClientMessage( Player, 0xC3C3C3FF, Str );
        }
        else
        {
            format( Str, sizeof (Str), "You set your weather to %d", Weather );
            SendClientMessage( playerid, 0xC3C3C3FF, Str );
        }
    }
    return 1;
}
With this you can start off.
Reply
#3

Quote:
Originally Posted by Zh3r0
Посмотреть сообщение
pawn Код:
CMD:setweather( playerid, params[ ] )
{
    new Player, Weather;
    if ( sscanf( params, "ui", Player, Weather ) ) return SendClientMessage( playerid, 0x20FF20FF, "USAGE: /setweather "GREY"<id> <weather id>");
    else
    {
        if ( Player == ( 0xFFFF ) )  return SendClientMessage( playerid, 0xFF2020FF, "Player not connected!");

        SetPlayerWeather( Player, Weather );

        new Str[ 256 ];
        if ( Player != playerid )
        {
            format( Str, sizeof (Str), "You set %s's weather to %d", Name( Player ), Weather );
            SendClientMessage( playerid, 0xC3C3C3FF, Str );
            format( Str, sizeof (Str), "Admin %s set your weather to %d", Name( playerid), Weather );
            SendClientMessage( Player, 0xC3C3C3FF, Str );
        }
        else
        {
            format( Str, sizeof (Str), "You set your weather to %d", Weather );
            SendClientMessage( playerid, 0xC3C3C3FF, Str );
        }
    }
    return 1;
}
With this you can start off.
Okay thanks!
Reply
#4

Sorry for duble post

Can you make me a /setallweather (i got errors while trying)
Reply
#5

@Zh3r0, you shouldn't abuse 256 cells for message strings, it's extremely inefficient. You can't use 50% of that string for formatting, seeing as the max message size is 128 cells, and you aren't even using anywhere near 128 cells of that string. You're also only parsing one integer, you really don't need to use sscanf, you can just use isnull & strval.

pawn Код:
CMD:setweatherall(playerid, params[]) {
    if(!isnull(params)) {
        return SendClientMessage(playerid, -1, "Usage: /setweatherall [weatherid]");
    } else {
        new
            szMessage[32],
            iWeather = strval(params);
           
        if(iWeather < 1 || iWeather > 45){
            format(szMessage, sizeof(szMessage), "%d is not a valid weather ID.", iWeather);
            return SendClientMessage(playerid, -1, szMessage);
        }
       
        format(szMessage, sizeof(szMessage), "Weather changed to ID: #%d.", iWeather);
        SendClientMessage(playerid, -1, szMessage);
        SetWeather(iWeather);
    }
    return 1;
}
The sscanf include should include the isnull function.
Reply
#6

Here:

pawn Код:
CMD:setallweather( playerid, params[ ] )
{
    new Weather;
    if ( sscanf( params, "i", Weather ) ) return SendClientMessage( playerid, 0x20FF20FF, "USAGE: /setallweather {C3C3C3}<weather id>");
    else
    {
        for ( new p = 0; p < MAX_PLAYERS; ++p )
        {
            if ( IsPlayerConnected( p ) )
            {
                SetPlayerWeather( p, Weather );
            }
        }
        new Str[ 256 ];
        format( Str, sizeof (Str), "Admin %s everyone's weather to %d", Name( playerid), Weather );
        SendClientMessageToAll( 0xC3C3C3FF, Str );
    }
    return 1;
}
@Calg00ne, oww yeah, forgot about the universal function!
Reply
#7

Thanks all! Helped me much!
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)