How to switch player weapon?
#1

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?
Reply
#2

https://sampwiki.blast.hk/wiki/SetPlayerArmedWeapon

You would have to do a check, maybe a timer to see when they changed their weapons.
Reply
#3

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;
}
Reply
#4

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
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)