SA-MP Forums

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

Reply
 
Thread Tools Display Modes
Old 10/12/2017, 04:17 AM   #1231
Kar
High-roller
 
Kar's Avatar
 
Join Date: May 2010
Location: Black Asylum
Posts: 3,169
Reputation: 471
Default Re: 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
Kar is offline   Reply With Quote
Old 15/12/2017, 11:03 PM   #1232
IstuntmanI
High-roller
 
IstuntmanI's Avatar
 
Join Date: Mar 2009
Location: Romania
Posts: 1,885
Reputation: 370
Default Re: Useful Snippets

I created this command quickly to find closest vehicles with their components, because I received some warnings in an area because of invalid vehicle mods, so here it is. I don't need it anymore, but it did its job:
PHP Code:
CMD:nearbyvehsplayeridparams[ ] )
{
    new 
lTemp 0Float:lPos] = { 0.00.00.0 };
    new 
Float:lStreamDistance 300.0Float:lDistance 0.0;

    
gBigString] = EOS;
    
strcatgBigString"{FFFFFF}ID (Model)\t{FFFFFF}Streamed In\t{FFFFFF}Components\t{FFFFFF}Coords (Distance)\n" );

    for( new 
1<= MAX_VEHICLES++ )
    {
        if( !
IsValidVehicle) )
            continue;

        
GetVehiclePosilPos], lPos], lPos] );
        
lDistance GetPlayerDistanceFromPointplayeridlPos], lPos], lPos] );
        if( 
lDistance lStreamDistance )
            continue;

        
gComponents] = EOS;

        for( new 
ii 0ii 14ii ++ )
        {
            
lTemp GetVehicleComponentInSlotiii );
            if( 
lTemp == )
                continue;

            
formatgComponents128"%s{FF0000}%d "gComponentslTemp );
        }

        
formatgBigString4096"%s%d (%d)\t%s\t%s\t%f %f %f (%.2f)\n"gBigStringiGetVehicleModel), IsVehicleStreamedIniplayerid ) ? ( "{C3C3C3}YES" ) : ( "{FF0000}NO" ), ( gComponents] == EOS ) ? ( "{FF0000}None" ) : ( gComponents ), lPos], lPos], lPos], lDistance );
    }

    
ShowPlayerDialogplayerid1DIALOG_STYLE_TABLIST_HEADERS"{FFFFFF}Nearby Vehicles:"gBigString"OK""" );
    return 
1;

lStreamDistance was supposed to be the value of stream_distance from Server.cfg, but because GetConsoleVarAsString and GetConsoleVarAsFloat are bugged, I simply added that value in the command without any retrieving.
There's a "Streamed In" column because I thought that vehicles with invalid mods aren't streamed in to the player (I thought that they fail to stream in and so I could detect them easily), but it looks like they are streamed in just like any other vehicle in range.
__________________


IstuntmanI is offline   Reply With Quote
Old 21/12/2017, 07:53 AM   #1233
RogueDrifter
Gangsta
 
RogueDrifter's Avatar
 
Join Date: Dec 2017
Location: SA-MP Drifting world.
Posts: 750
Reputation: 78
Default Re: Useful Snippets

Anti reconnect floods
READ THIS:
This MIGHT return false positives, why? because sometimes players crash on connecting and reconnect too fast, ALTHOUGH this is not very harmful as it doesn't ban it only blocks the player out for 60 seconds.
Why is this isn't like any other anti flooders? because i haven't seen many anti flood systems that counter at OnIncomingConnection ( which doesn't give a chance for the player to connect ).
here's the code using dini by dracoblue or dini2 edited by gammxi, 2 callbacks.
PHP Code:

#define AntiReconnecters "Reconnecters/%s.ini"
#define ReconnectTime 3

new ifile[256],pIPAddress[MAX_PLAYERS][32],iday[MAX_PLAYERS],iyear[MAX_PLAYERS],imonth[MAX_PLAYERS],ihour[MAX_PLAYERS],isec[MAX_PLAYERS],imin[MAX_PLAYERS];

public 
OnIncomingConnection(playeridip_address[], port)
{
    
gettime(ihour[playerid],imin[playerid],isec[playerid]),getdate(iyear[playerid],imonth[playerid],iday[playerid]);
    
format(ifile,sizeof(ifile),AntiReconnecters,ip_address);
    
format(pIPAddress[playerid], 32"%s"ip_address);
    new 
susec[MAX_PLAYERS];
    
susec[playerid] = isec[playerid] - dini_Int(ifile,"SECOND");
    if(!
dini_Exists(ifile))
    {
        
dini_Create(ifile);
        
dini_IntSet(ifile,"YEAR",iyear[playerid]),dini_IntSet(ifile,"MONTH",imonth[playerid]),dini_IntSet(ifile,"DAY",iday[playerid]);
        
dini_IntSet(ifile,"HOUR",ihour[playerid]),dini_IntSet(ifile,"MINUTE",imin[playerid]),dini_IntSet(ifile,"SECOUND",isec[playerid]);
        }
    else
    {
        if(
iyear[playerid] == dini_Int(ifile,"YEAR") && imonth[playerid] == dini_Int(ifile,"MONTH") && iday[playerid] == dini_Int(ifile,"DAY") && ihour[playerid] == dini_Int(ifile,"HOUR") && dini_Int(ifile,"MINUTE") == imin[playerid])
        {
            if(
susec[playerid] > ReconnectTime )
            {
                
BlockIpAddress(ip_address30 1000);
                
Kick(playerid);
                }
            }
        }
    return 
1;
}
public 
OnPlayerDisconnect(playerid,reason)
{
    
gettime(ihour[playerid],imin[playerid],isec[playerid]),getdate(iyear[playerid],imonth[playerid],iday[playerid]);
    
format(ifile,sizeof(ifile),AntiReconnecterspIPAddress[playerid]);
    
dini_IntSet(ifile,"YEAR",iyear[playerid]),dini_IntSet(ifile,"MONTH",imonth[playerid]),dini_IntSet(ifile,"DAY",iday[playerid]);
    
dini_IntSet(ifile,"HOUR",ihour[playerid]),dini_IntSet(ifile,"MINUTE",imin[playerid]),dini_IntSet(ifile,"SECOUND",isec[playerid]);
    return 
1;

READ THIS TOO:
To use it just create a file in ur scriptfiles and name it Reconnecters and put the stuff under OnPlayerDisconnect and OnIncomingConnection and put the defines/variables on top.
to CONTROL it simply by playing with #define ReconnectTime [value]
[value] is what to change lower it for less sensitivity and increase it for more sensitivity BUT NEVER GO BELOW 0 AND ABOVE 59!, default value is advised.
NOTE: Don't change anything if you've never dealt with OnIncomingConnection as it has very limited access to player's information.

Last edited by RogueDrifter; 22/12/2017 at 08:34 PM.
RogueDrifter is offline   Reply With Quote
Old 21/12/2017, 10:26 AM   #1234
AlexMSK
Big Clucker
 
AlexMSK's Avatar
 
Join Date: Apr 2016
Location: United States
Posts: 162
Reputation: 49
Default Re: Useful Snippets

Create a pickup and 3dtext label in the same time!
PHP Code:
stock CreateTextAndPickup(text[], Float:vXUFloat:vYUFloat:vZUvIntvVWpickupidFloat:radius) {
    
CreateDynamic3DTextLabel(text, -1vXUvYUvZUradiusINVALID_PLAYER_IDINVALID_VEHICLE_ID0vVWvInt, -120.0);
    
CreateDynamicPickup(pickupid1vXUvYUvZUvVWvInt);

AlexMSK is offline   Reply With Quote
Old 24/12/2017, 07:54 PM   #1235
Codeah
Big Clucker
 
Codeah's Avatar
 
Join Date: Jun 2016
Location: The Netherlands
Posts: 82
Reputation: 48
Default Re: Useful Snippets

I have recently added all Vehicle Component costs to the wiki (http://wiki.sa-mp.com/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)
{
	new retval = -1;

	if(componentid >= 1000 && componentid <= 1193)
	{
		retval = vehicleComponentPrices[componentid - 1000];
	}

	return retval;
}

Last edited by Codeah; 25/12/2017 at 10:18 AM.
Codeah is offline   Reply With Quote
Old 24/12/2017, 08:03 PM   #1236
RogueDrifter
Gangsta
 
RogueDrifter's Avatar
 
Join Date: Dec 2017
Location: SA-MP Drifting world.
Posts: 750
Reputation: 78
Default Re: Useful Snippets

Quote:
Originally Posted by Codeah View Post
I have recently added all Vehicle Component costs to the wiki (http://wiki.sa-mp.com/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];
}
Wouldn't that return negative values for the ids lower than 1000? shouldn't there be something like
if(componentid <=1000) return vehicleComponentprices[componentid];
else if(componentid >1000) return vehicleComponentprices[componentid-1000];
i might be wrong but let me know how is that snippet going to work with negative values, gj tho it must've taken time to add all of the component ids.
RogueDrifter is offline   Reply With Quote
Old 24/12/2017, 08:09 PM   #1237
Codeah
Big Clucker
 
Codeah's Avatar
 
Join Date: Jun 2016
Location: The Netherlands
Posts: 82
Reputation: 48
Default Re: Useful Snippets

Quote:
Originally Posted by RogueDrifter View Post
Wouldn't that return negative values for the ids lower than 1000? shouldn't there be something like
if(componentid <=1000) return vehicleComponentprices[componentid];
else if(componentid >1000) return vehicleComponentprices[componentid-1000];
i might be wrong but let me know how is that snippet going to work with negative values, gj tho it must've taken time to add all of the component ids.
Vehicle component id's range from 1000 to 1193. But you could always perform a sanity check.

It certainly did, it took me about 3-4 hours. But it was well worth the time.
Codeah is offline   Reply With Quote
Old 24/12/2017, 08:15 PM   #1238
RogueDrifter
Gangsta
 
RogueDrifter's Avatar
 
Join Date: Dec 2017
Location: SA-MP Drifting world.
Posts: 750
Reputation: 78
Default Re: Useful Snippets

Quote:
Originally Posted by Codeah View Post
Vehicle component id's range from 1000 to 1193. But you could always perform a sanity check.

It certainly did, it took me about 3-4 hours. But it was well worth the time.
oooh damn wait i thought that was the actual component id but then i realized they were the prices but aren't those listed on SA-MP wiki ? also is that like Cost x [id - 1000] ?
RogueDrifter is offline   Reply With Quote
Old 24/12/2017, 08:22 PM   #1239
Codeah
Big Clucker
 
Codeah's Avatar
 
Join Date: Jun 2016
Location: The Netherlands
Posts: 82
Reputation: 48
Default Re: Useful Snippets

Quote:
Originally Posted by RogueDrifter View Post
oooh damn wait i thought that was the actual component id but then i realized they were the prices but aren't those listed on SA-MP wiki ? also is that like Cost x [id - 1000] ?
Yes, they are listed on the SA-MP wiki because I added them :P
Codeah is offline   Reply With Quote
Old 24/12/2017, 08:24 PM   #1240
RogueDrifter
Gangsta
 
RogueDrifter's Avatar
 
Join Date: Dec 2017
Location: SA-MP Drifting world.
Posts: 750
Reputation: 78
Default Re: Useful Snippets

Quote:
Originally Posted by Codeah View Post
Yes, they are listed on the SA-MP wiki because I added them :P
oh lmao mb just noticed the page edit date well gj.
RogueDrifter 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 12:22 PM


All times are GMT. The time now is 03:24 AM.


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