Raised This Month: $ Target: $400
 0% 

Item Gold AK little problem / Question


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
NYZANN
Junior Member
Join Date: Mar 2022
Location: Turkey
Old 04-05-2022 , 04:40   Item Gold AK little problem / Question
Reply With Quote #1

I apologize for bothering you again but I just don't understand .. my code restricts the "ak-47 gold" weapon from being bought twice a round .. I wish I couldn't buy it if I have it in my hand, but if he throws it down, he can buy it from the shop again.


Code:
public zp_extra_item_selected(player, itemid)
{
	if ( itemid == g_itemid )
	{
	if(g_HasAk[player])
	{
	new name[32]
	get_user_name(player, name, 31)
	ColorChat(player, "^4[ZP]^3 %s^1, you already have the ^4Golden Kalashnikov^1 !", name);
	return ZP_PLUGIN_HANDLED;
	}
	if ( user_has_weapon(player, CSW_AK47) )
	{
	drop_prim(player)
	}

	give_item(player, "weapon_ak47")
	new name[32]
	get_user_name(player, name, 31)
	ColorChat(player, "^4[ZP]^3 %s^1, you bought ^4Golden Kalashnikov^1, Good Luck !", name)
	g_HasAk[player] = true;
	}
	return PLUGIN_CONTINUE;
}
full code !
Code:
#include <amxmodx>
#include <fakemeta>
#include <fun>
#include <hamsandwich>
#include <cstrike>
#include <zp_apocalypse>

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

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

/* Pcvars */
new cvar_dmgmultiplier, cvar_goldbullets,  cvar_custommodel, cvar_uclip

// Item ID
new g_itemid

new bool:g_HasAk[33]

new g_hasZoom[ 33 ]
new bullets[ 33 ]

// Sprite
new m_spriteTexture

const Wep_ak47 = ((1<<CSW_AK47))

public plugin_init()
{
	
	/* CVARS */
	cvar_dmgmultiplier = register_cvar("zp_goldenak_dmg_multiplier", "4")
	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] Golden AK47", "1.1", "AlejandroSk")
	// Register Zombie Plague extra item
	g_itemid = zp_register_extra_item("\r[Item]\w Golden Kalashnikov", 45, ZP_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_forward( FM_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(id, pev_viewmodel2, AK_V_MODEL)
		set_pev(id, pev_weaponmodel2, AK_P_MODEL)
	}
	return PLUGIN_HANDLED
}

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



public fw_TakeDamage(victim, inflictor, attacker, Float:damage)
{
    if ( is_valid_player( attacker ) && get_user_weapon(attacker) == CSW_AK47 && g_HasAk[attacker] )
    {
        SetHamParamFloat(4, damage * get_pcvar_float( cvar_dmgmultiplier ) )
    }
}

public fw_CmdStart( id, uc_handle, seed )
{
	if( !is_user_alive( id ) ) 
		return PLUGIN_HANDLED
	
	if( ( get_uc( uc_handle, UC_Buttons ) & IN_ATTACK2 ) && !( pev( id, pev_oldbuttons ) & IN_ATTACK2 ) )
	{
		new szClip, szAmmo
		new szWeapID = get_user_weapon( id, szClip, szAmmo )
		
		if( szWeapID == CSW_AK47 && g_HasAk[id] == true && !g_hasZoom[id] == true)
		{
			g_hasZoom[id] = true
			cs_set_user_zoom( id, CS_SET_AUGSG552_ZOOM, 0 )
			emit_sound( id, CHAN_ITEM, "weapons/zoom.wav", 0.20, 2.40, 0, 100 )
		}
		
		else if ( szWeapID == CSW_AK47 && g_HasAk[id] == true && g_hasZoom[id])
		{
			g_hasZoom[ id ] = false
			cs_set_user_zoom( id, CS_RESET_ZOOM, 0 )
			
		}
		
	}
	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(id, pteam, 15)
		
		if ((bullets[id] > clip) && (wpnid == CSW_AK47) && g_HasAk[id]) 
		{
			new vec1[3], vec2[3]
			get_user_origin(id, vec1, 1) // origin; your camera point.
			get_user_origin(id, vec2, 4) // termina; where your bullet goes (4 is cs-only)
			
			
			//BEAMENTPOINTS
			message_begin( MSG_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_short( m_spriteTexture )
			write_byte(1) // framestart
			write_byte(5) // framerate
			write_byte(2) // life
			write_byte(10) // width
			write_byte(0) // noise
			write_byte( 255 )     // r, g, b
			write_byte( 215 )       // r, g, b
			write_byte( 0 )       // r, g, b
			write_byte(200) // brightness
			write_byte(150) // speed
			message_end()
		}
	
		bullets[id] = clip
	}
	
}

public zp_extra_item_selected(player, itemid)
{
	if ( itemid == g_itemid )
	{
	if(g_HasAk[player])
	{
	new name[32]
	get_user_name(player, name, 31)
	ColorChat(player, "^4[ZP]^3 %s^1, you already have the ^4Golden Kalashnikov^1 !", name);
	return ZP_PLUGIN_HANDLED;
	}
	if ( user_has_weapon(player, CSW_AK47) )
	{
	drop_prim(player)
	}

	give_item(player, "weapon_ak47")
	new name[32]
	get_user_name(player, name, 31)
	ColorChat(player, "^4[ZP]^3 %s^1, you bought ^4Golden Kalashnikov^1, Good Luck !", name)
	g_HasAk[player] = true;
	}
	return PLUGIN_CONTINUE;
}

stock drop_prim(id) 
{
	new weapons[32], num
	get_user_weapons(id, weapons, num)
	for (new i = 0; i < num; i++) {
		if (Wep_ak47 & (1<<weapons[i])) 
		{
			static wname[32]
			get_weaponname(weapons[i], wname, sizeof wname - 1)
			engclient_cmd(id, "drop", wname)
		}
	}
}

stock ColorChat(id, String[], any:...)
{
	static szMesage[192];
	vformat(szMesage, charsmax(szMesage), String, 3);
	
	replace_all(szMesage, charsmax(szMesage), "!1", "^1");
	replace_all(szMesage, charsmax(szMesage), "!3", "^3");
	replace_all(szMesage, charsmax(szMesage), "!4", "^4");
	
	static g_msg_SayText = 0;
	if(!g_msg_SayText)
		g_msg_SayText = get_user_msgid("SayText");
	
	new Players[32], iNum = 1, i;

 	if(id) Players[0] = id;
	else get_players(Players, iNum, "ch");
	
	for(--iNum; iNum >= 0; iNum--)
	{
		i = Players[iNum];
	
		message_begin(MSG_ONE_UNRELIABLE, g_msg_SayText, _, i);
		write_byte(i);
		write_string(szMesage);
		message_end();
	}
}
NYZANN is offline
Supremache
Veteran Member
Join Date: Sep 2019
Location: Egypt
Old 04-05-2022 , 06:56   Re: Item Gold AK little problem / Question
Reply With Quote #2

Combine it: if ( g_HasAk[player] && user_has_weapon(player, CSW_AK47) )

Or
if ( user_has_weapon(player, CSW_AK47) )
{
drop_prim(player)
}
else g_HasAk[player] = false
__________________
Youtube.com/Supremache

Bank System [Nvault - SQL Support]
VIP System
  • If you think it's that simple, then do it yourself.

Last edited by Supremache; 04-05-2022 at 07:04.
Supremache is offline
NYZANN
Junior Member
Join Date: Mar 2022
Location: Turkey
Old 04-05-2022 , 16:48   Re: Item Gold AK little problem / Question
Reply With Quote #3

I tried this variant and the other one, everything works as I would like, one problem ... now I don't lose ammo packs when I buy it ..


Code:
public zp_extra_item_selected(player, itemid)
{
	if ( itemid == g_itemid )
	{
	if(g_HasAk[player] && user_has_weapon(player, CSW_AK47))
	{
	new name[32]
	get_user_name(player, name, 31)
	ColorChat(player, "^4[ZP]^3 %s^1, you already have the ^4Golden Kalashnikov^1 !", name);
	return ZP_PLUGIN_HANDLED;
	}
	if ( user_has_weapon(player, CSW_AK47) )
	{
	drop_prim(player)
	}

	give_item(player, "weapon_ak47")
	new name[32]
	get_user_name(player, name, 31)
	ColorChat(player, "^4[ZP]^3 %s^1, you bought ^4Golden Kalashnikov^1, Good Luck !", name)
	g_HasAk[player] = true;
	}
	return PLUGIN_CONTINUE;
}

Last edited by NYZANN; 04-05-2022 at 17:05.
NYZANN is offline
Dyaus
Member
Join Date: Aug 2021
Old 04-05-2022 , 18:26   Re: Item Gold AK little problem / Question
Reply With Quote #4

use another variable + new round event .
also use first variant from original post or else if you have ak in your hands when buying you won't lose ammo(can be exploited as a bug)
PHP Code:
//add this at the top
new g_bought
//add this to plugin_init()
register_event("HLTV""event_new_round""a""1=0""2=0")
//event new round
public event_new_round()
{
    
// i dont know if this is supposed to loop through all players but i'm sure some1 will correct me
    
g_bought 0
}
//extra item selected
public zp_extra_item_selected(playeritemid)
{
    if ( 
itemid == g_itemid && g_bought 0)
    {
    if(
g_HasAk[player])
    {
    new 
name[32]
    
get_user_name(playername31)
    
ColorChat(player"^4[ZP]^3 %s^1, you already have the ^4Golden Kalashnikov^1 !"name);
    return 
ZP_PLUGIN_HANDLED;
    }
    if ( 
user_has_weapon(playerCSW_AK47) )
    {
    
drop_prim(player)
    }

    
give_item(player"weapon_ak47")
    new 
name[32]
    
get_user_name(playername31)
    
ColorChat(player"^4[ZP]^3 %s^1, you bought ^4Golden Kalashnikov^1, Good Luck !"name)
    
g_HasAk[player] = true;
    
g_bought 1
    
}
    return 
PLUGIN_CONTINUE;

Dyaus is offline
NYZANN
Junior Member
Join Date: Mar 2022
Location: Turkey
Old 04-06-2022 , 05:17   Re: Item Gold AK little problem / Question
Reply With Quote #5

C:\Users\MARIUS\Desktop\zpx_shop_item_goldenA K_test.sma(229) : warning 211: possibly unintended assignment
C:\Users\MARIUS\Desktop\zpx_shop_item_goldenA K_test.sma(229) : error 022: must be lvalue (non-constant)
C:\Users\MARIUS\Desktop\zpx_shop_item_goldenA K_test.sma(229) : warning 215: expression has no effect
C:\Users\MARIUS\Desktop\zpx_shop_item_goldenA K_test.sma(229) : error 001: expected token: ";", but found ")"
C:\Users\MARIUS\Desktop\zpx_shop_item_goldenA K_test.sma(229) : error 029: invalid expression, assumed zero
C:\Users\MARIUS\Desktop\zpx_shop_item_goldenA K_test.sma(229) : fatal error 107: too many error messages on one line


Code:
public zp_extra_item_selected(player, itemid)
{
    if(itemid == g_itemid && g_bought = 0);
    {
    if(g_HasAk[player])
    {
    new name[32]
    get_user_name(player, name, 31)
    ColorChat(player, "^4[ZP]^3 %s^1, you already have the ^4Golden Kalashnikov^1 !", name);
    return ZP_PLUGIN_HANDLED;
    }
    if ( user_has_weapon(player, CSW_AK47) )
    {
    drop_prim(player)
    }

    give_item(player, "weapon_ak47")
    new name[32]
    get_user_name(player, name, 31)
    ColorChat(player, "^4[ZP]^3 %s^1, you bought ^4Golden Kalashnikov^1, Good Luck !", name)
    g_HasAk[player] = true;
    g_bought = 1
    }
    return PLUGIN_CONTINUE;
}
line problem
Code:
    if(itemid == g_itemid && g_bought = 0);
I thought of a simpler solution ... but honestly I'm not very good at it, I thought that in the round where he buys the golden ak-47 he can't throw it down until the next round when he will give it a and normal.

Last edited by NYZANN; 04-06-2022 at 05:21.
NYZANN is offline
Dyaus
Member
Join Date: Aug 2021
Old 04-06-2022 , 06:40   Re: Item Gold AK little problem / Question
Reply With Quote #6

Quote:
I thought of a simpler solution ... but honestly I'm not very good at it, I thought that in the round where he buys the golden ak-47 he can't throw it down until the next round when he will give it a and normal.
that can work but it's not as simple as you make it out to be , not dropping it is a different code from zp_extra_item_selected() and will cause error by contradicting with the stock drop_prim() when buying so the new round solution is simpler now for my code :
if(itemid == g_itemid && g_bought = 0); >>>>>> if(itemid == g_itemid && g_bought == 0);

my mistake .

Edit : if you want a chat message to be added to that like "this item can onlt be bought once per round" , just ask

Last edited by Dyaus; 04-06-2022 at 06:43.
Dyaus is offline
NYZANN
Junior Member
Join Date: Mar 2022
Location: Turkey
Old 04-06-2022 , 15:07   Re: Item Gold AK little problem / Question
Reply With Quote #7

Code:
Edit : if you want a chat message to be added to that like "this item can onlt be bought once per round" , just ask
sure if you don't mind: D

and
Code:
if(itemid == g_itemid && g_bought == 0);
zpx_shop_item_goldenAK_test.sma(229) : error 036: empty statement

Last edited by NYZANN; 04-06-2022 at 15:15.
NYZANN is offline
Dyaus
Member
Join Date: Aug 2021
Old 04-06-2022 , 16:46   Re: Item Gold AK little problem / Question
Reply With Quote #8

PHP Code:
public zp_extra_item_selected(playeritemid)
{
    if ( 
itemid == g_itemid && g_bought == 0)
    {
    if(
g_HasAk[player])
    {
    new 
name[32]
    
get_user_name(playername31)
    
ColorChat(player"^4[ZP]^3 %s^1, you already have the ^4Golden Kalashnikov^1 !"name);
    return 
ZP_PLUGIN_HANDLED;
    }
    if ( 
user_has_weapon(playerCSW_AK47) )
    {
    
drop_prim(player)
    }

    
give_item(player"weapon_ak47")
    new 
name[32]
    
get_user_name(playername31)
    
ColorChat(player"^4[ZP]^3 %s^1, you bought ^4Golden Kalashnikov^1, Good Luck !"name)
    
g_HasAk[player] = true;
    
g_bought 1
    
}
    if ( 
itemid == g_itemid && g_bought == 1)
    {
        
ColorChat(player"^4[ZP]^1 Golden AK can only be bought ONCE Per Round !")
        return 
ZP_PLUGIN_HANDLED
    
}
    return 
PLUGIN_CONTINUE;

don't forget to remove the ";" after "if ( itemid == g_itemid && g_bought == 0)" the error comes from there
Dyaus is offline
NYZANN
Junior Member
Join Date: Mar 2022
Location: Turkey
Old 04-06-2022 , 17:04   Re: Item Gold AK little problem / Question
Reply With Quote #9

Forgive me for the headache, it's okay, thank you
NYZANN 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 22:44.


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