SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Filterscripts

Reply
 
Thread Tools Display Modes
Old 11/02/2019, 06:28 AM   #1161
Riddick94
Banned
 
Join Date: Mar 2010
Location: Poland
Posts: 1,768
Reputation: 223
Default Re: Useful Snippets

Quote:
Originally Posted by Kasichok View Post


Time script

[image]...[/image]

PHP Code:
#include <a_samp>

static timer;
static 
Text:time;

public 
OnFilterScriptInit()
{
    
time TextDrawCreate(552.90020732.800006"00:00");
    
TextDrawLetterSize(time0.4103332.321777);
    
TextDrawAlignment(time1);
    
TextDrawColor(time255);
    
TextDrawSetShadow(time0);
    
TextDrawSetOutline(time1);
    
TextDrawBackgroundColor(time, -2139062017);
    
TextDrawFont(time0);
    
TextDrawSetProportional(time1);
    
timer SetTimer("Update_Time"1000true);
    return 
1;
}

public 
OnFilterScriptExit()
{
    
TextDrawDestroy(time);
    
KillTimer(timer);
    return 
1;
}

public 
OnPlayerConnect(playerid)
{
    
TextDrawShowForPlayer(playeridtime);
    return 
1;
}

forward Update_Time();

public 
Update_Time()
{
    new 
str[6], hm;
    
gettime(hm);
    
format(strsizeof(str), "%02d:%02d"hm);
    
TextDrawSetString(timestr);
    return 
1;

https://en.wikipedia.org/wiki/Snippet_(programming)

Quote:
Originally Posted by Wikipedia
Snippet is a programming term for a small region of re-usable source code, machine code, or text. Ordinarily, these are formally defined operative units to incorporate into larger programming modules.

[...]
Explain me how's your a snippet?
Riddick94 is offline   Reply With Quote
Old 15/02/2019, 08:22 PM   #1162
iamjems
Big Clucker
 
iamjems's Avatar
 
Join Date: Aug 2016
Location: Croatia
Posts: 123
Reputation: 7
Default Re: Useful Snippets

Replacing Discord mentions with the mentioned user's (nick)name


NOTE: dc_Guild must be the ID of your guild (Discord server).

PHP Code:
ReplaceDiscordMentions(const message[])
{    
    new 
DCC_User:mention_id
        
mention_name[33],
        
user[19],
        
string[166], 
        
pos;

    
format(stringsizeof(string), message);

    for(new 
isizeof(string); i++)
    {    
        if(
string[i] == '<' && string[1] == '@')
        {    
            
pos i;

            if(
string[2] == '!')
                
i++;

            
strmid(userstring221);

            
mention_id DCC_FindUserById(user);

            if(!
mention_id)
                continue;

            
DCC_GetGuildMemberNickname(dc_Guildmention_idmention_name);

            if(
isnull(mention_name))
                
DCC_GetUserName(mention_idmention_name);

            
format(mention_namesizeof(mention_name), "@%s"mention_name);

            
strdel(stringpospos 21 + (pos));
            
strins(stringmention_namepos);
        }
    }

    return 
string;

USAGE:

PHP Code:
public DCC_OnChannelMessage(DCC_Channel:channelDCC_User:author, const message[])
{
    if(
channel == yourDiscordChannel)
    {    
        
SendClientMessageToAll(-1ReplaceDiscordMentions(message));
    }

    return 
1;

This code will transform this:

hello <@172459264917204728>
OR
hello <@!172459264917204728>

to this:

hello @John

Last edited by iamjems; 16/02/2019 at 01:29 AM.
iamjems is offline   Reply With Quote
Old 06/04/2019, 03:42 PM   #1163
Lokii
Huge Clucker
 
Join Date: Sep 2017
Posts: 375
Reputation: 87
Default Re: Useful Snippets

Anti Rapid Fire

PHP Code:
#include <a_samp>

static const Rapid_Amount[17] =
{
    
10755101025151515253400075
};

static 
p_bullets_wep[MAX_PLAYERS] = {0,...};
static 
p_bullets_timer[MAX_PLAYERS] = {-1,...};
static 
p_bullets[MAX_PLAYERS] = {0,...};

public 
OnPlayerConnect(playerid)
{
    
p_bullets_wep[playerid] = 0;
    
p_bullets[playerid] = 0;
    
p_bullets_timer[playerid] = SetTimerEx("RAPID_TIMER"1000true"d"playerid);
    return 
1;
}

public 
OnPlayerDisconnect(playeridreason)
{
    
p_bullets_wep[playerid] = 0;
    
p_bullets[playerid] = 0;
    
KillTimer(p_bullets_timer[playerid]);
    
p_bullets_timer[playerid] = -1;
    return 
1;
}

forward RAPID_TIMER(playerid);

public 
RAPID_TIMER(playerid)
{
    new 
str[48], name[24];
    if(
p_bullets[playerid] >= Rapid_Amount[p_bullets_wep[playerid]-22])
    {
        
GetPlayerName(playeridname24);
        
format(str48"%s kicked for rapid fire"name);
        
SendClientMessageToAll(0xFF0000FFstr);
        
Kick(playerid); //the hacker wont see the message, if you want the hacker to see the message delay the kick.
    
}
    
p_bullets[playerid] = 0;
    return 
1;
}

public 
OnPlayerWeaponShot(playeridweaponidhittypehitidFloat:fXFloat:fYFloat:fZ)
{
    
p_bullets_wep[playerid] = weaponid;
    
p_bullets[playerid] ++;
    return 
1;

__________________
Lokii is offline   Reply With Quote
Old 02/07/2019, 05:25 PM   #1164
OstGot
Gangsta
 
OstGot's Avatar
 
Join Date: Mar 2013
Location: Gomel, Belarus
Posts: 865
Reputation: 325
Default Re: Useful Snippets

Here are the coordinates of all garages from the game, the doors of which open and close to the player when he approaches them. Note: this is taken from mta wiki and adapted to use as pawn array

Code:
new const Float:GaragesCoords[][] =
{
	{1643.43, -1521.95, 13.56},
	{1877.30, -2097.85, 13.53},
	{1842.32, -1856.37, 13.38},
	{1797.62, -2146.73, 13.55},
	{1699.06, -2089.99, 13.55},
	{2741.21, -2003.46, 13.55},
	{2644.90, -2038.41, 13.55},
	{2072.40, -1831.38, 13.55},
	{2505.68, -1689.95, 13.56},
	{1041.42, -1026.78, 32.10},
	{1025.09, -1030.52, 32.04},
	{488.41, -1733.88, 11.18},
	{322.60, -1769.86, 4.72},
	{1353.23, -625.68, 109.13},
	{-2715.30, 217.61, 4.32},
	{-2730.48, 74.22, 4.34},
	{-2455.66, -123.73, 26.09},
	{-1935.88, 237.90, 34.31},
	{-1904.53, 276.63, 41.05},
	{-2101.90, -16.07, 35.32},
	{-2026.94, 130.57, 28.84},
	{-2038.18, 178.87, 28.84},
	{-1786.78, 1208.87, 25.13},
	{-2105.22, 897.84, 76.71},
	{-2425.70, 1029.37, 50.39},
	{-2695.94, 820.34, 49.98},
	{1585.90, 1226.73, 10.81},
	{2609.68, 1436.90, 10.82},
	{2386.75, 1042.44, 10.82},
	{2448.44, 697.76, 11.46},
	{2006.11, 2302.69, 10.82},
	{1967.55, 2162.43, 10.82},
	{1407.23, 1902.37, 11.46},
	{1280.85, 2529.82, 10.82},
	{928.43, 2011.86, 11.46},
	{-1420.43, 2591.78, 55.82},
	{-100.00, 1110.53, 19.74},
	{-360.72, 1193.05, 19.74},
	{428.90, 2546.57, 16.21},
	{-388.78, 2228.05, 42.43},
	{404.97, 2478.38, 16.48},
	{-2113.93, -2459.94, 30.63},
	{719.96, -464.34, 16.34},
	{2231.22, 167.27, 27.48},
	{785.95, -494.23, 17.34}
};
__________________
aka Nexius
Don't want to always check for updates of my scripts?
Include it the last, after all others
Nexius's Update Checker
OstGot is offline   Reply With Quote
Old 02/09/2019, 11:47 PM   #1165
Lokii
Huge Clucker
 
Join Date: Sep 2017
Posts: 375
Reputation: 87
Default Re: Useful Snippets

Fix knife desync
PHP Code:
public OnPlayerDeath(playeridkilleridreason)
{
    if(
reason == 4)
    {
        new 
world GetPlayerVirtualWorld(playerid);
        
SetPlayerVirtualWorld(playeridplayerid+1); //you can change player+1 to something else if you want
        
SetPlayerVirtualWorld(playeridworld);
    }
    return 
1;

__________________

Last edited by Lokii; 03/09/2019 at 12:58 PM.
Lokii is offline   Reply With Quote
Old 03/09/2019, 12:40 PM   #1166
OstGot
Gangsta
 
OstGot's Avatar
 
Join Date: Mar 2013
Location: Gomel, Belarus
Posts: 865
Reputation: 325
Default Re: Useful Snippets

Quote:
Originally Posted by Lokii View Post
Fix knife desync
PHP Code:
public OnPlayerDeath(playeridkilleridreason)
{
    if(
reason == 4)
    {
        
SetPlayerVirtualWorld(playeridplayerid+1);
        
SetPlayerVirtualWorld(playerid0);
    }
    return 
1;

And what if the player killed in vw more that 0? For example, some servers have dm areas in other interiors and virtual worlds or something, so it's more correct to return the previous player's virtual world which you can get via GetPlayerVirtualWorld, put it in a variable before the first vw change and give to a player after it.
__________________
aka Nexius
Don't want to always check for updates of my scripts?
Include it the last, after all others
Nexius's Update Checker
OstGot is offline   Reply With Quote
Old 03/09/2019, 12:54 PM   #1167
Lokii
Huge Clucker
 
Join Date: Sep 2017
Posts: 375
Reputation: 87
Default Re: Useful Snippets

Quote:
Originally Posted by OstGot View Post
And what if the player killed in vw more that 0? For example, some servers have dm areas in other interiors and virtual worlds or something, so it's more correct to return the previous player's virtual world which you can get via GetPlayerVirtualWorld, put it in a variable before the first vw change and give to a player after it.
Updated
__________________
Lokii is offline   Reply With Quote
Old 27/09/2019, 09:00 AM   #1168
AbyssMorgan
Banned
 
Join Date: Apr 2015
Location: Poland
Posts: 1,213
Reputation: 352
Default Re: Useful Snippets

I don't have snippets but i want say i come to release next 6 scripts in this year

Last edited by AbyssMorgan; 03/10/2019 at 09:57 AM.
AbyssMorgan is offline   Reply With Quote
Old 05/11/2019, 06:58 PM   #1169
Lokii
Huge Clucker
 
Join Date: Sep 2017
Posts: 375
Reputation: 87
Default Re: Useful Snippets


Rainbow Car



PHP Code:
#include <a_samp>
#include <foreach>
#include <zcmd>

#define CAR_RAINBOW_DELAY (150)
static bool:car_rainbow[MAX_PLAYERS char] = {false,...};
static 
car_rainbow_timer;

public 
OnFilterScriptInit()
{
    
car_rainbow_timer SetTimer("CarRainbow"CAR_RAINBOW_DELAYtrue);
    return 
1;
}

public 
OnFilterScriptExit()
{
    
KillTimer(car_rainbow_timer);
    return 
1;
}

forward CarRainbow();

public 
CarRainbow()
{
    foreach(new 
Player)
    {
        if(!
car_rainbow{i} || GetPlayerState(i) != 2) continue;
        
ChangeVehicleColor(GetPlayerVehicleID(i), random(255), random(255));
    }
    return 
1;
}

CMD:rainbowcar(playeridparams[])
{
    if(!
car_rainbow{playerid})
    {
        
SendClientMessage(playerid0xFFFF00FF"Rainbow Car Set ON");
        
car_rainbow{playerid} = true;
        
PlayerPlaySound(playerid10570.00.00.0);
        return 
1;
    }
    
SendClientMessage(playerid0xFFFF00FF"Rainbow Car Set OFF");
    
car_rainbow{playerid} = false;
    
PlayerPlaySound(playerid10580.00.00.0);
    return 
1;
}

public 
OnPlayerDisconnect(playeridreason)
{
    
car_rainbow{playerid} = false;
    return 
1;

__________________
Lokii is offline   Reply With Quote
Old 05/11/2019, 07:02 PM   #1170
Lokii
Huge Clucker
 
Join Date: Sep 2017
Posts: 375
Reputation: 87
Default Re: Useful Snippets


Display Vehicle Names (random Color + fade)



PHP Code:
#include <a_samp>

static const RandomColors[][] =
{
    
"~r~""~w~""~g~""~b~""~y~""~p~",
    
"~r~~h~""~g~~h~""~y~~h~""~p~~h~""~b~~h~",
    
"~r~~h~~h~""~g~~h~~h~""~y~~h~~h~""~p~~h~~h~""~b~~h~~h~"
};

static const 
VehicleNames[][] =
{
    
"Landstalker""Bravura""Buffalo""Linerunner""Perrenial""Sentinel",
    
"Dumper""Firetruck""Trashmaster""Stretch""Manana""Infernus",
    
"Voodoo""Pony""Mule""Cheetah""Ambulance""Leviathan""Moonbeam",
    
"Esperanto""Taxi""Washington""Bobcat""Whoopee""BF Injection",
    
"Hunter""Premier""Enforcer""Securicar""Banshee""Predator""Bus",
    
"Rhino""Barracks""Hotknife""Trailer""Previon""Coach""Cabbie",
    
"Stallion""Rumpo""RC Bandit""Romero""Packer""Monster""Admiral",
    
"Squalo""Seasparrow""Pizzaboy""Tram""Trailer""Turismo""Speeder",
    
"Reefer""Tropic""Flatbed""Yankee""Caddy""Solair""Berkley's RC Van",
    
"Skimmer""PCJ-600""Faggio""Freeway""RC Baron""RC Raider""Glendale",
    
"Oceanic","Sanchez""Sparrow""Patriot""Quad""Coastguard""Dinghy",
    
"Hermes""Sabre""Rustler""ZR-350""Walton""Regina""Comet""BMX",
    
"Burrito""Camper""Marquis""Baggage""Dozer""Maverick""News Chopper",
    
"Rancher""FBI Rancher""Virgo""Greenwood""Jetmax""Hotring""Sandking",
    
"Blista Compact""Police Maverick""Boxville""Benson""Mesa""RC Goblin",
    
"Hotring Racer A""Hotring Racer B""Bloodring Banger""Rancher""Super GT",
    
"Elegant""Journey""Bike""Mountain Bike""Beagle""Cropduster""Stunt",
     
"Tanker""Roadtrain""Nebula""Majestic""Buccaneer""Shamal""Hydra",
     
"FCR-900""NRG-500""HPV1000""Cement Truck""Tow Truck""Fortune",
     
"Cadrona""FBI Truck""Willard""Forklift""Tractor""Combine""Feltzer",
     
"Remington""Slamvan""Blade""Freight""Streak""Vortex""Vincent",
    
"Bullet""Clover""Sadler""Firetruck""Hustler""Intruder""Primo",
    
"Cargobob""Tampa""Sunrise""Merit""Utility""Nevada""Yosemite",
    
"Windsor""Monster""Monster""Uranus""Jester""Sultan""Stratium",
    
"Elegy""Raindance""RC Tiger""Flash""Tahoma""Savanna""Bandito",
    
"Freight Flat""Streak Carriage""Kart""Mower""Dune""Sweeper",
    
"Broadway""Tornado""AT-400""DFT-30""Huntley""Stafford""BF-400",
    
"News Van""Tug""Trailer""Emperor""Wayfarer""Euros""Hotdog""Club",
    
"Freight Box""Trailer""Andromada""Dodo""RC Cam""Launch""Police Car",
     
"Police Car""Police Car""Police Ranger""Picador""S.W.A.T""Alpha",
     
"Phoenix""Glendale""Sadler""Luggage""Luggage""Stairs""Boxville",
     
"Tiller""Utility Trailer"
};

public 
OnPlayerStateChange(playeridnewstateoldstate)
{
    new 
string[22];
    if(
newstate == 2)
    {
        
format(string22"%s%s"RandomColors[random(sizeof(RandomColors))], VehicleNames[GetVehicleModel(GetPlayerVehicleID(playerid))-400]);
        
GameTextForPlayer(playeridstring20001);
    }
    return 
1;

__________________
Lokii is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
READ Usefull Links to snippets and other -Sneaky- Help Archive 5 02/05/2009 12:22 PM


All times are GMT. The time now is 10:29 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.