Raised This Month: $2 Target: $400
 0% 

Solved [Help] Drop weapon if user is under level 10


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
elmedin
Senior Member
Join Date: Nov 2013
Old 05-11-2020 , 03:15   [Help] Drop weapon if user is under level 10
Reply With Quote #1

Hey i need a little bit of help, when a player picks up a weapon on the ground that the weapon level is higher than user level i want the weapon to drop from his hand. (The native of level is get_user_level(id))
Code:
public orHere{

if(get_user_level(id) > 10){

// idk what to write here

           }
}

PHP Code:
/*
[ZP] Extra Item: Golden Ak 47
Team: Humans

Description: This plugin adds a new weapon for Human Teams.
Weapon Cost: 30

Features:
- This weapon do more damage
- This weapon has zoom
- Launch Lasers
- This weapon has unlimited bullets

Credits:

KaOs - For his Dual MP5 mod

Cvars:


- zp_goldenak_dmg_multiplier <5> - Damage Multiplier for Golden Ak 47
- zp_goldenak_gold_bullets <1|0> - Golden bullets effect ?
- zp_goldenak_custom_model <1|0> - Golden ak Custom Model
- zp_goldenak_unlimited_clip <1|0> - Golden ak Unlimited Clip 

*/



#include <amxmodx>
#include <fakemeta>
#include <fun>
#include <hamsandwich>
#include <cstrike>
#include <zombieplague>

#define is_valid_player(%1) (1 <= %1 <= 32)

new AK_V_MODEL[64] = "models/zombie_plague/v_golden_ak47.mdl"
new AK_P_MODEL[64] = "models/zombie_plague/p_golden_ak47.mdl"

/* Pcvars */
new cvar_dmgmultipliercvar_goldbullets,  cvar_custommodelcvar_uclip

// Item ID
new g_itemid

new bool:g_HasAk[33]

new 
g_hasZoom33 ]
new 
bullets33 ]

// Sprite
new m_spriteTexture

const Wep_ak47 = ((1<<CSW_AK47))

public 
plugin_init()
{
    
    
/* CVARS */
    
cvar_dmgmultiplier register_cvar("zp_goldenak_dmg_multiplier""5")
    
cvar_custommodel register_cvar("zp_goldenak_custom_model""1")
    
cvar_goldbullets register_cvar("zp_goldenak_gold_bullets""1")
    
cvar_uclip register_cvar("zp_goldenak_unlimited_clip""1")
    
    
// Register The Plugin
    
register_plugin("[ZP] Extra: Golden Ak 47""1.1""AlejandroSk")
    
// Register Zombie Plague extra item
    
g_itemid zp_register_extra_item("Golden Ak 47"30ZP_TEAM_HUMAN)
    
// Death Msg
    
register_event("DeathMsg""Death""a")
    
// Weapon Pick Up
    
register_event("WeapPickup","checkModel","b","1=19")
    
// Current Weapon Event
    
register_event("CurWeapon","checkWeapon","be","1=1")
    
register_event("CurWeapon""make_tracer""be""1=1""3>0")
    
// Ham TakeDamage
    
RegisterHam(Ham_TakeDamage"player""fw_TakeDamage")
    
register_forwardFM_CmdStart"fw_CmdStart" )
    
RegisterHam(Ham_Spawn"player""fwHamPlayerSpawnPost"1)
    
}

public 
client_connect(id)
{
    
g_HasAk[id] = false
}

public 
client_disconnect(id)
{
    
g_HasAk[id] = false
}

public 
Death()
{
    
g_HasAk[read_data(2)] = false
}

public 
fwHamPlayerSpawnPost(id)
{
    
g_HasAk[id] = false
}

public 
plugin_precache()
{
    
precache_model(AK_V_MODEL)
    
precache_model(AK_P_MODEL)
    
m_spriteTexture precache_model("sprites/dot.spr")
    
precache_sound("weapons/zoom.wav")
}

public 
zp_user_infected_post(id)
{
    if (
zp_get_user_zombie(id))
    {
        
g_HasAk[id] = false
    
}
}

public 
checkModel(id)
{
    if ( 
zp_get_user_zombie(id) )
        return 
PLUGIN_HANDLED
    
    
new szWeapID read_data(2)
    
    if ( 
szWeapID == CSW_AK47 && g_HasAk[id] == true && get_pcvar_num(cvar_custommodel) )
    {
        
set_pev(idpev_viewmodel2AK_V_MODEL)
        
set_pev(idpev_weaponmodel2AK_P_MODEL)
    }
    return 
PLUGIN_HANDLED
}

public 
checkWeapon(id)
{
    new 
plrClipplrAmmoplrWeap[32]
    new 
plrWeapId
    
    plrWeapId 
get_user_weapon(idplrClip plrAmmo)
    
    if (
plrWeapId == CSW_AK47 && g_HasAk[id])
    {
        
checkModel(id)
    }
    else 
    {
        return 
PLUGIN_CONTINUE
    
}
    
    if (
plrClip == && get_pcvar_num(cvar_uclip))
    {
        
// If the user is out of ammo..
        
get_weaponname(plrWeapIdplrWeap31)
        
// Get the name of their weapon
        
give_item(idplrWeap)
        
engclient_cmd(idplrWeap
        
engclient_cmd(idplrWeap)
        
engclient_cmd(idplrWeap)
    }
    return 
PLUGIN_HANDLED
}



public 
fw_TakeDamage(victiminflictorattackerFloat:damage)
{
    if ( 
is_valid_playerattacker ) && get_user_weapon(attacker) == CSW_AK47 && g_HasAk[attacker] )
    {
        
SetHamParamFloat(4damage get_pcvar_floatcvar_dmgmultiplier ) )
    }
}

public 
fw_CmdStartiduc_handleseed )
{
    if( !
is_user_aliveid ) ) 
        return 
PLUGIN_HANDLED
    
    
if( ( get_ucuc_handleUC_Buttons ) & IN_ATTACK2 ) && !( pevidpev_oldbuttons ) & IN_ATTACK2 ) )
    {
        new 
szClipszAmmo
        
new szWeapID get_user_weaponidszClipszAmmo )
        
        if( 
szWeapID == CSW_AK47 && g_HasAk[id] == true && !g_hasZoom[id] == true)
        {
            
g_hasZoom[id] = true
            cs_set_user_zoom
idCS_SET_AUGSG552_ZOOM)
            
emit_soundidCHAN_ITEM"weapons/zoom.wav"0.202.400100 )
        }
        
        else if ( 
szWeapID == CSW_AK47 && g_HasAk[id] == true && g_hasZoom[id])
        {
            
g_hasZoomid ] = false
            cs_set_user_zoom
idCS_RESET_ZOOM)
            
        }
        
    }
    return 
PLUGIN_HANDLED
}


public 
make_tracer(id)
{
    if (
get_pcvar_num(cvar_goldbullets))
    {
        new 
clip,ammo
        
new wpnid get_user_weapon(id,clip,ammo)
        new 
pteam[16]
        
        
get_user_team(idpteam15)
        
        if ((
bullets[id] > clip) && (wpnid == CSW_AK47) && g_HasAk[id]) 
        {
            new 
vec1[3], vec2[3]
            
get_user_origin(idvec11// origin; your camera point.
            
get_user_origin(idvec24// termina; where your bullet goes (4 is cs-only)
            
            
            //BEAMENTPOINTS
            
message_beginMSG_BROADCAST,SVC_TEMPENTITY)
            
write_byte (0)     //TE_BEAMENTPOINTS 0
            
write_coord(vec1[0])
            
write_coord(vec1[1])
            
write_coord(vec1[2])
            
write_coord(vec2[0])
            
write_coord(vec2[1])
            
write_coord(vec2[2])
            
write_shortm_spriteTexture )
            
write_byte(1// framestart
            
write_byte(5// framerate
            
write_byte(2// life
            
write_byte(10// width
            
write_byte(0// noise
            
write_byte255 )     // r, g, b
            
write_byte215 )       // r, g, b
            
write_byte)       // r, g, b
            
write_byte(200// brightness
            
write_byte(150// speed
            
message_end()
        }
    
        
bullets[id] = clip
    
}
    
}

public 
zp_extra_item_selected(playeritemid)
{
    if ( 
itemid == g_itemid )
    {
        if ( 
user_has_weapon(playerCSW_AK47) )
        {
            
drop_prim(player)
        }
        
        
give_item(player"weapon_ak47")
        
client_print(playerprint_chat"[ZP] You bought Golden Ak - 47")
        
g_HasAk[player] = true;
    }
}

stock drop_prim(id
{
    new 
weapons[32], num
    get_user_weapons
(idweaponsnum)
    for (new 
0numi++) {
        if (
Wep_ak47 & (1<<weapons[i])) 
        {
            static 
wname[32]
            
get_weaponname(weapons[i], wnamesizeof wname 1)
            
engclient_cmd(id"drop"wname)
        }
    }
}
/* AMXX-Studio Notes - DO NOT MODIFY BELOW HERE
*{\\ rtf1\\ ansi\\ deff0{\\ fonttbl{\\ f0\\ fnil Tahoma;}}\n\\ viewkind4\\ uc1\\ pard\\ lang1034\\ f0\\ fs16 \n\\ par }
*/ 

Last edited by elmedin; 05-11-2020 at 20:50.
elmedin is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 05-11-2020 , 07:36   Re: [Help] Drop weapon if user is under level 10
Reply With Quote #2

Code:
engclient_cmd(id, "drop")
__________________

Last edited by OciXCrom; 05-11-2020 at 07:36.
OciXCrom is offline
Send a message via Skype™ to OciXCrom
elmedin
Senior Member
Join Date: Nov 2013
Old 05-11-2020 , 09:48   Re: [Help] Drop weapon if user is under level 10
Reply With Quote #3

Quote:
Originally Posted by OciXCrom View Post
Code:
engclient_cmd(id, "drop")
Hm, can u give me an example if someone is trying to pick it from the ground ?
elmedin is offline
thEsp
Veteran Member
Join Date: Aug 2017
Location: Land of Eagles
Old 05-11-2020 , 15:08   Re: [Help] Drop weapon if user is under level 10
Reply With Quote #4

Pre-hook Ham_Touch and block it if the client has insufficient level?
thEsp is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 05-11-2020 , 17:43   Re: [Help] Drop weapon if user is under level 10
Reply With Quote #5

I agree with thEsp, instead of picking up and dropping, just block the pickup, it is super easy. This would apply to weaponbox and armoury_entity.

This is a very rough example that will block picking up weapons, you can add more logic/conditions to it. E.g. only if the weapon is on the ground, type of weapon, only particular players, only in certain scenarios, etc.
PHP Code:
#include <amxmodx>
#include <engine>

public plugin_init() 
{
    
register_touch"weaponbox" "player" "PlayerTouchWeaponbox" );
}

public 
PlayerTouchWeaponboxiEntity iPlayer )
{
    return 
PLUGIN_HANDLED;

__________________
Bugsy is online now
elmedin
Senior Member
Join Date: Nov 2013
Old 05-11-2020 , 19:15   Re: [Help] Drop weapon if user is under level 10
Reply With Quote #6

Quote:
Originally Posted by Bugsy View Post
I agree with thEsp, instead of picking up and dropping, just block the pickup, it is super easy. This would apply to weaponbox and armoury_entity.

This is a very rough example that will block picking up weapons, you can add more logic/conditions to it. E.g. only if the weapon is on the ground, type of weapon, only particular players, only in certain scenarios, etc.
PHP Code:
#include <amxmodx>
#include <engine>

public plugin_init() 
{
    
register_touch"weaponbox" "player" "PlayerTouchWeaponbox" );
}

public 
PlayerTouchWeaponboxiEntity iPlayer )
{
    return 
PLUGIN_HANDLED;

Hm, can you give me 1 example ? the native is get_user_level(id)
elmedin is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 05-11-2020 , 19:23   Re: [Help] Drop weapon if user is under level 10
Reply With Quote #7

Do you have an array that stores weapon levels?
__________________
Bugsy is online now
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 05-11-2020 , 20:05   Re: [Help] Drop weapon if user is under level 10
Reply With Quote #8

Here's the framework, you just need to fill in the weapon level function, and delete my get_user_level() since you have your own. I have the get user level and get weapon level returning dummy values for testing purposes.

PHP Code:

#include <amxmodx>
#include <cstrike>
#include <hamsandwich>
#include <engine>

new const Version[] = "0.1";

#define MAX_PLAYERS 32

#define XO_CWEAPONBOX 4

new const m_rgpPlayerItems_CWeaponBox] = { 34 35 , ... };

enum WeaponInfo
{
    
WeaponBoxIndex,
    
ReturnType
}

new 
g_iLastTouchedMAX_PLAYERS ][ WeaponInfo ];

public 
plugin_init() 
{
    
register_plugin"Weapon Pickup Level" Version "0.1" );
    
    
register_touch"weaponbox" "player" "PlayerTouchWeaponbox" );
}

public 
PlayerTouchWeaponboxiEntity iPlayer )
{    
    if ( 
g_iLastTouchediPlayer ][ WeaponBoxIndex ] == iEntity )
    {
        return 
g_iLastTouchediPlayer ][ ReturnType ];
    }
    else
    {
        
g_iLastTouchediPlayer ][ WeaponBoxIndex ] = iEntity;
        return ( 
g_iLastTouchediPlayer ][ ReturnType ] = ( ( get_user_leveliPlayer ) < get_weapon_levelcs_get_weaponbox_typeiEntity ) ) ) ? PLUGIN_HANDLED PLUGIN_CONTINUE ) );
    }


public 
get_user_levelid )
{
    return 
7;
}

public 
get_weapon_leveliCSWeaponIndex )
{
    
//iCSWeaponIndex holds CSW_ weapon index.

    
return 6;
}

cs_get_weaponbox_typeiWeaponBox )
{
    new 
iWeaponEntity iWeaponID;
    
    for ( new 
<= i++ )
    {
        if ( ( 
iWeaponEntity get_pdata_cbaseiWeaponBox m_rgpPlayerItems_CWeaponBox] , XO_CWEAPONBOX ) ) > )
        {
            
iWeaponID cs_get_weapon_idiWeaponEntity );
            break;
        }
    }
    
    return 
iWeaponID;

__________________
Bugsy is online now
elmedin
Senior Member
Join Date: Nov 2013
Old 05-11-2020 , 20:50   Re: [Help] Drop weapon if user is under level 10
Reply With Quote #9

Quote:
Originally Posted by Bugsy View Post
Here's the framework, you just need to fill in the weapon level function, and delete my get_user_level() since you have your own. I have the get user level and get weapon level returning dummy values for testing purposes.

PHP Code:

#include <amxmodx>
#include <cstrike>
#include <hamsandwich>
#include <engine>

new const Version[] = "0.1";

#define MAX_PLAYERS 32

#define XO_CWEAPONBOX 4

new const m_rgpPlayerItems_CWeaponBox] = { 34 35 , ... };

enum WeaponInfo
{
    
WeaponBoxIndex,
    
ReturnType
}

new 
g_iLastTouchedMAX_PLAYERS ][ WeaponInfo ];

public 
plugin_init() 
{
    
register_plugin"Weapon Pickup Level" Version "0.1" );
    
    
register_touch"weaponbox" "player" "PlayerTouchWeaponbox" );
}

public 
PlayerTouchWeaponboxiEntity iPlayer )
{    
    if ( 
g_iLastTouchediPlayer ][ WeaponBoxIndex ] == iEntity )
    {
        return 
g_iLastTouchediPlayer ][ ReturnType ];
    }
    else
    {
        
g_iLastTouchediPlayer ][ WeaponBoxIndex ] = iEntity;
        return ( 
g_iLastTouchediPlayer ][ ReturnType ] = ( ( get_user_leveliPlayer ) < get_weapon_levelcs_get_weaponbox_typeiEntity ) ) ) ? PLUGIN_HANDLED PLUGIN_CONTINUE ) );
    }


public 
get_user_levelid )
{
    return 
7;
}

public 
get_weapon_leveliCSWeaponIndex )
{
    
//iCSWeaponIndex holds CSW_ weapon index.

    
return 6;
}

cs_get_weaponbox_typeiWeaponBox )
{
    new 
iWeaponEntity iWeaponID;
    
    for ( new 
<= i++ )
    {
        if ( ( 
iWeaponEntity get_pdata_cbaseiWeaponBox m_rgpPlayerItems_CWeaponBox] , XO_CWEAPONBOX ) ) > )
        {
            
iWeaponID cs_get_weapon_idiWeaponEntity );
            break;
        }
    }
    
    return 
iWeaponID;

Thanks <3
elmedin is offline
elmedin
Senior Member
Join Date: Nov 2013
Old 05-11-2020 , 21:08   Re: [Help] Drop weapon if user is under level 10
Reply With Quote #10

Quote:
Originally Posted by Bugsy View Post
Do you have an array that stores weapon levels?
Yes, i do have the array that stores weapons in the weapon menu + levels which for me it was a pain in the ass cause im an amature


HTML Code:
if (zp_get_user_level(id) < ArrayGetCell(i_lvl , ItemId))
	{
		Show_MainEquipMenu(id)
		client_printc(id , "%L" , id , "ZX_NOT_AT_LVL")
		return ITEM_DISABLED
	} //this is the array that i use in the main weapon plugin

Last edited by elmedin; 05-11-2020 at 21:21.
elmedin is offline
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

Forum Jump


All times are GMT -4. The time now is 23:07.


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