Useful Functions

Erm, i've tried to type • in chat at a few servers, including my own, and nothing happened.. Nothing crashed or whatever :P. You just see 'Robin: ', and not 'Robin: •'

erm? :P
Reply

Robin,only Work in Windows XP.

Hugs.
Reply

@[FeK]DraKiNs:
I guess it will be better if you just add an amount to the vehicleid. Then vehicles never have odds to have the same numberplate (how they also are) and it's better instead random numbers I guess.
pawn Код:
stock CreateRandomNumberPlate(vehicleid)
{
    new
        string[8]
    ;
    format(string, sizeof(string), "NUM-%d", (vehicleid + 1000));
    SetVehicleNumberPlate(vehicleid, string);
    SetVehicleToRespawn(vehicleid);
    return vehicleid;
}
Reply

pawn Код:
IsPlayerStopped(playerid)
{
    if(GetPlayerAnimationIndex(playerid) == 1189) return true;
    return false;
}
Reply

@RyDeR

Oh Ye,Good Idea,but is Plate RAMDOM:

But here:

Plate Cars

pawn Код:
stock CreateVehicleNumberPlate(vehicleid)
{
    static
        sPlate[22];
    format(sPlate,22,"Plate: %d",(1000 + vehicleid));
    SetVehicleNumberPlate(vehicleid,sPlate);
    return SetVehicleToRespawn(vehicleid)
}
Thanks


@Cynic
What this code do?
Reply

Checks if the player is doing nothing.
Reply

@Cynic

Ok,Thanks

#Topic:

Give Value To PVARs
pawn Код:
stock
    GivePVarInt(playerid, var[], val)                                           //- PVars++
        return SetPVarInt(playerid,var,GetPVarInt(playerid, var)+val);
Crash Player in 0.3b
pawn Код:
stock
    CrashPlayer(playerid)                                                       //- Crash the Player (0.3b)
        SetPlayerHoldingObject(playerid, 0, 0);
Get ID Player From Part Name

pawn Код:
stock
    GetIDFromName(part[])                                                       //Geta id from part of nome
{
    static
        namep[24]
    ;
    for(new id; id < MAX_PLAYERS; id++)
    {
        GetPlayerName(i,namep,24);
        if(!strfind(namep,part, true))      return id;
    }
    return -1;
}
Functions from Matrix Uselful [FeK]
Reply

Use macros for your first 2 functions (I already made the first one though, not sure if I posted it in the topic or not).
Reply

@[03]Garsino
Ya,is + best using macros,but i like stocks,sorry.

Hugs

pawn Код:
//**** Change here for version of servers
#define ServerVersion 1 // 0 = 0.3a | 1 = 0.3b | 2 = 0.3c

//  here the includes
#if ServerVersion ==  0
#include "../Includes0.3a/a_samp.inc" // others includes 0.3a \/
#endif

#if ServerVersion ==  1
#include "../Includes0.3b/a_samp.inc"  // others includes 0.3b \/
#endif

#if ServerVersion ==  2
#include "../Includes0.3c/a_samp.inc"  // others includes 0.3a \/
#endif
Reply

GetBiggestArrayNumber
pawn Код:
stock GetBiggestArrayNumber(array[], len = sizeof(array))
{
    new
        biggest = cellmin
    ;
    for(new i ; i != len; ++i)
    {
        if(array[i] > biggest)
        {
            biggest = array[i];
        }
    }
    return biggest;
}
GetSmallestArrayNumber
pawn Код:
stock GetSmallestArrayNumber(array[], len = sizeof(array))
{
    new
        smallest = cellmax
    ;
    for(new i ; i != len; ++i)
    {
        if(array[i] < smallest)
        {
            smallest = array[i];
        }
    }
    return smallest;
}
Reply

Loop String

pawn Код:
#define sLoop(%0,%1) for(new %1; %0[%1]; ++%1)
Use:
pawn Код:
sLoop(string,i)
{
     printf("Char %s",string[i]);
}
Loop String

Simple loop for string (best for not use strlen)
Reply

GetNumArgs
pawn Код:
stock GetNumArgs(var[], ...)
{
    for(new i = 1; i != numargs(); ++i)
    {
        var[(i - 1)] = getarg(i);
    }
    return 1;
}
Example
pawn Код:
new
    var[4]
;
GetNumArgs(var, 1, 5, 9, 4);
printf("Numbers stored in array var are: %d %d %d %d", var[0], var[1], var[2], var[3]);
Will give us:
Код:
Numbers stored in array var are 1 5 9 4
GetStringArgs
pawn Код:
stock GetStringArgs(string[][], ...)
{
    for(new i = 1; i != numargs(); ++i)
    {
        for(new x; getarg(i, x) != 0; ++x)
        {
            string[(i - 1)][x] = getarg(i, x);
        }
    }
    return 1;
}
Example
pawn Код:
new
    string[4][16]
;
GetStringArgs(string, "My", "Nick", "Is", "RyDeR`");
printf("Strings stored in 2D array string are: %s %s %s %s", string[0], string[1], string[2], string[3]);
Will give us:
Код:
Strings stored in 2D array string are: My Nick Is RyDeR`
Notice: These functions are just to give you more information about the usage of args.
Reply

GetBiggestArrayNumber and GetSmallestArrayNumber not true.
Reply

As far as I tested they both do work perfect.
Reply

Quote:
Originally Posted by [FeK]DraKiNs
Посмотреть сообщение
Loop String

pawn Код:
#define sLoop(%0,%1) for(new %1; %0[%1]; ++%1)
Use:
pawn Код:
sLoop(string,i)
{
     printf("Char %s",string[i]);
}
Loop String

Simple loop for string (best for not use strlen)
Using a for-loop with strlen is a lot faster actually.
Reply

@Slice:
It's not. The way DraKiNs uses is a lot faster.

EDIT: Just did a speedtest and realised that strlen is almost 3 times slower. This way:
pawn Код:
for(new i; i != strlen(string); ++i)

EDIT2: You're right if we assign the return (of strlen) to a variable first, and I also think this was what you meant.
pawn Код:
for(new i, j = strlen(string); i != j; ++i)
Reply

I'm assuming you're talking about checking the value returned by strlen( ) each increment. Try this code compared to his:
pawn Код:
for( new i = 0, j = strlen( string ); i < j; i++ )
Reply

Huh, indeed; that's a little bit faster. Didn't know that.
Reply

@Ryder

Yes,Is right, this form is like a foreach to string.

Of course nothing very optimized.

Equals:

pawn Код:
while (i <10) if (string [i]! = EOS)
And I still used '++i' which further optimizes the code.

@Grim:
The method is good, but use ++array and not array++ for optimizes a little more

Thanks
Reply

RyDeR`, no, no true...
new arr[10] = {-10,-20,-100,-100,-500,-7,-1,-5,-8}; ...
true version:
Код:
stock GetBiggestArrayNumber(array[], len = sizeof(array))
{
    new biggest=-2147483647;
    for(new i=0; i != len; ++i)
		if(array[i] > biggest)
            biggest = array[i];
    return biggest;
}
stock GetSmallestArrayNumber(array[], len = sizeof(array))
{
    new smallest=2147483647;
    for(new i; i != len; ++i)
        if(array[i] < smallest)
            smallest = array[i];
    return smallest;
}
Reply


Forum Jump:


Users browsing this thread: 10 Guest(s)