New Function, would it work?
#1

Hi
Im currently creating an anti-weapons function (or 'Timer' if you like) - I'm not sure if it will work however, and thought i'd ask on here:

Here's the code:
pawn Код:
//I have forwarded it earlier in the script by the way :)
public AntiWeapon(playerid)
{
    new Weapons = 1 || 2 || 3 || 4 || 5 || 6 || 7 || 8 || 9 || 10 || 11 || 12 || 13 || 14 || 15 || 16 || 17 || 18 || 22 || 23 || 24 || 25 || 26 || 27 || 28 || 29 || 30 || 31 || 32 || 33 || 34 || 35 || 36 || 37 || 38 || 39 || 40 || 41 || 42 || 43 || 44 || 45;
    if(GetPlayerWeapon(playerid, Weapons) == 1)
    {
        Cheat(playerid, "Weapon Hack");
    }
}
I know alot of you will say "Try it yourself" but i just want to know, from a coding point of view, should it work?

Thanks
Ash
Reply
#2

It won't work, at least I think so.

And you also had an extra parameter on GetPlayerWeapon.

pawn Код:
public AntiWeapon(playerid)
{
    for(new i = 1; i < 46; i++)
    {
        if(GetPlayerWeapon(playerid) == i)
       {
            Cheat(playerid, "Weapon Hack");
       }
    }
}
Should work.
Reply
#3

Use single switch, not loop.
Reply
#4

Thanks O_x

Quote:
Originally Posted by Sergei
Посмотреть сообщение
Use single switch, not loop.
How would i do this? Like:

pawn Код:
switch(Weapons)
{
     case 0:
     case 1:
     //etc etc
}
Reply
#5

No, it wont:

1. GetPlayerWeapon returns the id of the players current weapon with only one parameter. Weapons does not fit in there (https://sampwiki.blast.hk/wiki/GetPlayerWeapon)

2. Your new Weapons = 1 || 2 || 3 ... will just be = 1, becuase 1 <or> 2 <or> 3 ... is true(1)


Do it like [XST]O_x or like this:

pawn Код:
if(GetPlayerWeapon(playerid) > 0 && GetPlayerWeapon(playerid) < 46)
{
    //...
}
Reply
#6

You are right Sergei, I'm not an expert in these though. I'll give it a shot.

pawn Код:
public AntiWeapon(playerid)
{
    new weaps = GetPlayerWeapon(playerid);
    switch(weaps)
    {
        case 1..45:
        {
            Cheat(playerid, "Weapon Hack");
        }
     }
}
Reply
#7

Ah, thanks everyone - the threads turned into a pick'n'mix xD

Which is the most effective, or fast?
Reply
#8

Код:
new weapon = GetPlayerWeapon( playerid );
switch ( weapon )
{
	case WEAPON_MINIGUN, WEAPON_FLAMETHROWER:
	{
		Ban( playerid );
	}
}
Something like this maybe?
Reply
#9

Quote:
Originally Posted by g_aSlice
Посмотреть сообщение
Код:
new weapon = GetPlayerWeapon( playerid );
switch ( weapon )
{
	case WEAPON_MINIGUN, WEAPON_FLAMETHROWER:
	{
		Ban( playerid );
	}
}
Something like this maybe?
My Cheat(playerid, reason[]) function handles the "Ban" settings, and i need it for all weapons, but something like that i guess would work...
Reply
#10

Oh for all weapons?

Код:
if ( GetPlayerWeapon( playerid ) )
{
	// banban
}
This will ban all weapons, and it's the fastest way to check.

However, if you would like to ban all weapons except for parachute and golf club for example, I'd suggest this:

Код:
switch ( weapon )
{
	case WEAPON_PARACHUTE, WEAPON_GOLFCLUB:{}
	default:
	{
		// banban
	}
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)