AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Change secondary weapon to a new one (https://forums.alliedmods.net/showthread.php?t=207760)

leonardo_ 02-06-2013 13:49

Change secondary weapon to a new one
 
Hi guys!

I am beginner in programming plugins and that kind of stuff, so please don't judge me so much :) Thank you!

So I have that:

PHP Code:

public LogEvent_RoundStart2()
{
    
CurrentRound++;
    new 
players[32], playerpnum;
    
get_players(playerspnum"a");
    for(new 
0pnumi++)
    {
        
player players[i];
        if(
is_user_alive(player) && get_user_flags(player) & ADMIN_LEVEL_G)
        {
            
give_item(player"weapon_deagle")
            
give_item(player"ammo_50ae")
            
give_item(player"ammo_50ae")
            
give_item(player"ammo_50ae")
            
            if (!
get_pcvar_num(g_menu_active))
                return 
PLUGIN_CONTINUE
            
            
if(CurrentRound >= 3)
            {
                
Showrod(player);
            }
        }
    }
    return 
PLUGIN_HANDLED


And I need to make it like, If at the beginning of 1 round player has USP or Glock, script changes it into Deagle and player has only deagle... How can I do that? Thank you! :) :)

EpicMonkey 02-06-2013 14:16

Re: Change secondary weapon to a new one
 
PHP Code:

if (!get_pcvar_num(g_menu_active))
                return 
PLUGIN_CONTINUE 

From what i can see, you should use a bool there instead

as for the usp or glock thing, strip their weapons and give them a deagle

wickedd 02-06-2013 14:18

Re: Change secondary weapon to a new one
 
Strip their weapons first, then give them a weapon.

PHP Code:

if(is_user_alive(player) && get_user_flags(player) & ADMIN_LEVEL_G)
        {
            
strip_user_weaponsplayer)
            
give_item(player"weapon_deagle")
            
give_item(player"ammo_50ae")
            
give_item(player"ammo_50ae")
            
give_item(player"ammo_50ae"
                        
            
if (!get_pcvar_num(g_menu_active))
                return 
PLUGIN_CONTINUE
            
            
if(CurrentRound >= 3)
            {
                
Showrod(player);
            }
        }
    } 


.Dare Devil. 02-06-2013 14:24

Re: Change secondary weapon to a new one
 
Quote:

Originally Posted by wickedd (Post 1888578)
Strip their weapons first, then give them a weapon.

PHP Code:

if(is_user_alive(player) && get_user_flags(player) & ADMIN_LEVEL_G)
        {
            
strip_user_weaponsplayer)
            
give_item(player"weapon_deagle")
            
give_item(player"ammo_50ae")
            
give_item(player"ammo_50ae")
            
give_item(player"ammo_50ae"
                        
            
if (!get_pcvar_num(g_menu_active))
                return 
PLUGIN_CONTINUE
            
            
if(CurrentRound >= 3)
            {
                
Showrod(player);
            }
        }
    } 


do i remember it right that "strip_user_weapons()" also drop knife? :)

wickedd 02-06-2013 15:24

Re: Change secondary weapon to a new one
 
Quote:

Originally Posted by .Dare Devil. (Post 1888581)
do i remember it right that "strip_user_weapons()" also drop strips knife? :)

Yes it does. He can give it back to them;
PHP Code:

give_itemplayer"weapon_knife" 


leonardo_ 02-06-2013 19:07

Re: Change secondary weapon to a new one
 
Quote:

Originally Posted by wickedd (Post 1888578)
Strip their weapons first, then give them a weapon.

PHP Code:

if(is_user_alive(player) && get_user_flags(player) & ADMIN_LEVEL_G)
        {
            
strip_user_weaponsplayer)
            
give_item(player"weapon_deagle")
            
give_item(player"ammo_50ae")
            
give_item(player"ammo_50ae")
            
give_item(player"ammo_50ae"
                        
            
if (!get_pcvar_num(g_menu_active))
                return 
PLUGIN_CONTINUE
            
            
if(CurrentRound >= 3)
            {
                
Showrod(player);
            }
        }
    } 



PHP Code:

strip_user_weaponsplayer

what should I do there? Do I change ( player) into something?

Because when I compile it, It gives me 1 warning on that line... What should I do?

and when I deleted that line:
PHP Code:

strip_user_weaponsplayer

It doesn't show an error.

Doc-Holiday 02-06-2013 19:17

Re: Change secondary weapon to a new one
 
Whats the warning?

PHP Code:

#include <amxmodx>
#include <fakemeta>
#include <hamsandwich>

const OFFSET_PRIMARYWEAPON 116;
const 
OFFSET_C4_SLOT 372;

StripUserWeapons(id)
{
    new 
iC4Ent get_pdata_cbase(idOFFSET_C4_SLOT);
    
    if( 
iC4Ent )
    {
        
set_pdata_cbase(idOFFSET_C4_SLOTFM_NULLENT);
    }

    
strip_user_weapons(id);
    
give_item(id"weapon_knife");
    
set_pdata_int(idOFFSET_PRIMARYWEAPON0);

    if( 
iC4Ent )
    {
        
entity_set_int(idEV_INT_weaponsentity_get_int(idEV_INT_weapons) | (1<<CSW_C4));
        
set_pdata_cbase(idOFFSET_C4_SLOTiC4Ent);
        
cs_set_user_bpammo(idCSW_C41);
        
cs_set_user_plant(id1);
    }
    return 
PLUGIN_HANDLED;


This stock is from Conor If the player has the C4 it will give him the c4 back so that you dont strip that.. and of course the knife also

leonardo_ 02-06-2013 19:25

Re: Change secondary weapon to a new one
 
Quote:

Originally Posted by Doc-Holiday (Post 1888769)
Whats the warning?

PHP Code:

#include <amxmodx>
#include <fakemeta>
#include <hamsandwich>

const OFFSET_PRIMARYWEAPON 116;
const 
OFFSET_C4_SLOT 372;

StripUserWeapons(id)
{
    new 
iC4Ent get_pdata_cbase(idOFFSET_C4_SLOT);
    
    if( 
iC4Ent )
    {
        
set_pdata_cbase(idOFFSET_C4_SLOTFM_NULLENT);
    }

    
strip_user_weapons(id);
    
give_item(id"weapon_knife");
    
set_pdata_int(idOFFSET_PRIMARYWEAPON0);

    if( 
iC4Ent )
    {
        
entity_set_int(idEV_INT_weaponsentity_get_int(idEV_INT_weapons) | (1<<CSW_C4));
        
set_pdata_cbase(idOFFSET_C4_SLOTiC4Ent);
        
cs_set_user_bpammo(idCSW_C41);
        
cs_set_user_plant(id1);
    }
    return 
PLUGIN_HANDLED;


This stock is from Conor If the player has the C4 it will give him the c4 back so that you dont strip that.. and of course the knife also

that warning:
http://joxi.ru/uploads/prod/20130207...9a64c1ee1.jpeg

and line 144 is that one:

PHP Code:

strip_user_weapons(player

http://joxi.ru/uploads/prod/20130207...7d3d909a7.jpeg


And tried that code:
PHP Code:

 for(new 0pnumi++)
    {
        
player players[i];
        if(
is_user_alive(player) && get_user_flags(player) & ADMIN_LEVEL_G)
        {
            
strip_user_weaponsplayer)
            
give_item(player"weapon_deagle")
            
give_item(player"ammo_50ae")
            
give_item(player"ammo_50ae")
            
give_item(player"ammo_50ae")
            
give_item(player"weapon_knife")
            
            if (!
get_pcvar_num(g_menu_active))
                return 
PLUGIN_CONTINUE
            
            
if(CurrentRound >= 3)
            {
                
Showrod(player);
            }
        }
    } 

and I didn't have anything, just deagle... even knife was deleted, like the menu that usually shows on the top-left of the screen was deleted too... Like when you choosing between knife and primary weapon it shows you a yellow menu on the top, and with that code it didn't show me anything...

Can anyone help me to fix that...

wickedd 02-07-2013 02:19

Re: Change secondary weapon to a new one
 
You can ignore that warning or if you really want to fix search for "loose indentation". Also, strip_user_weapons will remove ALL weapons from players. To give them a knife just add the code below to your plugin.
PHP Code:

give_itemplayer"weapon_knife" 


naven 02-07-2013 04:13

Re: Change secondary weapon to a new one
 
loose identation usually means that your code looks like this: (note that code itself is the same)
Code:

{
        if(player)
        {
        if(g_bSolid[host] && g_bSolid[ent] && get_distance_f( g_fOrigin[host], g_fOrigin[ent] ) <= 10000)
        {
        if(get_pcvar_num(g_iCvar[1]) && g_iTeam[host] != g_iTeam[ent])
        return FMRES_IGNORED;
        set_es(es_handle, ES_Solid, SOLID_NOT); // makes semiclip flawless

It should be:
Code:

        if(player)
        {
                if(g_bSolid[host] && g_bSolid[ent] && get_distance_f( g_fOrigin[host], g_fOrigin[ent] ) <= 10000)
                {
                        if(get_pcvar_num(g_iCvar[1]) && g_iTeam[host] != g_iTeam[ent])
                        return FMRES_IGNORED;
                        set_es(es_handle, ES_Solid, SOLID_NOT); // makes semiclip flawless

Also, post your complete code and tell me again what is the problem because i can't understand you right now.


All times are GMT -4. The time now is 20:31.

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