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,795
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: 121
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: 330
Reputation: 82
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
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 08:56 AM.


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