Re: Useful Snippets -
Slice - 10.08.2012
http://spelsajten.net/bitarray/
Fill in IDs, generate, and there you go:
pawn Код:
stock IsValidAirVehicle(value) {
static const valid_values[6] = {
1073742081, 135268352, -1073676096, 192, 262408, 98305
};
if (417 <= value <= 593) {
value -= 417;
return (valid_values[value >>> 5] & (1 << (value & 31))) || false;
}
return false;
}
Re: Useful Snippets -
FireCat - 10.08.2012
Quote:
Originally Posted by Slice
http://spelsajten.net/bitarray/
Fill in IDs, generate, and there you go:
pawn Код:
stock IsValidAirVehicle(value) { static const valid_values[6] = { 1073742081, 135268352, -1073676096, 192, 262408, 98305 };
if (417 <= value <= 593) { value -= 417;
return (valid_values[value >>> 5] & (1 << (value & 31))) || false; }
return false; }
|
Awesome!
Re: Useful Snippets -
kurta999 - 10.08.2012
The generator is very nice!
Anyway can you give some info how it works? (How generate and how you read this information)
I tried to do it myself without generator, but I don't know read the values without cycle.
AW: Re: Useful Snippets -
Nero_3D - 10.08.2012
Quote:
Originally Posted by kurta999
The generator is very nice!
Anyway can you give some info how it works? (How generate and how you read this information)
I tried to do it myself without generator, but I don't know read the values without cycle.
|
First it sorts the values and gets the lowest and highest values
Than it creates a list of bits from the lowest till the highest value (cells = ((max - min) / 32))
At last it sets the bits at the correct positions (value1 - min; value2 - min; ...)
pawn Код:
stock func(value) {
static const valid_values[] = {
// values
};
if (min <= value <= max) {
value -= min;
// it gets the correct cell with "valid_values[value >>> 5]" or "valid_values[value / 32]"
// with "value & 31" it extracts the position, similar to "value % 32"
// 1 << position, is just 2 ^ position (Exponentiation)
// the & just checks now if the bit is set in the cell
return (valid_values[value >>> 5] & (1 << (value & 31))) || false;
}
return false;
}
Re: Useful Snippets -
Akira297 - 21.08.2012
<Removed>
Re: Useful Snippets -
Youarex - 21.08.2012
Quote:
Originally Posted by Finn
Why don't you just use foreach?
|
You can use foreach. I do use foreach myself, but perhaps someone might find useful to keep track of joins.
Re: Useful Snippets -
Finn - 21.08.2012
Quote:
Originally Posted by YouareX
You can use foreach. I do use foreach myself, but perhaps someone might find useful to keep track of joins.
|
That's what foreach does too.
Re: Useful Snippets -
Youarex - 21.08.2012
Quote:
Originally Posted by Finn
That's what foreach does too.
|
Are you sure about that? To my knowledge, it doesn't. However, I haven't looked foreach code in depth.
Re: Useful Snippets -
kacper55331 - 21.08.2012
pawn Code:
#define formatex(%1,%2,%3,%4) new %1[%2];format(%1, %2, %3, %4)
Usage:
pawn Code:
formatex(string, 20, "My awasome ID: %d", playerid);
SendClientMessage(playerid, 0, string);
Re: Useful Snippets -
TheArcher - 21.08.2012
Quote:
Originally Posted by kacper55331
pawn Code:
#define formatex(%1,%2,%3,%4) new %1[%2];format(%1, %2, %3, %4)
Usage:
pawn Code:
formatex(string, 20, "My awasome ID: %d", playerid); SendClientMessage(playerid, 0, string);
|
I guess
this is a better way.
Re: Useful Snippets - Glint - 22.08.2012
/deleted\
Re: Useful Snippets - Glint - 22.08.2012
Sorry guys i failed i posted hat through my phone and thin, how hard it is to write a code in a cellphone, sorry.
Re: Useful Snippets - Glint - 22.08.2012
Quote:
Originally Posted by ******
It's even harder to compile and test it - implying you didn't!
|
Sorry for the 2'nd time.
Re: Useful Snippets -
Lorenc_ - 04.09.2012
Quote:
Originally Posted by [HLF]Southclaw
Something like this?
I'm sure I've posted this command about 3 times to different people in the past week...
...
|
You can also use the ternary operator:
pawn Code:
CMD:bugreport(playerid, params[])
{
if(IsNull(params))
{
SendClientMessage(playerid, -1, "USAGE: /bugreport [bug information]");
return 1;
}
new
File:Bugs;
Bugs = fopen( "bugs.txt", ( fexist("bugs.txt") ? io_append : io_write ) );
fwrite(Bugs, params);
fclose(Bugs);
SendClientMessage(playerid, -1, "Your bug has been submitted successfully! Thank you for your feedback.");
return 1;
}
Re: Useful Snippets -
Slice - 17.09.2012
First off, that won't work because "rstring" isn't an array. Secondly, you don't need to use format because, well, you're not doing any formatting.
Re: Useful Snippets - Glint - 17.09.2012
It will be something like this :
pawn Код:
public OnPlayerUpdate(playerid)
{
if(GetPlayerWeaponState(playerid) == 3)
{
SetPlayerChatBubble(playerid, "RELOADING", 0x660000AA, 150.0, 2500);
}
return 1;
}
Re: Useful Snippets - Glint - 17.09.2012
Quote:
Originally Posted by AtItsMax
No shit?
|
Didn't notice that sorry i need to be more careful the next time thanks for the heads-up.
Re: Useful Snippets -
kaisersouse - 17.09.2012
Show player damage (hit counter as you shoot them) in chat bubble above victim
Top of script:
Then:
Код:
public OnPlayerTakeDamage(playerid, issuerid, Float: amount, weaponid)
{
format(string,sizeof(string),"-%.0f hp",amount);
SetPlayerChatBubble(playerid,string,0x660000AA,150.0,2500);
return 1;
}
This will display how much health/armor the player lost when hit in a chat bubble above the player's head (for 2.5 seconds).
Note: this is a good way to spot cheaters, because I've noticed people using health/armor hacks do NOT call OnPlayerTakeDamage...so if you shoot a player and never see the chat bubble, they are likely cheating. Food for thought.
Re: Useful Snippets -
TheArcher - 17.09.2012
@kaisersouse string can be easly a local variable....
Re: Useful Snippets -
jameskmonger - 17.09.2012
Quote:
Originally Posted by TheArcher
@kaisersouse string can be easly a local variable....
|
This is probably the best way, considering that most people use "string" for a general string name.