SA-MP Forums

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

Reply
 
Thread Tools Display Modes
Old 11/02/2019, 05:28 AM   #1161
Riddick94
Banned
 
Join Date: Mar 2010
Location: Poland
Posts: 1,794
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, 07: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 12:29 AM.
iamjems is offline   Reply With Quote
Old 06/04/2019, 02:42 PM   #1163
Lokii
Huge Clucker
 
Join Date: Sep 2017
Posts: 342
Reputation: 85
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 online now   Reply With Quote
Old 02/07/2019, 04:25 PM   #1164
OstGot
Gangsta
 
OstGot's Avatar
 
Join Date: Mar 2013
Location: Gomel, Belarus
Posts: 817
Reputation: 322
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, 10:47 PM   #1165
Lokii
Huge Clucker
 
Join Date: Sep 2017
Posts: 342
Reputation: 85
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 11:58 AM.
Lokii is online now   Reply With Quote
Old 03/09/2019, 11:40 AM   #1166
OstGot
Gangsta
 
OstGot's Avatar
 
Join Date: Mar 2013
Location: Gomel, Belarus
Posts: 817
Reputation: 322
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, 11:54 AM   #1167
Lokii
Huge Clucker
 
Join Date: Sep 2017
Posts: 342
Reputation: 85
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 online now   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 11:22 AM


All times are GMT. The time now is 07:40 AM.


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