Code optimization
#1

Any way to optimize this code?

pawn Код:
public OnPlayerUpdate(playerid)
{
    if(GetPlayerWeapon(playerid) == WEAPON_MINIGUN)
    {
    Punishplayer(playerid, "Weapon Cheat Minigun",3,1);
    return 0;
    }
    if(GetPlayerWeapon(playerid) == WEAPON_HEATSEEKER)
    {
    Punishplayer(playerid, "Weapon Cheat RPG",3,1);
    return 0;
    }
    if(GetPlayerWeapon(playerid) == WEAPON_ROCKETLAUNCHER)
    {
    Punishplayer(playerid, "Weapon Cheat Rocket Launcer",3,1);
    return 0;
    }
    if(GetPlayerWeapon(playerid) == WEAPON_CAMERA)
    {
    Punishplayer(playerid, "Weapon Cheat Camera",3,1);
    return 0;
    }
    if(GetPlayerWeapon(playerid) == 44)
    {
    Punishplayer(playerid, "Weapon Cheat Nightvision Goggles",3,1);
    return 0;
    }
    if(GetPlayerWeapon(playerid) == 45)
    {
    Punishplayer(playerid, "Weapon Cheat Infrared Vision",3,1);
    return 0;
    }
    if(GetPlayerWeapon(playerid) == WEAPON_BOMB)
    {
    Punishplayer(playerid, "Weapon Cheat Detonator",3,1);
    return 0;
    }
    if(GetPlayerWeapon(playerid) == 44)
    {
    Punishplayer(playerid, "Weapon Cheat Nightvision Goggles",3,1);
    return 0;
    }
    if(GetPlayerSpecialAction(playerid) == SPECIAL_ACTION_USEJETPACK)
    {
    Punishplayer(playerid, "Jetpack cheat",Jetpack_PUNISH,1);
    }
  new Float:VehHP;
  new VID;
  GetPlayerHealth(playerid,HP);
  GetPlayerArmour(playerid,ARM);
  VID = GetPlayerVehicleID(playerid);
    GetVehicleHealth(VID,VehHP);
  if(HP > 100)
  {
  Punishplayer(playerid, "Godmod",godmod_PUNISH,1);
  }
  if(ARM > 100)
  {
  Punishplayer(playerid, "Armour Hack",godmod_PUNISH,1);
  }
  if(VehHP >= 1001 && GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
  {
  Punishplayer(playerid, "Car Godmode",cargodmod_PUNISH,1);
  }
  return 1;
}
Reply
#2

First part of the code can be done like this

pawn Код:
switch(GetPlayerWeapon(playerid))
{
    case WEAPON_MINIGUN:
    {
        Punishplayer(playerid, "Weapon Cheat Minigun",3,1);
        return 0;
    }
    case WEAPON_HEATSEEKER:
    {
        Punishplayer(playerid, "Weapon Cheat RPG",3,1);
        return 0;
    }
    case WEAPON_ROCKETLAUNCHER:
    {
        Punishplayer(playerid, "Weapon Cheat Rocket Launcer",3,1);
        return 0;
    }
    case WEAPON_CAMERA:
    {
        Punishplayer(playerid, "Weapon Cheat Camera",3,1);
        return 0;
    }
    case 44:
    {
        Punishplayer(playerid, "Weapon Cheat Nightvision Goggles",3,1);
        return 0;
    }
    case 45:
    {
        Punishplayer(playerid, "Weapon Cheat Infrared Vision",3,1);
        return 0;
    }
    case WEAPON_BOMB:
    {
        Punishplayer(playerid, "Weapon Cheat Detonator",3,1);
        return 0;
    }
    case 44:
    {
        Punishplayer(playerid, "Weapon Cheat Nightvision Goggles",3,1);
        return 0;
    }
}
Reply
#3

Tank you. I know that this code will be called like 20000 mil times aday so it needs to be perfekt.
Reply
#4

Quote:
Originally Posted by Roban[swe
]
Tank you. I know that this code will be called like 20000 mil times aday so it needs to be perfekt.
Thats right. Thats how we see sa-mp players...
Reply
#5

One more thing is it stupid to have all this in OnPlayerUpdate?
Reply
#6

Quote:
Originally Posted by Roban[swe
]
One more thing is it stupid to have all this in OnPlayerUpdate?
It depends. If you really want it to be called every time a player gets updated, no. But i guess it would work almost same, if you would make a timer of one second. No player can kill many during 1 second. That's what i think about it

Cheerz.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)