SA-MP Forums

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

Reply
 
Thread Tools Display Modes
Old 27/01/2007, 11:33 PM   #1
Pixels^
Gangsta
 
Join Date: Dec 2006
Posts: 845
Reputation: 22
Default Useful Snippets

As i see that the Post your interesting/weird... commands is flooded with not just commands,
but other snippets that go in different areas of the SA:MP Scripts, i decided to make this
topic with Y_Less' approval for people to post there useful, weird, or interesting snippets that not just
go into the OnPlayerCommandText Area but other areas of the SA:MP scripts. Ill start it out.

Connect icon in DeathStats from Y_Less
Code:
public OnPlayerConnect(playerid)
{
   SendDeathMessage(playerid, INVALID_PLAYER_ID, 200);
   return 1;
}


Disconnect icon in DeathStats from Y_Less
Code:
public OnPlayerDisconnect(playerid)
{
  SendDeathMessage(INVALID_PLAYER_ID, playerid, 201);
}
Pixels^ is offline   Reply With Quote
Old 28/01/2007, 12:32 AM   #2
Pixels^
Gangsta
 
Join Date: Dec 2006
Posts: 845
Reputation: 22
Default Re: Useful Snippets

Admin Lock

Code:
new aVehicle; //Above Main

Code:
//gamemodeinit
aVehicle = AddStaticVehicle(598,2256.0903,2477.0115,10.5668,178.5022,0,1); //gamemodeinit
Code:
public AdminLock(playerid) //Anywhere in script
{
 if(IsPlayerConnected(playerid))
 {
   if(IsPlayerAdmin(playerid))
   {
    SetVehicleParamsForPlayer(aVehicle, playerid,0,0);
   }
   else
   {
    SetVehicleParamsForPlayer(aVehicle, playerid,0,1);
   }
 }
}
Code:
public OnPlayerSpawn(playerid)
{
   AdminLock(playerid);
   return 1;
}

Code:
AddStaticVehicleEx(598,2256.0903,2477.0115,10.5668,178.5022,0,1,never);
Pixels^ is offline   Reply With Quote
Old 28/01/2007, 10:49 AM   #3
Sacky
Big Clucker
 
Join Date: Aug 2006
Posts: 78
Reputation: 0
Default Re: Useful Snippets

Well this is a small thing but i find it a bit more efficient,

instead of using for(new i=0;i<MAX_PLAYERS

I use this:

Code:
new maxplayers; //Global Variable

public OnPlayerConnect(playerid){
	if(playerid > maxplayers-1) maxplayers = playerid+1; //Getting the maximum playerid
}

public OnPlayerDisconnect(playerid){
	if(playerid == maxplayers+1) for(new i=0;i<maxplayers;i++) if(IsPlayerConnected(i)) maxplayers = i+1; //Getting the minimum playerid
}

for(new i=0;i<maxplayers;i++) //the new more efficient loop
Sacky is offline   Reply With Quote
Old 28/01/2007, 02:18 PM   #4
Sacky
Big Clucker
 
Join Date: Aug 2006
Posts: 78
Reputation: 0
Default Re: Useful Snippets

Quote:
That won't work, you're assuming that all players are consecutive, which is rarely the case, you could have 10 players max, but only players 1, 4, 7 and 9 connected, which would make the max thing 9, saving almost nothing, and you would still need to check for connection.
No I'm not assuming there consecutive, check my code again, i find the highest playerid according to OnPlayerConnect and make the max loop that, then when a player disconnects i reevaluate the highest playerid

since basically all MAX_PLAYERS loops try to loop according to playerids you only need the highest one, hence this is more efficient
Sacky is offline   Reply With Quote
Old 28/01/2007, 06:38 PM   #5
-Sneaky-
High-roller
 
Join Date: Jul 2006
Posts: 1,010
Reputation: 24
Default Re: Useful Snippets

ok about the admin vehcile's
i added 13 admin vehicle's and i can open them when im not admin.. now i realized that i had to add this, before it would work:

Code:
AddStaticVehicleEx(425,2137.0598,1729.9246,20.5675,59.3952,0,1,never);
    AddStaticVehicleEx(522,2164.1125,1720.9868,20.1695,161.4324,0,1,never);
	AddStaticVehicleEx(522,2168.9771,1719.4484,19.9998,169.0915,0,1,never);
	AddStaticVehicleEx(522,2174.8657,1718.4332,20.1868,165.7749,0,1,never);
	AddStaticVehicleEx(522,2179.6699,1717.1212,19.9994,166.9654,0,1,never);
	AddStaticVehicleEx(444,2208.9463,1654.0419,20.0004,2.0738,0,1,never);
	AddStaticVehicleEx(556,2184.9636,1654.0623,20.0956,2.9973,0,1,never);
	AddStaticVehicleEx(425,2201.3828,1716.8575,34.2190,88.4603,0,1,never);
	AddStaticVehicleEx(520,2141.1396,1637.6151,20.1024,120.4169,0,1,never);
	AddStaticVehicleEx(541,2175.4431,1613.0690,20.0886,182.6934,0,1,never);
	AddStaticVehicleEx(411,2168.8147,1614.7198,20.0885,181.9470,0,1,never);
	AddStaticVehicleEx(451,2163.6968,1613.2709,20.0878,175.1219,0,1,never);
	AddStaticVehicleEx(447,2141.5942,1591.2502,31.6095,124.6433,0,1,never);
And get this error:

Code:
(19229) : error 021: symbol already defined: "AddStaticVehicleEx"
I searched thru the forums how i could fix this error but found nothing.

Greetz, Sneaky


-Sneaky- is offline   Reply With Quote
Old 28/01/2007, 06:43 PM   #6
Pixels^
Gangsta
 
Join Date: Dec 2006
Posts: 845
Reputation: 22
Default Re: Useful Snippets

only 1 vehicle can be locked with the lock i posted
you need maxvehicles for all of them to be unlocked

Everybody needs sleep Code


Code:
enum pInfo
{
	Sleeping,
	Awake,
	Tired
}
new Info[MAX_PLAYERS][pInfo];
Code:
SetTimer("Motels",5000,1);
SetTimer("SleepTime",300000,1);
Code:
public SleepTime()
{
	for(new i=0; i<MAX_PLAYERS; i++)
	{
	  SendClientMessage(i,COLOR_GREY,"* You are starting to feel sleep *");
		SendClientMessage(i,COLOR_GREY,"* Go to the nearest /hotel and get a rest *");
		Info[i] [Tired] = 1;
		Info[i] [Awake] = 0;
		Info[i] [Sleeping] = 0;
	}
}
Code:
		
public Motels()
{
	for(new i=0; i<MAX_PLAYERS; i++)
	{
	  if(IsPlayerInCube(i,2236,-1076,1040,2245,-1066,1100))
	  {
	    if(Info[i][Tired] == 1)
	    {
	            GameTextForPlayer(i,"~w~Please wait while your energy is ~b~restored",3000,3);
				Info[i] [Tired] = 0;
				Info[i] [Sleeping] = 1;
				Info[i] [Awake] = 0;
				TogglePlayerControllable(i,0);
		}
		if(Info[i] [Awake] == 1)
		{
		     	GameTextForPlayer(i,"~w~You ~g~don't ~w~need to rest",2000,3);
	    }
	    if(Info[i] [Sleeping] == 1)
	    {
	            Info[i] [Awake] = 1;
				Info[i] [Tired] = 0;
				Info[i] [Sleeping] = 0;
				GameTextForPlayer(i,"~w~Rise and Shine",2000,3);
				TogglePlayerControllable(i,1);
		}
	  }
	  if(IsPlayerInCube(i,2202,-1070,1000,2211,-1078,1100))
	  {
	    if(Info[i][Tired] == 1)
	    {
	            GameTextForPlayer(i,"~w~Please wait while your energy is ~b~restored",3000,3);
				Info[i] [Tired] = 0;
				Info[i] [Sleeping] = 1;
				Info[i] [Awake] = 0;
				TogglePlayerControllable(i,0);
		}
		if(Info[i] [Awake] == 1)
		{
		  	    GameTextForPlayer(i,"~w~You ~g~don't ~w~need to rest",2000,3);
	    }
	    if(Info[i] [Sleeping] == 1)
	    {
	            Info[i] [Awake] = 1;
				Info[i] [Tired] = 0;
				Info[i] [Sleeping] = 0;
				GameTextForPlayer(i,"~w~Rise and Shine",2000,3);
				TogglePlayerControllable(i,1);
		}
	  }
	}
  return 1;
}
Pixels^ is offline   Reply With Quote
Old 28/01/2007, 07:01 PM   #7
yom
High-roller
 
Join Date: Jul 2006
Posts: 2,005
Reputation: 6
Default Re: Useful Snippets

Why not simply:

Code:
if ( IsPlayerInCube(i,2236,-1076,1040,2245,-1066,1100) || IsPlayerInCube(i,2202,-1070,1000,2211,-1078,1100) )

So you can delete half of the timer func. Also check if they are connected before doing anything.
yom is offline   Reply With Quote
Old 28/01/2007, 07:03 PM   #8
Pixels^
Gangsta
 
Join Date: Dec 2006
Posts: 845
Reputation: 22
Default Re: Useful Snippets

I made it a long time ago so i didn't know about that then.
Pixels^ is offline   Reply With Quote
Old 28/01/2007, 08:05 PM   #9
-Sneaky-
High-roller
 
Join Date: Jul 2006
Posts: 1,010
Reputation: 24
Default Re: Useful Snippets

ok pixels, how can i make all vehicles unlocked for admin and locked for normal players then?
i really dont know how
-Sneaky- is offline   Reply With Quote
Old 28/01/2007, 08:13 PM   #10
Pixels^
Gangsta
 
Join Date: Dec 2006
Posts: 845
Reputation: 22
Default Re: Useful Snippets

Something like this

Code:
#define MAX_VEHICLES 255 //amount of cars in script
new aVehicle[MAX_VEHICLES] //define of aVehicle
Code:
    new never = 1000000;
    aVehicle[1] = AddStaticVehicleEx(522,2164.1125,1720.9868,20.1695,161.4324,0,1,never);
	aVehicle[2] = AddStaticVehicleEx(522,2168.9771,1719.4484,19.9998,169.0915,0,1,never);

Code:
public AdminLock(playerid) //Anywhere in script
{
  if(IsPlayerConnected(playerid))
  {
   if(IsPlayerAdmin(playerid))
   {
     SetVehicleParamsForPlayer(aVehicle[MAX_VEHICLES], playerid,0,0);
   }
   else
   {
     SetVehicleParamsForPlayer(aVehicle[MAX_VEHICLES], playerid,0,1);
   }
  }
}
Pixels^ 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 07:04 PM.


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