Raised This Month: $51 Target: $400
 12% 

Replace weapon with another?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Bloodlvst
Senior Member
Join Date: Jul 2007
Old 12-03-2011 , 15:41   Replace weapon with another?
Reply With Quote #1

So I have a plugin for donators that allows them to buy any weapon from the opposite team.

A slight problem I'm having while testing is that let's say I'm a terrorist. I have an AK, but issues the command to buy an M4. The M4 just drops to my feet while I still have the AK. I want to have the AK dropped and the M4 in the player's hands.

If I'm gathering what I've searched correctly, I need to use SDKHooks to force a weapon to be dropped, correct? In either case, I could use the help. Someone else wrote it for me as a paid plugin, but he has been hard to reach lately.

PHP Code:
        if(StrEqual(info"elite"))
        {
            new 
currentmoney GetEntData(clientMoneyOffset);
            if(
currentmoney ELITE_COST)
            {
                
PrintToChat(client"[SM] You do not have enough money.");
                return;
            }
            
SetEntData(clientMoneyOffsetcurrentmoney ELITE_COST4true);
            
GivePlayerItem(client"weapon_elite");
        }
        if(
StrEqual(info"mac10"))
        {
            new 
currentmoney GetEntData(clientMoneyOffset);
            if(
currentmoney MAC10_COST)
            {
                
PrintToChat(client"[SM] You do not have enough money.");
                return;
            }
            
SetEntData(clientMoneyOffsetcurrentmoney MAC10_COST4true);
            
GivePlayerItem(client"weapon_mac10");
        } 
__________________
Quote:
skywalker: I have cs source client 5 how to upgrade to client 7
BAILOPAN: oh
Bloodlvst is offline
Impact123
Veteran Member
Join Date: Oct 2011
Location: Germany
Old 12-03-2011 , 16:26   Re: Replace weapon with another?
Reply With Quote #2

Quote:
If I'm gathering what I've searched correctly, I need to use SDKHooks to force a weapon to be dropped, correct?
No, not correct, why everybody think's he need an extension for everything?

Here is an example:
PHP Code:
MyFunction(client)
{
    
// Gets the Clients weapon in slot 0 - Primary
    
new index GetPlayerWeaponSlot(client0);

    
// If the index is not -1 - Client has a Primary weapon 
    
if(index != -1)
    {
        
// Drop it
        
CS_DropWeapon(clientindexfalsetrue);

        
// If you want the weapon to be destroyed after tossing
        // AcceptEntityInput(index, "Kill");
    
}

    
// Give the player the named weapon
    
GivePlayerItem(client"weaponname");

I commented it because it sounds like you are not familiar with scripting.

Yours sincerely
Impact
__________________

Last edited by Impact123; 12-03-2011 at 16:37.
Impact123 is offline
thetwistedpanda
Good Little Panda
Join Date: Sep 2008
Old 12-03-2011 , 16:26   Re: Replace weapon with another?
Reply With Quote #3

Take a look at my Buy Command plugin, it has the code you need (since I'm too hungover to pull up the api >.<)
__________________
thetwistedpanda is offline
Bloodlvst
Senior Member
Join Date: Jul 2007
Old 12-03-2011 , 17:43   Re: Replace weapon with another?
Reply With Quote #4

So if I have both primary and secondary weapons to check (since there is a CT and T only pistol) should I make it like this?

Original code:
PHP Code:
TWeapons(client, const String:weapon[])
{
    if(!
IsPlayerAlive(client) && GetClientTeam(client) != 2)
        return;
        
    if(
StrEqual(weapon"fiveseven"))
    {
        new 
currentmoney GetEntData(clientMoneyOffset);
        if(
currentmoney FIVESEVEN_COST)
        {
            
PrintToChat(client"[SM] You do not have enough money.");
            return;
        }
        
SetEntData(clientMoneyOffsetcurrentmoney FIVESEVEN_COST4true);
        
GivePlayerItem(client"weapon_fiveseven");
    }
    else if(
StrEqual(weapon"tmp"))
    {
        new 
currentmoney GetEntData(clientMoneyOffset);
        if(
currentmoney TMP_COST)
        {
            
PrintToChat(client"[SM] You do not have enough money.");
            return;
        }
        
SetEntData(clientMoneyOffsetcurrentmoney TMP_COST4true);
        
GivePlayerItem(client"weapon_tmp");
    }



New code:
PHP Code:
TWeapons(client, const String:weapon[])
{
    new 
index GetPlayerWeaponSlot(client0);
    new 
index =  GetPlayerWeaponSlot(client1);
    
    if(!
IsPlayerAlive(client) && GetClientTeam(client) != 2)
        return;
        
    if(
StrEqual(weapon"fiveseven"))
    {
        new 
currentmoney GetEntData(clientMoneyOffset);
        if(
currentmoney FIVESEVEN_COST)
        {
            
PrintToChat(client"[SM] You do not have enough money.");
            return;
        }
        
SetEntData(clientMoneyOffsetcurrentmoney FIVESEVEN_COST4true);
        if(
index != -1)
        {
            
CS_DropWeapon(clientindexfalsetrue);
        }
        
GivePlayerItem(client"weapon_fiveseven");
    }
    else if(
StrEqual(weapon"tmp"))
    {
        new 
currentmoney GetEntData(clientMoneyOffset);
        if(
currentmoney TMP_COST)
        {
            
PrintToChat(client"[SM] You do not have enough money.");
            return;
        }
        
SetEntData(clientMoneyOffsetcurrentmoney TMP_COST4true);
        if(
index != -1)
        {
            
CS_DropWeapon(clientindexfalsetrue);
        }
        
GivePlayerItem(client"weapon_tmp");
    }

I'm guessing index is just a name you gave the variable? Would I name one "Primary" and another "Secondary" or is the way I have it right?
__________________
Quote:
skywalker: I have cs source client 5 how to upgrade to client 7
BAILOPAN: oh

Last edited by Bloodlvst; 12-03-2011 at 17:44.
Bloodlvst is offline
Impact123
Veteran Member
Join Date: Oct 2011
Location: Germany
Old 12-04-2011 , 04:19   Re: Replace weapon with another?
Reply With Quote #5

Quote:
Originally Posted by Bloodlvst View Post
I'm guessing index is just a name you gave the variable? Would I name one "Primary" and another "Secondary" or is the way I have it right?
No, you cannot create 2 variables with the same name in the same (i think it's called scope).
Your example should look like this, much shorter and reusable:
View Code

You should post the whole code for best help.

Yours sincerely
Impact
__________________

Last edited by Impact123; 12-04-2011 at 04:26.
Impact123 is offline
Bloodlvst
Senior Member
Join Date: Jul 2007
Old 12-04-2011 , 09:06   Re: Replace weapon with another?
Reply With Quote #6

Quote:
Originally Posted by Impact123 View Post
No, you cannot create 2 variables with the same name in the same (i think it's called scope).
Your example should look like this, much shorter and reusable:
View Code

You should post the whole code for best help.

Yours sincerely
Impact
Oh okay, so I just strip the weapon slot desire before giving the weapon. Good to know I had the right idea.

The whole code is pretty much just that except with some more guns, a menu panel, and a chat command to call it.

I'll make this change, compile, and let you know how it works. Thanks again!
__________________
Quote:
skywalker: I have cs source client 5 how to upgrade to client 7
BAILOPAN: oh
Bloodlvst is offline
blodia
Veteran Member
Join Date: Sep 2009
Location: UK
Old 12-04-2011 , 10:41   Re: Replace weapon with another?
Reply With Quote #7

if you're not bothered about removing the old weapon you can use the EquipPlayerWeapon native with the new weapon to force a player equip it and drop their old one.
blodia is offline
Bloodlvst
Senior Member
Join Date: Jul 2007
Old 12-04-2011 , 14:47   Re: Replace weapon with another?
Reply With Quote #8

Quote:
Originally Posted by blodia View Post
if you're not bothered about removing the old weapon you can use the EquipPlayerWeapon native with the new weapon to force a player equip it and drop their old one.
So instead of just giving the weapon I would equip it instead?
__________________
Quote:
skywalker: I have cs source client 5 how to upgrade to client 7
BAILOPAN: oh
Bloodlvst is offline
blodia
Veteran Member
Join Date: Sep 2009
Location: UK
Old 12-04-2011 , 18:46   Re: Replace weapon with another?
Reply With Quote #9

give it then equip it, but it depends if you want the old weapon to be removed or not.
blodia is offline
Bloodlvst
Senior Member
Join Date: Jul 2007
Old 12-05-2011 , 16:21   Re: Replace weapon with another?
Reply With Quote #10

Quote:
Originally Posted by Impact123 View Post
No, you cannot create 2 variables with the same name in the same (i think it's called scope).
Your example should look like this, much shorter and reusable:
View Code

You should post the whole code for best help.

Yours sincerely
Impact
I keep getting compile errors, so as you stated, here is the original code in its entirety.

View Code
__________________
Quote:
skywalker: I have cs source client 5 how to upgrade to client 7
BAILOPAN: oh

Last edited by Bloodlvst; 12-05-2011 at 17:39.
Bloodlvst is offline
Reply



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

Forum Jump


All times are GMT -4. The time now is 05:48.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode