Useful Snippets

RandomPlayerScreen(playerid)
This is a Function from my Selfmade Script.
RandomPlayerScreen gives the Player randomly a Screen, yuo can use it as LoginScreen, it would change on every Relog!

pawn Код:
forward RandomPlayerScreen(playerid);
public RandomPlayerScreen(playerid) {
    new screen = random(10);
    SetPlayerInterior(playerid, 0);
    switch(screen) {
        case 0: {
            SetPlayerPos(playerid,-346.083618,1599.942139,164.472366);
            SetPlayerCameraPos(playerid,-345.877228,1601.342896,164.518951);
            SetPlayerCameraLookAt(playerid,-340.641968,1938.658447,83.722984); }
        case 1: {
            SetPlayerPos(playerid,1485.0194,-892.1475,74.4098);
            SetPlayerCameraPos(playerid,1479.7717,-886.2401,73.9461);
            SetPlayerCameraLookAt(playerid,1415.3817,-807.9097,85.0613); }
        case 2: {
            SetPlayerPos(playerid,589.1550,373.1002,15.7948);
            SetPlayerCameraPos(playerid,543.9864,349.3647,14.9968);
            SetPlayerCameraLookAt(playerid,422.1727,599.0107,19.1812); }
        case 3: {
            SetPlayerPos(playerid,2155.0137,1129.7897,18.6397);
            SetPlayerCameraPos(playerid,2149.3992,1132.6051,24.3125);
            SetPlayerCameraLookAt(playerid,2105.0222,1156.5306,11.6470); }
        case 4: {
            SetPlayerPos(playerid,-2818.1499,1144.0898,19.2409);
            SetPlayerCameraPos(playerid,-2808.0366,1161.1864,20.3125);
            SetPlayerCameraLookAt(playerid,-2817.9348,1143.5291,19.3762); }
        case 5: {
            SetPlayerPos(playerid,2144.2822,1279.8054,7.9840);
            SetPlayerCameraPos(playerid,2154.24,1306.50,41.46);
            SetPlayerCameraLookAt(playerid,2273.45,1262.09,33.78); }
        case 6: {
            SetPlayerPos(playerid,-1771.7858,-565.5638,-0.5834);
            SetPlayerCameraPos(playerid,-1771.4641,-566.3715,16.4844);
            SetPlayerCameraLookAt(playerid,2105.0222,1156.5306,11.6470); }
        case 7: {
            SetPlayerPos(playerid,-1254.7159,953.9262,139.2734);
            SetPlayerCameraPos(playerid,-1256.6115,953.2058,139.2734);
            SetPlayerCameraLookAt(playerid,-1529.6639,689.2731,45.3311); }
        case 8: {
            SetPlayerPos(playerid,-2295.7979,712.2764,69.7422);
            SetPlayerCameraPos(playerid,-2265.6101,730.9575,49.2969);
            SetPlayerCameraLookAt(playerid,-2243.5103,731.5889,62.7217); }
        case 9: {
            SetPlayerPos(playerid,50.0000,50.0000,70.0000);
            SetPlayerCameraPos(playerid,50.0000,50.0000,70.2203);
            SetPlayerCameraLookAt(playerid,499.8851,504.5435,7.6593); } } }
Reply

This is not actually a snippet, but it can make your code more read-able. I already posted something using this definitions in Useful codes board.

pawn Код:
#define String:: str_
#define Integer:: int_
#define function
#define private static stock

// Example
private function String::ToInteger(const string[]) {
    return strval(string);
}
Reply

Flash the map for the player who has streamed with another:

http://pastebin.com/u3Zmuvf7
Reply

Quote:
Originally Posted by Luka P.
Посмотреть сообщение
This is not actually a snippet, but it can make your code more read-able. I already posted something using this definitions in Useful codes board.

pawn Код:
#define String:: str_
#define Integer:: int_
#define function
#define private static stock

// Example
private function String::ToInteger(const string[]) {
    return strval(string);
}
I'm sorry but I fell down from my chair laughing at this what you said. That your example hurts my eyes.

If you really want to rename a function, why don't you just (yeah, you can add your ::'s if that's needed):
pawn Код:
#define StringToInteger strval
Just because ****** is able to simplify and shorten his code with epic macros doesn't mean everyone should start using macros more often with every single function, especially if you have no idea what it really does. It's not cool, it's not any faster - what's the point?
Reply

EDITED...
Reply

Quote:
Originally Posted by TheHoodRat
Посмотреть сообщение
Smooth Timer Loading
This script will stop lag (you must use this every time you load a timer for smooth results).
pawn Код:
#include < a_samp >

new Timer ;

public OnFilterScriptInit ( ) {
    return true ;
}

public OnFilterScriptExit ( ) {
    KillTimer( Timer ) ;
    return true ;
}

public OnPlayerConnect(playerid) {
    Timer = SetTimer( "TimerLoad" , 3000 , false ) ;
    return true ;
}

forward TimerLoad ( );
public TimerLoad ( ) {
    Timer = SetTimer( "TimerKill" , 20 ,  false ) ;
    return true ;
}

forward TimerKill ( );
public TimerKill ( ) {
    KillTimer( Timer ) ;
    return true ;
}
Um..ok.. I don't really understand what it does, but this is shit. For example 10 players connect in 3 seconds. So..?
Reply

EDITED...
Reply

Quote:
Originally Posted by TheHoodRat
Посмотреть сообщение
Learn how to read codes, and this is shit? You couldn't script shit like this, so shut the fuck up troll.

For all of you dumb shits who don't know what this code does, it loads a timer at OnPlayerConnect then 20 milliseconds later it kills the timer. Easy eh?

And what the fuck does this have to do with 10 players connecting in 3 seconds?
You even know what you are doing in that script.. ? LMAO
Reply

EDITED...
Reply

Quote:
Originally Posted by TheHoodRat
Посмотреть сообщение
Learn how to read codes, and this is shit? You couldn't script shit like this, so shut the fuck up troll.

For all of you dumb shits who don't know what this code does, it loads a timer at OnPlayerConnect then 20 milliseconds later it kills the timer. Easy eh?

And what the fuck does this have to do with 10 players connecting in 3 seconds?
LMAO you suck..
Reply

EDITED...
Reply

TheHoodRat: Your code is not making timer loading any smoother, you load it the exact same way any other code does, you just destroy it differently. And like wups said, if you have multiple people connect quickly, the code would overwrite itself and only use the timer for one person, since you use one global variable.
Reply

Quote:
Originally Posted by Grim_
Посмотреть сообщение
TheHoodRat: Your code is not making timer loading any smoother, you load it the exact same way any other code does, you just destroy it differently. And like wups said, if you have multiple people connect quickly, the code would overwrite itself and only use the timer for one person, since you use one global variable.
Thanks for pointing that out. There's always another way to duplicate a script.
Reply

Workaround for the bug in format/printf when putting long hex numbers:

pawn Код:
#include <a_samp>

#define HEXNUM        "%04h%04h"
#define PRINTHEX(%0)  ( ( ( %0 ) & ( 0xFFFF0000 ) ) >>> 16 ), ( ( %0 ) & ( 0xFFFF ) )

public OnFilterScriptInit( )
{
    printf( "Bad: %x.", 0xFFFFFFFF );
    printf( "Good: " HEXNUM ".", PRINTHEX( 0xFFFFFFFF ) );
}

Using GetPlayerColor for the new text coloring in 0.3c:
pawn Код:
#define StripAlpha(%0)  ( ( %0 ) >>> 8 )

format( .., .., "blablalba{%h}blabla", StripAlpha( GetPlayerColor( playerid ) ) );
Reply

Quote:
Originally Posted by TheAlienForce
Посмотреть сообщение
pawn Код:
stock GivePlayerScore(playerid,score)
{
     SetPlayerScore(playerid,GetPlayerScore(playerid)+score);
     return 1;
}
Wrong topic, this should go in the useful functions topic.

pawn Код:
#define GivePlayerScore(%0,%1) SetPlayerScore(%0, (GetPlayerScore(%0) + %1))
Reply

Language codes with IDs (1, 2, 3, 4, 5, ...).

Код:
enum LanguageCodes(+=1)
{
	AA = 1, // Afar
	AB, // Abkhazian
	AF, // Afrikaans
	AM, // Amharic
	AR, // Arabic
	AS, // Assamese
	AY, // Aymara
	AZ, // Azerbaijani
	BA, // Bashkir
	BE, // Byelorussian
	BG, // Bulgarian
	BH, // Bihari
	BI, // Bislama
	BN, // Bengali, Bangla
	BO, // Tibetan
	BR, // Breton
	CA, // Catalan
	CO, // Corsican
	CS, // Czech
	CY, // Welsh
	DA, // Danish
	DE, // German
	DZ, // Bhutani
	EL, // Greek
	EN, // English, American
	EO, // Esperanto
	ES, // Spanish
	ET, // Estonian
	EU, // Basque
	FA, // Persian
	FI, // Finnish
	FJ, // Fiji
	FO, // Faeroese
	FR, // French
	FY, // Frisian
	GA, // Irish
	GD, // Gaelic Scots, Gaelic
	GL, // Galician
	GN, // Guarani
	GU, // Gujarati
	HA, // Hausa
	HI, // Hindi
	HR, // Croatian
	HU, // Hungarian
	HY, // Armenian
	IA, // Interlingua
	IE, // Interlingue
	IK, // Inupiak
	IN, // Indonesian
	IS, // Icelandic
	IT, // Italian
	IW, // Hebrew
	JA, // Japanese
	JI, // Yiddish
	JW, // Javanese
	KA, // Georgian
	KK, // Kazakh
	KL, // Greenlandic
	KM, // Cambodian
	KN, // Kannada
	KO, // Korean
	KS, // Kashmiri
	KU, // Kurdish
	KY, // Kirghiz
	LA, // Latin
	LN, // Lingala
	LO, // Laothian
	LT, // Lithuanian
	LV, // Latvian Lettish
	MG, // Malagasy
	MI, // Maori
	MK, // Macedonian
	ML, // Malayalam
	MN, // Mongolian
	MO, // Moldavian
	MR, // Marathi
	MS, // Malay
	MT, // Maltese
	MY, // Burmese
	NA, // Nauru
	NE, // Nepali
	NL, // Dutch
	NO, // Norwegian
	OC, // Occitan
	OM, // Oromo Afan
	OR, // Oriya
	PA, // Punjabi
	PL, // Polish
	PS, // Pashto Pushto
	PT, // Portuguese
	QU, // Quechua
	RM, // Rhaeto-Romance
	RN, // Kirundi
	RO, // Romanian
	RU, // Russian
	RW, // Kinyarwanda
	SA, // Sanskrit
	SD, // Sindhi
	SG, // Sangro
	SH, // Serbo-Croatian
	SI, // Singhalese
	SK, // Slovak
	SL, // Slovenian
	SM, // Samoan
	SN, // Shona
	SO, // Somali
	SQ, // Albanian
	SR, // Serbian
	SS, // Siswati
	ST, // Sesotho
	SU, // Sudanese
	SV, // Swedish
	SW, // Swahili
	TA, // Tamil
	TE, // Tegulu
	TG, // Tajik
	TH, // Thai
	TI, // Tigrinya
	TK, // Turkmen
	TL, // Tagalog
	TN, // Setswana
	TO, // Tonga
	TR, // Turkish
	TS, // Tsonga
	TT, // Tatar
	TW, // Twi
	UK, // Ukrainian
	UR, // Urdu
	UZ, // Uzbek
	VI, // Vietnamese
	VO, // Volapuk
	WO, // Wolof
	XH, // Xhosa
	YO, // Yoruba
	ZH, // Chinese
	ZU  // Zulu
};
Reply

@[03]Garsino:
It's actually a snippet.
Reply

pawn Код:
stock UpdateVehicleParamsEx(vehicleid, bool: status, { _, Float }: ...)
{
    new
        vehicleParams[7],
        vehicleParamsData[7][10] =
        {
            { "Engine" },
            { "Lights" },
            { "Alarm" },
            { "Doors" },
            { "Bonnet" },
            { "Boot" },
            { "Objective" }
        },
        totalArgs = numargs()
    ;
    if(totalArgs < 3)
    {
        return 0;
    }
    GetVehicleParamsEx(vehicleid, vehicleParams[0], vehicleParams[1], vehicleParams[2], vehicleParams[3], vehicleParams[4], vehicleParams[5], vehicleParams[6]);

    for(new i = 2, j = 0, ch = '\0'; i != totalArgs; ++i)
    {
        new
            tempString[10]
        ;
        for(j = 0; (ch = getarg(i, j)) != EOS; ++j)
        {
            tempString[j] = ch;
        }
        for(j = 0; j != sizeof(vehicleParamsData); ++j)
        {
            if(!strcmp(vehicleParamsData[j], tempString, true))
            {
                vehicleParams[j] = status;
            }
        }
    }
    SetVehicleParamsEx(vehicleid, vehicleParams[0], vehicleParams[1], vehicleParams[2], vehicleParams[3], vehicleParams[4], vehicleParams[5], vehicleParams[6]);
    return 1;
}
Examples:
pawn Код:
UpdateVehicleParamsEx(vehicleid, true, "Engine", "Boot", "Doors");
will start engine, open boot and doors.

or
pawn Код:
UpdateVehicleParamsEx(vehicleid, true, "Alarm", "Bonnet", "Doors", "Boot", "Engine");
will start the alarm, open bonnet, doors, boot and engine.

Notice: true is for ON and false is for OFF.
Reply

Quote:
Originally Posted by RyDeR`
Посмотреть сообщение
pawn Код:
stock UpdateVehicleParamsEx(vehicleid, bool: status, { _, Float }: ...)
{
    new
        vehicleParams[7],
        vehicleParamsData[7][10] =
        {
            { "Engine" },
            { "Lights" },
            { "Alarm" },
            { "Doors" },
            { "Bonnet" },
            { "Boot" },
            { "Objective" }
        },
        totalArgs = numargs()
    ;
    if(totalArgs < 3)
    {
        return 0;
    }
    GetVehicleParamsEx(vehicleid, vehicleParams[0], vehicleParams[1], vehicleParams[2], vehicleParams[3], vehicleParams[4], vehicleParams[5], vehicleParams[6]);

    for(new i = 2, j = 0, ch = '\0'; i != totalArgs; ++i)
    {
        new
            tempString[10]
        ;
        for(j = 0; (ch = getarg(i, j)) != EOS; ++j)
        {
            tempString[j] = ch;
        }
        for(j = 0; j != sizeof(vehicleParamsData); ++j)
        {
            if(!strcmp(vehicleParamsData[j], tempString, true))
            {
                vehicleParams[j] = status;
            }
        }
    }
    SetVehicleParamsEx(vehicleid, vehicleParams[0], vehicleParams[1], vehicleParams[2], vehicleParams[3], vehicleParams[4], vehicleParams[5], vehicleParams[6]);
    return 1;
}
Examples:
pawn Код:
UpdateVehicleParamsEx(vehicleid, true, "Engine", "Boot", "Doors");
will start engine, open boot and doors.

or
pawn Код:
UpdateVehicleParamsEx(vehicleid, true, "Alarm", "Bonnet", "Doors", "Boot", "Engine");
will start the alarm, open bonnet, doors, boot and engine.

Notice: true is for ON and false is for OFF.
Grat.
The same little differently:
pawn Код:
enum
    Params_type
{
    Engine,
    Lights,
    Alarm,
    Doors,
    Bonnet,
    Boot,
    Objective
};
Modified verzion 1:
pawn Код:
stock UpdateVehicleParamsEx(vehicleid, status, {Params_type}:...)
{
    new
        v_Params[7],
    argpos = numargs() - 2;  // vehicleid and status = 2 arguments

    GetVehicleParamsEx(vehicleid, v_Params[0], v_Params[1], v_Params[2], v_Params[3], v_Params[4], v_Params[5], v_Params[6]);
    while(argpos--)
    {
        switch(Params_type:getarg(argpos+2))
        {
            case Engine: v_Params[0] = status;
            case Lights: v_Params[1] = status;
            case Alarm: v_Params[2] = status;
            case Doors: v_Params[3] = status;
            case Bonnet: v_Params[4] = status;
            case Boot: v_Params[5] = status;
            case Objective: v_Params[6] = status;
        }
    }
    SetVehicleParamsEx(vehicleid, v_Params[0], v_Params[1], v_Params[2], v_Params[3], v_Params[4], v_Params[5], v_Params[6]);    
    return 1;
}
Modified verzion 2:
pawn Код:
stock
    UpdateVehicleParamsEx(vehicleid, status, {Params_type}:...)
{
    new
        v_Params[7],
        argpos = numargs() - 2;  // vehicleid and status = 2 arguments
    GetVehicleParamsEx(vehicleid, v_Params[0], v_Params[1], v_Params[2], v_Params[3], v_Params[4], v_Params[5], v_Params[6]);
    while(argpos--)
        v_Params[getarg(argpos+2)] = status;
    SetVehicleParamsEx(vehicleid, v_Params[0], v_Params[1], v_Params[2], v_Params[3], v_Params[4], v_Params[5], v_Params[6]);    
    return 1;
}
Test command:
pawn Код:
COMMAND:testparams(playerid, params[])
{
    new
        vehicleid = GetPlayerVehicleID(playerid);
    if(vehicleid)
        UpdateVehicleParamsEx(vehicleid, VEHICLE_PARAMS_ON, Lights, Boot, Bonnet);
    return 1;
}
Reply

Nice, I thought about though.
Reply


Forum Jump:


Users browsing this thread: 5 Guest(s)