Useful Snippets

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;
}
Reply

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!
Reply

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

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;
}
Reply

<Removed>
Reply

Quote:
Originally Posted by Finn
View Post
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.
Reply

Quote:
Originally Posted by YouareX
View Post
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.
Reply

Quote:
Originally Posted by Finn
View Post
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.
Reply

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);
Reply

Quote:
Originally Posted by kacper55331
View Post
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.
Reply

/deleted\
Reply

Sorry guys i failed i posted hat through my phone and thin, how hard it is to write a code in a cellphone, sorry.
Reply

Quote:
Originally Posted by ******
View Post
It's even harder to compile and test it - implying you didn't!
Sorry for the 2'nd time.
Reply

Quote:
Originally Posted by [HLF]Southclaw
View Post
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;

}
Reply

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

It will be something like this :
pawn Код:
public OnPlayerUpdate(playerid)
{
    if(GetPlayerWeaponState(playerid) == 3)
    {
        SetPlayerChatBubble(playerid, "RELOADING", 0x660000AA, 150.0, 2500);
    }
    return 1;
}
Reply

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

Show player damage (hit counter as you shoot them) in chat bubble above victim

Top of script:

Код:
new string[16];
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.
Reply

@kaisersouse string can be easly a local variable....
Reply

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


Forum Jump:


Users browsing this thread: 2 Guest(s)