SA-MP Forums Archive
Some /set commands - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Some /set commands (/showthread.php?tid=243589)



Some /set commands - Markx - 23.03.2011

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


Re: Some /set commands - Zh3r0 - 23.03.2011

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.


Re: Some /set commands - Markx - 23.03.2011

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!


Re: Some /set commands - Markx - 23.03.2011

Sorry for duble post

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


Re: Some /set commands - Calgon - 23.03.2011

@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.


Re: Some /set commands - Zh3r0 - 23.03.2011

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!


Re: Some /set commands - Markx - 23.03.2011

Thanks all! Helped me much!