SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 10/08/2015, 04:04 PM   #1
Yerro
Little Clucker
 
Join Date: Oct 2013
Location: Spain
Posts: 35
Reputation: 3
Default How can I do this?

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?
Yerro is offline   Reply With Quote
Old 10/08/2015, 04:11 PM   #2
Tamy
Big Clucker
 
Join Date: Sep 2014
Posts: 87
Reputation: 20
Default Re: How can I do this?

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.
Tamy is offline   Reply With Quote
Old 10/08/2015, 04:15 PM   #3
SoFahim
Gangsta
 
SoFahim's Avatar
 
Join Date: May 2015
Location: Bangladesh.
Posts: 879
Reputation: 86
Default Re: How can I do this?

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.
__________________
Lead Developer & Mapping manager of SARP

You can contact me at Discord, my ID: Gold#8839 available for paid works
Quote:
SoFahim is offline   Reply With Quote
Old 10/08/2015, 04:17 PM   #4
Michael B
High-roller
 
Michael B's Avatar
 
Join Date: Oct 2014
Location: Romania
Posts: 1,004
Reputation: 127
Default Re: How can I do this?

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.
__________________
Michael B is offline   Reply With Quote
Old 10/08/2015, 04:23 PM   #5
SickAttack
High-roller
 
Join Date: Dec 2013
Posts: 4,759
Reputation: 754
Default Re: How can I do this?

@Michael - Use booleans and a timer instead. You do not always need that code to run, I assume.
SickAttack is offline   Reply With Quote
Old 10/08/2015, 04:32 PM   #6
Yerro
Little Clucker
 
Join Date: Oct 2013
Location: Spain
Posts: 35
Reputation: 3
Default Respuesta: How can I do this?

Thank you @Tamy and @SoFahim.

Solved
Yerro is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



All times are GMT. The time now is 12:41 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.