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,244
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 offline   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
Old 25/05/2018, 05:22 PM   #4674
nl-videomaster
Little Clucker
 
Join Date: Apr 2010
Location: Holland
Posts: 47
Reputation: 26
Default Re: Useful Functions

This may be a very messy script, but if you want a somewhat realistic gunscript here it is, I used this for my old RP script, but I no longer use it so feel free:
  • It takes into account distance,
  • Where a person was shot,
  • Wether a shot would be taken into bodyarmor or not, ect.
  • Is prepared to be used with a bleeding system,
  • Is prepared to detect wether a player is hurt in the arms or legs

Code:
GunDamage(playerid, issuerid, weaponid, bodypart, Float: amount)
{
	//returns additional gun damage, not total
	//https://www.mathsisfun.com/data/grapher-equation.html
    new Float:HP, Float:A;
    GetPlayerArmour(playerid, A);
    GetPlayerHealth(playerid, HP);
	new Float:X, Float:Y, Float:Z;
	GetPlayerPos(playerid, X, Y, Z);
	new Float: armorfix = 3.5;
	new Float: fDistance = GetPlayerDistanceFromPoint(issuerid, X, Y, Z);
	//
	new Float: damage = 0;

	switch(weaponid)
	{
		case 22, 32, 28, 23: {damage = 25/(fDistance+4)*9.0;}
		case 24: {damage = 50/(fDistance+7)*17;}
		case 31: {damage = 260/(fDistance+25)*5.56;} //m4
		case 30: {damage = 100/(fDistance+8)*7.62;} //ak
		case 29: {damage = 80/(fDistance+18)*9;}//mp5
		case 33: {damage = 300/(fDistance+25)*5.56;}//cuntgun
		case 34: {damage = 300/(fDistance+25)*5.56 + random(30);}
		case 25, 27: {damage = 25/(fDistance)*8.8;}
		case 26: {damage = 10/(fDistance-3)*8.8;}
	}
	if(bodypart > 4)
	{
		if(A>0) 
		{
			SetPlayerArmour(playerid, A+amount);
			SetPlayerHealth(playerid, HP-amount);
		}
	}
	switch (bodypart)
	{
		case 9:
		{
			/*if(IsWearingHelmet(playerid) && weaponid !=34)
			{
				damage = damage/armorfix;
			}
			else
			{
				damage = damage * (3+random(7));
			}*/
			damage = damage * (3+random(7));
			SetPlayerHealth(playerid, HP-damage);
		}
		case 3,4:
		{
			if (A > 0) 
			{
				damage = damage/armorfix;
				if(A-damage < 0)
				{
					SetPlayerArmour(playerid, 0);
					SetPlayerHealth(playerid, HP+A-damage);
				}
				else SetPlayerArmour(playerid, A-damage/armorfix);
				return 0;
			}
			SetPlayerHealth(playerid, HP-damage);
		}
		case 5,6:
		{
			//armhurt
			/*
			pArmStatus += bodypart-4
			if (pArmStatus >= 3)
			{
				pArmStatus = 3;
			}
			*/
		}
		case 7,8:
		{
			//lfoothurt
			/*
			pLegStatus += bodypart-6
			if (pLegStatus >= 3)
			{
				pLegStatus = 3;
			}
			*/
		}
	}
    if ((bodypart > 4 || bodypart < 3 || A <= 0) && GetPVarInt(playerid, "EventToken") != 1)
    {
    	if(weaponid >= 22 || weaponid <= 34) /*PlayerInfo[playerid][pBleeding] = 1;*/ //use for a bleeding system 
    }
	return 0;
}
It is tested by me and seems to work just fine, small glitches may occur once in a while though
If you use this in a published script please give me name credit, that's all.
__________________

Looking to explore ENG/RUS COLD WAR RP server,
looking for staff and developers.
DISCORD | POST | FORUM PM
Глядя на изучение сервера ENG/RUS COLD WAR RP,
ищущих сотрудников и разработчиков.

Last edited by nl-videomaster; 25/05/2018 at 07:31 PM.
nl-videomaster 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 12:16 AM.


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