Useful Snippets

Quote:
Originally Posted by verlaj
View Post
PHP Code:
stock PutPlayerInFreeSeat(playerid,vehicleid)
{
    new 
countiSeatoccupied[11];
    for(new 
s=3;s<10;s++)
    {
    foreach(new 
Player)
    {
        if(
GetPlayerVehicleID(i) == vehicleid)
        {
            
count++;
            
iSeat GetPlayerVehicleSeat(i);
            if(
== iSeat)
            {
                
occupied[s] = 1;
            }
        }
        
         if(
!= iSeat && == Iter_Last(Player) && occupied[s] == 0)
        {
            return 
PutPlayerInVehicle(playerid,vehicleid,s);
        }
    }
    }
    
SCM(playerid,COLOR_FIREBRICK,"Vehicle is full of passengers.");
    return 
1;

Code:
isValidVehicleModel(modelid) return (400 <= modelid <= 611);

GetVehicleMaxPassengers(iModel)
{
	if(isValidVehicleModel(iModel)) {
		static s_MaxPassengers[] =
		{
			271782163, 288428337, 288559891, -2146225407, 327282960, 271651075, 268443408, 286339857, 319894289, 823136512, 805311233,
			285414161, 286331697, 268513553, 18026752, 286331152, 286261297, 286458129, 856765201, 286331137, 856690995, 269484528,
			51589393, -15658689, 322109713, -15527663, 65343
		};
		new result = ((s_MaxPassengers[(iModel -= 400) >>> 3] >>> ((iModel & 7) << 2)) & 0xF);
		switch(iModel)
		{
			case 449: result = 3; // Tram
			case 483: result = 2; // Camper
		}
		return result;
	}
	return 0xF;
}

getFreeVehicleSeat(vehicleid, startSeat = 1)
{
	if(!(vehicleid >= 1 && vehicleid < MAX_VEHICLES))
		return -1;

	new bool:sVehicleSeats[8] = {false, ...}, seatid, maxSeats = GetVehicleMaxPassengers(GetVehicleModel(vehicleid));

	if(maxSeats == 0)
		return -1;

	if(maxSeats > 8)
		maxSeats = 8;

	foreach(new i : Character)
	{
		if(IsPlayerInVehicle(i, vehicleid)) {
			seatid = GetPlayerVehicleSeat(i);
			if(seatid >= startSeat && seatid <= maxSeats && seatid != 128)
				sVehicleSeats[seatid] = true;
		}
	}
	for (new i = startSeat; i <= maxSeats; ++i) {
		if(!sVehicleSeats[i]) return i;
	}
	return -1;
}
Change startSeat to 0 if you want to check for the driver.

#KCNRCode
Reply

Quote:
Originally Posted by Codeah
View Post
I have recently added all Vehicle Component costs to the wiki (https://sampwiki.blast.hk/wiki/Car_Component_ID)

This little function will allow you to get the cost of the component

Code:
new vehicleComponentPrices[] =
{
	400, 550, 200, 250, 100, 150, 80, 500, 500, 200, 1000, 220, 250, 100, 400, 500,
	200, 500, 350, 300, 250, 200, 150, 350, 50, 1000, 480, 480, 770, 680, 370, 370,
	170, 120, 790, 150, 500, 690, 190, 390, 500, 390, 1000, 500, 500, 510, 710, 670,
	530, 810, 620, 670, 530, 130, 210, 230, 520, 430, 620, 720, 530, 180, 550, 430,
	830, 850, 750, 250, 200, 550, 450, 550, 450, 1100, 1030, 980, 1560, 1620, 1200,
	1030, 900, 1230, 820, 1560, 1350, 770, 100, 1500, 150, 650, 450, 100, 750, 350,
	450, 350, 1000, 620, 1140, 1000, 940, 780, 830, 3250, 1610, 1540, 780, 780, 780,
	1610, 1540, 0, 0, 3340, 3250, 2130, 2050, 2040, 780, 940, 780, 940, 780, 860, 780,
	1120, 3340, 3250, 3340, 1650, 3380, 3290, 1590, 830, 800, 1500, 1000, 800, 580, 470,
	870, 980, 150, 150, 100, 100, 490, 600, 890, 1000, 1090, 840, 910, 1200, 1030, 1030,
	920, 930, 550, 1050, 1050, 950, 650, 450, 550, 850, 950, 850, 950, 970, 880, 990,
	900, 950, 1000, 900, 1000, 900, 2050, 2150, 2130, 2050, 2130, 2040, 2150, 2040, 2095,
	2175, 2080, 2200, 1200, 1040, 940, 1100
};

stock GetVehicleComponentCost(componentid)
{
	return vehicleComponentPrices[componentid - 1000];
}
so 940 - 1000?

price: -60?

Maybe, if(vehicleComponentPrices[componentid] > 1000) {vehicleComponentPrices[componentid - 1000];}
Reply

Quote:
Originally Posted by rfr
View Post
so 940 - 1000?

price: -60?

Maybe, if(vehicleComponentPrices[componentid] > 1000) {vehicleComponentPrices[componentid - 1000];}
Anything inside of those square brackets is the row, what I'm doing here is using the componentid which was provided in the functions arguments (Ex. 1004) and subtracting 1000, that means that it will access the fourth row in the array.

The price would be -60 if "minus 1000" were to be outside of the square brackets.
Reply

It would still be nice to have some bounds checking in there to avoid invalid memory access.
Reply

FRMT:
PHP Code:
#define frmt(%3,%4,%1,%2) new %3[%4]; \
            
format(%3sizeof(%3), %1, %2
__________________________________________________ ___

now instead of doing this:

PHP Code:
new d[20];
format(d20"Server max slot: %d"GetMaxPlayers());
printf(d); 
you can do this:

PHP Code:
frmt(d20"Server max slot: %d"GetMaxPlayers());
printf(d); 
its not much but you will be able to code format lil bit faster
Reply

Aha thanks! i edited my post with that valid thing and i'll check your implementation once i get time but just a comment shouldn't this:
PHP код:
new bool:is_occupied false
        for(new 
0MAX_PLAYERSp++) 
        { 
            if(!
IsPlayerConnected(p)) continue; //Forgot this, foreach could be even better 
            
if(IsPlayerInVehicle(pi)) 
            { 
                
is_occupied true
                break; 
//avoid any more useless loops, we know the vehicle is occupied 
            

        } 
        if(!
is_occupied//without any driver 
be like this?
PHP код:
new bool:is_occupied[MAX_VEHICLES] = false;
        for(new 
0MAX_PLAYERSp++)
        {
            if(!
IsPlayerConnected(p)) continue; //Forgot this, foreach could be even better
            
if(IsPlayerInVehicle(pi))
            {
                
is_occupied[i] = true;
                break; 
//avoid any more useless loops, we know the vehicle is occupied
            
}
        }
        if(!
is_occupied[i]) //without any driver 
Reply

Quote:
Originally Posted by RogueDrifter
Посмотреть сообщение
Aha thanks! i edited my post with that valid thing and i'll check your implementation once i get time but just a comment shouldn't this:
PHP код:
new bool:is_occupied false
        for(new 
0MAX_PLAYERSp++) 
        { 
            if(!
IsPlayerConnected(p)) continue; //Forgot this, foreach could be even better 
            
if(IsPlayerInVehicle(pi)) 
            { 
                
is_occupied true
                break; 
//avoid any more useless loops, we know the vehicle is occupied 
            

        } 
        if(!
is_occupied//without any driver 
be like this?
PHP код:
new bool:is_occupied[MAX_VEHICLES] = false;
        for(new 
0MAX_PLAYERSp++)
        {
            if(!
IsPlayerConnected(p)) continue; //Forgot this, foreach could be even better
            
if(IsPlayerInVehicle(pi))
            {
                
is_occupied[i] = true;
                break; 
//avoid any more useless loops, we know the vehicle is occupied
            
}
        }
        if(!
is_occupied[i]) //without any driver 
Well, it would be really pointless to use an array for this case (loop through all the unoccupied vehicles), as the variable is_occupied only serves the purpose of telling you whether the vehicle with ID: i is occupied or not and if so it's value changes to true. This line:

PHP код:
if(!is_occupied
Simply checks whether is_occupied was not changed for vehicle ID: i

If you wanted to make an array of the unoccupied vehicles (can't find a use for that) then what you propose might be possible.
Reply

Quote:
Originally Posted by ThePhenix
Посмотреть сообщение
Well, it would be really pointless to use an array for this case (loop through all the unoccupied vehicles), as the variable is_occupied only serves the purpose of telling you whether the vehicle with ID: i is occupied or not and if so it's value changes to true. This line:

PHP код:
if(!is_occupied
Simply checks whether is_occupied was not changed for vehicle ID: i

If you wanted to make an array of the unoccupied vehicles (can't find a use for that) then what you propose might be possible.
Ohh now i see the use for it thanks for the clarification :)
Reply

This function will return the slot of the weapon id you insert into it: GetWeaponSlot(weaponid)
PHP код:
stock GetWeaponSlot(weaponid)
{
    switch(
weaponid)
    {
        case 
0..1:   return 0;
        case 
2..9:   return 1;
        case 
22..24: return 2;
        case 
25..27: return 3;
        case 
28..29: return 4;
        case 
32:     return 4;
        case 
30..31: return 5;
        case 
33..34: return 6;
        case 
35..38: return 7;
        case 
16..18: return 8;
        case 
39:     return 8;
        case 
41..43: return 9;
        case 
10..15: return 10;
        case 
44..46: return 11;
        case 
40:     return 12;
    }
    return 
0;//If invalid return 0 you can change that to whatever u want

Can be helpful if u use GetPlayerWeaponData so you won't need to look online for the weapon's slot.
Reply

*Features:
This system contain, 4 commands, are the following:
-/w (/whisper).
-/cw (whispering inside a car).
-/wspy (spying whisper messages).
-/cwspy (spying car whisper)


*Includes used:
-a_samp...
-Zeex command processor.
-sscanf2


Source:

Includes:

PHP код:
//===Includes===//
#include <a_samp>
#include <zcmd>
#include <sscanf2>
//-------------// 
Variables:
PHP код:
//===Variables===//
new wspy[MAX_PLAYERS];
new 
cwspy[MAX_PLAYERS];
new 
pmspy[MAX_PLAYERS];
new 
IsSpawned[MAX_PLAYERS];
//=================// 
some optimization under public OnPlayerConnect(playerid) callback:

PHP код:
public OnPlayerConnect(playerid)
{
   
IsSpawned[playerid] = 0;
   
wspy[playerid] = 0;
   
cwspy[playerid] = 0;
   
pmspy[playerid] = 0;
   return 
1;

Also under public OnPlayerSpawn(playerid):

PHP код:
public OnPlayerSpawn(playerid)
{
   
IsSpawned[playerid] = 1;
   return 
1;

/*Car Whisper Code:*/
PHP код:
CMD:cw(playeridparams[])
{
        if(
IsSpawned[playerid] == 0) return SendClientMessage(playerid,0xf8f8f8fff,"ERROR: {f00f00}You should be spawned first!");
        new 
string[250], textes[120], name[MAX_PLAYER_NAME];
        
GetPlayerName(playeridname,sizeof(name));
        if (
sscanf(params"s[250]"string))
        {
            
SendClientMessage(playerid0xf8f8f8fff"Syntax: {f48006}/cw <message>");
        }
        else
        {
            if(
IsPlayerInAnyVehicle(playerid))
            {
                new 
vehicleID GetPlayerVehicleID(playerid);
                new 
string2[250];
                
format(string2sizeof(string2), "{adf407}[Car Whisper] {FFFFFF}%s(%i): {adf407}%s",nameplayeridstring);
                for(new 
0<= MAX_PLAYERSi++)
                {
                    if(
IsPlayerInVehicle(ivehicleID))
                    {
                        
SendClientMessage(i, -1string2);
                    }
                }
            }
            else
            {
                
SendClientMessage(playerid,0xf8f8f8fff"ERROR: {F00f00}You are not in a vehicle.");
            }
            for(new 
0<= MAX_PLAYERSi++)
            {
                if(
IsPlayerConnected(i))
                {
                    if(
IsPlayerInAnyVehicle(playerid))
                    {
                        if (
IsPlayerAdmin(i))
                        {
                            if (
cwspy[i])
                            {
                                new 
cwtext[200];
                                
format(cwtextsizeof(cwtext), "{f00f00}[Car Whisper SPY]>> %s: %s",namestringtextes);
                                
SendClientMessage(i, -1cwtext);
                            }
                          }
                      }
                }
            }
        }
        return 
1;

/*Note: you can replaceIsPlayerAdmin(playerid) with your own administrator's system variable.*/

/* Car Whisper Spying */

PHP код:
CMD:cwspy(playeridparams[])
{
    if(
IsSpawned[playerid] == 0) return SendClientMessage(playerid,0xf8f8f8fff,"ERROR: {f00f00}You should be spawned first!");
    if(
IsPlayerConnected(playerid))
    {
        if(
IsPlayerAdmin(playerid))
        {
            if (
cwspy[playerid])
            {
                
cwspy[playerid] = false;
                
SendClientMessage(playerid0xf8f8f8fff"[SERVER] {f41f07}You are not spying on car whisper.");
            }
            else
            {
                
cwspy[playerid] = true;
                
SendClientMessage(playerid0xf8f8f8fff"[SERVER] {adf407}You are now spying on car whisper.");
            }
        }
    }
    return 
1;

/* Whisper */

PHP код:
CMD:w(playeridparams[])
{
        new 
string[250];
        new 
nameplaya[MAX_PLAYER_NAME];
        new 
textes2[120];
        
GetPlayerName(playeridnameplaya,sizeof(nameplaya));
        if(
IsSpawned[playerid] == 0) return SendClientMessage(playerid,0xf8f8f8fff,"ERROR: {f00f00}You should be spawned first!");
        if (
sscanf(params"s[250]"string))
        {
            
SendClientMessage(playerid0xf8f8f8fff"Syntax: {f48006}/(w)hisper <message>");
        }
        else
        {
            new 
Float:x,Float:y,Float:z;
            
GetPlayerPos(playerid,x,y,z);
            new 
string2[250];
            
format(string2sizeof(string2), "{f47e07}[WHISPER] {FFFFFF}%s(%i): {f47e07}%s",nameplayaplayeridstring);
            for(new 
0<= MAX_PLAYERSi++)
            {
                if(
IsPlayerInRangeOfPoint(i15.0xyz))
                {
                    
SendClientMessage(i, -1string2);
                    
PlayerPlaySound(i1085,0.0,0.0,0.0);
                }
                 if(
IsPlayerConnected(i))
                {
                    if(
IsPlayerAdmin(i))
                    {
                         if (
wspy[i])
                        {
                        new 
wtext[200];
                        
format(wtextsizeof(wtext), "{f904e9}[WHISPER SPY]> {FFFFFF}%s: %s",nameplayastringtextes2);
                        
SendClientMessage(i, -1wtext);
                        }
                    }
                }
            }
        }
        return 
1;

/* Whisper spy */

PHP код:
COMMAND:wspy(playeridparams[])
{
    if(
IsSpawned[playerid] == 0) return SendClientMessage(playerid,0xf8f8f8fff,"ERROR: {f00f00}You should be spawned first!");
    if(
IsPlayerConnected(playerid))
    {
        if(
IsPlayerAdmin(playerid))
        {
            if (
wspy[playerid])
            {
                
wspy[playerid] = false;
                
SendClientMessage(playerid0xf8f8f8fff"[SERVER] {f41f07}You are no longer spying on WHISPERS.");
            }
            else
            {
                
wspy[playerid] = true;
                
SendClientMessage(playerid0xf8f8f8fff"[SERVER] {a1f406}You are now spying on WHISPERS.");
            }
        }
    }
    return 
1;

*Whole source code:
PHP код:
//Whisper, Car Whsiper simple systems, with some administration control.
//Made by RxErT
//===Includes===//
#include <a_samp>
#include <zcmd>
#include <sscanf2>
//-------------//
//===Variables===//
new wspy[MAX_PLAYERS];
new 
cwspy[MAX_PLAYERS];
new 
pmspy[MAX_PLAYERS];
new 
IsSpawned[MAX_PLAYERS];
//=================//
public OnPlayerConnect(playerid)
{
   
IsSpawned[playerid] = 0;
   
wspy[playerid] = 0;
   
cwspy[playerid] = 0;
   
pmspy[playerid] = 0;
   return 
1;
}
public 
OnPlayerSpawn(playerid)
{
   
IsSpawned[playerid] = 1;
   return 
1;
}
/*Car Whisper*/
CMD:cw(playeridparams[])
{
        if(
IsSpawned[playerid] == 0) return SendClientMessage(playerid,0xf8f8f8fff,"ERROR: {f00f00}You should be spawned first!");
        new 
string[250], textes[120], name[MAX_PLAYER_NAME];
        
GetPlayerName(playeridname,sizeof(name));
        if (
sscanf(params"s[250]"string))
        {
            
SendClientMessage(playerid0xf8f8f8fff"Syntax: {f48006}/cw <message>");
        }
        else
        {
            if(
IsPlayerInAnyVehicle(playerid))
            {
                new 
vehicleID GetPlayerVehicleID(playerid);
                new 
string2[250];
                
format(string2sizeof(string2), "{adf407}[Car Whisper] {FFFFFF}%s(%i): {adf407}%s",nameplayeridstring);
                for(new 
0<= MAX_PLAYERSi++)
                {
                    if(
IsPlayerInVehicle(ivehicleID))
                    {
                        
SendClientMessage(i, -1string2);
                    }
                }
            }
            else
            {
                
SendClientMessage(playerid,0xf8f8f8fff"ERROR: {F00f00}You are not in a vehicle.");
            }
            for(new 
0<= MAX_PLAYERSi++)
            {
                if(
IsPlayerConnected(i))
                {
                    if(
IsPlayerInAnyVehicle(playerid))
                    {
                        if (
IsPlayerAdmin(i))
                        {
                            if (
cwspy[i])
                            {
                                new 
cwtext[200];
                                
format(cwtextsizeof(cwtext), "{f00f00}[Car Whisper SPY]>> %s: %s",namestringtextes);
                                
SendClientMessage(i, -1cwtext);
                            }
                          }
                      }
                }
            }
        }
        return 
1;
}
/* Car Whisper Spying */
CMD:cwspy(playeridparams[])
{
    if(
IsSpawned[playerid] == 0) return SendClientMessage(playerid,0xf8f8f8fff,"ERROR: {f00f00}You should be spawned first!");
    if(
IsPlayerConnected(playerid))
    {
        if(
IsPlayerAdmin(playerid))
        {
            if (
cwspy[playerid])
            {
                
cwspy[playerid] = false;
                
SendClientMessage(playerid0xf8f8f8fff"[SERVER] {f41f07}You are not spying on car whisper.");
            }
            else
            {
                
cwspy[playerid] = true;
                
SendClientMessage(playerid0xf8f8f8fff"[SERVER] {adf407}You are now spying on car whisper.");
            }
        }
    }
    return 
1;
}
/*Done*/
/* Whisper */
CMD:w(playeridparams[])
{
        new 
string[250];
        new 
nameplaya[MAX_PLAYER_NAME];
        new 
textes2[120];
        
GetPlayerName(playeridnameplaya,sizeof(nameplaya));
        if(
IsSpawned[playerid] == 0) return SendClientMessage(playerid,0xf8f8f8fff,"ERROR: {f00f00}You should be spawned first!");
        if (
sscanf(params"s[250]"string))
        {
            
SendClientMessage(playerid0xf8f8f8fff"Syntax: {f48006}/(w)hisper <message>");
        }
        else
        {
            new 
Float:x,Float:y,Float:z;
            
GetPlayerPos(playerid,x,y,z);
            new 
string2[250];
            
format(string2sizeof(string2), "{f47e07}[WHISPER] {FFFFFF}%s(%i): {f47e07}%s",nameplayaplayeridstring);
            for(new 
0<= MAX_PLAYERSi++)
            {
                if(
IsPlayerInRangeOfPoint(i15.0xyz))
                {
                    
SendClientMessage(i, -1string2);
                    
PlayerPlaySound(i1085,0.0,0.0,0.0);
                }
                 if(
IsPlayerConnected(i))
                {
                    if(
IsPlayerAdmin(i))
                    {
                         if (
wspy[i])
                        {
                        new 
wtext[200];
                        
format(wtextsizeof(wtext), "{f904e9}[WHISPER SPY]> {FFFFFF}%s: %s",nameplayastringtextes2);
                        
SendClientMessage(i, -1wtext);
                        }
                    }
                }
            }
        }
        return 
1;
}
/* Whisper spy */
COMMAND:wspy(playeridparams[])
{
    if(
IsSpawned[playerid] == 0) return SendClientMessage(playerid,0xf8f8f8fff,"ERROR: {f00f00}You should be spawned first!");
    if(
IsPlayerConnected(playerid))
    {
        if(
IsPlayerAdmin(playerid))
        {
            if (
wspy[playerid])
            {
                
wspy[playerid] = false;
                
SendClientMessage(playerid0xf8f8f8fff"[SERVER] {f41f07}You are no longer spying on WHISPERS.");
            }
            else
            {
                
wspy[playerid] = true;
                
SendClientMessage(playerid0xf8f8f8fff"[SERVER] {a1f406}You are now spying on WHISPERS.");
            }
        }
    }
    return 
1;
}
/* Done */ 
If you find anything strange feel free to remind me!
Reply

This function will return true if the player is UNDER water and false if he isn't,
PHP код:
stock IsPlayerUnderWater(playerid)
{
    new 
PPAnim GetPlayerAnimationIndex(playerid);
    return (
PPAnim == 1540 || PPAnim == 1544);

Very simple and basic but yeah didn't see it anywhere.
Reply

Extra functions created by me for extract value from one key in Y_INI:

Код:
// 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;
}
Reply

GetVehicleSpeed:

PHP код:
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:

Код:
type 1 - mph
any other type - kmh
Example:

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

Reply

Код:
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;
			}
		}
	}
}
Reply

^^That won't work for melee weapons.
Reply

Quote:
Originally Posted by Lokii
View Post
forwardex:
I dislike such usage of macros, forwarding is more cleaner.
Reply

Check player skin gender

PHP код:
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;

Reply

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


Код:
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; 
}
Reply

Quote:
Originally Posted by RogerCosta
Посмотреть сообщение
Extra functions created by me for extract value from one key in Y_INI:

Код:
// 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!
Reply

Quote:
Originally Posted by RxErT
Посмотреть сообщение
Ping Kicker

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

Code:

PHP код:
#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.
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)