SA-MP Forums

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

Reply
 
Thread Tools Display Modes
Old 05/06/2008, 07:18 PM   #11
boemeles
Gangsta
 
Join Date: Aug 2007
Posts: 814
Reputation: 1
Default Re: Useful Functions

In addition to Andre:
NOTE! this is not made by me, i dont take any credits!

use this in your script:
Code:
if(!IsPlayerInInvalidNosVehicle(playerid, vehicleid) //notice the "!"

Code:
//----------[ IsPlayerInValidNosVehicle made by [fackin']luke]---------------------
IsPlayerInInvalidNosVehicle(playerid,vehicleid)
{
  #define MAX_INVALID_NOS_VEHICLES 29

  new InvalidNosVehicles[MAX_INVALID_NOS_VEHICLES] =
  {
	581,523,462,521,463,522,461,448,468,586,
	509,481,510,472,473,493,595,484,430,453,
	452,446,454,590,569,537,538,570,449
  };

  vehicleid = GetPlayerVehicleID(playerid);

  if(IsPlayerInVehicle(playerid,vehicleid))
  {
		for(new i = 0; i < MAX_INVALID_NOS_VEHICLES; i++)
		{
		  if(GetVehicleModel(vehicleid) == InvalidNosVehicles[i])
		  {
		    return true;
		  }
		}
  }
  return false;
}
// end of it!
boemeles is offline   Reply With Quote
Old 06/06/2008, 02:27 AM   #12
Luk0r
Big Clucker
 
Join Date: Jun 2007
Posts: 122
Reputation: 2
Default Re: Useful Functions

CheckPlayerName - checks a string to ensure it follows the traditional Firstname_Lastname roleplay name format

Returns:
0 - Invalid roleplay name
1 - Valid roleplay name

Code:
CheckPlayerName(const name[]) // by Luk0r
{
	if (strlen(name) < 6) return 0;
	if (strfind(name, "_", true) == -1) return 0;
	new underscorecount, expectinguppercase = 1;
	for (new i = 0, j = strlen(name); i < j; i++)
	{
		if (expectinguppercase == 1)
		{
			if (name[i] < 'A' || name[i] > 'Z') return 0;
			expectinguppercase = 0;
			continue;
		}
		switch (name[i])
		{
			case '_':
			{
				if (underscorecount == 1) return 0;
				else
				{
					underscorecount = 1;
					expectinguppercase = 1;
				}
				continue;
			}
			case 'A' .. 'Z': continue;
			case 'a' .. 'z': continue;
			default: return 0;
		}
	}
	return 1;
}
Luk0r is offline   Reply With Quote
Old 06/06/2008, 06:09 AM   #13
boemeles
Gangsta
 
Join Date: Aug 2007
Posts: 814
Reputation: 1
Default Re: Useful Functions

Again: to complete andre's list: IsABoat

IsABoat(carid)
carid - Vehicle ID that we check
Code:
stock IsABoat(carid)
{
  new Operative[] = { 472, 473, 493, 495, 484, 430, 454, 453, 452, 446 };
  for(new i = 0; i < sizeof(Operative); i++)
  {
	if(GetVehicleModel(carid) == i) return 1;
  }
  return 0;
}

boemeles is offline   Reply With Quote
Old 06/06/2008, 06:33 AM   #14
boemeles
Gangsta
 
Join Date: Aug 2007
Posts: 814
Reputation: 1
Default Re: Useful Functions

Quote:
Originally Posted by Andre9977
Quote:
Originally Posted by [ߣ®†
$!7£Ñ©!Õ™ ]
Again: to complete andre's list: IsABoat
Thank you.
I hope you don't mind - I added to my post with your credit and link to your account of course.
no problem, you could clearly see i used your layout!
boemeles is offline   Reply With Quote
Old 06/06/2008, 11:28 AM   #15
boylett
Gangsta
 
Join Date: Jul 2006
Posts: 656
Reputation: 0
Default Re: Useful Functions

RPName
Returns first and last name of an RP style name (e.g. John_Bortch will return John and Bortch). It returns 0 if the RP Name isnt valid

Code:
RPName(name[],ret_first[],ret_last[])
{
	new len = strlen(name),
		point = -1,
		bool:done = false;
	for(new i = 0; i < len; i++)
	{
	  if(name[i] == '_')
	  {
	    if(point != -1) return 0;
	    else {
				if(i == 0) return 0;
				point = i + 1;
			}
	  } else if(point == -1) ret_first[i] = name[i];
	  else {
			ret_last[i - point] = name[i];
			done = true;
		}
	}
	if(!done) return 0;
	return 1;
}
Usage:
Code:
public OnPlayerConnect(playerid)
{
	new name[MAX_PLAYER_NAME], first[MAX_PLAYER_NAME], last[MAX_PLAYER_NAME], ret;
	GetPlayerName(playerid,name,sizeof(name));
	if(RPName(name,first,last))
	{
		// Valid name, player is called first_last
	} else {
	  // Invalid name, deal accordingly
	}
	return 1;
}
strtok

Code:
strtok(string[],&idx,seperator = ' ')
{
	new ret[128], i = 0, len = strlen(string);
	while(string[idx] == seperator && idx < len) idx++;
	while(string[idx] != seperator && idx < len)
	{
	  ret[i] = string[idx];
	  i++;
		idx++;
	}
	while(string[idx] == seperator && idx < len) idx++;
	return ret;
}
rand
An exact copy of the function "rand" in PHP.

Code:
rand(minnum = cellmin,maxnum = cellmax) return random(maxnum - minnum + 1) + minnum;

GetVehicleName
Returns the vehicle name from a modelid.
http://boylett.pastebin.com/f3a9a059c

Float:GetPointDistanceToPoint
Code:
Float:GetPointDistanceToPoint(Float:x1,Float:y1,Float:x2,Float:y2)
{
  new Float:x, Float:y;
  x = x1-x2;
  y = y1-y2;
  return floatsqroot(x*x+y*y);
}
Float:GetPointDistanceToPointEx
Code:
Float:GetPointDistanceToPointEx(Float:x1,Float:y1,Float:z1,Float:x2,Float:y2,Float:z2)
{
  new Float:x, Float:y, Float:z;
  x = x1-x2;
  y = y1-y2;
  z = z1-z2;
  return floatsqroot(x*x+y*y+z*z);
}
boylett is offline   Reply With Quote
Old 07/06/2008, 08:12 AM   #16
boemeles
Gangsta
 
Join Date: Aug 2007
Posts: 814
Reputation: 1
Default Re: Usefull Functions

Quote:
Originally Posted by DragSta
It also wont work
Code:
GetPlayerScore(playerid);
AHHH! stupid me! well here's one that does work!

GivePlayerVehicle(playerid, vehicleid);
Code:
stock GivePlayerVehicle(playerid, vehicleid)
{
	if(!IsPlayerInAnyVehicle(playerid) && vehicleid > 399 && vehicleid < 612)
	{
		new Float:x, Float:y, Float:z, Float:a, vehicle;
		GetPlayerPos(playerid, x, y, z);
		GetPlayerFacingAngle(playerid, a);
		vehicle = CreateVehicle(vehicleid, x, y, z, a, -1, -1, 50000);
		PutPlayerInVehicle(playerid, vehicle, 0);
	}
}

saves a lot of time when u need to to do this eveytime you want to spawn a vehicle!

boemeles is offline   Reply With Quote
Old 07/06/2008, 04:41 PM   #17
LarzI
High-roller
 
LarzI's Avatar
 
Join Date: Apr 2007
Location: Norway
Posts: 3,501
Reputation: 133
Default Re: Useful Functions

Not all is made by me, but some!



GetObjectToPlayerDistance(playerid, objectid);
Code:
stock GetObjectToPlayerDistance(playerid, objectid) //By me, Credits: Whoever made GetDistanceBetweenPlayers
{
	new Float:ox, Float:oy, Float:oz, Float:px, Float:py, Float:pz;
	new Float:distance;
	GetObjectPos(objectid, ox, oy, oz);
	GetPlayerPos(playerid, px, py, pz);
	distance = floatsqroot(floatpower(floatabs(floatsub(ox, px)),2)+floatpower(floatabs(floatsub(oy, py)),2)+floatpower(floatabs(floatsub(oz, pz)),2));
	return floatround(distance);
}

GetDistanceFromPlayerToVehicle(playerid, vehicleid);
Code:
stock GetDistanceFromPlayerToVehicle(playerid, vehicleid)
{
	new Float:x1,Float:y1,Float:z1,Float:x2,Float:y2,Float:z2;
	new Float:tmpdis;
	GetPlayerPos(playerid,x1,y1,z1);
	GetVehiclePos(vehicleid2,x2,y2,z2);
	tmpdis = floatsqroot(floatpower(floatabs(floatsub(x2,x1)),2)+floatpower(floatabs(floatsub(y2,y1)),2)+floatpower(floatabs(floatsub(z2,z1)),2));
	return floatround(tmpdis);
}

GetVehiclePlayerID(vehicleid);
Code:
stock GetVehiclePlayerID(vehicleid)
{
	for(new i=0; i<MAX_PLAYERS; i++)
	{
		if(vehicleid == GetPlayerVehicleID(i))
		{
			return vehicleid;
		}
	}
	return INVALID_PLAYER_ID;
}

GetDistanceBetweenVehicles(vehicleid, vehicleid2);
Code:
stock GetDistanceBetweenVehicles(vehicleid, vehicleid2)
{
	new Float:x1,Float:y1,Float:z1,Float:x2,Float:y2,Float:z2;
	new Float:tmpdis;
	GetVehiclePos(vehicleid,x1,y1,z1);
	GetVehiclePos(vehicleid2,x2,y2,z2);
	tmpdis = floatsqroot(floatpower(floatabs(floatsub(x2,x1)),2)+floatpower(floatabs(floatsub(y2,y1)),2)+floatpower(floatabs(floatsub(z2,z1)),2));
	return floatround(tmpdis);
}

GetDistanceBetweenPlayers(playerid, playerid2)
Code:
stock GetDistanceBetweenPlayers(playerid, playerid2)
{
	new Float:x1,Float:y1,Float:z1,Float:x2,Float:y2,Float:z2;
	new Float:tmpdis;
	GetPlayerPos(playerid,x1,y1,z1);
	GetPlayerPos(playerid2,x2,y2,z2);
	tmpdis = floatsqroot(floatpower(floatabs(floatsub(x2,x1)),2)+floatpower(floatabs(floatsub(y2,y1)),2)+floatpower(floatabs(floatsub(z2,z1)),2));
	return floatround(tmpdis);
}

GetPlayerVehicleModel(playerid);
Code:
stock GetPlayerVehicleModel(playerid)
{
	new vehicleid = GetPlayerVehicleID(playerid);
	new model = GetVehicleModel(vehicleid);
	return model;
}
__________________


NEW: [FS] Simple Cellphones

if( strfind( title, "REP", true ) != -1 )
{________________________________________
Sigh();__________________________
}________________________________________


LarzI is offline   Reply With Quote
Old 07/06/2008, 04:50 PM   #18
boemeles
Gangsta
 
Join Date: Aug 2007
Posts: 814
Reputation: 1
Default Re: Useful Functions

SafeKill(playerid);
Makes you spawn without losing weapons
Code:
stock SafeKill(playerid)
{
  new Weapons[MAX_PLAYERS][11], Ammo[MAX_PLAYERS][11]; // news
  for(new j=0; j<11; j++)	GetPlayerWeaponData(playerid, j, Weapons[playerid][j], Ammo[playerid][j]);// loop through all weapon slots + ammo
  SpawnPlayer(playerid); //respawn the player
  for(new j=0; j<11; j++)	GivePlayerWeapon(playerid, Weapons[playerid][j], Ammo[playerid][j]);// loop through all weapon slots + ammo
}

yes, i know this can be abused, but i made this keeping in mind how stupid it is to somehow be stuck, do /kill, and have to start all over...
boemeles is offline   Reply With Quote
Old 07/06/2008, 05:01 PM   #19
Sandra18[NL]
Gangsta
 
Join Date: Jun 2007
Posts: 806
Reputation: 45
Default Re: Useful Functions

Quote:
Originally Posted by LarzI aka. GloZzy
GetVehiclePlayerID(vehicleid);
Code:
stock GetVehiclePlayerID(vehicleid)
{
	for(new i=0; i<MAX_PLAYERS; i++)
	{
		if(vehicleid == GetPlayerVehicleID(i))
		{
			return vehicleid;
		}
	}
	return INVALID_PLAYER_ID;
}
Shouldn't it be:
Code:
return i;
instead of
Code:
return vehicleid;
??
Sandra18[NL] is offline   Reply With Quote
Old 07/06/2008, 05:27 PM   #20
weedarr
High-roller
 
weedarr's Avatar
 
Join Date: Nov 2006
Location: Scotland Awesomeness: 1924 Occupation: Farmer
Posts: 2,295
Reputation: 368
Default Re: Useful Functions

http://web.archive.org/web/200702250...hp?topic=638.0

Latest archive of the usefull functions topic. I suggest you add to the first post.

WeeDarr
__________________



weedarr 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
Functions? sciman001 Help Archive 7 19/03/2011 04:03 PM
How to get functions? Twain32 Help Archive 4 08/10/2010 08:37 PM
[Include] [INC] SA:MP New Functions 0.4a DKN ipsBruno Lançamentos/Releases 22 17/06/2010 09:38 AM
[Include] [INC] LSF - Lorenc's Simple Functions (w/ gang/clan functions) Lorenc_ Includes 11 03/05/2010 10:47 PM
What this functions do? harrold Help Archive 2 09/05/2009 12:30 AM


All times are GMT. The time now is 10:45 PM.


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