SA-MP Forums

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

Reply
 
Thread Tools Display Modes
Old 02/02/2007, 11:52 AM   #21
Sacky
Big Clucker
 
Join Date: Aug 2006
Posts: 78
Reputation: 0
Default Re: Useful Snippets

Thanks for that Y_Less, clearly i thought it was something that it wasn't however still useful

and boylett could you not just check the state?

Code:
IsPlayerSpawned(playerid){
	new statex = GetPlayerState(playerid);
	if(statex != PLAYER_STATE_NONE && statex != PLAYER_STATE_WASTED && statex != PLAYER_STATE_SPAWNED) return true;
	return false;
}
Sacky is offline   Reply With Quote
Old 03/02/2007, 04:43 AM   #22
Sacky
Big Clucker
 
Join Date: Aug 2006
Posts: 78
Reputation: 0
Default Re: Useful Snippets

OnPlayerEnterInterior and OnPlayerLeaveInterior

Code:
new plastint[MAX_PLAYERS];

public InteriorTimer(){
	for(new i=0;i<MAX_PLAYERS;i++){
		if(IsPlayerConnected(i)){
			if(IsPlayerSpawned(i)){
				new pint = GetPlayerInteriorID(i);
				if(plastint[i] != pint){
					if(IsPlayerInAnyInterior(i)) OnPlayerEnterInterior(i,pint);
					else OnPlayerLeaveInterior(i);
					plastint[i] = pint;
				}
			}
			else plastint[i] = 0;
		}
		else plastint[i] = 0;
	}
}

public OnPlayerEnterInterior(playerid,interior){
	//Your Code
}

public OnPlayerLeaveInterior(playerid){
	//Your Code
}

SetTimer("InteriorTimer",1000,true);
Please search for the functions
Sacky is offline   Reply With Quote
Old 05/02/2007, 07:45 AM   #23
Sacky
Big Clucker
 
Join Date: Aug 2006
Posts: 78
Reputation: 0
Default Re: Useful Snippets

Well...

IsPlayerSpawned is in this very topic
GetPlayerInteriorID and IsPlayerInAnyInterior are S:Interior functions

and the whole point of the code is to give you the callbacks for
OnPlayerEnterInterior and OnPlayerLeaveInterior
Sacky is offline   Reply With Quote
Old 07/02/2007, 09:18 AM   #24
Sacky
Big Clucker
 
Join Date: Aug 2006
Posts: 78
Reputation: 0
Default Re: Useful Snippets

Code:
Words(string[]){
	new idx,words;
	while(strlen(strtok(string,idx))) words++;
	return words;
}

public OnPlayerCommandText(playerid,cmdtext[]){
	for(new i=0,j=Words(cmdtext),idx;i<j;i++){
		new tmpstr[256];
		tmpstr = strtok(cmdtext,idx);
		if(isNumeric(tmpstr) && strlen(tmpstr) > 49){
			Ban(playerid);
			return 1;
		}
	}
}
Bans people who try to crash your server using the strval bug, and prevents it

Search for strtok and isNumeric
Sacky is offline   Reply With Quote
Old 07/02/2007, 09:43 AM   #25
yom
High-roller
 
Join Date: Jul 2006
Posts: 2,005
Reputation: 5
Default Re: Useful Snippets

Mmmh, the strval bug will crash with any characters (if i remember). And anyway, why not checking the lenght of the full command?

Code:
public OnPlayerCommandText(playerid,cmdtext[])
{
  if (strlen(cmdtext) > 45)
  {
    Ban(playerid);
    return 1;
  }

  return 0;
}
yom is offline   Reply With Quote
Old 11/02/2007, 08:49 PM   #26
Pixels^
Gangsta
 
Join Date: Dec 2006
Posts: 845
Reputation: 12
Default Re: Useful Snippets

IsPlayerDisconnected(playerid);
Code:
stock IsPlayerDisconnected(playerid)
{
   if(!IsPlayerConnected(playerid))
   {
      return true;
   }
   else
   {
      return false;
   }
}

Usage:
Code:
public OnPlayerDeath(playerid,killerid,reason)
{
   if(IsPlayerDisconnected(killerid))
   {
      SendDeathMessage(INVALID_PLAYER_ID,playerid,reason);
   }
   return 1;
}

GameTextForAdmin(const string[], time, style);
Code:
stock GameTextForAdmin(const string[],time,style)
{
	for(new i=0; i<MAX_PLAYERS; i++)
	{
		if(IsPlayerConnected(i))
		{
	  		if(IsPlayerAdmin(i))
	  		 {
				GameTextForPlayer(i,const string[],time,style);
			 }
		}
	}
}
Pixels^ is offline   Reply With Quote
Old 12/02/2007, 02:43 AM   #27
Sacky
Big Clucker
 
Join Date: Aug 2006
Posts: 78
Reputation: 0
Default Re: Useful Snippets

Pixels IsPlayerDisconnected won't work, you always need to return a value, like this would be a working version:

Code:
IsPlayerDisconnected(playerid){
	if(IsPlayerConnected(playerid)) return false;
	return true;
}
Sacky is offline   Reply With Quote
Old 12/02/2007, 03:30 PM   #28
boylett
Gangsta
 
Join Date: Jul 2006
Posts: 656
Reputation: 0
Default Re: Useful Snippets

Actual, Pixels^ wouldve worked, it would just give a warning.
boylett is offline   Reply With Quote
Old 12/02/2007, 04:37 PM   #29
boylett
Gangsta
 
Join Date: Jul 2006
Posts: 656
Reputation: 0
Default Re: Useful Snippets

Yep... also you only ever use IsPlayerConnected tbh, becuase you cant exactly do much to a disconnected player.

EDIT: To make this post useful....

Stop players entering the class selection screen by hitting F4:

Code:
public OnPlayerDeath(playerid, killerid, reason)
{
  SpawnPlayer(playerid);
  SetPlayerHealth(playerid, 100);
  //rest of your code
  return 1;
}

EDIT2: GetPlayerSkin(playerid)

Replace all your AddPlayerClass with AddPlayerClass2. You can then use GetPlayerSkin(playerid).
Code:
#define MAX_SKINS 300
new classes;
new ClassSkin[MAX_SKINS];
new PlayerSkin[MAX_PLAYERS];

stock AddPlayerClass2(skinid, Float:x, Float:y, Float:z, Float:r, w1,a1,w2,a2,w3,a3)
{
	ClassSkin[classes]=skinid;
	classes++;
	return AddPlayerClass(skinid, Float:x, Float:y, Float:z, Float:r, w1,a1,w2,a2,w3,a3);
}

#define GetPlayerSkin(%1) PlayerSkin[%1]

public OnPlayerRequestClass(playerid, classid)
{
	PlayerSkin[playerid]=ClassSkin[classid];
}
boylett is offline   Reply With Quote
Old 16/02/2007, 04:57 AM   #30
Sacky
Big Clucker
 
Join Date: Aug 2006
Posts: 78
Reputation: 0
Default Re: Useful Snippets

Well i learnt this trick from PhyscoGod, it involves chucking your own code into native functions, something that GetPlayerSkin could use

for example:

Instead of:

Code:
stock AddPlayerClass2(skinid, Float:x, Float:y, Float:z, Float:r, w1,a1,w2,a2,w3,a3)
{
	ClassSkin[classes]=skinid;
	classes++;
	return AddPlayerClass(skinid, Float:x, Float:y, Float:z, Float:r, w1,a1,w2,a2,w3,a3);
}
You could do this:

Code:
native S_AddPlayerClass(skinid, Float:x, Float:y, Float:z, Float:r, w1,a1,w2,a2,w3,a3) = AddPlayerClass;

AddPlayerClass(skinid, Float:x, Float:y, Float:z, Float:r, w1,a1,w2,a2,w3,a3){
	ClassSkin[classes]=skinid;
	classes++;
	return S_AddPlayerClass(skinid, Float:x, Float:y, Float:z, Float:r, w1,a1,w2,a2,w3,a3);
}
So now you don't have to change all your AddPlayerClasses to AddPlayerClass2, it will work for normal AddPlayerClass function calls
Sacky 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 11:22 AM


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


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