stock IsPlayerInWater(playerid) { new index = GetPlayerAnimationIndex(playerid); return ((index >= 1538 && index <= 1541) || index == 1544); }
[ARG] Funzioni e Comandi Utili
#262
Inviato il 03 settembre 2010 - 02:12
Converte i ticks (millisecondi) in giorni, ore, minuti, secondi e millisecondi. Utili per le gare, anche se sicuramente giorni e ore non serviranno praticamente mai, ma basterà modificare il format dentro TicksConvert a vostro piacimento tenendo soltanto minuti secondi e millisecondi se volete.
stock TicksConvert(ticks) { new d, h, m, s, ms; d = ticks/86400000; h = ticks/3600000 - d*24; m = ticks/60000 - (ticks/3600000)*60; s = ticks/1000 - (ticks/60000)*60; ms = ticks - (ticks/1000)*1000; new str[128]; format(str, 128, "%d giorni, %d ore, %d minuti, %d secondi, %d millisecondi", d, h, m, s, ms); return str; }
Un format adatto per le race sarebbe per esempio:
format(str, 128, "%d:%d:%d", m, s, ms);
Tutto testato e funzionante.
edit: Versione aggiornata qui -> http://forum.gta-exp...post__p__446818
#263
Inviato il 03 settembre 2010 - 09:07
Quote
Grx a Peppe ho creato il IsPlayerInWater(playerid)
stock IsPlayerInWater(playerid) { new index = GetPlayerAnimationIndex(playerid); return ((index >= 1538 && index <= 1541) || index == 1544); }
Di sicuro sarò io che non capisco molto i return ma sei sicuro che funzioni? Io l'avrei fatto così:
stock IsPlayerInWater(playerid) { new index = GetPlayerAnimationIndex(playerid); if((index >= 1538 && index <= 1541) || (index == 1544)) return 1; else return 0; }
Messaggio modificato da peppinux aka Peppe_Stasu il 03 settembre 2010 - 11:07
#264
Inviato il 03 settembre 2010 - 09:50
Quote
Grx a Peppe ho creato il IsPlayerInWater(playerid)
stock IsPlayerInWater(playerid) { new index = GetPlayerAnimationIndex(playerid); return ((index >= 1538 && index <= 1541) || index == 1544); }
In pratica l'ho creato io, tu hai preso soltanto gli index delle animazioni D:
Comunque Peppinux è la stessa cosa, anzi, così come ho fatto io è anche più corto e un pò più veloce..
#266
Inviato il 03 settembre 2010 - 10:56
Peppe951, il 03 settembre 2010 - 10:50 ha detto:
Quote
Grx a Peppe ho creato il IsPlayerInWater(playerid)
stock IsPlayerInWater(playerid) { new index = GetPlayerAnimationIndex(playerid); return ((index >= 1538 && index <= 1541) || index == 1544); }
In pratica l'ho creato io, tu hai preso soltanto gli index delle animazioni D:
Comunque Peppinux è la stessa cosa, anzi, così come ho fatto io è anche più corto e un pò più veloce..
Vabbe il codice l'avevo fatto io tu l'hai soltanto accorciato xD il mio era
stock IsPlayerInWater(playerid) { new index = GetPlayerAnimationIndex(playerid); if(index == 1538||index == 1539||index == 1540||index == 1541|| index == 1544) return 1; else return 0; }
Cmq grx a te ora so a cosa serve GetPlayerAnimationIndex

[/CODE]
#269
Inviato il 04 settembre 2010 - 19:46
stock IsPlayerInAir(playerid) { new index = GetPlayerAnimationIndex(playerid); if(index ==1130 || index == 1132 && !IsPlayerInAnyVehicle(playerid)) }
Determina se un player sta cadendo
stock IsPlayerShooting(playerid) { new index = GetPlayerAnimationIndex(playerid); return(index == 1167 || index == 363); }
Determina se un player sta sparando
stock IsPlayerLaunching(playerid) { return(GetPlayerAnimationIndex(playerid) == 645); }
Determina se un player sta lanciando qualche arma(granate ecc)
stock IsPlayerOpeningPara(playerid) { return(GetPlayerAnimationIndex(playerid) == 971); }
Determina se un player sta aprendo il paracadute
stock IsPlayerUsingSpecialGlasses(playerid) { return(GetPlayerAnimationIndex(playerid) == 638); }
Determina se un player indossa gli occhiali Infrarossi o Visione notturna
P.S. non testati
#272
Inviato il 05 settembre 2010 - 16:18
public OnPlayerUpdate(playerid) { if(GetPlayerAnimationIndex(playerid)) { new msg[128]; new animlib[32]; new animname[32]; GetAnimationName(GetPlayerAnimationIndex(playerid),animlib,32,animname,32); format(msg, 128, "Running anim:%s %s ID:%d", animlib,animname,GetPlayerAnimationIndex(playerid)); SendClientMessage(playerid, 0xFFFFFFFF, msg); } return 1; }
Preso da wiki e modificato
#274
Inviato il 13 settembre 2010 - 19:03
Nel pawn ogni cella è costituita di default da 32 bit, ovvero delle cifre che possono assumere il valore di 1 o 0.
Utilizzando gli operatori bitwise sono riuscito a creare delle funzioni che modificano il valore del bit di una cella di una variabile o agiscono su questi.
In poche parole utilizzando una sola variabile con queste funzioni potete inserire fino a 32 valori che possono essere true o false (booleani).
#define bit(%1) (1 << %1) #define setBit(%1,%2) %1 |= bit(%2) #define unsetBit(%1,%2) %1 ^= bit(%2) #define getBit(%1,%2) ((%1 & bit(%2)) != 0) #define setAllBits(%1) %1 = 2147483647 #define unsetAllBits(%1) %1 = 0 stock encodeBits({bool}:...) { new result = getarg(0), num = numargs(), arg; while(++arg < num) { if(getarg(arg)) { setBit(result, arg); } } return result; }
La macro "bit" è utilizzata privatamente nelle altre funzioni, quindi non vi serve.
Ecco a cosa servono le altre funzioni:
setBit(var, slot)
Setta il valore di un bit della variabile a true.
La variabile var è la variabile in cui memorizzare i bit mentre slot è il numero del bit, che va da 0 a 31.
unsetBit(var, slot)
Setta il valore di un bit della variabile a false.
La variabile var è la variabile in cui memorizzare i bit mentre slot è il numero del bit, che va da 0 a 31.
getBit(var, slot)
Returna true o false a seconda di ciò che è stato settato nella variabile di bit.
setAllBits(var)
Setta il valore di tutti i bit della variabile var a true.
unsetAllBits(var)
Setta il valore di tutti i bit della variabile var a false.
Esempi:
enum { Connected, Logged, Spawned, Dead } new pBools[MAX_PLAYERS]; OnPlayerDeath(playerid, killerid, reason) { unsetBit(pBools[playerid], Spawned); setBit(pBools[playerid], Dead); return 1; } OnPlayerRequestSpawn(playerid) { if(!getBit(pBools[playerid], Logged)) return 0; return 1; } OnPlayerSpawn(playerid) { if(getBit(pBools[playerid], Dead)) { SendClientMessage(playerid, COLOR_WHITE, "Eri morto"); unsetBit(pBools[playerid], Dead); } setBit(pBools[playerid], Spawned); return 1; } OnPlayerConnect(playerid) { setBit(pBools[playerid], Connected); return 1; } OnPlayerDisconnect(playerid, reason) { unsetAllBits(pBools[playerid]); return 1; } // Cosi abbiamo memorizzato quattro valori booleani in un unica variabile, risparmiando memoria
encodeBits({Bool:}...)
Returna un set di bit secondo i valori dati tra le parentesi (infiniti), che possono essere true o false. Questa funzione ad esempio può essere utilizzata al posto di quelle dell'UpdateVehicleDamageStatus, come encode_tires, encode_panels o altre, ed è anche "universale", ovvero non dovete usare più funzioni.
Esempio:
new panels, doors, lights, tires; GetVehicleDamageStatus(vehicleid, panels, doors, lights, tires); UpdateVehicleDamageStatus(vehicleid, panels, doors, lights, encodeBits(true, true, false, true));
Messaggio modificato da Peppe951 il 14 settembre 2010 - 07:33
#276
Inviato il 16 settembre 2010 - 19:16
(%1) vicino ai define?
Address: 95.110.228.30:7777
Players: 38 / 50
Ping: 40
Mode: RolePlay v 0.4
Map: San Andreas
Siamo in cerca di CF
#277
Inviato il 18 settembre 2010 - 13:25
Quote
complicvato devo dire, quindi mi complimento con te se funziona, ma, mi potete spiegare cosa servirebbero
(%1) vicino ai define?
Esempio
#define MandaMsg(%1, %2, %3) SendClientMessage(%1, %2, %3);
In questo caso "MandaMsg" Avrà la stessa funzione di SendClientMessage e %1 corrisponde al playerid, %2 al colore e %3 al testo
MandaMsg(playerid, COLOR_RED, "TESTO");
#278
Inviato il 18 settembre 2010 - 14:09
Angelo_95, il 18 settembre 2010 - 14:25 ha detto:
Quote
complicvato devo dire, quindi mi complimento con te se funziona, ma, mi potete spiegare cosa servirebbero
(%1) vicino ai define?
Esempio
#define MandaMsg(%1, %2, %3) SendClientMessage(%1, %2, %3);
In questo caso "MandaMsg" Avrà la stessa funzione di SendClientMessage e %1 corrisponde al playerid, %2 al colore e %3 al testo
MandaMsg(playerid, COLOR_RED, "TESTO");
Ma in questo caso basterebbe fare
#define MandaMsg SendClientMessage
oppure se proprio vuoi fare così devi fare
#define MandaMsg(%1,%2,%3) SendClientMessage(%1,%2,%3)
altrimenti se fai
MandaMsg(playerid,color,string);
non te lo riconosce.
#280
Inviato il 21 settembre 2010 - 12:30
Address: 95.110.228.30:7777
Players: 38 / 50
Ping: 40
Mode: RolePlay v 0.4
Map: San Andreas
Siamo in cerca di CF