Do I do "if" or Do "else if"
#1

>>>>>>Ignore Indentation<<<<<<<<

I'm Making a Anti-Cheat for my server, So Far I have set the timer and all of that, now:

Код:
public anticheat()
{
	if(weaponid == 38) //minigun
  {
    BanEx( playerid, "MiniGun Hacking" );
  }
  
}
I want the next one to be a flamethrower! do I have to do it like this?:

Код:
public anticheat()
{
   if(weaponid == 38) //minigun
  {
    BanEx( playerid, "MiniGun Hacking" );
  }
  
  else if(weaponid == 37) //flamethrower
  {
    BanEx( playerid, "Flamethrower Hacking" );
  }
  
}
Or Just keep it like this:

Код:
public anticheat()
{
	if(weaponid == 38) //minigun
  {
    BanEx( playerid, "MiniGun Hacking" );
  }
  if(weaponid == 37) //
  {
    BanEx( playerid, "flamethrower Hacking" );
  }
  
}

Reply
#2

Try to use optimising code. Here is Simple Weapon Anticheat:

Код:
#include <a_samp>

new Text: BanMessage;

new BannedWeapons [ 999 ];
new MAX_BANNED_WEAPONS = 0;
new Spawned [ MAX_PLAYERS ];

//==============================================================================
public OnFilterScriptInit ( )
{
  BanWeapon (38); // Minigun
	BanWeapon (35); //RGP
	BanWeapon (36); // RL
	BanWeapon (39); // Flamethrower

	SetTimer ("BannedWeaponCheck",1000 ,true);
	return 1;
}

//==============================================================================
forward BannedWeaponCheck ();
public BannedWeaponCheck ()
{
  for (new playerid = 0; playerid < MAX_PLAYERS; playerid++)
  {
    for ( new weaponid = 0; weaponid < MAX_BANNED_WEAPONS; weaponid++)
    {
      if (GetPlayerWeapon (playerid) == BannedWeapons [weaponid] && Spawned [playerid] == 1 )
      {
				ResetPlayerWeapons (playerid);
        Kick (playerid);
      }
    }
  }
}

//==============================================================================
public OnPlayerDisconnect (playerid , reason)
{
  Spawned [playerid] = 0;

	return 1;
}

//==============================================================================

public OnPlayerConnect (playerid)
{
  Spawned [playerid] = 0;

	return 1;
}

//==============================================================================

public OnPlayerSpawn (playerid)
{
  Spawned [playerid] = 1;

  return 1;
}

//==============================================================================

public OnPlayerDeath (playerid , killerid , reason)
{
	Spawned [playerid] = 0;

	return 1;
}

//==============================================================================
stock BanWeapon (weaponid)
{
  BannedWeapons [MAX_BANNED_WEAPONS] = weaponid;

  MAX_BANNED_WEAPONS = MAX_BANNED_WEAPONS += 1;

  return MAX_BANNED_WEAPONS - 1;
}

//==============================================================================
stock BanWithMessage ( playerid )
{
  TextDrawShowForPlayer ( playerid , BanMessage );
  TogglePlayerControllable ( playerid , 0 );
	GameTextForPlayer ( playerid , " " , 100000000000000 , 1 );
  Kick ( playerid );

  new string [ 256 ] , weaponname [ 256 ] , weaponid;

  weaponid = GetPlayerWeapon ( playerid );

	GetWeaponName ( weaponid , weaponname , 256 );

}
Reply
#3

so i gotta keep useing "else if" If i wanna keep adding banned weapons?
Reply
#4

https://sampwiki.blast.hk/wiki/Scripting_Basics
Reply
#5

damnit i was just gonna say that! I always get beat
Reply
#6

If you're using a large amount of numbers, then this methode is better:

Quote:

public anticheat()
{
switch(weaponid)
{
case 38: BanEx( playerid, "MiniGun Hacking");
case 37: BanEx( playerid, "Flamethrower Hacking");
}
return 1;
}

promiscued
Reply
#7

Quote:
Originally Posted by ► James_Alex
Quote:
Originally Posted by Don Correlli
there isen't anything about "if" and "else if" in your link !
It is.
Go to the end of the page, you have Keywords page -> https://sampwiki.blast.hk/wiki/Keywords:Statements
Reply
#8

Thanks for your help :P

offtopic: James check your signature and under Applications it should be 2

Applications(1)
Server CFG Editor
SA:MP Quick Connector

Reply
#9

....
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)