Useful Functions

Check if it's a even number
pawn Код:
#define IsEven(%1) ((%1 % 2 == 0)?(true):(false))
I think it's like that
Credits: Drakins
Reply

Quote:
Originally Posted by ******
View Post
There's a much better one in the code optimisations topic.
Yes, I know. Nero_3D made that already clear:
Quote:
Originally Posted by Nero_3D
View Post
@Ryder

Just use strcat for plain strings

pawn Code:
#define strcpy(%0,%1,%2) strcat((%0[0] = '\0', %0), %1, %2)
memcpy is more useful for non-strings (in my opinion ^^")
Reply

Quote:
Originally Posted by ******
View Post
OK, well why did you link to that post in very recent topic if you know there are better ones?
That was just an example. I did mention that 'strcat' was a possibility though.
Reply

pawn Код:
#define RandomEx(%1,%2) (random(%2-%1)+%1)
Chooses a random number between the first and the second parameter.
Reply

My second macro
pawn Код:
#define GetDoubleNumber(%0) ((0%)x(2))
Reply

Quote:
Originally Posted by FireCat
Посмотреть сообщение
My second macro
pawn Код:
#define GetDoubleNumber(%0) ((0%)x(2))
Nice try. I actually laughed on this one for no reason...
It's a very silly function (which Southclaw already pointed out) but if you want a correct one, here it is:
pawn Код:
#define GetDoubleNumber(%0) \
    ((%0) << 1)
Reply

Quote:
Originally Posted by RyDeR`
Посмотреть сообщение
Nice try. I actually laughed on this one for no reason...
It's a very silly function (which Southclaw already pointed out) but if you want a correct one, here it is:
pawn Код:
#define GetDoubleNumber(%0) \
    ((%0) << 1)
I never got what "<<" "<<<" do...
Reply

Quote:
Originally Posted by RyDeR`
Посмотреть сообщение
Nice try. I actually laughed on this one for no reason...
It's a very silly function (which Southclaw already pointed out) but if you want a correct one, here it is:
pawn Код:
#define GetDoubleNumber(%0) \
    ((%0) << 1)
I was just trying to be smart
Reply

This is a beautiful tutorial for this to learn:

https://sampforum.blast.hk/showthread.php?tid=177523
Reply

GetVehicleSize - Gets the size of a vehicle obviously.
pawn Код:
stock GetVehicleSize(modelID, &Float: size_X, &Float: size_Y, &Float: size_Z) // Author: RyDeR`
{
    static const
        Float: sizeData[212][3] =
        {
            { 2.32, 5.11, 1.63 }, { 2.56, 5.82, 1.71 }, { 2.41, 5.80, 1.52 }, { 3.15, 9.22, 4.17 },
            { 2.20, 5.80, 1.84 }, { 2.34, 6.00, 1.49 }, { 5.26, 11.59, 4.42 }, { 2.84, 8.96, 2.70 },
            { 3.11, 10.68, 3.91 }, { 2.36, 8.18, 1.52 }, { 2.25, 5.01, 1.79 }, { 2.39, 5.78, 1.37 },
            { 2.45, 7.30, 1.38 }, { 2.27, 5.88, 2.23 }, { 2.51, 7.07, 4.59 }, { 2.31, 5.51, 1.13 },
            { 2.73, 8.01, 3.40 }, { 5.44, 23.27, 6.61 }, { 2.56, 5.67, 2.14 }, { 2.40, 6.21, 1.40 },
            { 2.41, 5.90, 1.76 }, { 2.25, 6.38, 1.37 }, { 2.26, 5.38, 1.54 }, { 2.31, 4.84, 4.90 },
            { 2.46, 3.85, 1.77 }, { 5.15, 18.62, 5.19 }, { 2.41, 5.90, 1.76 }, { 2.64, 8.19, 3.23 },
            { 2.73, 6.28, 3.48 }, { 2.21, 5.17, 1.27 }, { 4.76, 16.89, 5.92 }, { 3.00, 12.21, 4.42 },
            { 4.30, 9.17, 3.88 }, { 3.40, 10.00, 4.86 }, { 2.28, 4.57, 1.72 }, { 3.16, 13.52, 4.76 },
            { 2.27, 5.51, 1.72 }, { 3.03, 11.76, 4.01 }, { 2.41, 5.82, 1.72 }, { 2.22, 5.28, 1.47 },
            { 2.30, 5.55, 2.75 }, { 0.87, 1.40, 1.01 }, { 2.60, 6.67, 1.75 }, { 4.15, 20.04, 4.42 },
            { 3.66, 6.01, 3.28 }, { 2.29, 5.86, 1.75 }, { 4.76, 17.02, 4.30 }, { 2.42, 14.80, 3.15 },
            { 0.70, 2.19, 1.62 }, { 3.02, 9.02, 4.98 }, { 3.06, 13.51, 3.72 }, { 2.31, 5.46, 1.22 },
            { 3.60, 14.56, 3.28 }, { 5.13, 13.77, 9.28 }, { 6.61, 19.04, 13.84 }, { 3.31, 9.69, 3.63 },
            { 3.23, 9.52, 4.98 }, { 1.83, 2.60, 2.72 }, { 2.41, 6.13, 1.47 }, { 2.29, 5.71, 2.23 },
            { 10.85, 13.55, 4.44 }, { 0.69, 2.46, 1.67 }, { 0.70, 2.19, 1.62 }, { 0.69, 2.42, 1.34 },
            { 1.58, 1.54, 1.14 }, { 0.87, 1.40, 1.01 }, { 2.52, 6.17, 1.64 }, { 2.52, 6.36, 1.66 },
            { 0.70, 2.23, 1.41 }, { 2.42, 14.80, 3.15 }, { 2.66, 5.48, 2.09 }, { 1.41, 2.00, 1.71 },
            { 2.67, 9.34, 4.86 }, { 2.90, 5.40, 2.22 }, { 2.43, 6.03, 1.69 }, { 2.45, 5.78, 1.48 },
            { 11.02, 11.28, 3.28 }, { 2.67, 5.92, 1.39 }, { 2.45, 5.57, 1.74 }, { 2.25, 6.15, 1.99 },
            { 2.26, 5.26, 1.41 }, { 0.70, 1.87, 1.32 }, { 2.33, 5.69, 1.87 }, { 2.04, 6.19, 2.10 },
            { 5.34, 26.20, 7.15 }, { 1.97, 4.07, 1.44 }, { 4.34, 7.84, 4.44 }, { 2.32, 15.03, 4.67 },
            { 2.32, 12.60, 4.65 }, { 2.53, 5.69, 2.14 }, { 2.92, 6.92, 2.14 }, { 2.30, 6.32, 1.28 },
            { 2.34, 6.17, 1.78 }, { 4.76, 17.82, 3.84 }, { 2.25, 6.48, 1.50 }, { 2.77, 5.44, 1.99 },
            { 2.27, 4.75, 1.78 }, { 2.32, 15.03, 4.65 }, { 2.90, 6.59, 4.28 }, { 2.64, 7.19, 3.75 },
            { 2.28, 5.01, 1.85 }, { 0.87, 1.40, 1.01 }, { 2.34, 5.96, 1.51 }, { 2.21, 6.13, 1.62 },
            { 2.52, 6.03, 1.64 }, { 2.53, 5.69, 2.14 }, { 2.25, 5.21, 1.16 }, { 2.56, 6.59, 1.62 },
            { 2.96, 8.05, 3.33 }, { 0.70, 1.89, 1.32 }, { 0.72, 1.74, 1.12 }, { 21.21, 21.19, 5.05 },
            { 11.15, 6.15, 2.99 }, { 8.69, 9.00, 2.23 }, { 3.19, 10.06, 3.05 }, { 3.54, 9.94, 3.42 },
            { 2.59, 6.23, 1.71 }, { 2.52, 6.32, 1.64 }, { 2.43, 6.00, 1.57 }, { 20.30, 19.29, 6.94 },
            { 8.75, 14.31, 2.16 }, { 0.69, 2.46, 1.67 }, { 0.69, 2.46, 1.67 }, { 0.69, 2.47, 1.67 },
            { 3.58, 8.84, 3.64 }, { 3.04, 6.46, 3.28 }, { 2.20, 5.40, 1.25 }, { 2.43, 5.71, 1.74 },
            { 2.54, 5.55, 2.14 }, { 2.38, 5.63, 1.86 }, { 1.58, 4.23, 2.68 }, { 1.96, 3.70, 1.66 },
            { 8.61, 11.39, 4.17 }, { 2.38, 5.42, 1.49 }, { 2.18, 6.26, 1.15 }, { 2.67, 5.48, 1.58 },
            { 2.46, 6.42, 1.29 }, { 3.32, 18.43, 5.19 }, { 3.26, 16.59, 4.94 }, { 2.50, 3.86, 2.55 },
            { 2.58, 6.07, 1.50 }, { 2.26, 4.94, 1.24 }, { 2.48, 6.40, 1.70 }, { 2.38, 5.73, 1.86 },
            { 2.80, 12.85, 3.89 }, { 2.19, 4.80, 1.69 }, { 2.56, 5.86, 1.66 }, { 2.49, 5.84, 1.76 },
            { 4.17, 24.42, 4.90 }, { 2.40, 5.53, 1.42 }, { 2.53, 5.88, 1.53 }, { 2.66, 6.71, 1.76 },
            { 2.65, 6.71, 3.55 }, { 28.73, 23.48, 7.38 }, { 2.68, 6.17, 2.08 }, { 2.00, 5.13, 1.41 },
            { 3.66, 6.36, 3.28 }, { 3.66, 6.26, 3.28 }, { 2.23, 5.25, 1.75 }, { 2.27, 5.48, 1.39 },
            { 2.31, 5.40, 1.62 }, { 2.50, 5.80, 1.78 }, { 2.25, 5.30, 1.50 }, { 3.39, 18.62, 4.71 },
            { 0.87, 1.40, 1.01 }, { 2.02, 4.82, 1.50 }, { 2.50, 6.46, 1.65 }, { 2.71, 6.63, 1.58 },
            { 2.71, 4.61, 1.41 }, { 3.25, 18.43, 5.03 }, { 3.47, 21.06, 5.19 }, { 1.57, 2.32, 1.58 },
            { 1.65, 2.34, 2.01 }, { 2.93, 7.38, 3.16 }, { 1.62, 3.84, 2.50 }, { 2.49, 5.82, 1.92 },
            { 2.42, 6.36, 1.85 }, { 62.49, 61.43, 34.95 }, { 3.15, 11.78, 2.77 }, { 2.47, 6.21, 2.55 },
            { 2.66, 5.76, 2.24 }, { 0.69, 2.46, 1.67 }, { 2.44, 7.21, 3.19 }, { 1.66, 3.66, 3.21 },
            { 3.54, 15.90, 3.40 }, { 2.44, 6.53, 2.05 }, { 0.69, 2.79, 1.96 }, { 2.60, 5.76, 1.45 },
            { 3.07, 8.61, 7.53 }, { 2.25, 5.09, 2.11 }, { 3.44, 18.39, 5.03 }, { 3.18, 13.63, 4.65 },
            { 44.45, 57.56, 18.43 }, { 12.59, 13.55, 3.56 }, { 0.50, 0.92, 0.30 }, { 2.84, 13.47, 2.21 },
            { 2.41, 5.90, 1.76 }, { 2.41, 5.90, 1.76 }, { 2.41, 5.78, 1.76 }, { 2.92, 6.15, 2.14 },
            { 2.40, 6.05, 1.55 }, { 3.07, 6.96, 3.82 }, { 2.31, 5.53, 1.28 }, { 2.64, 6.07, 1.42 },
            { 2.52, 6.17, 1.64 }, { 2.38, 5.73, 1.86 }, { 2.93, 3.38, 1.97 }, { 3.01, 3.25, 1.60 },
            { 1.45, 4.65, 6.36 }, { 2.90, 6.59, 4.21 }, { 2.48, 1.42, 1.62 }, { 2.13, 3.16, 1.83 }
        }
    ;
    if(400 <= modelID <= 611)
    {
        size_X = sizeData[modelID - 400][0];
        size_Y = sizeData[modelID - 400][1];
        size_Z = sizeData[modelID - 400][2];       
        return 1;
    }
    return 0;
}
Examples:
pawn Код:
new
    Float: vehSize[3]
;
GetVehicleSize(451, vehSize[0], vehSize[1], vehSize[2]);
printf("%f %f %f", vehSize[0], vehSize[1], vehSize[2]); // Prints "2.309999 5.460000 1.220000"
Reply

Quote:
Originally Posted by Y_Less
View Post
Gotta love Kye deleting my account and thus all the topics that went with it. Anyway, some of my useful functions I've made over the years have been ported to YSI and put in the YSI_misc.own file. The file can be found:

here

Functions include:

swap(var1, var2) - Swap two variables without a third variable.
xor:==xor: - Do a logical xor check on two variables.
ceildiv - Divide two integers and round up.
isnull - Used for empty strings passed via CallRemoteFunction.
iseven - Obvious.
isodd - Obvious.
floordiv - Rounded down integer division.
chrfind - Find a single character in a string, faster than strfind for single characters.
chrnfind - Find the end of a set of characters in a string (for example to skip a set of spaces).
strcpy - Copy a string.
bernstein - Like Adler32 hash but faster and less collisions.
bernstein_copy - Mix of strcpy and bernstein for speed.
StripNL - Similar to PHP's rtrim.
strconcat - Stick two strings together.
QuickSort - Call wrapper for QSort, sorts an array into newmerical order.
QSort - Workhorse recursive function for QuickSort.
chrtolower - Convert a character to lowercase.
strtolower - Convert a string to lowercase.
hexstr - strval for hex strings.
binstr - Checks if a string is "0" or "false".
ReturnPlayerName - Obvious.
ishex - Checks if a string is hexadecimal.
numstr - Converts a number to a string, should use valstr but doesn't.
chrtoupper - Convert a character to upper case.
strtoupper - Convert a string to upper case.
timestamp - Get the unix timestamp for the current time.
mktime - Get the unix timestamp for a given time.
GetIP - Return a player's IP as a 32bit integer.
getintpar - Gets a number from a string apparently.
IsConnected - Like IsPlayerConnected but uses YSI's internal foreach system.
KickDelay - Kick a player after a given amount of time. Used to ensure they get the message sent.
KickDelayCall - public function KickDelay calls.
BanDelay - Like KickDelay but ban.
BanDelayCall - Like KickDelayCall but ban.
endofline - Checks if the current position is the end of non-whitespace data.
isnumeric - Checks if a string is numeric.
abs - Returns the absolute (positive) value of a number.
sscanf - Deserves (and has) it's own tutorial on use.
explode - Like PHP's explode function.
IsPlayerInRangeOfPoint - Checks if a player is near a point without calling floatsqroot for speed.

The library also has a couple of useful variables:

TRUE - Always true, used for infinate loops.
FALSE - Always false, used for large code macros.
NULL - The string passed instead of an empty string by CallRemoteFunction due to the way the PAWN VM works.
Is there a valid link to these anymore ?
Reply

Quote:
Originally Posted by RyDeR`
Посмотреть сообщение
GetVehicleSize - Gets the size of a vehicle obviously.
pawn Код:
stock GetVehicleSize(modelID, &Float: size_X, &Float: size_Y, &Float: size_Z) // Author: RyDeR`
{
    static const
        Float: sizeData[212][3] =
        {
            { 2.32, 5.11, 1.63 }, { 2.56, 5.82, 1.71 }, { 2.41, 5.80, 1.52 }, { 3.15, 9.22, 4.17 },
            { 2.20, 5.80, 1.84 }, { 2.34, 6.00, 1.49 }, { 5.26, 11.59, 4.42 }, { 2.84, 8.96, 2.70 },
            { 3.11, 10.68, 3.91 }, { 2.36, 8.18, 1.52 }, { 2.25, 5.01, 1.79 }, { 2.39, 5.78, 1.37 },
            { 2.45, 7.30, 1.38 }, { 2.27, 5.88, 2.23 }, { 2.51, 7.07, 4.59 }, { 2.31, 5.51, 1.13 },
            { 2.73, 8.01, 3.40 }, { 5.44, 23.27, 6.61 }, { 2.56, 5.67, 2.14 }, { 2.40, 6.21, 1.40 },
            { 2.41, 5.90, 1.76 }, { 2.25, 6.38, 1.37 }, { 2.26, 5.38, 1.54 }, { 2.31, 4.84, 4.90 },
            { 2.46, 3.85, 1.77 }, { 5.15, 18.62, 5.19 }, { 2.41, 5.90, 1.76 }, { 2.64, 8.19, 3.23 },
            { 2.73, 6.28, 3.48 }, { 2.21, 5.17, 1.27 }, { 4.76, 16.89, 5.92 }, { 3.00, 12.21, 4.42 },
            { 4.30, 9.17, 3.88 }, { 3.40, 10.00, 4.86 }, { 2.28, 4.57, 1.72 }, { 3.16, 13.52, 4.76 },
            { 2.27, 5.51, 1.72 }, { 3.03, 11.76, 4.01 }, { 2.41, 5.82, 1.72 }, { 2.22, 5.28, 1.47 },
            { 2.30, 5.55, 2.75 }, { 0.87, 1.40, 1.01 }, { 2.60, 6.67, 1.75 }, { 4.15, 20.04, 4.42 },
            { 3.66, 6.01, 3.28 }, { 2.29, 5.86, 1.75 }, { 4.76, 17.02, 4.30 }, { 2.42, 14.80, 3.15 },
            { 0.70, 2.19, 1.62 }, { 3.02, 9.02, 4.98 }, { 3.06, 13.51, 3.72 }, { 2.31, 5.46, 1.22 },
            { 3.60, 14.56, 3.28 }, { 5.13, 13.77, 9.28 }, { 6.61, 19.04, 13.84 }, { 3.31, 9.69, 3.63 },
            { 3.23, 9.52, 4.98 }, { 1.83, 2.60, 2.72 }, { 2.41, 6.13, 1.47 }, { 2.29, 5.71, 2.23 },
            { 10.85, 13.55, 4.44 }, { 0.69, 2.46, 1.67 }, { 0.70, 2.19, 1.62 }, { 0.69, 2.42, 1.34 },
            { 1.58, 1.54, 1.14 }, { 0.87, 1.40, 1.01 }, { 2.52, 6.17, 1.64 }, { 2.52, 6.36, 1.66 },
            { 0.70, 2.23, 1.41 }, { 2.42, 14.80, 3.15 }, { 2.66, 5.48, 2.09 }, { 1.41, 2.00, 1.71 },
            { 2.67, 9.34, 4.86 }, { 2.90, 5.40, 2.22 }, { 2.43, 6.03, 1.69 }, { 2.45, 5.78, 1.48 },
            { 11.02, 11.28, 3.28 }, { 2.67, 5.92, 1.39 }, { 2.45, 5.57, 1.74 }, { 2.25, 6.15, 1.99 },
            { 2.26, 5.26, 1.41 }, { 0.70, 1.87, 1.32 }, { 2.33, 5.69, 1.87 }, { 2.04, 6.19, 2.10 },
            { 5.34, 26.20, 7.15 }, { 1.97, 4.07, 1.44 }, { 4.34, 7.84, 4.44 }, { 2.32, 15.03, 4.67 },
            { 2.32, 12.60, 4.65 }, { 2.53, 5.69, 2.14 }, { 2.92, 6.92, 2.14 }, { 2.30, 6.32, 1.28 },
            { 2.34, 6.17, 1.78 }, { 4.76, 17.82, 3.84 }, { 2.25, 6.48, 1.50 }, { 2.77, 5.44, 1.99 },
            { 2.27, 4.75, 1.78 }, { 2.32, 15.03, 4.65 }, { 2.90, 6.59, 4.28 }, { 2.64, 7.19, 3.75 },
            { 2.28, 5.01, 1.85 }, { 0.87, 1.40, 1.01 }, { 2.34, 5.96, 1.51 }, { 2.21, 6.13, 1.62 },
            { 2.52, 6.03, 1.64 }, { 2.53, 5.69, 2.14 }, { 2.25, 5.21, 1.16 }, { 2.56, 6.59, 1.62 },
            { 2.96, 8.05, 3.33 }, { 0.70, 1.89, 1.32 }, { 0.72, 1.74, 1.12 }, { 21.21, 21.19, 5.05 },
            { 11.15, 6.15, 2.99 }, { 8.69, 9.00, 2.23 }, { 3.19, 10.06, 3.05 }, { 3.54, 9.94, 3.42 },
            { 2.59, 6.23, 1.71 }, { 2.52, 6.32, 1.64 }, { 2.43, 6.00, 1.57 }, { 20.30, 19.29, 6.94 },
            { 8.75, 14.31, 2.16 }, { 0.69, 2.46, 1.67 }, { 0.69, 2.46, 1.67 }, { 0.69, 2.47, 1.67 },
            { 3.58, 8.84, 3.64 }, { 3.04, 6.46, 3.28 }, { 2.20, 5.40, 1.25 }, { 2.43, 5.71, 1.74 },
            { 2.54, 5.55, 2.14 }, { 2.38, 5.63, 1.86 }, { 1.58, 4.23, 2.68 }, { 1.96, 3.70, 1.66 },
            { 8.61, 11.39, 4.17 }, { 2.38, 5.42, 1.49 }, { 2.18, 6.26, 1.15 }, { 2.67, 5.48, 1.58 },
            { 2.46, 6.42, 1.29 }, { 3.32, 18.43, 5.19 }, { 3.26, 16.59, 4.94 }, { 2.50, 3.86, 2.55 },
            { 2.58, 6.07, 1.50 }, { 2.26, 4.94, 1.24 }, { 2.48, 6.40, 1.70 }, { 2.38, 5.73, 1.86 },
            { 2.80, 12.85, 3.89 }, { 2.19, 4.80, 1.69 }, { 2.56, 5.86, 1.66 }, { 2.49, 5.84, 1.76 },
            { 4.17, 24.42, 4.90 }, { 2.40, 5.53, 1.42 }, { 2.53, 5.88, 1.53 }, { 2.66, 6.71, 1.76 },
            { 2.65, 6.71, 3.55 }, { 28.73, 23.48, 7.38 }, { 2.68, 6.17, 2.08 }, { 2.00, 5.13, 1.41 },
            { 3.66, 6.36, 3.28 }, { 3.66, 6.26, 3.28 }, { 2.23, 5.25, 1.75 }, { 2.27, 5.48, 1.39 },
            { 2.31, 5.40, 1.62 }, { 2.50, 5.80, 1.78 }, { 2.25, 5.30, 1.50 }, { 3.39, 18.62, 4.71 },
            { 0.87, 1.40, 1.01 }, { 2.02, 4.82, 1.50 }, { 2.50, 6.46, 1.65 }, { 2.71, 6.63, 1.58 },
            { 2.71, 4.61, 1.41 }, { 3.25, 18.43, 5.03 }, { 3.47, 21.06, 5.19 }, { 1.57, 2.32, 1.58 },
            { 1.65, 2.34, 2.01 }, { 2.93, 7.38, 3.16 }, { 1.62, 3.84, 2.50 }, { 2.49, 5.82, 1.92 },
            { 2.42, 6.36, 1.85 }, { 62.49, 61.43, 34.95 }, { 3.15, 11.78, 2.77 }, { 2.47, 6.21, 2.55 },
            { 2.66, 5.76, 2.24 }, { 0.69, 2.46, 1.67 }, { 2.44, 7.21, 3.19 }, { 1.66, 3.66, 3.21 },
            { 3.54, 15.90, 3.40 }, { 2.44, 6.53, 2.05 }, { 0.69, 2.79, 1.96 }, { 2.60, 5.76, 1.45 },
            { 3.07, 8.61, 7.53 }, { 2.25, 5.09, 2.11 }, { 3.44, 18.39, 5.03 }, { 3.18, 13.63, 4.65 },
            { 44.45, 57.56, 18.43 }, { 12.59, 13.55, 3.56 }, { 0.50, 0.92, 0.30 }, { 2.84, 13.47, 2.21 },
            { 2.41, 5.90, 1.76 }, { 2.41, 5.90, 1.76 }, { 2.41, 5.78, 1.76 }, { 2.92, 6.15, 2.14 },
            { 2.40, 6.05, 1.55 }, { 3.07, 6.96, 3.82 }, { 2.31, 5.53, 1.28 }, { 2.64, 6.07, 1.42 },
            { 2.52, 6.17, 1.64 }, { 2.38, 5.73, 1.86 }, { 2.93, 3.38, 1.97 }, { 3.01, 3.25, 1.60 },
            { 1.45, 4.65, 6.36 }, { 2.90, 6.59, 4.21 }, { 2.48, 1.42, 1.62 }, { 2.13, 3.16, 1.83 }
        }
    ;
    if(400 <= modelID <= 611)
    {
        size_X = sizeData[modelID - 400][0];
        size_Y = sizeData[modelID - 400][1];
        size_Z = sizeData[modelID - 400][2];       
        return 1;
    }
    return 0;
}
Examples:
pawn Код:
new
    Float: vehSize[3]
;
GetVehicleSize(451, vehSize[0], vehSize[1], vehSize[2]);
printf("%f %f %f", vehSize[0], vehSize[1], vehSize[2]); // Prints "2.309999 5.460000 1.220000"
Thanks for this function RyDeR. I don't know how the function works, but is it possible to detect rear position of this vehicle by using this code?
Reply

Quote:
Originally Posted by Skorch
Посмотреть сообщение
Thanks for this function RyDeR. I don't know how the function works, but is it possible to detect rear position of this vehicle by using this code?
try it with the half of the y_size since its the lenght of the vehicle

That goes the half of the y_size to the back of the vehicle
pawn Код:
new Float: Pos[6];
GetVehicleZAngle(vehicleid, Pos[3]);
GetVehicleSize(GetVehicleModel(vehicleid), Pos[2], Pos[4], Pos[5]);
GetVehiclePos(vehicleid, Pos[0], Pos[1], Pos[2]);
Pos[0] += (floatsin(Pos[3], degrees) * 0.5 * Pos[4]);
Pos[1] -= (floatcos(Pos[3], degrees) * 0.5 * Pos[4]);
CreateExplosion(Pos[0], Pos[1], Pos[2] + 0.5 * Pos[5], 0, 5.0);
If that doesnt work correctly try it with JernejL's list (first reply of this page)
Reply

Quote:
Originally Posted by Nero_3D
Посмотреть сообщение
try it with the half of the y_size since its the lenght of the vehicle

That goes the half of the y_size to the back of the vehicle
pawn Код:
new Float: Pos[6];
GetVehicleZAngle(vehicleid, Pos[3]);
GetVehicleSize(GetVehicleModel(vehicleid), Pos[2], Pos[4], Pos[5]);
GetVehiclePos(vehicleid, Pos[0], Pos[1], Pos[2]);
Pos[0] += (floatsin(Pos[3], degrees) * 0.5 * Pos[4]);
Pos[1] -= (floatcos(Pos[3], degrees) * 0.5 * Pos[4]);
CreateExplosion(Pos[0], Pos[1], Pos[2] + 0.5 * Pos[5], 0, 5.0);
If that doesnt work correctly try it with JernejL's list (first reply of this page)
Thank you, that code works perfectly.
Reply

This function balance the server teams distributing all players on how many teams you put in the brackets.
Just tested with variables manipulation.
pawn Код:
stock BalanceTeams(...)
{
    new PlayersIds[MAX_PLAYERS] = {-1, ...}, highid, Args = numargs(), divisor;
   
    for(new i, slot, j = GetMaxPlayers(); i < j; i++)
    {
        if(IsPlayerConnected(i) && !IsPlayerNPC(i) && GetPlayerState(i))
        {
            do
            {
                if(PlayersIds[slot] == -1)
                {
                    PlayersIds[slot] = i;
                    break;
                }
                slot++;
            }
            while(slot < sizeof PlayersIds);
            highid++;
        }
    }

    divisor = (highid / Args);
   
    if(highid <= 1 || Args <= 1) return false;

    if(Args > highid) Args = highid;
   
    for(new i = 0, Arg = 0; i < highid; i++)
    {
        if(i == (highid - 1) && (highid % Args))
        {
            SetPlayerTeamEx(PlayersIds[i], getarg(random(Args)));//Put the remaining in a random team
            return true;
        }
        SetPlayerTeamEx(PlayersIds[i], getarg(Arg));
        if((i == (((divisor * Arg) + divisor) - 1) && i) || (i == ((divisor * 1) - 1)) ) Arg++;
    }
    return true;
}
Reply

oh! Thanks.

Heres a nice function, made based off PgnPunkids (current name?) shark circling include.

pawn Код:
new Float:degree[MAX_OBJECTS] = 0.0;
forward CircleObject(objectid, Float:x, Float:y, Float:z, Float:speed, Float:radius, Float:Cdegree);
public CircleObject(objectid, Float:x, Float:y, Float:z, Float:speed, Float:radius, Float:Cdegree)
{
    new Float:X, Float:Y, Float:Px, Float:Py, Float:Temp;
    if(degree[objectid] < 360) degree[objectid] += Cdegree;
    else degree[objectid] = 0.0;
    X = (floatmul(floatcos(degree[objectid], degrees), radius));
    Temp = ((radius * radius) - floatpower(X, 2));
    Y = floatsqroot(Temp);
    if(degree[objectid] >= 180) Y *= -1;
    Px = floatadd(x, X);
    Py = floatadd(y, Y);
    MoveObject(objectid, Px, Py, z, speed);
    SetObjectRot(objectid, 0, 0, degree[objectid]);
    //printf("[System - Circling Object] - Degree: %f - X: %f - Y: %f - Px: %f - Py: %f", degree[objectid], X, Y, Px, Py);
    return 1;
}
It must be used in a timer to successfully circle a object.

To check when it's finished, check if the degree is back to 0 / 360.
Reply

Need a function, which inserts brakes (\n) automatically in a long sentence.
I think I saw one in this thread, but I've already looked in the last 50 page's
and fount nothing similar.

Edit:
Okay found it, ty.
Reply

Can someone give me function for get textdraw position ?

some like "GetTextDrawPos(textdraw id)"

thx
Reply

Quote:
Originally Posted by kakalakamakapaka
Посмотреть сообщение
Can someone give me function for get textdraw position ?

some like "GetTextDrawPos(textdraw id)"

thx
You must first create another function to create it, that simultaniously saves his pos in an array. And then GetTextDrawPos

pawn Код:
enum tData
{
    Float:tX,
    Float:tY,
    tText[256]
}

new TD[MAX_TEXT_DRAWS][tData];
static TID = 0;

stock CreateTextDraw(Float:X, Float:Y, const Text[])
{
    TID ++;
    TextDrawCreate(X, Y, Text);
    TD[TID][tX] = X;
    TD[TID][tY] = Y;
    TD[TID][tText] = Text;
    return TID;
}

stock GetTextDrawPosition(textid, &Float:X, &Float:Y)
{
    X = TD[textid][tX];
    Y = TD[textid][tY];
}

stock SetTextDrawPosition(textid, Float:X, Float:Y)
{
    TextDrawDestroy(textid);
    TextDrawCreate(X, Y, TD[textid][tText]);
}
Un-tested


Quote:
Originally Posted by ******
Посмотреть сообщение
Which means that "MAX_VEHICLES" is a valid ID.
I've never seen an user with rank "Godfather" LOL, the max I saw was High-Roller
Reply

[QUOTE='[GF]Sasino97;1334647']You must first create another function to create it, that simultaniously saves his pos in an array. And then GetTextDrawPos

pawn Код:
enum tData
{
    Float:tX,
    Float:tY,
    tText[256]
}

new TD[MAX_TEXT_DRAWS][tData];
static TID = 0;

stock CreateTextDraw(Float:X, Float:Y, const Text[])
{
    TID ++;
    TextDrawCreate(X, Y, Text);
    TD[TID][tX] = X;
    TD[TID][tY] = Y;
    TD[TID][tText] = Text;
    return TID;
}

stock GetTextDrawPosition(textid, &Float:X, &Float:Y)
{
    X = TD[textid][tX];
    Y = TD[textid][tY];
}

stock SetTextDrawPosition(textid, Float:X, Float:Y)
{
    TextDrawDestroy(textid);
    TextDrawCreate(X, Y, TD[textid][tText]);
}
only problem with this, that you should save all datas of the TD. Text size, font, color, box, alignment, etc... And you should save which players can see the textdraws.
Reply


Forum Jump:


Users browsing this thread: 36 Guest(s)