SA-MP Forums

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

Reply
 
Thread Tools Display Modes
Old 11/03/2018, 05:48 PM   #1261
Lokii
Big Clucker
 
Join Date: Sep 2017
Posts: 152
Reputation: 59
Default Re: Useful Snippets

GetVehicleSpeed:

PHP Code:
GetVehicleSpeed(vehicleidtype)
{
    new 
s;
    new 
Float:xFloat:yFloat:z;
    
GetVehicleVelocity(vehicleidxyz);
    switch(
type)
    {
        case 
1floatround((floatsqroot(floatpower(x2) + floatpower(y2) + floatpower(z2)))*112.1577floatround_round);
        default: 
floatround((floatsqroot(floatpower(x2) + floatpower(y2) + floatpower(z2)))*180.5000floatround_round);
    }
    return 
s;

Types:

Code:
type 1 - mph
any other type - kmh
Example:

PHP Code:
public sometcallaback(playerid)
{
    new 
str[3];
    
format(strsizeof(str), "%d"GetVehicleSpeed(GetPlayerVehicleID(playerid), 0));
    
GameTextForPlayer(playeridstr1004);
    return 
1;

Lokii is offline   Reply With Quote
Old 13/03/2018, 03:17 PM   #1262
RogerCosta
Huge Clucker
 
RogerCosta's Avatar
 
Join Date: Aug 2014
Location: Santos, Brazil.
Posts: 329
Reputation: 88
Default Re: Useful Snippets

Code:
stock RemovePlayerWeapon(playerid, weaponid) {
	if(GetPlayerWeapon(playerid) == weaponid) {
		GivePlayerWeapon(playerid, weaponid, -GetPlayerAmmo(playerid));
	}
	else {
		new slot, weapon, ammo, currentWeapon = GetPlayerWeapon(playerid);
		for(new i = 0; i < 12; i++) {
			GetPlayerWeaponData(playerid, i, weapon, ammo);
			if(weapon == weaponid && ammo > 0) {
				GivePlayerWeapon(playerid, weaponid, -ammo);
				SetPlayerArmedWeapon(playerid, currentWeapon);
				break;
			}
		}
	}
}
RogerCosta is offline   Reply With Quote
Old 13/03/2018, 03:51 PM   #1263
Gammix
High-roller
 
Gammix's Avatar
 
Join Date: Jan 2015
Location: Canada
Posts: 1,740
Reputation: 793
Default Re: Useful Snippets

^^That won't work for melee weapons.
__________________
Gammix is offline   Reply With Quote
Old 02/04/2018, 12:13 PM   #1264
iKarim
Gangsta
 
iKarim's Avatar
 
Join Date: Oct 2015
Posts: 583
Reputation: 132
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 online now   Reply With Quote
Old 19/04/2018, 03:43 PM   #1265
Lokii
Big Clucker
 
Join Date: Sep 2017
Posts: 152
Reputation: 59
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   #1266
Zorono
Huge Clucker
 
Zorono's Avatar
 
Join Date: Dec 2015
Location: Africa, Egypt, Alexandria
Posts: 363
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   #1267
Gammix
High-roller
 
Gammix's Avatar
 
Join Date: Jan 2015
Location: Canada
Posts: 1,740
Reputation: 793
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!
__________________
Gammix is offline   Reply With Quote
Old 26/05/2018, 08:22 PM   #1268
Cell_
Big Clucker
 
Join Date: May 2012
Posts: 122
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   #1269
[HLF]Southclaw
High-roller
 
[HLF]Southclaw's Avatar
 
Join Date: Apr 2009
Location: England
Posts: 4,885
Reputation: 1443
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   #1270
Fungi
Big Clucker
 
Fungi's Avatar
 
Join Date: Dec 2014
Location: Nuclues
Posts: 53
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
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 06:26 AM.


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