Useful functions
#1

[size=32px]Useful Functions, Defines, Macros...[/size]
[size=20px]For SA:MP 0.3[/size]
Please Sticky the Topic!

Collection of useful functions. Please write here usefull functions.
And plase use PAWN tag.
Код:
pawn Код:
code
pawn Код:
#define MAX_NPC_NAME_LEN (64)

//------------------------------------------------------------------------------
// Name: DisconnectNPC
// Prototype: DisconnectNPC( npc name );
// Author: Gamestar ©
//------------------------------------------------------------------------------
stock DisconnectNPC( npcname[ ] )
{
  for( new i = 0; i < GetMaxPlayers( ); i++ )
  {
    if( IsPlayerNPC( i ))
    {
      new name[ MAX_NPC_NAME_LEN ];
      GetPlayerName( i, name, MAX_NPC_NAME_LEN );
      if( !strcmp( name, "npcname", true ) )
      {
         return Kick( i );
      }
    }
  }
  return INVALID_PLAYER_ID;
}

//------------------------------------------------------------------------------
// Name: DisconnectNPCEx
// Prototype: DisconnectNPCEx( npc id );
// Author: Gamestar ©
//------------------------------------------------------------------------------
stock DisconnectNPCEx( npcid )
{
  if( IsPlayerNPC( npcid ) )
  {
    return Kick( npcid );
  }
  return INVALID_PLAYER_ID;
}

//------------------------------------------------------------------------------
// Name: DisconnectAllNPC
// Prototype: DisconnectAllNPC( No parameters );
// Author: Gamestar ©
//------------------------------------------------------------------------------
stock DisconnectAllNPC( )
{
  for( new i = 0; i < GetMaxPlayers( ); i++ )
  {
    if( IsPlayerNPC( i ))
    {
      return Kick( i );
    }
  }
  return INVALID_PLAYER_ID;
}
Gamestar
Reply
#2

I suggest you to test your code because it doesn't work.
Reply
#3

NPC Disconnect code /1 line/:
pawn Код:
stock DisconnectNPC(npcid) if(!IsPlayerNPC(npcid)) return -1; else return Kick(npcid);
Reply
#4

Just a few things I want to point out dude, only so you can fix them (I'm being constructive).

Calling the GetMaxPlayers() function on each itteration is pointless as it will always give the same return so you are wasting every single call after the first one. You can store the result of the function first outside the loop and then use this value in the loop if you wish to use it instead of the MAX_PLAYERS define.

The string comparison in the disconnect function is wrong, you have used your variable name as a string "...". I think this is what Tr1viUm was pointing out to you unless I missed something else.

The DisconnectAllNPC() function will only kick the first found NPC as you kill the loop on the first itteration which finds a valid NPC.
Reply
#5

its 'useful' not 'usefull'
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)