Useful Snippets

Saves weapon (on the entrance to the car)
Switch weapon to UZI, MP5 or TEC-9
Switch weapon to the one that was (on exit of the car)

pawn Код:
new ArmedWeapon[MAX_PLAYERS];

public OnPlayerStateChange(playerid, newstate, oldstate)
{
    if(newstate == PLAYER_STATE_DRIVER)
    {
        new weap, ammo;
        ArmedWeapon[playerid] = GetPlayerWeapon(playerid);
        GetPlayerWeaponData(playerid, 4, weap, ammo);
        SetPlayerArmedWeapon(playerid, weap);
    }
    else if(oldstate == PLAYER_STATE_DRIVER) SetPlayerArmedWeapon(playerid, ArmedWeapon[playerid]);
    return 1;
}
Reply

Hooked foreach iterator for FCNPC...probably useless for most of the people...
Please note that MAX_PLAYERS must be actual number of server slots (FCNPC connects NPC's backwards), or replace MAX_PLAYERS macro below...
pawn Код:
new Iterator:FCNPC<MAX_PLAYERS>;
stock FCNPC_CreateHook(name[])
{
    new npcid = FCNPC_Create(name);
    if(npcid == INVALID_PLAYER_ID) return INVALID_PLAYER_ID;
    Iter_Add(FCNPC, npcid);
    return npcid;
}
stock FCNPC_DestroyHook(npcid)
{
    if(!FCNPC_Destroy(npcid)) return 0;
    Iter_Remove(FCNPC, npcid);
    return 1;
}
#define FCNPC_Create FCNPC_CreateHook
#define FCNPC_Destroy FCNPC_DestroyHook
Usage...
pawn Код:
foreach(new npcid : FCNPC
{
    //Do your shit...
}
Now after posting these i can rightfully feel like a noob
Reply

Here's a quick and easy command that uses zcmd, and sscanf. To teleport the player to an NPC. I use it for debugging. Use as you wish.

Код:
CMD:gotonpc(playerid, params[])
{
	new targetid, string[128], string2[128], Float:X, Float:Y, Float:Z, vehid;
	if(sscanf(params, "d", targetid)) return SendMessage(playerid, COLOR_RED, "USAGE: /gotonpc <NPCID>");
	if(IsPlayerNPC(targetid))
	{
		GetPlayerPos(targetid, X, Y, Z);
		SetPlayerPos(playerid, X, Y, Z);
		if(IsPlayerInAnyVehicle(targetid))
		{
			vehid = GetPlayerVehicleID(targetid);
			PutPlayerInVehicle(playerid, vehid, 1);
			format(string, sizeof(string), "You have teleported to %s(%d)'s vehicle, and have been placed inside.", PlayerName(targetid), targetid);
			SendMessage(playerid, COLOR_GREEN, string);
		}
		else if(!IsPlayerInAnyVehicle(targetid))
		{
			format(string2, sizeof(string2), "You have teleported to %s(%d)'s current location.", PlayerName(targetid), targetid);
			SendMessage(playerid, COLOR_GREEN, string2);
		}
	}
	else if(!IsPlayerNPC(targetid)) return SendMessage(playerid, COLOR_RED, "This player is not an NPC. Please use /goto for actual players.");
	return 1;
}
Reply

Count how many times a text was found in a file

pawn Код:
#define plural_singular(%0,%1,%2) ((%0) == 1) ? ((#%1)) : ((#%2))

main()
{
    CountTextInFile("count_text_in_file.txt", "hello");
}

stock CountTextInFile(const file_name[], const text[])
{
    new File:file = fopen(file_name, io_read);
    if(file)
    {
        new line[128], count, pos, last_pos, length = strlen(text);
        while(fread(file, line))
        {
            for(;;)
            {
                pos = strfind(line, text, false, last_pos);

                if(pos != -1)
                {
                    last_pos = (pos + length);
                    count ++;
                }
                else
                {
                    pos = 0;
                    last_pos = 0;
                    break;
                }
            }
        }

        printf("Found \"%s\" %d %s in \"%s\".", text, count, plural_singular(count, "time", "times"), file_name);
    }
    else
    {
        printf("Couldn't open \"%s\".", file_name);
    }

    fclose(file);
    return 1;
}
count_text_in_file.txt:
Quote:

hello how are you

hey

hello hey hello bro hello

yo

yooooo hello

hey yo

hello bro

Result:
Found "hello" 6 times in "count_text_in_file.txt".

It could come in handy if you know what to use it for.

For example: On some sort of log, you could execute the following:
CountTextInFile("count_text_in_file.txt", "hacker");

And it will tell you how many times "hacker" was found in the file. You could then check the log and see who said hacker and/or to who.
Reply

-Using hook on OnPlayerEditDynamicObject wont work, since it's over 31 letters.
Here's your fix:
PHP код:
forward OPEDO(playeridobjectidresponsexyzrxryrz);
public 
OPEDO(playeridobjectidresponsexyzrxryrz)
{
    
CallRemoteFunction("OnPlayerEditDynamicObject""iisffffff"playeridobjectidresponsexyzrxryrz);

Then to call it.
PHP код:
hook OPEDO(playeridobjectidresponseFloat:xFloat:yFloat:zFloat:rxFloat:ryFloat:rz
Reply

Hats object IDs:

PHP код:
19069,
19096,
19068,
18976,
18969,
19098,
19106,
19521,
12528,
19163,
19137// cluck n bell
19113,
18968,
18962,
18929,
18933,
18903,
18899,
18894,
18934,
18944,
18957,
18951,
18947,
18945,
18636 
Reply

Sudoku solver using Recursive Backtracking Algorithm - pawn version
This was one of my favourite programs that i did in c++ .I decided to port it to pawn. It can be useful for making mini games like sudoku.

Gist Link


PHP код:
/*
        Sudoku solver using 
            
        Recursive Backtracking algorithm 
        
        pawn version by Sreyas
*/
UAN(a[][9],&i,&j)
{
    for(
i=0;i<9;i++)
        for(
j=0;j<9;j++)
            if(
a[i][j]==0)
                return 
1;
    return 
0;
}
ROW(a[][9],in,num)
{
    for(new 
i=0;i<9;i++)
        if(
a[in][i]==num)
            return 
1;
    return 
0;
}
COL(a[][9],in,num)
{
    for(new 
i=0;i<9;i++)
        if(
a[i][in]==num)
            return 
1;
    return 
0;
}
GRID(a[][9],i,j,num)
{
    for(new 
u=0;u<3;u++)
        for(new 
y=0;y<3;y++)
            if(
a[i+u][j+y]==num)
                return 
1;
    return 
0;
}
safe(a[][9],i,j,num)
{
    if(!
ROW(a,i,num)&&!COL(a,j,num)&&!GRID(a,i-i%3,j-j%3,num))
        return 
1;
    return 
0;
}
solve(a[][9])
{
    new 
i,j;
    if(!
UAN(a,i,j))
         return 
1;
    for(new 
k=1;k<=9;k++)
    {
        if(
safe(a,i,j,k))
        {
            
a[i][j] = k;
            if(
solve(a))
                return 
1;
            
a[i][j] = 0;
        }
    }
    return 
0;
}
main()
{
    
//initialize the below matrix with your sudoku assuming empty space as 0
    
new a[9][9] =
    {
        {
0,8,07,1,20,9,0},
        {
0,0,00,0,07,1,0},
        {
0,0,00,9,42,6,0},
        
        {
0,0,03,6,04,0,5},
        {
5,0,00,0,00,0,9},
        {
7,0,60,2,50,0,0},
        
        {
0,5,82,7,00,0,0},
        {
0,1,70,0,00,0,0},
        {
0,6,09,4,10,5,7}
    };
    
    if(
solve(a))
    {
        for(new 
i=0;i<9;i++)
        {
            for(new 
j=0;j<9;j++)
            {
                
printf("%d ",a[i][j]);
                if((
j+1)%3==0)printf(" ");
            }
        
printf("\n");
        if((
i+1)%3==0)printf("\n");
        }
    }
    
    else 
printf("NO solution");

NOTE: This code is not recommended to newbies due to its complex nature.You should learn about its process before doing any modification to this code Link
Reply

Alphabet Sorter


This function sorts the strings in alphabetical order


Gist Link


PHP код:
#define strcpy(%0,%1) strcat((%0[0] = '\0', %0), %1) 
/*Alphabet sorter by Sreyas*/ 
alpha(str[MAX_NAMES][MAX_PLAYER_NAME]) //MAX_NAME - total number of strings in that matrix

    new 
ij,t[24]; 
    for(
i=1i<MAX_NAMESi++) 
    { 
        for(
j=1j<MAX_NAMESj++) 
        { 
            if(
strcmp(str[j-1], str[j])>0
            { 
                
strcpy(tstr[j-1]); 
                
strcpy(str[j-1], str[j]); 
                
strcpy(str[j], t); 
            } 
        } 
    } 
    
printf("Names in alphabetical order "); 
    
    for(
i=0i<MAX_NAMESi++) 
    { 
      
printf("%s",str[i]); 
    }

Reply

Just adding this here so it doesn't get lost.

Automatic house replacement in GTA.

Quote:
Originally Posted by [HLF]Southclaw
Посмотреть сообщение
I made an edit that adds doors and windows to all house models.
It took a while! So to save other people having to do it, I'll release it here!

I also added some more default models to replace, in total I think there are around 150 houses replaced in each city, instead of 40 in SF/33 in LV/80 in LS.

Thank you again to YJIET for his function to get attached object offsets, I used the code to position the extra objects based on the house rotation.

pawn Код:
#include <a_samp>
#include <sscanf2>

public OnFilterScriptInit()
{
    new
        line[128],
        File:file;
    file = fopen("DATA\\index.ini", io_read);
    if (file)
    {
        new
            File:LS,
            File:SF,
            File:LV;
        LS = fopen("LS.txt", io_write);
        SF = fopen("SF.txt", io_write);
        LV = fopen("LV.txt", io_write);
        while (fread(file, line))
        {
            new
                File:ipl;
            strdel(line, strlen(line) - 2, strlen(line));
            ipl = fopen(line, io_read);
            if (ipl)
            {
                new
                    model,
                    Float:px,
                    Float:py,
                    Float:pz,
                    Float:rx,
                    Float:ry,
                    Float:rz,
                    Float:qx,
                    Float:qy,
                    Float:qz,
                    Float:qw;
                while (fread(ipl, line))
                {
                    if (sscanf(line, "p<,>i{s[32]i}fffffff{i}", model, px, py, pz, qx, qy, qz, qw))
                    {
                        continue;
                    }
                    model = GetSAMP03EModel(model);
                    if (model)
                    {
                        // Los Santos
                        if (19505 <= model <= 19511)
                        {
                            QuatToEulerZXY(qx, qy, qz, qw, rx, ry, rz);
                            AddObject(model, px, py, pz, rx, ry, rz, LS);
                            continue;
                        }
                        // San Fierro
                        if (19489 <= model <= 19495)
                        {
                            QuatToEulerZXY(qx, qy, qz, qw, rx, ry, rz);
                            AddObject(model, px, py, pz, rx, ry, rz, SF);
                            continue;
                        }
                        // Las Venturas
                        if (19497 <= model <= 19503)
                        {
                            QuatToEulerZXY(qx, qy, qz, qw, rx, ry, rz);
                            AddObject(model, px, py, pz, rx, ry, rz, LV);
                            continue;
                        }
                    }
                }
                fclose(ipl);
            }
        }
        fclose(file);
        fclose(LS);
        fclose(LV);
        fclose(SF);
    }
}

new gDoors[5]=
{
    1491,
    1492,
    1494,
    1499,
    1502
};

AddObject(model, Float:x, Float:y, Float:z, Float:rx, Float:ry, Float:rz, File:handle)
{
    new
        str[256];

    format(str, 256, "CreateObject(%d, %f, %f, %f, %f, %f, %f);\r\nCreateObject(%d, %f, %f, %f, %f, %f, %f);\r\n", model, x, y, z, rx, ry, rz, model + 1, x, y, z, rx, ry, rz);
    fwrite(handle, str);
   
   
    // LOS SANTOS
    if(model == 19509)
    {
        SaveOffsetObj(gDoors[random(sizeof(gDoors))], x, y, z, rx, ry, rz, -1.00, 3.36, -2.13, 0.00, 0.00, 0.0, handle);
        SaveOffsetObj(gDoors[random(sizeof(gDoors))], x, y, z, rx, ry, rz, -0.24, -5.79, -2.81, 0.00, 0.00, 0.0, handle);
        SaveOffsetObj(19466, x, y, z, rx, ry, rz, 2.56, 3.35, -0.47, 0.00, 0.00, 90.0, handle);
        SaveOffsetObj(19466, x, y, z, rx, ry, rz, -2.71, 3.34, -0.47, 0.00, 0.00, 90.0, handle);
    }
    if(model == 19507)
    {
        SaveOffsetObj(gDoors[random(sizeof(gDoors))], x, y, z, rx, ry, rz, -5.03, 0.41, -2.55,   0.00, 0.00, 90.00, handle); // doors
        SaveOffsetObj(gDoors[random(sizeof(gDoors))], x, y, z, rx, ry, rz, 6.36, 2.53, -2.54,   0.00, 0.00, 90.00, handle);
        SaveOffsetObj(19466, x, y, z, rx, ry, rz, -3.92, 6.52, -1.03,   0.00, 0.00, 90.00, handle); // windows
        SaveOffsetObj(19466, x, y, z, rx, ry, rz, -0.79, 6.52, -1.03,   0.00, 0.00, 90.00, handle);
        SaveOffsetObj(19466, x, y, z, rx, ry, rz, 1.99, 6.52, -1.03,   0.00, 0.00, 90.00, handle);
        SaveOffsetObj(19466, x, y, z, rx, ry, rz, 4.99, 6.52, -1.03,   0.00, 0.00, 90.00, handle);
        SaveOffsetObj(19466, x, y, z, rx, ry, rz, 6.41, -1.89, -0.92,   0.00, 0.00, 0.00, handle);
        SaveOffsetObj(19466, x, y, z, rx, ry, rz, 6.41, -3.89, -0.92,   0.00, 0.00, 0.00, handle);
        SaveOffsetObj(19466, x, y, z, rx, ry, rz, -2.80, -5.95, -0.99,   0.00, 0.00, 90.00, handle);
        SaveOffsetObj(19466, x, y, z, rx, ry, rz, -5.08, 3.59, -0.91,   0.00, 0.00, 0.00, handle);
        SaveOffsetObj(19466, x, y, z, rx, ry, rz, -5.08, -3.92, -0.91,   0.00, 0.00, 0.00, handle);
    }
    if(model == 19505)
    {
        SaveOffsetObj(gDoors[random(sizeof(gDoors))], x, y, z, rx, ry, rz, 7.71, -4.28, -2.14,   0.00, 0.00, 90.00, handle); // doors
        SaveOffsetObj(gDoors[random(sizeof(gDoors))], x, y, z, rx, ry, rz, -6.04, -0.31, -2.14,   0.00, 0.00, 270.00, handle);
        SaveOffsetObj(19466, x, y, z, rx, ry, rz, 7.76, 3.93, -0.52,   0.00, 0.00, 0.00, handle); // windows
        SaveOffsetObj(19466, x, y, z, rx, ry, rz, 7.76, 1.70, -0.52,   0.00, 0.00, 0.00, handle);
        SaveOffsetObj(19466, x, y, z, rx, ry, rz, -6.14, 2.20, -0.72,   0.00, 0.00, 0.00, handle);
        SaveOffsetObj(19466, x, y, z, rx, ry, rz, -6.14, 4.44, -0.72,   0.00, 0.00, 0.00, handle);
        SaveOffsetObj(19466, x, y, z, rx, ry, rz, -3.33, 5.68, -0.50,   0.00, 0.00, 90.00, handle);
        SaveOffsetObj(19466, x, y, z, rx, ry, rz, -4.57, -6.23, -0.46,   0.00, 0.00, 90.00, handle);
        SaveOffsetObj(19466, x, y, z, rx, ry, rz, -0.95, -6.23, -0.46,   0.00, 0.00, 90.00, handle);
        SaveOffsetObj(19466, x, y, z, rx, ry, rz, 2.72, -6.23, -0.46,   0.00, 0.00, 90.00, handle);
        SaveOffsetObj(19466, x, y, z, rx, ry, rz, 5.91, -6.23, -0.46,   0.00, 0.00, 90.00, handle);
        SaveOffsetObj(19466, x, y, z, rx, ry, rz, -6.14, -3.44, -0.44,   0.00, 0.00, 0.00, handle);
    }
    if(model == 19511)
    {
        SaveOffsetObj(gDoors[random(sizeof(gDoors))], x, y, z, rx, ry, rz, -1.12, -5.35, -2.05,   0.00, 0.00, 90.00, handle); // doors
        SaveOffsetObj(gDoors[random(sizeof(gDoors))], x, y, z, rx, ry, rz, 2.65, 5.93, -1.96,   0.00, 0.00, 0.00, handle);
        SaveOffsetObj(19466, x, y, z, rx, ry, rz, 1.27, 5.96, -0.26,   0.00, 0.00, 90.00, handle); // windows
        SaveOffsetObj(19466, x, y, z, rx, ry, rz, -2.13, 5.96, -0.26,   0.00, 0.00, 90.00, handle);
        SaveOffsetObj(19466, x, y, z, rx, ry, rz, 5.16, 3.32, -0.40,   0.00, 0.00, 0.00, handle);
        SaveOffsetObj(19466, x, y, z, rx, ry, rz, 5.16, -1.80, -0.40,   0.00, 0.00, 0.00, handle);
        SaveOffsetObj(19466, x, y, z, rx, ry, rz, 5.16, 0.65, -0.40,   0.00, 0.00, 0.00, handle);
        SaveOffsetObj(19466, x, y, z, rx, ry, rz, 1.19, -3.36, -0.57,   0.00, 0.00, 90.00, handle);
        SaveOffsetObj(19466, x, y, z, rx, ry, rz, -3.03, -5.92, -0.55,   0.00, 0.00, 90.00, handle);
    }
   
    // SAN FIERRO
    if(model == 19491)
    {
        SaveOffsetObj(gDoors[random(sizeof(gDoors))], x, y, z, rx, ry, rz, -3.19, 1.96, -4.94,   0.00, 0.00, 90.00, handle);
        SaveOffsetObj(gDoors[random(sizeof(gDoors))], x, y, z, rx, ry, rz, 6.14, -2.76, -4.78,   0.00, 0.00, 90.00, handle);
        SaveOffsetObj(gDoors[random(sizeof(gDoors))], x, y, z, rx, ry, rz, 0.34, -3.40, -2.13,   0.00, 0.00, 270.00, handle);
        SaveOffsetObj(19466, x, y, z, rx, ry, rz, -6.05, -1.76, -3.28,   0.00, 0.00, 0.00, handle);
        SaveOffsetObj(19466, x, y, z, rx, ry, rz, -6.05, 0.47, -3.28,   0.00, 0.00, 0.00, handle);
        SaveOffsetObj(19466, x, y, z, rx, ry, rz, 6.47, 3.83, -3.05,   0.00, 0.00, 0.00, handle);
        SaveOffsetObj(19466, x, y, z, rx, ry, rz, 6.45, 1.60, -3.05,   0.00, 0.00, 0.00, handle);
        SaveOffsetObj(19466, x, y, z, rx, ry, rz, 6.40, 0.33, -3.05,   0.00, 0.00, 0.00, handle);
        SaveOffsetObj(19466, x, y, z, rx, ry, rz, 6.44, 1.56, -0.54,   0.00, 0.00, 0.00, handle);
        SaveOffsetObj(19466, x, y, z, rx, ry, rz, 6.44, 3.74, -0.54,   0.00, 0.00, 0.00, handle);
        SaveOffsetObj(19466, x, y, z, rx, ry, rz, 6.44, -1.26, -0.54,   0.00, 0.00, 0.00, handle);
        SaveOffsetObj(19466, x, y, z, rx, ry, rz, -6.06, 1.07, -0.42,   0.00, 0.00, 0.00, handle);
        SaveOffsetObj(19466, x, y, z, rx, ry, rz, -6.06, -1.16, -0.42,   0.00, 0.00, 0.00, handle);
        SaveOffsetObj(19466, x, y, z, rx, ry, rz, -6.06, 3.31, -0.42,   0.00, 0.00, 0.00, handle);
    }
    if(model == 19489)
    {
        SaveOffsetObj(gDoors[random(sizeof(gDoors))], x, y, z, rx, ry, rz, -6.66, 1.01, -0.42,   0.00, 0.00, 0.00, handle);
        SaveOffsetObj(gDoors[random(sizeof(gDoors))], x, y, z, rx, ry, rz, 1.36, -4.99, -0.48,   0.00, 0.00, 90.00, handle);
        SaveOffsetObj(19466, x, y, z, rx, ry, rz, -5.13, -1.89, 1.17,   0.00, 0.00, 0.00, handle);
        SaveOffsetObj(19466, x, y, z, rx, ry, rz, -6.65, 3.72, 0.46,   0.00, 0.00, 0.00, handle);
        SaveOffsetObj(19466, x, y, z, rx, ry, rz, -6.65, 2.34, 0.46,   0.00, 0.00, 0.00, handle);
        SaveOffsetObj(19466, x, y, z, rx, ry, rz, -6.66, 2.39, 1.50,   0.00, 0.00, 0.00, handle);
        SaveOffsetObj(19466, x, y, z, rx, ry, rz, -6.65, 3.84, 1.50,   0.00, 0.00, 0.00, handle);
        SaveOffsetObj(19466, x, y, z, rx, ry, rz, 6.66, 2.09, 1.12,   0.00, 0.00, 0.00, handle);
        SaveOffsetObj(19466, x, y, z, rx, ry, rz, 6.66, 3.69, 1.12,   0.00, 0.00, 0.00, handle);
        SaveOffsetObj(19466, x, y, z, rx, ry, rz, 5.10, -0.10, 1.04,   0.00, 0.00, 0.00, handle);
        SaveOffsetObj(19466, x, y, z, rx, ry, rz, 5.12, -2.28, 1.04,   0.00, 0.00, 0.00, handle);
        SaveOffsetObj(19466, x, y, z, rx, ry, rz, 6.72, -1.81, -1.61,   0.00, 0.00, 0.00, handle);
        SaveOffsetObj(19466, x, y, z, rx, ry, rz, 6.70, 0.30, -1.61,   0.00, 0.00, 0.00, handle);
        SaveOffsetObj(19466, x, y, z, rx, ry, rz, 6.68, 3.75, -1.61,   0.00, 0.00, 0.00, handle);
        SaveOffsetObj(19466, x, y, z, rx, ry, rz, 6.69, 1.52, -1.61,   0.00, 0.00, 0.00, handle);
    }
    if(model == 19495)
    {
        SaveOffsetObj(gDoors[random(sizeof(gDoors))], x, y, z, rx, ry, rz, 5.68, -4.41, -4.33,   0.00, 0.00, 90.00, handle);
        SaveOffsetObj(gDoors[random(sizeof(gDoors))], x, y, z, rx, ry, rz, 3.30, -0.23, -4.66,   0.00, 0.00, 0.00, handle);
        SaveOffsetObj(gDoors[random(sizeof(gDoors))], x, y, z, rx, ry, rz, -1.95, -3.92, -4.50,   0.00, 0.00, 90.00, handle);
        SaveOffsetObj(19466, x, y, z, rx, ry, rz, 6.00, 3.41, -2.82,   0.00, 0.00, 0.00, handle);
        SaveOffsetObj(19466, x, y, z, rx, ry, rz, 6.00, 1.17, -2.82,   0.00, 0.00, 0.00, handle);
        SaveOffsetObj(19466, x, y, z, rx, ry, rz, 6.00, -1.56, -2.84,   0.00, 0.00, 0.00, handle);
        SaveOffsetObj(19466, x, y, z, rx, ry, rz, 6.00, 3.34, -0.07,   0.00, 0.00, 0.00, handle);
        SaveOffsetObj(19466, x, y, z, rx, ry, rz, 6.00, 1.10, -0.07,   0.00, 0.00, 0.00, handle);
        SaveOffsetObj(19466, x, y, z, rx, ry, rz, 6.00, -3.05, -0.02,   0.00, 0.00, 0.00, handle);
        SaveOffsetObj(19466, x, y, z, rx, ry, rz, -6.00, -0.48, 0.23,   0.00, 0.00, 0.00, handle);
        SaveOffsetObj(19466, x, y, z, rx, ry, rz, -6.00, -2.72, 0.23,   0.00, 0.00, 0.00, handle);
        SaveOffsetObj(19466, x, y, z, rx, ry, rz, -4.84, 3.00, -0.83,   0.00, 0.00, 0.00, handle);
        SaveOffsetObj(19466, x, y, z, rx, ry, rz, -4.85, 3.00, 0.46,   0.00, 0.00, 0.00, handle);
    }
    if(model == 19493)
    {
        SaveOffsetObj(gDoors[random(sizeof(gDoors))], x, y, z, rx, ry, rz, -3.05, -3.72, -4.34,   0.00, 0.00, 90.00, handle);
        SaveOffsetObj(gDoors[random(sizeof(gDoors))], x, y, z, rx, ry, rz, 5.34, -3.52, -4.67,   0.00, 0.00, 90.00, handle);
        SaveOffsetObj(19466, x, y, z, rx, ry, rz, 5.70, -0.60, -2.89,   0.00, 0.00, 0.00, handle);
        SaveOffsetObj(19466, x, y, z, rx, ry, rz, 5.68, 1.07, -3.25,   0.00, 0.00, 0.00, handle);
        SaveOffsetObj(19466, x, y, z, rx, ry, rz, 5.68, 3.23, -3.15,   0.00, 0.00, 0.00, handle);
        SaveOffsetObj(19466, x, y, z, rx, ry, rz, -4.62, -0.58, -2.96,   0.00, 0.00, 0.00, handle);
        SaveOffsetObj(19466, x, y, z, rx, ry, rz, 5.70, -2.29, -0.27,   0.00, 0.00, 0.00, handle);
        SaveOffsetObj(19466, x, y, z, rx, ry, rz, 5.67, 2.95, -0.27,   0.00, 0.00, 0.00, handle);
        SaveOffsetObj(19466, x, y, z, rx, ry, rz, 5.67, 0.71, -0.27,   0.00, 0.00, 0.00, handle);
        SaveOffsetObj(19466, x, y, z, rx, ry, rz, -5.19, -1.93, -0.19,   0.00, 0.00, 0.00, handle);
        SaveOffsetObj(19466, x, y, z, rx, ry, rz, -5.15, 3.03, -0.29,   0.00, 0.00, 0.00, handle);
        SaveOffsetObj(19466, x, y, z, rx, ry, rz, -5.15, 0.80, -0.29,   0.00, 0.00, 0.00, handle);
    }
   
    // LAS VENTURAS
    if(model == 19497)
    {
        SaveOffsetObj(gDoors[random(sizeof(gDoors))], x, y, z, rx, ry, rz, -1.62, -0.99, -1.73,   0.00, 0.00, 90.00, handle);
        SaveOffsetObj(gDoors[random(sizeof(gDoors))], x, y, z, rx, ry, rz, 5.56, -5.33, -1.70,   0.00, 0.00, 0.00, handle);
        SaveOffsetObj(gDoors[random(sizeof(gDoors))], x, y, z, rx, ry, rz, 9.45, -8.08, -1.66,   0.00, 0.00, 90.00, handle);
        SaveOffsetObj(19466, x, y, z, rx, ry, rz, -4.46, 4.24, 0.30,   0.00, 0.00, 0.00, handle);
        SaveOffsetObj(19466, x, y, z, rx, ry, rz, -4.46, 8.49, 0.30,   0.00, 0.00, 0.00, handle);
        SaveOffsetObj(19466, x, y, z, rx, ry, rz, 9.60, 8.99, 0.46,   0.00, 0.00, 0.00, handle);
        SaveOffsetObj(19466, x, y, z, rx, ry, rz, 9.60, 0.32, -0.01,   0.00, 0.00, 0.00, handle);
        SaveOffsetObj(19466, x, y, z, rx, ry, rz, -1.75, -3.93, 0.01,   0.00, 0.00, 0.00, handle);
    }
    if(model == 19501)
    {
        SaveOffsetObj(gDoors[random(sizeof(gDoors))], x, y, z, rx, ry, rz, -6.91, -3.63, -3.10,   0.00, 0.00, 0.00, handle);
        SaveOffsetObj(1494, x, y, z, rx, ry, rz, -5.88, 8.85, -2.96,   0.00, 0.00, 0.00, handle);
        SaveOffsetObj(1494, x, y, z, rx, ry, rz, -2.88, 8.85, -2.96,   0.00, 0.00, 180.00, handle);
        SaveOffsetObj(19466, x, y, z, rx, ry, rz, -7.30, 0.90, -1.40,   0.00, 0.00, 0.00, handle);
        SaveOffsetObj(19466, x, y, z, rx, ry, rz, -7.30, -1.34, -1.52,   0.00, 0.00, 0.00, handle);
        SaveOffsetObj(19466, x, y, z, rx, ry, rz, -7.30, 3.22, -1.38,   0.00, 0.00, 0.00, handle);
        SaveOffsetObj(19466, x, y, z, rx, ry, rz, -7.30, 5.46, -1.38,   0.00, 0.00, 0.00, handle);
        SaveOffsetObj(19466, x, y, z, rx, ry, rz, 7.07, -2.27, -1.32,   0.00, 0.00, 0.00, handle);
        SaveOffsetObj(19466, x, y, z, rx, ry, rz, 7.07, -0.03, -1.32,   0.00, 0.00, 0.00, handle);
        SaveOffsetObj(19466, x, y, z, rx, ry, rz, 7.07, -4.51, -1.32,   0.00, 0.00, 0.00, handle);
        SaveOffsetObj(19466, x, y, z, rx, ry, rz, 7.07, 5.00, -1.41,   0.00, 0.00, 0.00, handle);
        SaveOffsetObj(19466, x, y, z, rx, ry, rz, 7.07, 2.76, -1.41,   0.00, 0.00, 0.00, handle);
    }
    if(model == 19499)
    {
        SaveOffsetObj(gDoors[random(sizeof(gDoors))], x, y, z, rx, ry, rz, -5.65, -2.95, -3.36,   0.00, 0.00, 0.00, handle);
        SaveOffsetObj(1494, x, y, z, rx, ry, rz, 2.42, 6.30, -3.39,   0.00, 0.00, 0.00, handle);
        SaveOffsetObj(1494, x, y, z, rx, ry, rz, 5.44, 6.30, -3.39,   0.00, 0.00, 180.00, handle);
        SaveOffsetObj(19466, x, y, z, rx, ry, rz, -6.07, -1.00, -1.78,   0.00, 0.00, 0.00, handle);
        SaveOffsetObj(19466, x, y, z, rx, ry, rz, -6.07, 1.24, -1.78,   0.00, 0.00, 0.00, handle);
        SaveOffsetObj(19466, x, y, z, rx, ry, rz, -6.07, 3.48, -1.78,   0.00, 0.00, 0.00, handle);
        SaveOffsetObj(19466, x, y, z, rx, ry, rz, 7.03, 1.92, -1.73,   0.00, 0.00, 0.00, handle);
        SaveOffsetObj(19466, x, y, z, rx, ry, rz, 7.03, 4.16, -1.73,   0.00, 0.00, 0.00, handle);
        SaveOffsetObj(19466, x, y, z, rx, ry, rz, 7.04, -4.87, -1.73,   0.00, 0.00, 0.00, handle);
        SaveOffsetObj(19466, x, y, z, rx, ry, rz, 7.04, -2.64, -1.73,   0.00, 0.00, 0.00, handle);
        SaveOffsetObj(19466, x, y, z, rx, ry, rz, 7.04, -7.11, -1.73,   0.00, 0.00, 0.00, handle);
    }
    if(model == 19503)
    {
        SaveOffsetObj(gDoors[random(sizeof(gDoors))], x, y, z, rx, ry, rz, -1.26, -1.87, -2.22,   0.00, 0.00, 0.00, handle);
        SaveOffsetObj(gDoors[random(sizeof(gDoors))], x, y, z, rx, ry, rz, 3.82, -1.78, -2.15,   0.00, 0.00, 0.00, handle);
        SaveOffsetObj(19363, x, y, z, rx, ry, rz, 1.85, -1.88, -1.50,   0.00, 0.00, 90.00, handle);
        SaveOffsetObj(19325, x, y, z, rx, ry, rz, -7.78, -9.10, -1.52,   0.00, 0.00, 90.00, handle);
        SaveOffsetObj(19466, x, y, z, rx, ry, rz, -12.07, -9.10, -0.85,   90.00, 0.00, 90.00, handle);
        SaveOffsetObj(19325, x, y, z, rx, ry, rz, -12.94, -5.09, -1.37,   0.00, 0.00, 0.00, handle);
        SaveOffsetObj(19325, x, y, z, rx, ry, rz, -12.94, 0.36, -1.29,   0.00, 0.00, 0.00, handle);
        SaveOffsetObj(19325, x, y, z, rx, ry, rz, -8.32, 8.00, -0.96,   0.00, 0.00, 90.00, handle);
        SaveOffsetObj(19325, x, y, z, rx, ry, rz, 0.81, 8.00, -1.73,   0.00, 0.00, 90.00, handle);
    }
}

SaveOffsetObj(
    model, Float:x, Float:y, Float:z, Float:rx, Float:ry, Float:rz,
    Float:object_px, Float:object_py, Float:object_pz, Float:object_rx, Float:object_ry, Float:object_rz,
    File:handle)
{
    new
        str[256],
        Float:new_x,
        Float:new_y,
        Float:new_z;

    GetAttachedObjectPos(
        x, y, z, rx, ry, rz,
        object_px, object_py, object_pz,
        new_x, new_y, new_z);


    format(str, 256, "CreateObject(%d, %f, %f, %f, %f, %f, %f);\r\n",
        model, new_x, new_y, new_z, object_rx+rx, object_ry+ry, object_rz+rz);

    fwrite(handle, str);


}
stock GetAttachedObjectPos(
    Float:object_px, Float:object_py, Float:object_pz, Float:object_rx, Float:object_ry, Float:object_rz,
    Float:offset_x, Float:offset_y, Float:offset_z,
    &Float:x, &Float:y, &Float:z)
{
    new
        Float:cos_x = floatcos(object_rx, degrees),
        Float:cos_y = floatcos(object_ry, degrees),
        Float:cos_z = floatcos(object_rz, degrees),
        Float:sin_x = floatsin(object_rx, degrees),
        Float:sin_y = floatsin(object_ry, degrees),
        Float:sin_z = floatsin(object_rz, degrees);

    x = object_px + offset_x * cos_y * cos_z - offset_x * sin_x * sin_y * sin_z - offset_y * cos_x * sin_z + offset_z * sin_y * cos_z + offset_z * sin_x * cos_y * sin_z;
    y = object_py + offset_x * cos_y * sin_z + offset_x * sin_x * sin_y * cos_z + offset_y * cos_x * cos_z + offset_z * sin_y * sin_z - offset_z * sin_x * cos_y * cos_z;
    z = object_pz - offset_x * cos_x * sin_y + offset_y * sin_x + offset_z * cos_x * cos_y;
}

QuatToEulerZXY(Float:quat_x, Float:quat_y, Float:quat_z, Float:quat_w, &Float:x, &Float:y, &Float:z)
{
    x = -asin(2 * ((quat_x * quat_z) + (quat_w * quat_y)));
    y = atan2(2 * ((quat_y * quat_z) + (quat_w * quat_x)), (quat_w * quat_w) - (quat_x * quat_x) - (quat_y * quat_y) + (quat_z * quat_z));
    z = -atan2(2 * ((quat_x * quat_y) + (quat_w * quat_z)), (quat_w * quat_w) + (quat_x * quat_x) - (quat_y * quat_y) - (quat_z * quat_z));
    return 1;
}

GetSAMP03EModel(model)
{
    // Los Santos
    if (model == 3592 || model == 3563 || model == 5664 || model == 3591) return 19509;
    if (model == 3647) return 19507;
    if (model == 3706 || model == 3654 || model == 5672) return 19505;
    if (model == 3720) return 19511;
    // San Fierro
    if (model == 3832 || model == 3840) return 19491;
    if (model == 3835 || model == 3833) return 19489;
    if (model == 3838 || model == 3848) return 19495;
    if (model == 3841 || model == 3836) return 19493;
    // Las Venturas
    if (model == 3536) return 19497;
    if (model == 3546) return 19501;
    if (model == 3547) return 19499;
    if (model == 3548) return 19503;
    return 0;
}
Reply

Hostname Changer
I made this script for fun when I was bored.

Features:
  • Requires no or very basic scripting knowledge
  • Very easy to write and read
  • Never selects a previously selected hostname!
PHP код:
/*
    Script Documentation
    
    Script name: Hostname Changer
    Script by: Logic_
    Script made in: 5 minutes
    Script indentation: perfect
    Script tested: yes
*/
// Includes
#include <a_samp>
// Defines
#define FILTERSCRIPT // define if you want to use it as a FS
#define DEFAULT_TIME    (5)  // In seconds
// Arrays & Variables
new HOST[]=
{
    {
"Script by Logic_"}, // Message ID 0
    
{"Logic_"}, // Messaege ID 1
    
{"No restrictions!"}, // Message ID 2
    
{"Add as many names you want"// Message ID 3
}, TimerCHHostLast = -1;
// Forwards
forward ChangeHost();
// Callbacks
#if defined FILTERSCRIPT
public OnFilterScriptInit()
{
    
TimerCH SetTimer("ChangeHost"DEFAULT_TIME 1000true);
    return 
1;
}
public 
OnFilterScriptExit()
{
    
KillTimer(TimerCH);
    return 
1;
}
#else
public OnGameModeInit()
{
    
TimerCH SetTimer("ChangeHost"DEFAULT_TIME 1000true);
    return 
1;
}
public 
OnGameModeExit()
{
    
KillTimer(TimerCH);
    return 
1;
}
#endif
FetchHostID()
{
    new 
ID random(sizeof HOST);
    return (
ID == HostLast) ? FetchHostID() : ID;
}
public 
ChangeHost()
{
    new 
ID FetchHostID(), str[60] = "hostname ";
    
HostLast ID;
    
strcat(strHOST[ID][HOSTNAME]);
    
SendRconCommand(str);
    return 
1;

Reply

pawn Код:
KillTimer(ChangeHost());
This will kill the timer with ID 1 as your public function returns that value. You need to store the timer ID (what SetTimer returns) and use that as argument in KillTimer function.

The enumeration is not really needed and sizeof HOST is a constant, what's the point in storing it to a variable?
Reply

str[60] = "hostname" would also be better.
Reply

Workpoints(INCOMPLETE)
This is snippet of a incomplete system, modify and use it as to your needs.

PHP код:
/*
    Script Documentation
    
    Script Name: Workpoints
    Script By: AliScripter
    Script Indentation: Perfect
*/
// Includes
#include <a_samp>
#include <streamer>
// Enums
enum E_WORKPOINTS
{
    
Text[50],
    
FloatX,
    
FloatY,
    
FloatZ,
    
Checkpoint,
    
Text3DLabel
};
// Arrays and Variables
new gWorkpoints[][E_WORKPOINTS] =
{
    {
"{FF00FF}Hospital\n{FFFFFF}Press 'N'"0.00.00.0},
    {
"{FF00FF}Testing\n{FFFFFF}Press 'N'"1.11.10.0}
};
// Defines
#define FILTERSCRIPT
// Callbacks
#if defined FILTERSCRIPT
public OnFilterScriptInit()
{
    
LoadWorkpoints();
    return 
1;
}
public 
OnFilterScriptExit()
{
    
UnloadWorkpoints();
    return 
1;
}
#endif
LoadWorkpoints()
{
    for(new 
isizeof gWorkpointsji++)
    {
        
gWorkpoints[i][Checkpoint] = CreateDynamicCP(gWorkpoints[i][X], gWorkpoints[i][Y], gWorkpoints[i][Z], 4.0);
        
gWorkpoints[i][Label] = CreateDynamic3DTextLabel(gWorkpoints[i][Text], 0xFFFFFFFFgWorkpoints[i][X], gWorkpoints[i][Y], gWorkpoints[i][Z] + 2.0100.0);
    }
    return 
1;
}
UnloadWorkpoints()
{
    for(new 
isizeof gWorkpointsji++)
    {
        
DestroyDynamicCP(gWorkpoints[i][Checkpoint]);
        
DestroyDynamic3DTextLabel(gWorkpoints[i][Label]);
    }
    return 
1;
}
public 
OnPlayerKeyStateChange(playeridnewkeysoldkeys)
{
    if(
newkeys KEY_NO)
    {
        for(new 
isizeof gWorkpointsji++)
        {
            if(
IsPlayerInRangeOfPoint(playerid3.0gWorkpoints[i][X], gWorkpoints[i][Y], gWorkpoints[i][Z])
            {
                
// Your Code
            
}
        }
    }
    return 
1;

Reply

Teleport player to the nearest hospital on death
GTA SA Singleplayer Feature
Credits to Konstantinos!

PHP код:
new Float:Hospitalcoor[][4] =
{
    {
2027.4375,-1421.0703,16.9922,137.2809}, // Los Santos Hospital
    
{1177.9089,-1323.9611,14.0939,269.8222},  // Los Santos Hospital #2
    
{1579.6106,1769.0625,10.8203,90.7178},  // Las Venturas Hospital
    
{-321.8259,1056.7279,19.7422,316.0064}, // Fort Carson Hospital
    
{-1514.8807,2527.8003,55.7315,358.6234},  // El Quebrados Hospital
    
{-2662.0439,630.5056,14.4531,177.8114}, // San Fierro Hospital
    
{-2199.2495,-2311.0444,30.6250,321.2772}, // Angel Pine Hospital
    
{1244.1959,332.2817,19.5547,338.3063// Montgomery Hospital
};
public 
OnPlayerDeath(playeridkilleridreason) {
        new 
Float:distance 99999.0,
               
Float:tmp_distanceclosest = -1;
        for (new 
isizeof(Hospitalcoor); ji++)
        {
            
tmp_distance GetPlayerDistanceFromPoint(playeridHospitalcoor[i][0], Hospitalcoor[i][1], Hospitalcoor[i][2]);
            if (
tmp_distance distance)
            {
                
distance tmp_distance;
                
closest i;
            }
        }
        
SetSpawnInfo(playeridNO_TEAMGetPlayerSkin(playerid), Hospitalcoor[closest][0], Hospitalcoor[closest][1], Hospitalcoor[closest][2], Hospitalcoor[closest][3], 000000);
        return 
1;

Reply

Quote:
Originally Posted by oMa37
Посмотреть сообщение
Teleport player to the nearest hospital
GTA SA Singleplayer Feature
Credits to Konstantinos!

PHP код:
new Float:Hospitalcoor[][4] =
{
    {
2027.4375,-1421.0703,16.9922,137.2809}, // Los Santos Hospital
    
{1177.9089,-1323.9611,14.0939,269.8222},  // Los Santos Hospital #2
    
{1579.6106,1769.0625,10.8203,90.7178},  // Las Venturas Hospital
    
{-321.8259,1056.7279,19.7422,316.0064}, // Fort Carson Hospital
    
{-1514.8807,2527.8003,55.7315,358.6234},  // El Quebrados Hospital
    
{-2662.0439,630.5056,14.4531,177.8114}, // San Fierro Hospital
    
{-2199.2495,-2311.0444,30.6250,321.2772}, // Angel Pine Hospital
    
{1244.1959,332.2817,19.5547,338.3063// Montgomery Hospital
};
public 
OnPlayerDeath(playeridkilleridreason) {
        for (new 
isizeof(Hospitalcoor); ji++)
        {
            
tmp_distance GetPlayerDistanceFromPoint(playeridHospitalcoor[i][0], Hospitalcoor[i][1], Hospitalcoor[i][2]);
            if (
tmp_distance distance)
            {
                
distance tmp_distance;
                
closest i;
            }
        }
        
SetSpawnInfo(playeridNO_TEAMGetPlayerSkin(playerid), Hospitalcoor[closest][0], Hospitalcoor[closest][1], Hospitalcoor[closest][2], Hospitalcoor[closest][3], 000000);
        return 
1;

It seems you forgot it:
PHP код:
public OnPlayerDeath(playeridkilleridreason) {
        new 
closestFloat:distance 99999.9//
        
for (new isizeof(Hospitalcoor), Float:tmp_distanceji++) //Float:tmp_distance
        
{
            
tmp_distance GetPlayerDistanceFromPoint(playeridHospitalcoor[i][0], Hospitalcoor[i][1], Hospitalcoor[i][2]);
            if (
tmp_distance distance)
            {
                
distance tmp_distance;
                
closest i;
            }
        }
        
SetSpawnInfo(playeridNO_TEAMGetPlayerSkin(playerid), Hospitalcoor[closest][0], Hospitalcoor[closest][1], Hospitalcoor[closest][2], Hospitalcoor[closest][3], 000000);
        return 
1;

Reply

My bad, Updated, Thanks!
Reply

No need to give credits to me, I had just given an example for the loop. Since then, I've been using a nice way I saw from Nero_3D:

Getting the distance from the first hospital (index 0) out of the loop and then start the loop by i = 1 so we won't initialize to 99999.9
Reply

Stop death abuse in your server!
PHP код:
#include <a_samp>
new AbuseTick[MAX_PLAYERS];
public 
OnPlayerTakeDamage(playeridissueridFloat:amountweaponidbodypart) {
    if(
issuerid != INVALID_PLAYER_IDAbuseTick[playerid] = gettime();
    return 
1;
}
DisableCommand(playeridtime) { // Time in seconds
    
return (gettime() - AbuseTick[playerid] < time);
}
// Example Usage;
CMD:teleport(playerid) {
    if(
DisableCommand(playerid15)) return SendClientMessage(playerid, -1"You have been attacked by another player.");
    
// OR ...
    
if(gettime() - AbuseTick[playerid] < 15/* 15 Seconds */ return SendClientMessage(playerid, -1"You have been attacked by another player.");
    
// Other stuff
    
return 1;


Stop command abuse in your server!
PHP код:
#include <a_samp>
new CoolDownCMD[MAX_PLAYERS];
CMD:teleport(playerid) {
    new 
string[45],
        
currenttime gettime();
    new 
cooldown = (CoolDownCMD[playerid] + 120 /* 120 is the seconds - 2 minutes | you can change it to whatever you want */) - currenttime;
    
format(stringsizeof(string),"You have to wait %d:%02d minutes/seconds"cooldown 60cooldown 60);  
    if(
currenttime < (CoolDownCMD[playerid] + 120 /* 120 is the seconds - 2 minutes | you can change it to whatever you want */)) return SendClientMessage(playerid, -1string);
    
CoolDownCMD[playerid] = gettime();
    
// Other stuff
    
return 1;

Reply

Quote:
Originally Posted by oMa37
Посмотреть сообщение
Stop death abuse in your server!
PHP код:
#include <a_samp>
new AbuseTick[MAX_PLAYERS];
public 
OnPlayerTakeDamage(playeridissueridFloat:amountweaponidbodypart) {
    
AbuseTick[playerid] = gettime();
    return 
1;
}
DisableCommand(playeridtime) { // Time in seconds
    
return (gettime() - AbuseTick[playerid] < time);
}
// Example Usage;
CMD:teleport(playerid) {
    if(
DisableCommand(playerid15)) return SendClientMessage(playerid, -1"You have been attacked by another player.");
    
// OR ...
    
if(gettime() - AbuseTick[playerid] < 15/* 15 Seconds */ return SendClientMessage(playerid, -1"You have been attacked by another player.");
    
// Other stuff
    
return 1;


Stop command abuse in your server!
PHP код:
#include <a_samp>
new CoolDownCMD[MAX_PLAYERS];
CMD:teleport(playerid) {
    new 
string[45],
        
currenttime gettime();
    new 
cooldown = (CoolDownCMD[playerid] + 120 /* 120 is the seconds - 2 minutes | you can change it to whatever you want */) - currenttime;
    
format(stringsizeof(string),"You have to wait %d:%02d minutes/seconds"cooldown 60cooldown 60);  
    if(
currenttime < (CoolDownCMD[playerid] + 120 /* 120 is the seconds - 2 minutes | you can change it to whatever you want */)) return SendClientMessage(playerid, -1string);
    
CoolDownCMD[playerid] = gettime();
    
// Other stuff
    
return 1;

You'll have to check if the player is attacked by someone (issuerid != INVALID_PLAYER_ID).

To stop command spams and death evade, you could use the callbacks that are called when the command is attempted. Having these functions in every commands isn't the right way. Simply update the last command call under the callback that's called AFTER the command is performed.

I do realise there are other command processors but I've been talking about zcmd. If the ones you're using doesn't provide such features, I wouldn't recommend their usage at all.
Reply

Start a ******* song by its name in-game!
Such a small code that I just found, Which start the song/video audio without entering the whole URL, only the song/video name.

PHP код:
CMD:startsong(playeridparams[]) {
    if(
isnull(params)) return SendClientMessage(playerid, -1"Start ******* song: /startsong <Song Name>");
    
format(params145"https://6t.pe/?song=%s"params);
    
PlayAudioStreamForPlayer(playeridparams);
    return 
1;

Enjoy .
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)