Cуdigos Ъteis #1

Quote:
Originally Posted by NicK_
Посмотреть сообщение
Comando /uptime (saber quando tempo o server estб ligado)

* Necessбrio estar em sua OnGameModeInit()/OnFilterScriptInit()
PHP код:
SetSVarInt("uptime_svr",gettime()); 
Comando (pode ficar em qualquer parte do seu script)
PHP код:
CMD:uptime(playerid) {
    new 
Msg[144], t[3];
    
t[0] = gettime() - GetSVarInt("uptime_svr");
    if(
t[0] >= (60*60)) {
        
t[1] = t[0] / (60*60);
        
t[0] = t[0] - (t[1] * (60*60));
    }
    if(
t[0] >= 60) {
        
t[2] = t[0] / 60;
        
t[0] = t[0] - (t[2] * 60);
    }
    
format(Msg,144,"{FFFF00}UPTIME: %02dhoras, %02dminutos, %02dsegundos.",t[1],t[2],t[0]);
    
SendClientMessage(playerid,-1,Msg);
    return 
1;

Irб mostrar no chat (exemplo):
https://sampwiki.blast.hk/wiki/Tickcount

Existe uma funзгo nativa para isso.
Reply

Quote:
Originally Posted by Gii
Посмотреть сообщение
https://sampwiki.blast.hk/wiki/Tickcount

Existe uma funзгo nativa para isso.
A funзгo nativa para isto, buga quando passa de 24 horas, pois й um valor retornado de milisegundos. Nesse caso do exemplo, o server pode ficar mais de 1 dia que serб informado com o cmd quanto tempo tem ligado sem problemas.
Reply

Quote:
Originally Posted by NicK_
Посмотреть сообщение
A funзгo nativa para isto, buga quando passa de 24 horas, pois й um valor retornado de milisegundos. Nesse caso do exemplo, o server pode ficar mais de 1 dia que serб informado com o cmd quanto tempo tem ligado sem problemas.
** 24 dias.
Reply

Ah verdade, viajei kk
Reply

Nгo й nenhum script especнfico mas й interessante. Sгo algumas dicas para otimizar seu script e deixб-lo mais "suave".

Setar o mesmo valor para vбrias variбveis
Quote:
//Nгo otimizado
Player[playerid][skin] = 0;
Player[playerid][admin] = 0;
Player[playerid][score] = 0;
Player[playerid][dinheiro] = 0;

Quote:
//Otimizado
Player[playerid][skin] = Player[playerid][admin] = Player[playerid][score] = Player[playerid][dinheiro] = 0;

Checar mesma condiзгo para vбrias variбveis
Quote:
//Nгo otimizado
if(Player[playerid][skin] == 0 && Player[playerid][admin] == 0 && Player[playerid][score] == 0){
print("Os valores de 'skin', 'admin', e 'score' sгo iguais a 0");
}

Quote:
//Otimizado
if(Player[playerid][skin] | Player[playerid][admin] | Player[playerid][score] == 0){
print("Os valores de 'skin', 'admin', e 'score' sгo iguais a 0");
}

Checar valores maior ou menor
Quote:
//Nгo otimizado
if(Player[playerid][skin] >= 0 && Player[playerid][skin] <= 311){
SetPlayerSkin(playerid, Player[playerid][skin]);
}

Quote:
//Otimizado
if(0 <= Player[playerid][skin] <= 311){
SetPlayerSkin(playerid, Player[playerid][skin]);
}

Para alguns nгo й novidade, mas para muitos serб ъtil.
Reply

Algum tempo atraz, eu tinha feito esse comando pra uma futura GM que iria postar aqui no fуrum, para ser um novo GM de mata-mata usado.. Sу que aн o projeto ficou para traz e decide postar esse cуdigo.. OBS: Esse cуdigo foi inspirado em um que vi do paulor а um tempo atraz.

PHP код:
#define D_ARMAS 4//coloque o ID do diбlogo.
#define D_ARMAS_PERSONALIZADAS 5 //mesma coisa a cima.
#define D_ARMAS_ESPECIAIS 6 //mesma coisa a cima. І
CMD:armas(playerid) return     ShowPlayerDialog(playeridD_ARMASDIALOG_STYLE_LIST"{FF0000}# {FFFFFF}Armas!""{FFFFFF}Armas padrхes\nArmas personalizadas\n{FFFF00}Armas especiais""Selecionar""Sair");
public 
OnDialogResponse(playeriddialogidresponselistiteminputtext[])
{
    if(
response)
    {
        switch(
dialogid)
        {
            case 
D_ARMAS:
            {
                switch(
listitem)
                {
                    case 
0:
                    {
                        
ResetPlayerWeapons(playerid);
                        
GiveThreePlayerWeapon(playerid19999229999259999);//Soco inglкs, 9mm normal e Escopeta '-'
                        
GiveThreePlayerWeapon(playerid309999289999349999);//AK-47, Micro-Uzi e Sniper '-'
                        
SendClientMessage(playerid, -1"{008B00}Vocк pegou as armas {00FF00}normais{008B00}.");
                    }
                    case 
1:
                    {
                        new 
Dialog[590], strca[590];
                        
format(Dialogsizeof(Dialog), "1 - Soco inglкs\n2 - Taco de golfe\n3 - Cacetete\n4 - Faca\n5 - Taco de Basebol\n6 - Pб\n7 - Taco de sinuca\n8 - Katana\n9 - Serra elйtrica\n10 - Vibrador mйdio\n11 - Vibrador Grosso, grande, e gostoso.\n12 - Vibrador branco\n13 - Vibrador pequeno\n14 - Flores\n15 - Granadas\n16 - Bomba de gбs\n17 - Cocktail Molotov\n18 - 9mm pistola\n"); strcat(strcaDialog);
                        
format(Dialogsizeof(Dialog), "19 - 9mm silenciada\n20 - Desert Eagle\n21 - Shotgun\n22 - Shotgun Cano Serrado\n23 - Escopeta de Combate\n24 - Micro Uzi\n25 - MP5\n26 - AK-47\n27 - M4\n28 - Tec 9\n29 - Rifle\n30 - Sniper\n31 - Spray\n32 - Extinto de Incкndio\n33 - Cвmera\n34 - Paraquedas"); strcat(strcaDialog);
                        
ShowPlayerDialog(playeridD_ARMAS_PERSONALIZADASDIALOG_STYLE_LIST"{FFFF00}# {FFFFFF}Armas personalizadas!"strca"Selecionar""");
                    }
                    case 
2:
                    {
                        new 
Dialog[68], strca[68];
                        
format(Dialogsizeof(Dialog), "1 - RPG\n2 - Bazuca\n3 - Lanзa-chamas\n4 - Minigun\n5 - Explosivos"); strcat(strcaDialog);
                        
ShowPlayerDialog(playeridD_ARMAS_ESPECIAISDIALOG_STYLE_LIST"{FFFF00}# {FFFFFF}Armas especiais!"strca"Selecionar""");
                    }
                }
            }
            case 
D_ARMAS_PERSONALIZADAS:
            {
                    {
                    switch(
listitem)
                    {
                        case 
.. 37:
                        {
                            if(!
response) return ShowPlayerDialog(playeridD_ARMASDIALOG_STYLE_LIST"{FF0000}# {FFFFFF}Armas!""{FFFFFF}Armas padrхes\nArmas personalizadas\n{FFFF00}Armas especiais""Selecionar""Sair");
                            new 
Arma[] = {1234567891011121314161718222324252627282930313233344243444346};
                            
GivePlayerWeapon(playeridArma[listitem], 9999);
                        }
                    }
                }
            }
            case 
D_ARMAS_ESPECIAIS:
            {
                    switch(
listitem)
                    {
                        case 
.. 5:
                        {
                            if(!
response) return ShowPlayerDialog(playeridD_ARMASDIALOG_STYLE_LIST"{FF0000}# {FFFFFF}Armas!""{FFFFFF}Armas padrхes\nArmas personalizadas\n{FFFF00}Armas especiais""Selecionar""Sair");
                            new 
Arma[] = {3536373839};
                            
GivePlayerWeapon(playeridArma[listitem], 9999);
                        }
                    }
                    if(!
response) return ShowPlayerDialog(playeridD_ARMASDIALOG_STYLE_LIST"{FF0000}# {FFFFFF}Armas!""{FFFFFF}Armas padrхes\nArmas personalizadas\n{FFFF00}Armas especiais""Selecionar""Sair");
            }
        }
    }
    return 
1;
}
//Funзгo para dar 3 armas.
GiveThreePlayerWeapon(playerid, const arma1arma1marma2arma2marma3arma3m)
{
    
GivePlayerWeapon(playeridarma1arma1m);
    
GivePlayerWeapon(playeridarma2arma2m);
    
GivePlayerWeapon(playeridarma3arma3m);
    return 
1;

Algumas armas podem sair meio misturadas, nгo mexi mais no cуdigo, da ъltima vez que olhei, ele tava respondendo bem.
Reply

3DTextLabel & Movable3DText

Olб, vim trazer um cуdigo para aqueles que sгo igual buce**, quer sу na boquinha, ou ate mesmo para quem й iniciante..

Se vocк quer encher o mapa de textos por todo lado, estб no lugar certo, mais agora, como fazer isso? simples eu te encino..

1° - Entre no Game e vб atй o lugar que vocк deseja colocar o Texto.

2° - Aperte "T" e digite "/save".

3° - Vб ate a pasta "GTA San Andreas User Files\SAMP" e abra o arquivo "savedpositions" Terб algo parecido com isso "AddPlayerClass(6,817.6572,-2220.7014,12.9828,360.0000,0,0,0,0,0,0);"

4° - Ignore o primeiro numero, copiando assim apenas o 2°,3° e 4°. No meu caso "817.6572,-2220.7014,12.9828"

5° - Adicione os numero no CODE no lugar de X,Y e Z Respectivamente.



Lembrando que pra criar novos Textos basta Copiar e Colar o jб criado..

pawn Code:
#include <a_samp>

#define     BRANCO      0xFFFFFFFF

public OnGameModeInit()
{
//  |      FUNЗГO    |  COR   |TEXTO QUE IRA APARECER| DEFINIDO ACIMA|   X    |     Y    |   Z   |DISTANCIA ONDE SERA VISTO|
    Create3DTextLabel("{CD0000}COLOQUE AQUI SEU TEXTO", BRANCO,       258.1041, -140.4503, 1.5781,           90.0,          0, 0); // TEXTO FIXO

//  |       FUNЗГO     |  COR   |TEXTO QUE IRA APARECER|    |DEFINIDO ACIMA|        |   X   |     Y     |   Z    |
    CreateMovable3DText("{CD0000}COLOQUE AQUI SEU TEXTO", 1,  0xFFFFFFFF,      18.0, 24.1553, -2646.3928, 40.4632, 0, 0); //TEXTO MOVEL
    return 1;
}

-Espero ter ajudado Alguйm..
Reply

Quote:
Originally Posted by MarcoAurelio
View Post
3DTextLabel & Movable3DText

Olб, vim trazer um cуdigo para aqueles que sгo igual buce**, quer sу na boquinha, ou ate mesmo para quem й iniciante..

Se vocк quer encher o mapa de textos por todo lado, estб no lugar certo, mais agora, como fazer isso? simples eu te encino..

1° - Entre no Game e vб atй o lugar que vocк deseja colocar o Texto.

2° - Aperte "T" e digite "/save".

3° - Vб ate a pasta "GTA San Andreas User Files\SAMP" e abra o arquivo "savedpositions" Terб algo parecido com isso "AddPlayerClass(6,817.6572,-2220.7014,12.9828,360.0000,0,0,0,0,0,0);"

4° - Ignore o primeiro numero, copiando assim apenas o 2°,3° e 4°. No meu caso "817.6572,-2220.7014,12.9828"

5° - Adicione os numero no CODE no lugar de X,Y e Z Respectivamente.



Lembrando que pra criar novos Textos basta Copiar e Colar o jб criado..

pawn Code:
#include <a_samp>

#define     BRANCO      0xFFFFFFFF

public OnGameModeInit()
{
//  |      FUNЗГO    |  COR   |TEXTO QUE IRA APARECER| DEFINIDO ACIMA|   X    |     Y    |   Z   |DISTANCIA ONDE SERA VISTO|
    Create3DTextLabel("{CD0000}COLOQUE AQUI SEU TEXTO", BRANCO,       258.1041, -140.4503, 1.5781,           90.0,          0, 0); // TEXTO FIXO

//  |       FUNЗГO     |  COR   |TEXTO QUE IRA APARECER|    |DEFINIDO ACIMA|        |   X   |     Y     |   Z    |
    CreateMovable3DText("{CD0000}COLOQUE AQUI SEU TEXTO", 1,  0xFFFFFFFF,      18.0, 24.1553, -2646.3928, 40.4632, 0, 0); //TEXTO MOVEL
    return 1;
}

-Espero ter ajudado Alguйm..
Ta primeiro, que cуdigo veio trazer? Sу vi um tutorial que provavelmente todo mundo jб saiba.

Segundo, passou a ideia de que a funзгo 'CreateMovable3DText' й nativa, nгo disse sua funcionalidade e nгo colocou referкncia da include.

Reveja antes de postar.
Reply

PHP Code:
IsABike(v) {
    new
        
v_ GetVehicleModel(v);
    if(!(
v_ 509) | !(v_ 510) | !(v_ 481)) return 1;
    return 
0;

Insignificantemente mais rбpido, porйm, mais bonito.
Reply

Quote:
Originally Posted by Abravanel
View Post
PHP Code:
IsABike(v) {
    new
        
v_ GetVehicleModel(v);
    if(!(
v_ 509) | !(v_ 510) | !(v_ 481)) return 1;
    return 
0;

Insignificantemente mais rбpido, porйm, mais bonito.
Eu sу nгo gostei da nomenclatura utilizada na variбvel V_, poderia ser vehicle ou algo do tipo, v_ fica um pouco estranho, e feio.

PHP Code:
isABike(v) {
    new 
vehicle GetVehicleModel(v);
    if(!(
vehicle 509) | !(vehicle 510) | !(vehicle 481)) return 1;
    return 
0;

com camelCase.
Reply

Gosto vai de cada um... quanto mais curto, melhor para mim. De qualquer forma, isso nгo altera em nada, apenas o aspecto visual.
Reply

Cуdigo simples, fiz pra passar tempo, mais pode ser ъtil pra alguйm..

stock para dar saudaзгo de acordo com o horбrio "boa madrugada, bom dia, boa tarde, boa noite"


PHP Code:
stock GetSaudacao()
{
    new 
HorMinSegstring[15];
    
gettime(HorMinSeg);
    switch(
Hor)
    {
        case 
0..5string "Boa madrugada";
        case 
6..11string "Bom dia";
        case 
12..18string "Boa tarde";
        case 
19..23string "Boa noite";
    }
    return 
string;

Exemplo de modo de uso:

PHP Code:
new msg[50], Nome[MAX_PLAYERS][24];
GetPlayerName(playeridNome[playerid], 24);
format(msgsizeof msg"Olб %s, %s!"Nome[playerid], GetSaudacao());
SendClientMessage(playerid, -1msg); 



:*
Reply

Quote:
Originally Posted by Cleyson
View Post
Cуdigo simples, fiz pra passar tempo, mais pode ser ъtil pra alguйm..

stock para dar saudaзгo de acordo com o horбrio "boa madrugada, bom dia, boa tarde, boa noite"


PHP Code:
stock GetSaudacao()
{
    new 
HorMinSegstring[15];
    
gettime(HorMinSeg);
    switch(
Hor)
    {
        case 
0..5string "Boa madrugada";
        case 
6..11string "Bom dia";
        case 
12..18string "Boa tarde";
        case 
19..23string "Boa noite";
    }
    return 
string;

Exemplo de modo de uso:

PHP Code:
new msg[50], Nome[MAX_PLAYERS][24];
GetPlayerName(playeridNome[playerid], 24);
format(msgsizeof msg"Olб %s, %s!"Nome[playerid], GetSaudacao());
SendClientMessage(playerid, -1msg); 



:*
Curti, algo simples, e ъtil, algo que nгo tinha pensado , vou usar, vlw.
Reply

Score mais alto online.
pawn Code:
m@Level() {
    static
        i, r, id, str[100], name[25];
    for(i = GetMaxPlayers() - 1; i > -1; --i) {
        if (IsPlayerConnected(i)) {
            if (((r-GetPlayerScore(i)) & 0x80000000)) {
                id = i, r = GetPlayerScore(i);
            }
        }
    }
    format(str, sizeof str, "Maior level й do jogador %s (Level %i)", (GetPlayerName(id, name, 25),name),r);
    SendClientMessageToAll(-1, str);
    return 0x1;
}

//exemplo
CMD:level(playerid) return m@Level();
Reply

Quebra de linha no chat.
PHP Code:
public OnPlayerText(playeridtext[])
{
    if (
text[100] != EOS)
    {
        new
            
buff[103],
            
str[150];
                
            
format(strsizeof strtext);
            
            
format(buffsizeof buff#...%s, (strdel(str, 0, 72), str));
            
            
SendPlayerMessageToAll(playerid, (strdel(text72strlen(text)),text));
            
            
SendClientMessageToAll(-1buff);
            
        return 
0;
    }
    return 
1;

Reply

Anti-Cleo Prу-Killer da AK-47 ( /kill ID )

PHP Code:
new ArmaJJBala;
public 
OnPlayerWeaponShotplayeridweaponidhittypehitidFloat:fXFloat:fYFloat:fZ ) {
    
GetPlayerWeaponData(playerid5ArmaJJBala);
    if ( 
ArmaJJ == 30 ) {
        if(
Bala 4000){
            
SendClientMessage(playerid, -1"Proibido usar esse cleo neste servidor");
            
Kick(playerid);
        }
    }
    return 
true;

Reply

Quote:
Originally Posted by JonathanFeitosa
Посмотреть сообщение
Anti-Cleo Prу-Killer da AK-47 ( /kill ID )

PHP код:
new ArmaJJBala;
public 
OnPlayerWeaponShotplayeridweaponidhittypehitidFloat:fXFloat:fYFloat:fZ ) {
    
GetPlayerWeaponData(playerid5ArmaJJBala);
    if ( 
ArmaJJ == 30 ) {
        if(
Bala 4000){
            
SendClientMessage(playerid, -1"Proibido usar esse cleo neste servidor");
            
Kick(playerid);
        }
    }
    return 
true;

Se eu usar: GivePlayerWeapon(playerid, 30, 4001); // Ou maior que 4001
Vai me dar falsos positivos seu cуdigo nгo й nenhum pouco funcional
Reply

Quote:
Originally Posted by Day_
Посмотреть сообщение
Se eu usar: GivePlayerWeapon(playerid, 30, 4001); // Ou maior que 4001
Vai me dar falsos positivos seu cуdigo nгo й nenhum pouco funcional
Entгo nгo dк uma Ak maior que 4000 balas. Caso contrбrio faзa pelo modo mais difнcil, detecte a velocidade dos tiros. Esse sim daria muitos "falsos positivos".
Reply

Limite mнnimo e mбximo:

PHP код:
// Uso:
// mincap(valor, limite)
// maxcap(valor, limite)
#define mincap(%0,%1) ((%0 < %1) ? %1 : %0))
#define maxcap(%0,%1) ((%0 > %1) ? %1 : %0)) 
Exemplo:
PHP код:
new add random(100);
new 
10;
maxcap((add), 15); // Se (x + add) passar de 15, a variбvel terб valor 15. Caso contrбrio, terб o valor retornado pela soma. 
A ideia surgiu neste tуpico.
Reply

PHP код:
GetVehicleFreeSeat(carro)
{
    new 
MaxSeats[212] = {
        
4222441224222422424244222144421912212942
        
4122241216121112224422222244224211221224
        
2143111422424122244222222224211211224221
        
1222222224111222200142222244224421222222
        
4422124410011212222442411422226122214442
        
222242111411
    
};
    new 
bool:Seat[9];
    foreach(
Playeri)
    {
        if(
IsPlayerConnected(i))
        {
            if(
IsPlayerInVehicle(icarro))
            {
                
Loop:s(0MaxSeats[carro 400])
                {
                    if(
GetPlayerVehicleSeat(i) == sSeat[s] = true;
                }
            }
        }
    }
    
Loop:s(0MaxSeats[carro 400])
    {
        if(
Seat[s] == false) return s;
    }
    return -
1;

Funзгo se auto explica..
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)