SA-MP Forums Archive
How can I do this? - 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)
+--- Thread: How can I do this? (/showthread.php?tid=585071)



How can I do this? - Yerro - 10.08.2015

Hello everybody,

I want to do when you have a desert eagle, for example, you can't change this weapon with the mouse scroll or "q/e". This weapon have to stay always in your hand. Can enyone help me?


Re: How can I do this? - Tamy - 10.08.2015

Code:
public OnPlayerUpdate(playerid)
{
    new weapons[14][2];
    for(new i=0; i<13; i++)
   {
       	GetPlayerWeaponData(playerid, i, weapons[i][0], weapons[i][1]);
        if(weapons[i][0] == 24)
        {
            SetPlayerArmedWeapon(playerid, 24);
        }
    }
    return 1;
}
You can also use this code under a timer, OnPlayerUpdate is called more than 50 times in a second.


Re: How can I do this? - SoFahim - 10.08.2015

By Using this SetPlayerArmedWeapon(playerid,**);

PHP Code:

public OnPlayerStateChange(playeridnewstateoldstate)
    
    {
        new 
gun GetPlayerWeapon(playerid);
        if((
27 gun 33)) SetPlayerArmedWeapon(playeridgun);
        else
        {
         
SetPlayerArmedWeapon(playerid0); // any you want to use
    
}
    return 
1;

PHP Code:
OnPlayerChangeWeapon(playeridnewweapon)
SetPlayerArmedWeapon(playerid,23); 
I just give you hint . Now make it properly for your own server

Also Follow

Quote:
Originally Posted by Tamy
View Post
Code:
public OnPlayerUpdate(playerid)
{
    new weapons[14][2];
    for(new i=0; i<13; i++)
   {
       	GetPlayerWeaponData(playerid, i, weapons[i][0], weapons[i][1]);
        if(weapons[i][0] == 24)
        {
            SetPlayerArmedWeapon(playerid, 24);
        }
    }
    return 1;
}
You can also use this code under a timer, OnPlayerUpdate is called more than 50 times in a second.



Re: How can I do this? - Michael B - 10.08.2015

You could give a try to this:

PHP Code:
new LockWeapon[MAX_PLAYERS];
new 
LockOn[MAX_PLAYERS];
public 
OnPlayerConnect(playerid)
{
    
LockOn[playerid] = 0;
    return 
1;
}
public 
OnPlayerUpdate(playerid)
{
    if(
LockOn[playerid] == 1)
    {
        if(
GetPlayerWeapon(playerid) != LockWeapon[playerid]) SetPlayerArmedWeapon(playeridLockWeapon[playerid]);
    }
    return 
1;
}
stock LockPlayerWeapon(playeridweaponid)
{
    
LockOn[playerid] = 1;
    
LockWeapon[playerid] = weaponid;
    return 
1;
}
stock UnlockPlayerWeapon(playerid)
{
    
LockOn[playerid] = 0;
    
LockWeapon[playerid] = -1;

Use LockPlayerWeapon(playerid, weaponid) to lock the weapon.
Use UnlockPlayerWeapon(playerid) unlock the weapon.


Re: How can I do this? - SickAttack - 10.08.2015

@Michael - Use booleans and a timer instead. You do not always need that code to run, I assume.


Respuesta: How can I do this? - Yerro - 10.08.2015

Thank you @Tamy and @SoFahim.

Solved