SA-MP Forums

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

Reply
 
Thread Tools Display Modes
Old 02/04/2018, 12:13 PM   #1261
iKarim
Gangsta
 
iKarim's Avatar
 
Join Date: Oct 2015
Posts: 584
Reputation: 135
Default Re: Useful Snippets

Quote:
Originally Posted by Lokii View Post
forwardex:
I dislike such usage of macros, forwarding is more cleaner.
__________________
Quote:
Originally Posted by Maximun View Post
Did he requested you some 'Kilobytes' in order to post this thread?
iKarim is offline   Reply With Quote
Old 19/04/2018, 03:43 PM   #1262
Lokii
Huge Clucker
 
Join Date: Sep 2017
Posts: 269
Reputation: 72
Default Re: Useful Snippets

Check player skin gender

PHP Code:
static const female_skins[] =
{
    
910111213313940415354555663,
    
6465697576778587888990919293,
    
129130131138139140141145148150151151,
    
157169172178190191192193194195196197,
    
198199201205207211214215216218219224,
    
225226231232233237238243244245246251,
    
256257263298
};

IsFemale(playerid)
{
    for(new 
0sizeof(female_skins); x++)
    {
        if(
GetPlayerSkin(playerid) == female_skins[x]) return 1;
    }
    return 
0;
}

CMD:gender(playerid)
{
    if(
IsFemale(playerid)) return SendClientMessage(playerid0x00FF00FF"Female");
    if(!
IsFemale(playerid)) return SendClientMessage(playerid0xFFFF00FF"Male");
    return 
1;

Lokii is offline   Reply With Quote
Old 22/05/2018, 02:25 PM   #1263
Zorono
Huge Clucker
 
Zorono's Avatar
 
Join Date: Dec 2015
Location: Africa, Egypt, Alexandria
Posts: 353
Reputation: 30
Thumbs up Re: Useful Snippets

A little snippet which checks whether Vehicle's Seat is Taken or not by Vehicle ID&Seat ID(optional)
[hr]

Code:
IsVehicleSeatTaken(vehicleid, seatid = 0)
{
    for(new p = 0; p < GetMaxPlayers(); p++)
    {
        if(!IsPlayerConnected(p)) continue;
        if(GetPlayerVehicleID(p) == vehicleid)
        {
           switch(GetPlayerVehicleSeat(p))
           {
              case -1: return (seatid == GetPlayerVehicleSeat(p));
              case 0: return (seatid == GetPlayerVehicleSeat(p));
              case 1,2,3: return (seatid == GetPlayerVehicleSeat(p));
              default: return false; // to avoid being crashed because of the invalid seat id 128....
           }
        }
    }
    return 0; 
}
Zorono is offline   Reply With Quote
Old 26/05/2018, 08:11 PM   #1264
Gammix
High-roller
 
Gammix's Avatar
 
Join Date: Jan 2015
Location: Canada
Posts: 1,790
Reputation: 822
Default Re: Useful Snippets

Quote:
Originally Posted by RogerCosta View Post
Extra functions created by me for extract value from one key in Y_INI:

Code:
// Global variables
enum {
    INT,
    FLOAT,
    STRING
}

new key_name[50], 
    key_type, 
    key_value_int, 
    Float:key_value_float, 
    key_value_str[128];

stock INI_GetInt(filename[], key[], &variable) {
    INI_ParseFile(filename, "LoadOnlyKey", .bExtra = true, .bLocal = true); 
    format(key_name, sizeof key_name, "%s", key);
    key_type = INT;
    variable = key_value_int;
}

stock INI_GetFloat(filename[], key[], &Float:variable) {
    INI_ParseFile(filename, "LoadOnlyKey", .bExtra = true, .bLocal = true); 
    format(key_name, sizeof key_name, "%s", key);
    key_type = FLOAT;
    variable = key_value_float;
}

stock INI_GetString(filename[], key[], variable[]) {
    INI_ParseFile(filename, "LoadOnlyKey", .bExtra = true, .bLocal = true); 
    format(key_name, sizeof key_name, "%s", key);
    key_type = STRING;
    format(variable, sizeof variable, "%s", key_value_float);
}

forward LoadOnlyKey(name[], value[]) {}
public LoadOnlyKey(name[], value[]) {
    switch(key_type) {
        case STRING:    INI_String(key_name, key_value_str, sizeof key_value_str);
        case FLOAT:     INI_Float(key_name, key_value_float);
        case INT:       INI_Int(key_name, key_value_int);
    }
    return true;
}
You just reinvented Dini but even slower!
__________________

My GitHub:

Gammix is offline   Reply With Quote
Old 26/05/2018, 08:22 PM   #1265
Cell_
Big Clucker
 
Join Date: May 2012
Posts: 121
Reputation: 29
Default Re: Useful Snippets

Quote:
Originally Posted by RxErT View Post
Ping Kicker

Information:
This snippet is all about kicking player, whose having high ping and lagging hard.
-script is editable.

Code:

PHP Code:
#define Ping_Kicker "SNIPPET"
/* Includes */
#include <a_samp>
/* Defines */
new MAX_PING 300//Changeable

/* Beginning */
public OnPlayerUpdate(playerid)
{
   new 
string[120],name[MAX_PLAYER_NAME];
   
GetPlayerName(playeridname,sizeof(name));
   if(
GetPlayerPing(playerid) >= MAX_PING) return Kick(playerid);
   
format(string,sizeof(string),"%s(%i) has been kicked for High ping! [MAX: %s]",name,playerid,MAX_PING);
   
SendClientMessageToAll(-1,string);
   return 
1;

-Not having any bug, if anyone has any trouble with running the script feel free to contact me.
That is actually going to spam your server with messages of players getting kicked with maximum ping warnings when they are still below the maximum ping limit. On top of that, when the players are actually above the maximum limit, other players in the server won't even get the message that the player was kicked. In addition, doing all that under OnPlayerUpdate is a very bad idea.

The only thing you are doing right in that piece of code the checking if the ping exceeds the maximum ping limit and kicking the player. The messages and the code placement is all wrong.
__________________
Cell_ is offline   Reply With Quote
Old 27/05/2018, 09:39 AM   #1266
[HLF]Southclaw
High-roller
 
[HLF]Southclaw's Avatar
 
Join Date: Apr 2009
Location: England
Posts: 4,947
Reputation: 1510
Default Re: Useful Snippets

You have now made the problem worse by starting a timer for every update where the player has exceeded the ping limit. You'll now get the exact same chat spam but 5 seconds later.

Ping does not need to be checked every ~20ms - you can just use a 1 second timer or even 5 second.

Another thing is you don't want to instantly kick someone who just has a momentary ping spike, it happens sometimes and one or two updates with higher ping is not a problem. If you do this you will end up with very angry users.

Instead, what you want to do is store a buffer of ping samples or count the number of times a user has exceeded the limit consecutively then use that data to kick. Here's some very old code that serves as a rough example of that idea: https://github.com/Southclaws/Scaven....pwn#L221-L240
__________________
Tools:

Plugins:

Links:

[HLF]Southclaw is offline   Reply With Quote
Old 27/05/2018, 11:03 AM   #1267
Fungi
Big Clucker
 
Fungi's Avatar
 
Join Date: Dec 2014
Location: Nuclues
Posts: 56
Reputation: 26
Default Re: Useful Snippets

Quote:
Originally Posted by RxErT View Post
Ping Kicker

.....................
sorry but this is a very bad way to do it
Fungi is offline   Reply With Quote
Old 28/05/2018, 08:07 AM   #1268
RxErT
Huge Clucker
 
RxErT's Avatar
 
Join Date: May 2016
Location: SA:MP Lemon
Posts: 256
Reputation: 12
Default Re: Useful Snippets

Quote:
Originally Posted by Fungi View Post
sorry but this is a very bad way to do it
Quote:
Originally Posted by [HLF]Southclaw View Post
You have now made the problem worse by starting a timer for every update where the player has exceeded the ping limit. You'll now get the exact same chat spam but 5 seconds later.

Ping does not need to be checked every ~20ms - you can just use a 1 second timer or even 5 second.

Another thing is you don't want to instantly kick someone who just has a momentary ping spike, it happens sometimes and one or two updates with higher ping is not a problem. If you do this you will end up with very angry users.

Instead, what you want to do is store a buffer of ping samples or count the number of times a user has exceeded the limit consecutively then use that data to kick. Here's some very old code that serves as a rough example of that idea: https://github.com/Southclaws/Scaven....pwn#L221-L240
I'm very thankful for your reply! thank you so much.
__________________
Filterscript:[UPDATED] DM Event [Friendly, Funny, Controllable]
Filterscript:[NEW] New Simple Parkour Event]
Snippet:Whisper and Car whisper commands, controllable
Discord: Flofey#8478
Github: RxErT's profile
Working-on: Administration script Based on SQLite
RxErT is offline   Reply With Quote
Old 28/05/2018, 05:46 PM   #1269
CodeStyle175
Huge Clucker
 
CodeStyle175's Avatar
 
Join Date: Apr 2014
Posts: 469
Reputation: 35
Default Re: Useful Snippets

when you use onplayerupdate, you have to limit the check amount. onplayerupdate is good because, when player is afk it won't be called.
CodeStyle175 is offline   Reply With Quote
Old 28/05/2018, 07:28 PM   #1270
RxErT
Huge Clucker
 
RxErT's Avatar
 
Join Date: May 2016
Location: SA:MP Lemon
Posts: 256
Reputation: 12
Default Re: Useful Snippets

Quote:
Originally Posted by CodeStyle175 View Post
when you use onplayerupdate, you have to limit the check amount. onplayerupdate is good because, when player is afk it won't be called.
Okay! Thanks for this advice!

Although I'm not gonna make it again, SouthClaw already put a link that includes a Ping kicker... so nvm
__________________
Filterscript:[UPDATED] DM Event [Friendly, Funny, Controllable]
Filterscript:[NEW] New Simple Parkour Event]
Snippet:Whisper and Car whisper commands, controllable
Discord: Flofey#8478
Github: RxErT's profile
Working-on: Administration script Based on SQLite
RxErT 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 04:06 AM.


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