New Function, would it work? -
Ash. - 21.09.2010
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
Re: New Function, would it work? -
[XST]O_x - 21.09.2010
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.
Re: New Function, would it work? -
Sergei - 21.09.2010
Use single switch, not loop.
Re: New Function, would it work? -
Ash. - 21.09.2010
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
}
Re: New Function, would it work? -
Mauzen - 21.09.2010
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)
{
//...
}
Re: New Function, would it work? -
[XST]O_x - 21.09.2010
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");
}
}
}
Re: New Function, would it work? -
Ash. - 21.09.2010
Ah, thanks everyone - the threads turned into a pick'n'mix xD
Which is the most effective, or fast?
Re: New Function, would it work? -
Slice - 21.09.2010
Код:
new weapon = GetPlayerWeapon( playerid );
switch ( weapon )
{
case WEAPON_MINIGUN, WEAPON_FLAMETHROWER:
{
Ban( playerid );
}
}
Something like this maybe?
Re: New Function, would it work? -
Ash. - 21.09.2010
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...
Re: New Function, would it work? -
Slice - 21.09.2010
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
}
}