SA-MP Forums

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

Reply
 
Thread Tools Display Modes
Old 16/11/2017, 05:44 PM   #4671
Eoussama
High-roller
 
Eoussama's Avatar
 
Join Date: Jul 2016
Location: Kingdom of Morocco // Tangier
Posts: 1,245
Reputation: 193
Default Re: Useful Functions

GetClosestLocation


A simple function that takes multiple coordinates packed into an array and returns the closest position index to the player.

- Function

PHP Code:
GetClosestLocation(playeridFloat:_cords[][3], size sizeof(_cords))
{
    new 
closestFloat:lastDist GetPlayerDistanceFromPoint(playerid_cords[closest][0], _cords[closest][1], _cords[closest][2]), Float:dist;

    for(new 
ii<sizei++)
    {
        
dist GetPlayerDistanceFromPoint(playerid_cords[i][0], _cords[i][1], _cords[i][2]);

        if(
dist lastDist)
        {
            
closest i;
            
lastDist dist;
        }
    }

    return 
closest;

- Usage

PHP Code:
main()
{
      new 
Float:_cords[][3] = {
              {
1552.614379,-1675.769287,15.195312},
              {-
1605.645019,711.671936,12.867186},
              {
2288.943603,2429.486083,9.820312}
             },
            
_closest;

      
_closest GetClosestIndex(playerid_cords);

__________________

|===[Web taxi]===|
List of my work
Github
Pastebin

|===[Interesting topics]===|
Semantic Versioning


Eoussama is online now   Reply With Quote
Old 16/12/2017, 12:55 PM   #4672
OstGot
Gangsta
 
OstGot's Avatar
 
Join Date: Mar 2013
Location: Gomel, Belarus
Posts: 692
Reputation: 293
Default Re: Useful Functions

SplitColor function
This is a pawn version of the same function in open-samp source code, which checks the string for color codes like {FFFF00} and deletes them. Useful for use in dialogs in which a player can enter his own text. An additional feature of the implementation is the correct removal of even such constructions as {FFFF00{FF00FF}}

PHP Code:
stock SplitColor(str[])
{
    if(
strlen(str) >= 8)
    {
        new 
ij;
        do
        {
            if(
str[i] == '{' && strlen(str[i]) >= && str[7] == '}'//First checking
            
{
                for(
17j++)
                {
                    if(!(
'A' <= str[j] <= 'F' || 'a' <= str[j] <= 'f' || '0' <= str[j] <= '9'))
                    {
                        
+= 8;
                        
= -1;
                        break;
                    }
                }
                if(
!= -1strdel(stri8);
            }
            else if(
str[i] == '}' && >= && str[7] == '{'-= 7//Check split glitch like "{FF0000{000000}} H4x0r !"
            
else i++;
        }
        while(
str[i]);
    }

__________________
aka Nexius
Don't want to always check for updates of my scripts?
Include it the last, after all others
Nexius's Update Checker

Last edited by OstGot; 15/01/2018 at 05:38 PM. Reason: Some important fixes, thanks to Jefff
OstGot is offline   Reply With Quote
Old 11/01/2018, 06:36 PM   #4673
Jefff
High-roller
 
Join Date: Dec 2007
Posts: 2,608
Reputation: 308
Default Re: Useful Functions

It can be done without bool:remove and should be j < i + 7;

Code:
for(j = i + 1; j < i + 7; j++)
{
	if(!('A' <= str[j] <= 'F' || 'a' <= str[j] <= 'f' || '0' <= str[j] <= '9'))
	{
		i += 8;
		j = -1; // bool:removed
		break;
	}
}
then

Code:
if(j != -1) strdel(str, i, i + 8);
Jefff 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
[Include] [INC] LSF - Lorenc's Simple Functions (w/ gang/clan functions) Lorenc_ Includes 14 21/04/2018 04:06 AM
Functions? sciman001 Help Archive 7 19/03/2011 03:03 PM
How to get functions? Twain32 Help Archive 4 08/10/2010 07:37 PM
[Include] [INC] SA:MP New Functions 0.4a DKN ipsBruno Lançamentos/Releases 22 17/06/2010 08:38 AM
What this functions do? harrold Help Archive 2 08/05/2009 11:30 PM


All times are GMT. The time now is 08:50 AM.


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