How to switch player weapon? - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (
https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: How to switch player weapon? (
/showthread.php?tid=267341)
How to switch player weapon? -
Outcast - 08.07.2011
Hi, me again xD.
I was wondering, is it possible to "lock" the player's current weapon, so he can't switch it. Like, example: You have an RPG, and if you try to switch to your M4, the script would automatically switch your weapon back to RPG.
So, is that possible?
Re: How to switch player weapon? -
[HiC]TheKiller - 08.07.2011
https://sampwiki.blast.hk/wiki/SetPlayerArmedWeapon
You would have to do a check, maybe a timer to see when they changed their weapons.
Re: How to switch player weapon? -
PotH3Ad - 08.07.2011
Try this:
pawn Код:
new LockWep[MAX_PLAYERS];
new LockOn[MAX_PLAYERS];
public OnPlayerConnect(playerid)
{
LockOn[playerid] = 0;
return 1;
}
public OnPlayerUpdate(playerid)
{
if(LockOn[playerid] == 1)
{
if(GetPlayerWeapon(playerid) != LockWep[playerid]) SetPlayerArmedWeapon(playerid, LockWep[playerid]);
}
return 1;
}
//Use "LockPlayerWeapon(playerid, weaponid)" to set the player's locked weapon.
//Use "UnlockPlayerWeapon(playerid)" to disable the weapon lock
stock LockPlayerWeapon(playerid, weaponid)
{
LockOn[playerid] = 1;
LockWep[playerid] = weaponid;
return 1;
}
stock UnlockPlayerWeapon(playerid)
{
LockOn[playerid] = 0;
LockWep[playerid] = -1;
}
Re: How to switch player weapon? -
Outcast - 08.07.2011
Quote:
Originally Posted by PotH3Ad
Try this:
pawn Код:
new LockWep[MAX_PLAYERS]; new LockOn[MAX_PLAYERS];
public OnPlayerConnect(playerid) { LockOn[playerid] = 0; return 1; }
public OnPlayerUpdate(playerid) { if(LockOn[playerid] == 1) { if(GetPlayerWeapon(playerid) != LockWep[playerid]) SetPlayerArmedWeapon(playerid, LockWep[playerid]); } return 1; }
//Use "LockPlayerWeapon(playerid, weaponid)" to set the player's locked weapon. //Use "UnlockPlayerWeapon(playerid)" to disable the weapon lock
stock LockPlayerWeapon(playerid, weaponid) { LockOn[playerid] = 1; LockWep[playerid] = weaponid; return 1; }
stock UnlockPlayerWeapon(playerid) { LockOn[playerid] = 0; LockWep[playerid] = -1; }
|
Thanks, I'll try it out. Will post back if it works.
EDIT: It works, thanks