Add gun to level_system

Unpaid Requests, Public Plugins
czirimbolo
Veteran Member
Veteran Member
Poland
Posts: 416
Joined: 1 Year Ago
Has thanked: 15 times
Been thanked: 1 time
Contact:

Add gun to level_system

#1

Post by czirimbolo » 1 Month Ago

Hello, can someone show me how to add a gun to my level system? Example: I would like to add JETPACK for players who have 40 level

here is jetpack.sma

Code: Select all

#include <zombie_escape>
#include <engine>
 
#define JETPACK_COST 1000
 
new const ClassInfoTarget[] = "info_target"
new const ClassBreakAble[] = "func_breakable"
new const ClassnameJetPack[] = "n4d_jetpack"
new const ClassnameRocket[] = "n4d_bazooka"
new const ModelVJetPack[] = "models/mu/v_jp_mu.mdl"
new const ModelPJetPack[] = "models/mu/p_jp_mu.mdl"
new const ModelWJetPack[] = "models/mu/w_jp_mu.mdl"
new const ModelRocket[] = "models/rpgrocket.mdl"
new const SoundPickup[] = "items/gunpickup2.wav"
new const SoundShoot[] = "mu/at4-1.wav"
new const SoundTravel[] = "mu/bfuu.wav"
new const SoundFly[] = "mu/fly.wav"
new const SoundBlow[] = "mu/blow.wav"
 
new bool:bHasJetPack[33]
new Float:fJetpackFuel[33]
new Float:fLastShoot[33]
new SprExp, SprTrail, ItemJetPack
new CvarMaxFuel, CvarRadius, CvarDamage, CvarSpeed, CvarCooldown, CvarRegen, CvarRocketSpeed, CvarRemove
new Float:CMaxFuel, Float:CRadius, Float:CDamage, CSpeed, Float:CCooldown, Float:CRegen, CRocketSpeed, Float:CRemove
new bool:g_bBlockBuy
 
//Uncomment this to draw ring effect
//#define DrawRing
 
//Uncomment this to draw flame effect
//#define DrawFlame
 
#if defined DrawRing
new SprRing
#endif
 
#if defined DrawFlame
new SprFlame
#endif
 
public plugin_precache()
{
    precache_sound(SoundPickup)
    precache_sound(SoundShoot)
    precache_sound(SoundTravel)
    precache_sound(SoundFly)
    precache_sound(SoundBlow)
   
    SprExp = precache_model("sprites/zerogxplode.spr")
    SprTrail = precache_model("sprites/smoke.spr")
   
    #if defined DrawFlame
    SprFlame = precache_model("sprites/xfireball3.spr")
    #endif
   
    #if defined DrawRing
    SprRing = precache_model("sprites/shockwave.spr")
    #endif
   
    precache_model(ModelVJetPack)
    precache_model(ModelPJetPack)
    precache_model(ModelWJetPack)
    precache_model(ModelRocket)
}
 
public plugin_init()
{
    register_plugin("New Jetpack", "0.0.3", "Bad_Bud,ZmOutStanding,Connor,wbyokomo")
   
    register_event("HLTV", "OnNewRound", "a", "1=0", "2=0")
    register_logevent("OnRoundEnd", 2, "1=Round_End")
   
    RegisterHam(Ham_Killed, "player", "OnPlayerKilled")
    RegisterHam(Ham_Player_Jump, "player", "OnPlayerJump")
    RegisterHam(Ham_Weapon_SecondaryAttack, "weapon_knife", "OnKnifeSecAtkPost", 1)
    RegisterHam(Ham_Item_Deploy, "weapon_knife", "OnKnifeDeployPost", 1)
   
    register_forward(FM_PlayerPreThink, "OnPlayerPreThink")
   
    register_touch(ClassnameRocket, "*", "OnTouchRocket")
    register_touch(ClassnameJetPack, "player", "OnTouchJetPack")
    register_think(ClassnameJetPack, "OnThinkJetPack")
   
    CvarMaxFuel = register_cvar("jp_maxfuel", "250.0")
    CvarRadius = register_cvar("jp_radius", "250.0")
    CvarDamage = register_cvar("jp_damage", "600.0")
    CvarSpeed = register_cvar("jp_speed", "300")
    CvarCooldown = register_cvar("jp_cooldown", "10.0")
    CvarRegen = register_cvar("jp_regen", "0.5")
    CvarRocketSpeed = register_cvar("jp_rocket_speed", "1500")
    CvarRemove = register_cvar("jp_remove_time", "420.0")
 
    ItemJetPack = ze_register_item("Jetpack", JETPACK_COST, 0)
   
    register_clcmd("drop", "CmdDropJP")
}
 
public client_putinserver(id)
{
    ResetValues(id)
}
 
public ze_user_infected(iVictim)
{
    ResetValues(iVictim)
}
 
public client_disconnected(id)
{
    ResetValues(id)
}
 
public ze_game_started()
{
    g_bBlockBuy = true
    set_task(20.0, "EnableBuy")
}
 
public EnableBuy()
{
    g_bBlockBuy = false
}
 
public OnNewRound()
{
    RemoveAllJetPack()
    CMaxFuel = get_pcvar_float(CvarMaxFuel)
    CRadius = get_pcvar_float(CvarRadius)
    CDamage = get_pcvar_float(CvarDamage)
    CSpeed = get_pcvar_num(CvarSpeed)
    CCooldown = get_pcvar_float(CvarCooldown)
    CRegen = get_pcvar_float(CvarRegen)
    CRocketSpeed = get_pcvar_num(CvarRocketSpeed)
    CRemove = get_pcvar_float(CvarRemove)
}
 
public ze_user_humanized(id)
{
    ResetValues(id) // Item lasts only one round
}
 
public OnRoundEnd()
{
    RemoveAllJetPack()
}
 
public OnPlayerKilled(id)
{
    if(bHasJetPack[id]) DropJetPack(id);
   
    ResetValues(id)
}
 
public OnPlayerJump(id)
{
    if(bHasJetPack[id] && fJetpackFuel[id] > 0.0 && get_user_weapon(id) == CSW_KNIFE && pev(id, pev_button) & IN_DUCK && ~pev(id, pev_flags) & FL_ONGROUND)
    {
        static Float:vVelocity[3], Float:upSpeed
        pev(id, pev_velocity, vVelocity)
        upSpeed = vVelocity[2] + 35.0
        velocity_by_aim(id, CSpeed, vVelocity)
        vVelocity[2] = upSpeed > 300.0 ? 300.0 : upSpeed
        set_pev(id, pev_velocity, vVelocity)
       
        #if defined DrawFlame
        pev(id, pev_origin, vVelocity)
        engfunc(EngFunc_MessageBegin, MSG_PVS, SVC_TEMPENTITY, vVelocity, 0)
        write_byte(TE_SPRITE)
        engfunc(EngFunc_WriteCoord, vVelocity[0])
        engfunc(EngFunc_WriteCoord, vVelocity[1])
        engfunc(EngFunc_WriteCoord, vVelocity[2])
        write_short(SprFlame)
        write_byte(8)
        write_byte(128)
        message_end()
        #endif
       
        fJetpackFuel[id] > 80.0 ? emit_sound(id, CHAN_STREAM, SoundFly, VOL_NORM, ATTN_NORM, 0,  PITCH_NORM) : emit_sound(id, CHAN_STREAM, SoundBlow, VOL_NORM, ATTN_NORM, 0, PITCH_NORM);
        fJetpackFuel[id] -= 1.0
    }
}
 
public ze_select_item_pre(id, itemid)
{
    // Return Available and we will block it in Post, So it dosen't affect other plugins
    if (itemid != ItemJetPack)
        return ZE_ITEM_AVAILABLE
   
    // Available for Humans only, So don't show it for zombies
    if (ze_is_user_zombie(id))
        return ZE_ITEM_DONT_SHOW
 
    if (bHasJetPack[id])
        return ZE_ITEM_UNAVAILABLE
   
    if (g_bBlockBuy && itemid == ItemJetPack)
        return ZE_ITEM_UNAVAILABLE
   
    return ZE_ITEM_AVAILABLE
}
 
 
public ze_select_item_post(id, item)
{
    if (item == ItemJetPack)
    {
        bHasJetPack[id] = true
        ze_colored_print(id, "JetPack usage: JUMP+DUCK")
        engclient_cmd(id, "weapon_knife")
        ReplaceModel(id)
    }
}
 
public OnKnifeSecAtkPost(ent2)
{
    if(pev_valid(ent2) == 2)
    {
        static id, Float:ctime
        id = get_pdata_cbase(ent2, 41, 4)
        ctime = get_gametime()
        if(is_user_alive(id) && bHasJetPack[id] && fLastShoot[id] < ctime)
        {
            new ent = create_entity(ClassInfoTarget)
            if(ent)
            {
                engfunc(EngFunc_SetModel, ent, ModelRocket)
                engfunc(EngFunc_SetSize, ent, Float:{0.0, 0.0, 0.0}, Float:{0.0, 0.0, 0.0})
                new Float:fOrigin[3]
                pev(id, pev_origin, fOrigin)
                fOrigin[2] += 16.0
                engfunc(EngFunc_SetOrigin, ent, fOrigin)
                set_pev(ent, pev_classname, ClassnameRocket)
                set_pev(ent, pev_dmg, 100.0)
                set_pev(ent, pev_owner, id)
                velocity_by_aim(id, CRocketSpeed, fOrigin)
                set_pev(ent, pev_velocity, fOrigin)
                new Float:vecAngles[3]
                engfunc(EngFunc_VecToAngles, fOrigin, vecAngles)
                set_pev(ent, pev_angles, vecAngles)
                set_pev(ent, pev_movetype, MOVETYPE_FLY)
                set_pev(ent, pev_effects, EF_LIGHT)
                set_pev(ent, pev_solid, SOLID_BBOX)
               
                emit_sound(id, CHAN_STATIC, SoundShoot, VOL_NORM, ATTN_NORM, 0, PITCH_NORM)
                emit_sound(ent, CHAN_WEAPON, SoundTravel, VOL_NORM, ATTN_NORM, 0, PITCH_NORM)
               
                message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
                write_byte(TE_BEAMFOLLOW)
                write_short(ent)
                write_short(SprTrail)
                write_byte(40)
                write_byte(5)
                write_byte(224)
                write_byte(224)
                write_byte(255)
                write_byte(192)
                message_end()
               
                fLastShoot[id] = ctime+CCooldown
            }
            else
            {
                client_print(id, print_chat, "[JpDebug] Failed to create rocket.")
                fLastShoot[id] = ctime+1.5
            }
        }
    }
}
 
public OnKnifeDeployPost(ent)
{
    if(pev_valid(ent) == 2)
    {
        static id; id = get_pdata_cbase(ent, 41, 4)
        if(is_user_alive(id) && bHasJetPack[id]) ReplaceModel(id);
    }
}
 
public OnPlayerPreThink(id)
{
    if(bHasJetPack[id] && fJetpackFuel[id] < CMaxFuel)
    {
        static button; button = pev(id, pev_button)
        if(!(button & IN_DUCK) && !(button & IN_JUMP)) fJetpackFuel[id] += CRegen;
    }
}
 
public OnTouchRocket(ent, id)
{
    static Float:fOrigin[3]
    pev(ent, pev_origin, fOrigin)
   
    engfunc(EngFunc_MessageBegin, MSG_PVS, SVC_TEMPENTITY, fOrigin, 0)
    write_byte(TE_EXPLOSION)
    engfunc(EngFunc_WriteCoord, fOrigin[0])
    engfunc(EngFunc_WriteCoord, fOrigin[1])
    engfunc(EngFunc_WriteCoord, fOrigin[2])
    write_short(SprExp)
    write_byte(40)
    write_byte(30)
    write_byte(10)
    message_end()
   
    #if defined DrawRing
    engfunc(EngFunc_MessageBegin, MSG_PVS, SVC_TEMPENTITY, fOrigin, 0)
    write_byte(TE_BEAMCYLINDER)
    engfunc(EngFunc_WriteCoord, fOrigin[0])
    engfunc(EngFunc_WriteCoord, fOrigin[1])
    engfunc(EngFunc_WriteCoord, fOrigin[2])
    engfunc(EngFunc_WriteCoord, fOrigin[0])
    engfunc(EngFunc_WriteCoord, fOrigin[1])
    engfunc(EngFunc_WriteCoord, fOrigin[2]+555.0)
    write_short(SprRing)
    write_byte(0)
    write_byte(1)
    write_byte(6)
    write_byte(8)
    write_byte(10)
    write_byte(224)
    write_byte(224)
    write_byte(255)
    write_byte(192)
    write_byte(5)
    message_end()
    #endif
   
    static attacker; attacker = pev(ent, pev_owner)
    if(!is_user_connected(attacker))
    {
        engfunc(EngFunc_RemoveEntity, ent)
        return PLUGIN_CONTINUE;
    }
   
    if(pev_valid(id) && !is_user_connected(id))
    {
        static szClassname[32]
        pev(id, pev_classname, szClassname, 31)
        if(equal(szClassname, ClassBreakAble) && (pev(id, pev_solid) != SOLID_NOT))
        {
            dllfunc(DLLFunc_Use, id, ent)
        }
    }
   
    static victim; victim = -1
    while((victim = engfunc(EngFunc_FindEntityInSphere, victim, fOrigin, CRadius)) != 0)
    {
        if(is_user_alive(victim) && ze_is_user_zombie(victim))
        {
            static Float:originV[3], Float:dist, Float:damage
            pev(victim, pev_origin, originV)
            dist = get_distance_f(fOrigin, originV)
            damage = CDamage-(CDamage/CRadius)*dist
            if(damage > 0.0)
            {
                ExecuteHamB(Ham_TakeDamage, victim, ent, attacker, damage, DMG_BULLET)
                //client_print(attacker, print_chat, "[Jp] Rocket damage: %.1f", damage)
            }
        }
    }
   
    engfunc(EngFunc_RemoveEntity, ent)
   
    return PLUGIN_CONTINUE;
}
 
public OnTouchJetPack(ent, id)
{
    if((pev(ent, pev_iuser4) != 11111) && is_user_alive(id) && !ze_is_user_zombie(id) && !bHasJetPack[id])
    {
        engfunc(EngFunc_RemoveEntity, ent)
        bHasJetPack[id] = true
        emit_sound(id, CHAN_STATIC, SoundPickup, VOL_NORM, ATTN_NORM, 0, PITCH_NORM)
        engclient_cmd(id,"weapon_knife")
        ReplaceModel(id)
    }
}
 
public OnThinkJetPack(ent)
{
    if(pev_valid(ent) == 2)
    {
        switch(pev(ent, pev_flTimeStepSound))
        {
            case 200:
            {
                set_pev(ent, pev_iuser4, 22222)
                set_pev(ent, pev_flTimeStepSound, 201)
                set_pev(ent, pev_nextthink, get_gametime()+CRemove)
            }
            case 201:
            {
                engfunc(EngFunc_RemoveEntity, ent)
            }
        }
    }
}
 
public CmdDropJP(id)
{
    if(is_user_alive(id) && bHasJetPack[id] && get_user_weapon(id) == CSW_KNIFE)
    {
        DropJetPack(id)
        bHasJetPack[id] = false
        set_pev(id, pev_viewmodel2, "models/v_knife.mdl")
        set_pev(id, pev_weaponmodel2, "models/p_knife.mdl")
        return PLUGIN_HANDLED;
    }
   
    return PLUGIN_CONTINUE;
}
 
ReplaceModel(id)
{
    set_pev(id, pev_viewmodel2, ModelVJetPack)
    set_pev(id, pev_weaponmodel2, ModelPJetPack)
}
 
DropJetPack(id)
{
    new ent = create_entity(ClassInfoTarget)
    if(!ent) return;
   
    engfunc(EngFunc_SetModel, ent, ModelWJetPack)
    engfunc(EngFunc_SetSize, ent, Float:{-8.0, -8.0, -8.0}, Float:{8.0, 8.0, 8.0})
    new Float:fOrigin[3]
    pev(id, pev_origin, fOrigin)
    fOrigin[2] += 16.0
    engfunc(EngFunc_SetOrigin, ent, fOrigin)
    set_pev(ent, pev_classname, ClassnameJetPack)
    velocity_by_aim(id, 800, fOrigin) //if it too far then reduce it
    set_pev(ent, pev_velocity, fOrigin)
    set_pev(ent, pev_movetype, MOVETYPE_TOSS)
    set_pev(ent, pev_effects, EF_LIGHT)
    set_pev(ent, pev_iuser4, 11111)
    set_pev(ent, pev_solid, SOLID_TRIGGER)
    set_pev(ent, pev_flTimeStepSound, 200)
    set_pev(ent, pev_nextthink, get_gametime()+2.0) // prevent drop/pickup exploit
}
 
RemoveAllJetPack()
{
    new ent = engfunc(EngFunc_FindEntityByString, -1, "classname", ClassnameJetPack)
    while(ent > 0)
    {
        engfunc(EngFunc_RemoveEntity, ent)
        ent = engfunc(EngFunc_FindEntityByString, -1, "classname", ClassnameJetPack)
    }
}
 
ResetValues(id)
{
    bHasJetPack[id] = false
    fJetpackFuel[id] = CMaxFuel
}
here is my weapon menu:

Code: Select all

#include <zombie_escape>
#include <ze_levels>

native give_golden_m3(id);
native give_golden_mp5(id);
native give_golden_m4a1(id);
native give_golden_ak47(id);

// Setting File
new const ZE_SETTING_RESOURCES[] = "zombie_escape.ini"

// Keys
const KEYSMENU = MENU_KEY_1|MENU_KEY_2|MENU_KEY_3|MENU_KEY_4|MENU_KEY_5|MENU_KEY_6|MENU_KEY_7|MENU_KEY_8|MENU_KEY_9|MENU_KEY_0
const OFFSET_CSMENUCODE = 205

// Primary Weapons Entities [Default Values]
new const szPrimaryWeaponEnt[][] =
{
	"weapon_xm1014",  // Level 0
	"weapon_ump45",   // Level 0
	"weapon_m3",      // Level 1
	"weapon_mp5navy", // Level 2
	"weapon_p90",     // Level 3
	"weapon_galil",   // Level 4
	"weapon_famas",   // Level 5
	"weapon_sg550",   // Level 6
	"weapon_g3sg1",   // Level 7
	"weapon_m249",    // Level 8
	"weapon_sg552",   // Level 9
	"weapon_aug",     // Level 10
	"weapon_m4a1",    // Level 11
	"weapon_ak47"     // Level 12
}

// Secondary Weapons Entities [Default Values]
new const szSecondaryWeaponEnt[][]=
{
	"weapon_usp",         // Level 0
	"weapon_p228",        // Level 0
	"weapon_glock18",     // Level 1
	"weapon_fiveseven",   // Level 2
	"weapon_deagle",      // Level 3
	"weapon_elite"        // Level 4
}

// Primary and Secondary Weapons Names [Default Values]
new const szWeaponNames[][] = 
{ 
	"", 
	"P228", 
	"",
	"Scout",
	"HE Grenade",
	"XM1014",
	"",
	"MAC-10",
	"AUG",
	"Smoke Grenade", 
	"Dual Elite",
	"Five Seven",
	"UMP 45",
	"SG-550",
	"Galil",
	"Famas",
	"USP",
	"Glock",
	"AWP",
	"MP5",
	"M249",
	"M3",
	"M4A1",
	"TMP",
	"G3SG1",
	"Flashbang",
	"Desert Eagle",
	"SG-552",
	"AK-47",
	"",
	"P90"
}

// Max Back Clip Ammo (Change it From here if you need)
new const szMaxBPAmmo[] =
{
	-1,
	52,
	-1,
	90,
	1,
	32,
	1,
	100,
	90,
	1,
	120,
	100,
	100,
	90,
	90,
	90,
	100,
	120,
	30,
	120,
	200,
	32,
	90,
	120,
	90,
	2,
	35,
	90,
	90,
	-1,
	100
}

// Menu selections
const MENU_KEY_AUTOSELECT = 7
const MENU_KEY_BACK = 7
const MENU_KEY_NEXT = 8
const MENU_KEY_EXIT = 9

// Variables
new Array:g_szPrimaryWeapons, Array:g_szSecondaryWeapons

new g_iMenuData[33][4],
	Float:g_fBuyTimeStart[33],
	bool:g_bBoughtPrimary[33],
	bool:g_bBoughtSecondary[33],
	WPN_MAXIDS[33]

// Define
#define WPN_STARTID g_iMenuData[id][0]
#define WPN_SELECTION (g_iMenuData[id][0]+key)
#define WPN_AUTO_ON g_iMenuData[id][1]
#define WPN_AUTO_PRI g_iMenuData[id][2]
#define WPN_AUTO_SEC g_iMenuData[id][3]

// Cvars
new g_pCvarBuyTime,
	g_pCvarHeGrenade,
	g_pCvarSmokeGrenade,
	g_pCvarFlashGrenade,
	g_pCvarBlockWeapLowLevel

public plugin_natives()
{
	register_native("ze_show_weapon_menu", "native_ze_show_weapon_menu", 1)
	register_native("ze_is_auto_buy_enabled", "native_ze_is_auto_buy_enabled", 1)
	register_native("ze_disable_auto_buy", "native_ze_disable_auto_buy", 1)
}

public plugin_precache()
{
	// Initialize arrays (32 is the max length of Weapon Entity like: weapon_ak47)
	g_szPrimaryWeapons = ArrayCreate(32, 1)
	g_szSecondaryWeapons = ArrayCreate(32, 1)
	
	// Load from external file
	amx_load_setting_string_arr(ZE_SETTING_RESOURCES, "Weapons Menu", "PRIMARY", g_szPrimaryWeapons)
	amx_load_setting_string_arr(ZE_SETTING_RESOURCES, "Weapons Menu", "SECONDARY", g_szSecondaryWeapons)
	
	// If we couldn't load from file, use and save default ones
	
	new iIndex
	
	if (ArraySize(g_szPrimaryWeapons) == 0)
	{
		for (iIndex = 0; iIndex < sizeof szPrimaryWeaponEnt; iIndex++)
			ArrayPushString(g_szPrimaryWeapons, szPrimaryWeaponEnt[iIndex])
		
		// If not found .ini File Create it and save default values in it
		amx_save_setting_string_arr(ZE_SETTING_RESOURCES, "Weapons Menu", "PRIMARY", g_szPrimaryWeapons)
	}
	
	if (ArraySize(g_szSecondaryWeapons) == 0)
	{
		for (iIndex = 0; iIndex < sizeof szSecondaryWeaponEnt; iIndex++)
			ArrayPushString(g_szSecondaryWeapons, szSecondaryWeaponEnt[iIndex])
		
		// If not found .ini File Create it and save default values in it
		amx_save_setting_string_arr(ZE_SETTING_RESOURCES, "Weapons Menu", "SECONDARY", g_szSecondaryWeapons)
	}
}

public plugin_init()
{
	register_plugin("[ZE] Levels Weapons Menu", "1.1", "Raheem")
	
	// Commands
	register_clcmd("guns", "Cmd_Buy")
	register_clcmd("say /enable", "Cmd_Enable")
	register_clcmd("say_team /enable", "Cmd_Enable")
	
	// Cvars
	g_pCvarBuyTime = register_cvar("ze_buy_time", "60")
	g_pCvarHeGrenade = register_cvar("ze_give_HE_nade", "1") // 0 Nothing || 1 Give HE
	g_pCvarSmokeGrenade = register_cvar("ze_give_SM_nade", "1")
	g_pCvarFlashGrenade = register_cvar("ze_give_FB_nade", "1")
	g_pCvarBlockWeapLowLevel = register_cvar("ze_block_weapons_lowlvl", "1")
	
	// Menus
	register_menu("Primary Weapons", KEYSMENU, "Menu_Buy_Primary")
	register_menu("Secondary Weapons", KEYSMENU, "Menu_Buy_Secondary")
	
	// Hams
	RegisterHam(Ham_Touch, "weaponbox", "Fw_TouchWeapon_Pre", 0)
	RegisterHam(Ham_Touch, "armoury_entity", "Fw_TouchWeapon_Pre", 0)
}

public client_disconnected(id)
{
	WPN_AUTO_ON = 0
	WPN_STARTID = 0
}

public Cmd_Enable(id)
{
	if (WPN_AUTO_ON)
	{
		ze_colored_print(id, "%L", LANG_PLAYER, "BUY_ENABLED")
		WPN_AUTO_ON = 0
	}
}

public Cmd_Buy(id)
{
	// Player Zombie
	if (ze_is_user_zombie(id))
	{
		ze_colored_print(id, "%L", LANG_PLAYER, "NO_BUY_ZOMBIE")
		return
	}
	
	// Player Dead
	if (!is_user_alive(id))
	{
		ze_colored_print(id, "%L", LANG_PLAYER, "DEAD_CANT_BUY_WEAPON")
		return
	}
	
	// Already bought
	if (g_bBoughtPrimary[id] && g_bBoughtSecondary[id])
	{
		ze_colored_print(id, "%L", LANG_PLAYER, "ALREADY_BOUGHT")
	}
	
	Show_Available_Buy_Menus(id)
}

public ze_user_humanized(id)
{
	// Static Values
	switch (ze_get_user_level(id))
	{
		case 0: WPN_MAXIDS[id] = 2
		case 1: WPN_MAXIDS[id] = 3
		case 2: WPN_MAXIDS[id] = 4
		case 3: WPN_MAXIDS[id] = 5
		case 4: WPN_MAXIDS[id] = 6
		case 5: WPN_MAXIDS[id] = 7
		case 6: WPN_MAXIDS[id] = 8
		case 7: WPN_MAXIDS[id] = 9
		case 8: WPN_MAXIDS[id] = 10
		case 9: WPN_MAXIDS[id] = 11
		case 10: WPN_MAXIDS[id] = 12
		case 11: WPN_MAXIDS[id] = 13
		case 12..14: WPN_MAXIDS[id] = 14
		case 15..19: WPN_MAXIDS[id] = 15 // Golden m3
		case 20..24: WPN_MAXIDS[id] = 16 // Golden MP5
		case 25..29: WPN_MAXIDS[id] = 17 // Golden M4A1
		case 30: WPN_MAXIDS[id] = 18     // Golden AK47
	}
	
	if (ze_get_user_level(id) > 30)
	{
		WPN_MAXIDS[id] = 18
	}

	// Buyzone time starts when player is set to human
	g_fBuyTimeStart[id] = get_gametime()
	
	g_bBoughtPrimary[id] = false
	g_bBoughtSecondary[id] = false
	
	// Player dead or zombie
	if (!is_user_alive(id) || ze_is_user_zombie(id))
		return
	
	if (WPN_AUTO_ON)
	{
		ze_colored_print(id, "%L", LANG_PLAYER, "RE_ENABLE_MENU")
		Buy_Primary_Weapon(id, WPN_AUTO_PRI)
		Buy_Secondary_Weapon(id, WPN_AUTO_SEC)
	}
	
	// Open available buy menus
	Show_Available_Buy_Menus(id)
	
	// Give HE Grenade
	if (get_pcvar_num(g_pCvarHeGrenade) != 0)
		rg_give_item(id, "weapon_hegrenade")
	
	// Give Smoke Grenade
	if (get_pcvar_num(g_pCvarSmokeGrenade) != 0)
		rg_give_item(id, "weapon_smokegrenade")
	
	// Give Flashbang Grenade
	if (get_pcvar_num(g_pCvarFlashGrenade) != 0)
		rg_give_item(id, "weapon_flashbang")
}

public Show_Available_Buy_Menus(id)
{
	// Already Bought
	if (g_bBoughtPrimary[id] && g_bBoughtSecondary[id])
		return
	
	// Here we use if and else if so we make sure that Primary weapon come first then secondary
	if (!g_bBoughtPrimary[id])
	{
		// Primary		
		Show_Menu_Buy_Primary(id)
	}
	else if (!g_bBoughtSecondary[id])
	{
		// Secondary
		Show_Menu_Buy_Secondary(id)
	}
}

public Show_Menu_Buy_Primary(id)
{
	new iMenuTime = floatround(g_fBuyTimeStart[id] + get_pcvar_float(g_pCvarBuyTime) - get_gametime())
	
	if (iMenuTime <= 0)
	{
		ze_colored_print(id, "%L", id, "BUY_MENU_TIME_EXPIRED")
		return
	}
	
	static szMenu[300], szWeaponName[32]
	new iLen, iIndex, iMaxLoops = min(WPN_STARTID+7, WPN_MAXIDS[id])
	
	// Title
	iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\y%L \w[\r%d\w-\r%d\w]^n^n", id, "MENU_PRIMARY_TITLE", WPN_STARTID+1, min(WPN_STARTID+7, WPN_MAXIDS[id]))
	
	// 1-7. Weapon List
	for (iIndex = WPN_STARTID; iIndex < iMaxLoops; iIndex++)
	{
		if (ze_get_user_level(id) == 0 && iIndex >= 2||
		ze_get_user_level(id) == 1 && iIndex >= 3 ||
		ze_get_user_level(id) == 2 && iIndex >= 4 ||
		ze_get_user_level(id) == 3 && iIndex >= 5 ||
		ze_get_user_level(id) == 4 && iIndex >= 6 ||
		ze_get_user_level(id) == 5 && iIndex >= 7 ||
		ze_get_user_level(id) == 6 && iIndex >= 8 ||
		ze_get_user_level(id) == 7 && iIndex >= 9 ||
		ze_get_user_level(id) == 8 && iIndex >= 10 ||
		ze_get_user_level(id) == 9 && iIndex >= 11 ||
		ze_get_user_level(id) == 10 && iIndex >= 12 ||
		ze_get_user_level(id) == 11 && iIndex >= 13 ||
		ze_get_user_level(id) == 12 && iIndex >= 14)
		{
			break
		}
		
		/*
		*  Note that WPN_MAXIDS start from 1 but iIndex start from 0.
		*/
		
		// Golden M3
		if (ze_get_user_level(id) >= 15 && ze_get_user_level(id) < 20)
		{
			if (iIndex == 14)
			{
				iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\w%d.\y %s^n", iIndex-WPN_STARTID+1, "Golden M3")
				break;
			}
		}
		
		// Golden MP5
		if (ze_get_user_level(id) >= 20 && ze_get_user_level(id) < 25)
		{
			if (iIndex == 14)
			{
				iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\w%d.\y %s^n", iIndex-WPN_STARTID+1, "Golden M3")
			}
			
			if (iIndex == 15)
			{
				iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\w%d.\y %s^n", iIndex-WPN_STARTID+1, "Golden MP5")
				break;
			}
		}
		
		// Golden M4A1
		if (ze_get_user_level(id) >= 25 && ze_get_user_level(id) < 30)
		{
			if (iIndex == 14)
			{
				iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\w%d.\y %s^n", iIndex-WPN_STARTID+1, "Golden M3")
			}
			
			if (iIndex == 15)
			{
				iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\w%d.\y %s^n", iIndex-WPN_STARTID+1, "Golden MP5")
			}
			
			if (iIndex == 16)
			{
				iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\w%d.\y %s^n", iIndex-WPN_STARTID+1, "Golden M4A1")
				break;
			}
		}
		
		// Golden AK47
		if (ze_get_user_level(id) >= 30)
		{
			if (iIndex == 14)
			{
				iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\w%d.\y %s^n", iIndex-WPN_STARTID+1, "Golden M3")
			}
			
			if (iIndex == 15)
			{
				iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\w%d.\y %s^n", iIndex-WPN_STARTID+1, "Golden MP5")
			}
			
			if (iIndex == 16)
			{
				iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\w%d.\y %s^n", iIndex-WPN_STARTID+1, "Golden M4A1")
			}
			
			if (iIndex == 17)
			{
				iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\w%d.\y %s^n", iIndex-WPN_STARTID+1, "Golden AK-47")
				break;
			}
		}
		
		// Must check if iIndex < 14 means max is AK47
		if (iIndex < 14)
		{
			ArrayGetString(g_szPrimaryWeapons, iIndex, szWeaponName, charsmax(szWeaponName))
			iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\w%d.\y %s^n", iIndex-WPN_STARTID+1, szWeaponNames[get_weaponid(szWeaponName)])
		}
	}
	
	if (iIndex < 7)
	{
		ArrayGetString(g_szPrimaryWeapons, iIndex, szWeaponName, charsmax(szWeaponName))
		iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "^n\r Next Level Unlock\w: \y%s^n", szWeaponNames[get_weaponid(szWeaponName)])
	}
	
	if (ze_get_user_level(id) == 5)
	{
		ArrayGetString(g_szPrimaryWeapons, 7, szWeaponName, charsmax(szWeaponName))
		iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "^n\r Next Level Unlock\w: \y%s^n", szWeaponNames[get_weaponid(szWeaponName)])
	}
	else if (ze_get_user_level(id) == 6)
	{
		ArrayGetString(g_szPrimaryWeapons, 8, szWeaponName, charsmax(szWeaponName))
		iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "^n\r Next Level Unlock\w: \y%s^n", szWeaponNames[get_weaponid(szWeaponName)])
	}
	else if (ze_get_user_level(id) == 7)
	{
		ArrayGetString(g_szPrimaryWeapons, 9, szWeaponName, charsmax(szWeaponName))
		iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "^n\r Next Level Unlock\w: \y%s^n", szWeaponNames[get_weaponid(szWeaponName)])
	}
	else if (ze_get_user_level(id) == 8)
	{
		ArrayGetString(g_szPrimaryWeapons, 10, szWeaponName, charsmax(szWeaponName))
		iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "^n\r Next Level Unlock\w: \y%s^n", szWeaponNames[get_weaponid(szWeaponName)])
	}
	else if (ze_get_user_level(id) == 9)
	{
		ArrayGetString(g_szPrimaryWeapons, 11, szWeaponName, charsmax(szWeaponName))
		iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "^n\r Next Level Unlock\w: \y%s^n", szWeaponNames[get_weaponid(szWeaponName)])
	}
	else if (ze_get_user_level(id) == 10)
	{
		ArrayGetString(g_szPrimaryWeapons, 12, szWeaponName, charsmax(szWeaponName))
		iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "^n\r Next Level Unlock\w: \y%s^n", szWeaponNames[get_weaponid(szWeaponName)])
	}
	else if (ze_get_user_level(id) == 11)
	{
		ArrayGetString(g_szPrimaryWeapons, 13, szWeaponName, charsmax(szWeaponName))
		iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "^n\r Next Level Unlock\w: \y%s^n", szWeaponNames[get_weaponid(szWeaponName)])
	}
	else if (ze_get_user_level(id) >= 12 && ze_get_user_level(id) < 15) // Golden M3
	{
		iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "^n\r Level 15 Unlock\w: \yGolden M3^n")
	}
	else if (ze_get_user_level(id) >= 15 && ze_get_user_level(id) < 20) // Golden MP5
	{
		iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "^n\r Level 20 Unlock\w: \yGolden MP5^n")
	}
	else if (ze_get_user_level(id) >= 20 && ze_get_user_level(id) < 25) // Golden M4A1
	{
		iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "^n\r Level 25 Unlock\w: \yGolden M4A1^n")
	}
	else if (ze_get_user_level(id) >= 25 && ze_get_user_level(id) < 30) // Golden Ak-47
	{
		iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "^n\r Level 30 Unlock\w: \yGolden AK-47^n")
	}

	// 8. Auto Select
	iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "^n\w8.\y %L \w[\r%L\w]", id, "MENU_AUTOSELECT", id, (WPN_AUTO_ON) ? "SAVE_YES" : "SAVE_NO")
	
	// 9. Next/Back - 0. Exit
	iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "^n^n\y9.\r %L \w/ \r%L^n^n\w0.\y %L", id, "NEXT", id, "BACK", id, "EXIT")
	
	// Fix for AMXX custom menus
	set_pdata_int(id, OFFSET_CSMENUCODE, 0)
	show_menu(id, KEYSMENU, szMenu, iMenuTime, "Primary Weapons")
}

public Show_Menu_Buy_Secondary(id)
{
	new iMenuTime = floatround(g_fBuyTimeStart[id] + get_pcvar_float(g_pCvarBuyTime) - get_gametime())
	
	if (iMenuTime <= 0)
	{
		ze_colored_print(id, "%L", id, "BUY_MENU_TIME_EXPIRED")
		return
	}
	
	static szMenu[250], szWeaponName[32]
	new iLen, iIndex, iMaxLoops = ArraySize(g_szSecondaryWeapons)
	
	// Title
	iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\y%L^n", id, "MENU_SECONDARY_TITLE")
	
	// 1-6. Weapon List
	for (iIndex = 0; iIndex < iMaxLoops; iIndex++)
	{
		if (ze_get_user_level(id) == 0 && iIndex >= 2 ||
		ze_get_user_level(id) == 1 && iIndex >= 3 ||
		ze_get_user_level(id) == 2 && iIndex >= 4 ||
		ze_get_user_level(id) == 3 && iIndex >= 5 ||
		ze_get_user_level(id) == 4 && iIndex >= 6)
		{
			break
		}
		
		ArrayGetString(g_szSecondaryWeapons, iIndex, szWeaponName, charsmax(szWeaponName))
		iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "^n\w%d.\y %s", iIndex+1, szWeaponNames[get_weaponid(szWeaponName)])
	}
	
	if (iIndex < ArraySize(g_szSecondaryWeapons))
	{
		ArrayGetString(g_szSecondaryWeapons, iIndex, szWeaponName, charsmax(szWeaponName))
		iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "^n^n\r Next Level Unlock\w: \y%s", szWeaponNames[get_weaponid(szWeaponName)])
	}
	
	// 8. Auto Select
	iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "^n^n\w8.\y %L \w[\r%L\w]", id, "MENU_AUTOSELECT", id, (WPN_AUTO_ON) ? "SAVE_YES" : "SAVE_NO")
	
	// 0. Exit
	iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "^n^n\w0.\y %L", id, "EXIT")
	
	// Fix for AMXX custom menus
	set_pdata_int(id, OFFSET_CSMENUCODE, 0)
	show_menu(id, KEYSMENU, szMenu, iMenuTime, "Secondary Weapons")
}

public Menu_Buy_Primary(id, key)
{
	// Player dead or zombie or already bought primary
	if (!is_user_alive(id) || ze_is_user_zombie(id) || g_bBoughtPrimary[id])
		return PLUGIN_HANDLED
	
	// Special keys / weapon list exceeded
	if (key >= MENU_KEY_AUTOSELECT || WPN_SELECTION >= WPN_MAXIDS[id])
	{
		switch (key)
		{
			case MENU_KEY_AUTOSELECT: // toggle auto select
			{
				WPN_AUTO_ON = 1 - WPN_AUTO_ON
			}
			case MENU_KEY_NEXT: // next/back
			{
				if (WPN_STARTID+7 < WPN_MAXIDS[id])
					WPN_STARTID += 7
				else
					WPN_STARTID = 0
			}
			case MENU_KEY_EXIT: // exit
			{
				return PLUGIN_HANDLED
			}
		}
		
		// Show buy menu again
		Show_Menu_Buy_Primary(id)
		return PLUGIN_HANDLED
	}
	
	// Store selected weapon id
	WPN_AUTO_PRI = WPN_SELECTION
	
	// Buy primary weapon
	Buy_Primary_Weapon(id, WPN_AUTO_PRI)
	
	// Show Secondary Weapons
	Show_Available_Buy_Menus(id)
	
	return PLUGIN_HANDLED
}

public Buy_Primary_Weapon(id, selection)
{
	if (selection == 14) // Golden M3
	{
		give_golden_m3(id)
		g_bBoughtPrimary[id] = true
		return true;
	}
	else if (selection == 15) // Golden MP5
	{
		give_golden_mp5(id)
		g_bBoughtPrimary[id] = true
		return true;
	}
	else if (selection == 16) // Golden M4A1
	{
		give_golden_m4a1(id)
		g_bBoughtPrimary[id] = true
		return true;
	}
	else if (selection == 17) // Golden AK47
	{
		give_golden_ak47(id)
		g_bBoughtPrimary[id] = true
		return true;
	}
	
	static szWeaponName[32]
	ArrayGetString(g_szPrimaryWeapons, selection, szWeaponName, charsmax(szWeaponName))
	new iWeaponId = get_weaponid(szWeaponName)
	
	// Strip and Give Full Weapon
	rg_give_item(id, szWeaponName, GT_REPLACE)
	rg_set_user_bpammo(id, WeaponIdType:iWeaponId, szMaxBPAmmo[iWeaponId])
	
	// Primary bought
	g_bBoughtPrimary[id] = true
	return true;
}

public Menu_Buy_Secondary(id, key)
{
	// Player dead or zombie or already bought secondary
	if (!is_user_alive(id) || ze_is_user_zombie(id) || g_bBoughtSecondary[id])
		return PLUGIN_HANDLED
	
	// Special keys / weapon list exceeded
	if (key >= ArraySize(g_szSecondaryWeapons))
	{
		// Toggle autoselect
		if (key == MENU_KEY_AUTOSELECT)
			WPN_AUTO_ON = 1 - WPN_AUTO_ON
		
		// Reshow menu unless user exited
		if (key != MENU_KEY_EXIT)
			Show_Menu_Buy_Secondary(id)
		
		return PLUGIN_HANDLED
	}
	
	// Store selected weapon id
	WPN_AUTO_SEC = key
	
	// Buy secondary weapon
	Buy_Secondary_Weapon(id, key)
	
	return PLUGIN_HANDLED
}

public Buy_Secondary_Weapon(id, selection)
{
	if ( ((selection == 2) && (ze_get_user_level(id) < 1)) ||
	((selection == 3) && (ze_get_user_level(id) < 2)) ||
	((selection == 4) && (ze_get_user_level(id) < 3)) ||
	((selection == 5) && (ze_get_user_level(id) < 4)) )
	{
		Show_Menu_Buy_Secondary(id)
		return;
	}

	static szWeaponName[32]
	ArrayGetString(g_szSecondaryWeapons, selection, szWeaponName, charsmax(szWeaponName))
	new iWeaponId = get_weaponid(szWeaponName)
	
	// Strip and Give Full Weapon
	rg_give_item(id, szWeaponName, GT_REPLACE)
	rg_set_user_bpammo(id, WeaponIdType:iWeaponId, szMaxBPAmmo[iWeaponId])
	
	// Secondary bought
	g_bBoughtSecondary[id] = true
}

public Fw_TouchWeapon_Pre(iEnt, id)
{
	if (get_pcvar_num(g_pCvarBlockWeapLowLevel) == 0)
		return HAM_IGNORED;
	
	// Not alive or Not Valid Weapon?
	if(!is_user_alive(id) || !pev_valid(iEnt))
		return HAM_IGNORED;
	
	// Get Weapon Model
	new szWeapModel[32]
	pev(iEnt, pev_model, szWeapModel, charsmax(szWeapModel))
	
	// Remove "models/w_" and ".mdl"
	copyc(szWeapModel, charsmax(szWeapModel), szWeapModel[contain(szWeapModel, "_" ) + 1], '.')
	
	// Set for mp5 to be same as "weapon_mp5navy"
	if(szWeapModel[1] == 'p' && szWeapModel[2] == '5')
		szWeapModel = "mp5navy"
	
	// Add "weapon_" to all model names
	static szWeaponEnt[32]
	formatex(szWeaponEnt, charsmax(szWeaponEnt), "weapon_%s", szWeapModel)

	// Get it's index in Weapon Array
	new iIndex, i
	
	// I won't explain the blew code if you need to understand ask me in Escapers-Zone.XYZ
	for (i = 0; i < ArraySize(g_szPrimaryWeapons); i++)
	{
		new szPrimaryWeapon[32]
		ArrayGetString(g_szPrimaryWeapons, i, szPrimaryWeapon, charsmax(szPrimaryWeapon))
		
		if (equali(szWeaponEnt, szPrimaryWeapon))
			iIndex = i
	}
	
	if (ze_get_user_level(id) == 0 && iIndex > 1)
	{
		return HAM_SUPERCEDE;
	}
	
	for (i = 1; i <= 11; i++)
	{
		if ((ze_get_user_level(id) == i) && iIndex > i+1)
		{
			return HAM_SUPERCEDE;
		}
	}
	
	return HAM_IGNORED;
}

// Natives
public native_ze_show_weapon_menu(id)
{
	if (!is_user_connected(id))
	{
		log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player (%d)", id)
		return false
	}
	
	Cmd_Buy(id)
	return true
}

public native_ze_is_auto_buy_enabled(id)
{
	if (!is_user_connected(id))
	{
		log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player (%d)", id)
		return -1;
	}
	
	return WPN_AUTO_ON;
}

public native_ze_disable_auto_buy(id)
{
	if (!is_user_connected(id))
	{
		log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player (%d)", id)
		return false
	}
	
	WPN_AUTO_ON = 0;
	return true
}
Image


czirimbolo
Veteran Member
Veteran Member
Poland
Posts: 416
Joined: 1 Year Ago
Has thanked: 15 times
Been thanked: 1 time
Contact:

#3

Post by czirimbolo » 1 Month Ago

Ok can you show me how to edit wepon menu and what should I change in gun's code?
Image

User avatar
Jack GamePlay
Mod Developer
Mod Developer
Egypt
Posts: 475
Joined: 1 Year Ago
Location: Egypt
Has thanked: 30 times
Been thanked: 32 times
Age: 18
Contact:

#4

Post by Jack GamePlay » 4 Weeks Ago

czirimbolo wrote:
1 Month Ago
Ok can you show me how to edit wepon menu and what should I change in gun's code?
If there are other versions of weapon menu already contains extra guns then edit it for your needs.
Also, that native i provided it to make your gun appear in extra items menu & will be available for people who have the submitted level.
Image

User avatar
Raheem
Mod Developer
Mod Developer
Egypt
Posts: 1702
Joined: 1 Year Ago
Location: Egypt
Has thanked: 28 times
Been thanked: 74 times
Age: 20
Contact:

#5

Post by Raheem » 3 Weeks Ago

Steps not static but the idea based on:

1. Make native in the item you need to add so we can give weapon from another plugin, and remove it from extra items menu.
2. Add the weapon to the weapons menu. There things to be edited
    1.     switch (ze_get_user_level(id))
    2.     {
    3.         case 0: WPN_MAXIDS[id] = 2
    4.         case 1: WPN_MAXIDS[id] = 3
    5.         case 2: WPN_MAXIDS[id] = 4
    6.         case 3: WPN_MAXIDS[id] = 5
    7.         case 4: WPN_MAXIDS[id] = 6
    8.         case 5: WPN_MAXIDS[id] = 7
    9.         case 6: WPN_MAXIDS[id] = 8
    10.         case 7: WPN_MAXIDS[id] = 9
    11.         case 8: WPN_MAXIDS[id] = 10
    12.         case 9: WPN_MAXIDS[id] = 11
    13.         case 10: WPN_MAXIDS[id] = 12
    14.         case 11: WPN_MAXIDS[id] = 13
    15.         case 12..14: WPN_MAXIDS[id] = 14
    16.         case 15..19: WPN_MAXIDS[id] = 15 // Golden m3
    17.         case 20..24: WPN_MAXIDS[id] = 16 // Golden MP5
    18.         case 25..29: WPN_MAXIDS[id] = 17 // Golden M4A1
    19.         case 30..39: WPN_MAXIDS[id] = 18 // Golden AK47
    20.         case 40: WPN_MAXIDS[id] = 19    // JatPack
    21.     }
    1.         // JetPack
    2.         if (ze_get_user_level(id) >= 40)
    3.         {
    4.             if (iIndex == 14)
    5.             {
    6.                 iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\w%d.\y %s^n", iIndex-WPN_STARTID+1, "Golden M3")
    7.             }
    8.            
    9.             if (iIndex == 15)
    10.             {
    11.                 iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\w%d.\y %s^n", iIndex-WPN_STARTID+1, "Golden MP5")
    12.             }
    13.            
    14.             if (iIndex == 16)
    15.             {
    16.                 iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\w%d.\y %s^n", iIndex-WPN_STARTID+1, "Golden M4A1")
    17.             }
    18.            
    19.             if (iIndex == 17)
    20.             {
    21.                 iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\w%d.\y %s^n", iIndex-WPN_STARTID+1, "Golden AK-47")
    22.             }
    23.            
    24.             if (iIndex == 18)
    25.             {
    26.                 iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\w%d.\y %s^n", iIndex-WPN_STARTID+1, "JetPack")
    27.                 break;
    28.             }
    29.         }
    1.     else if (ze_get_user_level(id) >= 30 && ze_get_user_level(id) < 40) // JetPack
    2.     {
    3.         iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "^n\r Level 40 Unlock\w: \yJetPack^n")
    4.     }
So finally, jectpack:
    1. #include <zombie_escape>
    2. #include <engine>
    3.  
    4. #define JETPACK_COST 1000
    5.  
    6. new const ClassInfoTarget[] = "info_target"
    7. new const ClassBreakAble[] = "func_breakable"
    8. new const ClassnameJetPack[] = "n4d_jetpack"
    9. new const ClassnameRocket[] = "n4d_bazooka"
    10. new const ModelVJetPack[] = "models/mu/v_jp_mu.mdl"
    11. new const ModelPJetPack[] = "models/mu/p_jp_mu.mdl"
    12. new const ModelWJetPack[] = "models/mu/w_jp_mu.mdl"
    13. new const ModelRocket[] = "models/rpgrocket.mdl"
    14. new const SoundPickup[] = "items/gunpickup2.wav"
    15. new const SoundShoot[] = "mu/at4-1.wav"
    16. new const SoundTravel[] = "mu/bfuu.wav"
    17. new const SoundFly[] = "mu/fly.wav"
    18. new const SoundBlow[] = "mu/blow.wav"
    19.  
    20. new bool:bHasJetPack[33]
    21. new Float:fJetpackFuel[33]
    22. new Float:fLastShoot[33]
    23. new SprExp, SprTrail
    24. new CvarMaxFuel, CvarRadius, CvarDamage, CvarSpeed, CvarCooldown, CvarRegen, CvarRocketSpeed, CvarRemove
    25. new Float:CMaxFuel, Float:CRadius, Float:CDamage, CSpeed, Float:CCooldown, Float:CRegen, CRocketSpeed, Float:CRemove
    26.  
    27. //Uncomment this to draw ring effect
    28. //#define DrawRing
    29.  
    30. //Uncomment this to draw flame effect
    31. //#define DrawFlame
    32.  
    33. #if defined DrawRing
    34. new SprRing
    35. #endif
    36.  
    37. #if defined DrawFlame
    38. new SprFlame
    39. #endif
    40.  
    41. public plugin_precache()
    42. {
    43.     precache_sound(SoundPickup)
    44.     precache_sound(SoundShoot)
    45.     precache_sound(SoundTravel)
    46.     precache_sound(SoundFly)
    47.     precache_sound(SoundBlow)
    48.    
    49.     SprExp = precache_model("sprites/zerogxplode.spr")
    50.     SprTrail = precache_model("sprites/smoke.spr")
    51.    
    52.     #if defined DrawFlame
    53.     SprFlame = precache_model("sprites/xfireball3.spr")
    54.     #endif
    55.    
    56.     #if defined DrawRing
    57.     SprRing = precache_model("sprites/shockwave.spr")
    58.     #endif
    59.    
    60.     precache_model(ModelVJetPack)
    61.     precache_model(ModelPJetPack)
    62.     precache_model(ModelWJetPack)
    63.     precache_model(ModelRocket)
    64. }
    65.  
    66. public plugin_natives()
    67. {
    68.     register_native("ze_give_jetpack", "native_ze_give_jetpack", 1)
    69. }
    70.  
    71. public plugin_init()
    72. {
    73.     register_plugin("New Jetpack", "0.0.3", "Bad_Bud,ZmOutStanding,Connor,wbyokomo")
    74.    
    75.     register_event("HLTV", "OnNewRound", "a", "1=0", "2=0")
    76.     register_logevent("OnRoundEnd", 2, "1=Round_End")
    77.    
    78.     RegisterHam(Ham_Killed, "player", "OnPlayerKilled")
    79.     RegisterHam(Ham_Player_Jump, "player", "OnPlayerJump")
    80.     RegisterHam(Ham_Weapon_SecondaryAttack, "weapon_knife", "OnKnifeSecAtkPost", 1)
    81.     RegisterHam(Ham_Item_Deploy, "weapon_knife", "OnKnifeDeployPost", 1)
    82.    
    83.     register_forward(FM_PlayerPreThink, "OnPlayerPreThink")
    84.    
    85.     register_touch(ClassnameRocket, "*", "OnTouchRocket")
    86.     register_touch(ClassnameJetPack, "player", "OnTouchJetPack")
    87.     register_think(ClassnameJetPack, "OnThinkJetPack")
    88.    
    89.     CvarMaxFuel = register_cvar("jp_maxfuel", "250.0")
    90.     CvarRadius = register_cvar("jp_radius", "250.0")
    91.     CvarDamage = register_cvar("jp_damage", "600.0")
    92.     CvarSpeed = register_cvar("jp_speed", "300")
    93.     CvarCooldown = register_cvar("jp_cooldown", "10.0")
    94.     CvarRegen = register_cvar("jp_regen", "0.5")
    95.     CvarRocketSpeed = register_cvar("jp_rocket_speed", "1500")
    96.     CvarRemove = register_cvar("jp_remove_time", "420.0")
    97.    
    98.     register_clcmd("drop", "CmdDropJP")
    99. }
    100.  
    101. public native_ze_give_jetpack(id)
    102. {
    103.     bHasJetPack[id] = true
    104.     ze_colored_print(id, "JetPack usage: JUMP+DUCK")
    105.     engclient_cmd(id, "weapon_knife")
    106.     ReplaceModel(id)
    107. }
    108.  
    109. public client_putinserver(id)
    110. {
    111.     ResetValues(id)
    112. }
    113.  
    114. public ze_user_infected(iVictim)
    115. {
    116.     ResetValues(iVictim)
    117. }
    118.  
    119. public client_disconnected(id)
    120. {
    121.     ResetValues(id)
    122. }
    123.  
    124. public OnNewRound()
    125. {
    126.     RemoveAllJetPack()
    127.     CMaxFuel = get_pcvar_float(CvarMaxFuel)
    128.     CRadius = get_pcvar_float(CvarRadius)
    129.     CDamage = get_pcvar_float(CvarDamage)
    130.     CSpeed = get_pcvar_num(CvarSpeed)
    131.     CCooldown = get_pcvar_float(CvarCooldown)
    132.     CRegen = get_pcvar_float(CvarRegen)
    133.     CRocketSpeed = get_pcvar_num(CvarRocketSpeed)
    134.     CRemove = get_pcvar_float(CvarRemove)
    135. }
    136.  
    137. public ze_user_humanized(id)
    138. {
    139.     ResetValues(id) // Item lasts only one round
    140. }
    141.  
    142. public OnRoundEnd()
    143. {
    144.     RemoveAllJetPack()
    145. }
    146.  
    147. public OnPlayerKilled(id)
    148. {
    149.     if(bHasJetPack[id]) DropJetPack(id);
    150.    
    151.     ResetValues(id)
    152. }
    153.  
    154. public OnPlayerJump(id)
    155. {
    156.     if(bHasJetPack[id] && fJetpackFuel[id] > 0.0 && get_user_weapon(id) == CSW_KNIFE && pev(id, pev_button) & IN_DUCK && ~pev(id, pev_flags) & FL_ONGROUND)
    157.     {
    158.         static Float:vVelocity[3], Float:upSpeed
    159.         pev(id, pev_velocity, vVelocity)
    160.         upSpeed = vVelocity[2] + 35.0
    161.         velocity_by_aim(id, CSpeed, vVelocity)
    162.         vVelocity[2] = upSpeed > 300.0 ? 300.0 : upSpeed
    163.         set_pev(id, pev_velocity, vVelocity)
    164.        
    165.         #if defined DrawFlame
    166.         pev(id, pev_origin, vVelocity)
    167.         engfunc(EngFunc_MessageBegin, MSG_PVS, SVC_TEMPENTITY, vVelocity, 0)
    168.         write_byte(TE_SPRITE)
    169.         engfunc(EngFunc_WriteCoord, vVelocity[0])
    170.         engfunc(EngFunc_WriteCoord, vVelocity[1])
    171.         engfunc(EngFunc_WriteCoord, vVelocity[2])
    172.         write_short(SprFlame)
    173.         write_byte(8)
    174.         write_byte(128)
    175.         message_end()
    176.         #endif
    177.        
    178.         fJetpackFuel[id] > 80.0 ? emit_sound(id, CHAN_STREAM, SoundFly, VOL_NORM, ATTN_NORM, 0,  PITCH_NORM) : emit_sound(id, CHAN_STREAM, SoundBlow, VOL_NORM, ATTN_NORM, 0, PITCH_NORM);
    179.         fJetpackFuel[id] -= 1.0
    180.     }
    181. }
    182.  
    183. public OnKnifeSecAtkPost(ent2)
    184. {
    185.     if(pev_valid(ent2) == 2)
    186.     {
    187.         static id, Float:ctime
    188.         id = get_pdata_cbase(ent2, 41, 4)
    189.         ctime = get_gametime()
    190.         if(is_user_alive(id) && bHasJetPack[id] && fLastShoot[id] < ctime)
    191.         {
    192.             new ent = create_entity(ClassInfoTarget)
    193.             if(ent)
    194.             {
    195.                 engfunc(EngFunc_SetModel, ent, ModelRocket)
    196.                 engfunc(EngFunc_SetSize, ent, Float:{0.0, 0.0, 0.0}, Float:{0.0, 0.0, 0.0})
    197.                 new Float:fOrigin[3]
    198.                 pev(id, pev_origin, fOrigin)
    199.                 fOrigin[2] += 16.0
    200.                 engfunc(EngFunc_SetOrigin, ent, fOrigin)
    201.                 set_pev(ent, pev_classname, ClassnameRocket)
    202.                 set_pev(ent, pev_dmg, 100.0)
    203.                 set_pev(ent, pev_owner, id)
    204.                 velocity_by_aim(id, CRocketSpeed, fOrigin)
    205.                 set_pev(ent, pev_velocity, fOrigin)
    206.                 new Float:vecAngles[3]
    207.                 engfunc(EngFunc_VecToAngles, fOrigin, vecAngles)
    208.                 set_pev(ent, pev_angles, vecAngles)
    209.                 set_pev(ent, pev_movetype, MOVETYPE_FLY)
    210.                 set_pev(ent, pev_effects, EF_LIGHT)
    211.                 set_pev(ent, pev_solid, SOLID_BBOX)
    212.                
    213.                 emit_sound(id, CHAN_STATIC, SoundShoot, VOL_NORM, ATTN_NORM, 0, PITCH_NORM)
    214.                 emit_sound(ent, CHAN_WEAPON, SoundTravel, VOL_NORM, ATTN_NORM, 0, PITCH_NORM)
    215.                
    216.                 message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
    217.                 write_byte(TE_BEAMFOLLOW)
    218.                 write_short(ent)
    219.                 write_short(SprTrail)
    220.                 write_byte(40)
    221.                 write_byte(5)
    222.                 write_byte(224)
    223.                 write_byte(224)
    224.                 write_byte(255)
    225.                 write_byte(192)
    226.                 message_end()
    227.                
    228.                 fLastShoot[id] = ctime+CCooldown
    229.             }
    230.             else
    231.             {
    232.                 client_print(id, print_chat, "[JpDebug] Failed to create rocket.")
    233.                 fLastShoot[id] = ctime+1.5
    234.             }
    235.         }
    236.     }
    237. }
    238.  
    239. public OnKnifeDeployPost(ent)
    240. {
    241.     if(pev_valid(ent) == 2)
    242.     {
    243.         static id; id = get_pdata_cbase(ent, 41, 4)
    244.         if(is_user_alive(id) && bHasJetPack[id]) ReplaceModel(id);
    245.     }
    246. }
    247.  
    248. public OnPlayerPreThink(id)
    249. {
    250.     if(bHasJetPack[id] && fJetpackFuel[id] < CMaxFuel)
    251.     {
    252.         static button; button = pev(id, pev_button)
    253.         if(!(button & IN_DUCK) && !(button & IN_JUMP)) fJetpackFuel[id] += CRegen;
    254.     }
    255. }
    256.  
    257. public OnTouchRocket(ent, id)
    258. {
    259.     static Float:fOrigin[3]
    260.     pev(ent, pev_origin, fOrigin)
    261.    
    262.     engfunc(EngFunc_MessageBegin, MSG_PVS, SVC_TEMPENTITY, fOrigin, 0)
    263.     write_byte(TE_EXPLOSION)
    264.     engfunc(EngFunc_WriteCoord, fOrigin[0])
    265.     engfunc(EngFunc_WriteCoord, fOrigin[1])
    266.     engfunc(EngFunc_WriteCoord, fOrigin[2])
    267.     write_short(SprExp)
    268.     write_byte(40)
    269.     write_byte(30)
    270.     write_byte(10)
    271.     message_end()
    272.    
    273.     #if defined DrawRing
    274.     engfunc(EngFunc_MessageBegin, MSG_PVS, SVC_TEMPENTITY, fOrigin, 0)
    275.     write_byte(TE_BEAMCYLINDER)
    276.     engfunc(EngFunc_WriteCoord, fOrigin[0])
    277.     engfunc(EngFunc_WriteCoord, fOrigin[1])
    278.     engfunc(EngFunc_WriteCoord, fOrigin[2])
    279.     engfunc(EngFunc_WriteCoord, fOrigin[0])
    280.     engfunc(EngFunc_WriteCoord, fOrigin[1])
    281.     engfunc(EngFunc_WriteCoord, fOrigin[2]+555.0)
    282.     write_short(SprRing)
    283.     write_byte(0)
    284.     write_byte(1)
    285.     write_byte(6)
    286.     write_byte(8)
    287.     write_byte(10)
    288.     write_byte(224)
    289.     write_byte(224)
    290.     write_byte(255)
    291.     write_byte(192)
    292.     write_byte(5)
    293.     message_end()
    294.     #endif
    295.    
    296.     static attacker; attacker = pev(ent, pev_owner)
    297.     if(!is_user_connected(attacker))
    298.     {
    299.         engfunc(EngFunc_RemoveEntity, ent)
    300.         return PLUGIN_CONTINUE;
    301.     }
    302.    
    303.     if(pev_valid(id) && !is_user_connected(id))
    304.     {
    305.         static szClassname[32]
    306.         pev(id, pev_classname, szClassname, 31)
    307.         if(equal(szClassname, ClassBreakAble) && (pev(id, pev_solid) != SOLID_NOT))
    308.         {
    309.             dllfunc(DLLFunc_Use, id, ent)
    310.         }
    311.     }
    312.    
    313.     static victim; victim = -1
    314.     while((victim = engfunc(EngFunc_FindEntityInSphere, victim, fOrigin, CRadius)) != 0)
    315.     {
    316.         if(is_user_alive(victim) && ze_is_user_zombie(victim))
    317.         {
    318.             static Float:originV[3], Float:dist, Float:damage
    319.             pev(victim, pev_origin, originV)
    320.             dist = get_distance_f(fOrigin, originV)
    321.             damage = CDamage-(CDamage/CRadius)*dist
    322.             if(damage > 0.0)
    323.             {
    324.                 ExecuteHamB(Ham_TakeDamage, victim, ent, attacker, damage, DMG_BULLET)
    325.                 //client_print(attacker, print_chat, "[Jp] Rocket damage: %.1f", damage)
    326.             }
    327.         }
    328.     }
    329.    
    330.     engfunc(EngFunc_RemoveEntity, ent)
    331.    
    332.     return PLUGIN_CONTINUE;
    333. }
    334.  
    335. public OnTouchJetPack(ent, id)
    336. {
    337.     if((pev(ent, pev_iuser4) != 11111) && is_user_alive(id) && !ze_is_user_zombie(id) && !bHasJetPack[id])
    338.     {
    339.         engfunc(EngFunc_RemoveEntity, ent)
    340.         bHasJetPack[id] = true
    341.         emit_sound(id, CHAN_STATIC, SoundPickup, VOL_NORM, ATTN_NORM, 0, PITCH_NORM)
    342.         engclient_cmd(id,"weapon_knife")
    343.         ReplaceModel(id)
    344.     }
    345. }
    346.  
    347. public OnThinkJetPack(ent)
    348. {
    349.     if(pev_valid(ent) == 2)
    350.     {
    351.         switch(pev(ent, pev_flTimeStepSound))
    352.         {
    353.             case 200:
    354.             {
    355.                 set_pev(ent, pev_iuser4, 22222)
    356.                 set_pev(ent, pev_flTimeStepSound, 201)
    357.                 set_pev(ent, pev_nextthink, get_gametime()+CRemove)
    358.             }
    359.             case 201:
    360.             {
    361.                 engfunc(EngFunc_RemoveEntity, ent)
    362.             }
    363.         }
    364.     }
    365. }
    366.  
    367. public CmdDropJP(id)
    368. {
    369.     if(is_user_alive(id) && bHasJetPack[id] && get_user_weapon(id) == CSW_KNIFE)
    370.     {
    371.         DropJetPack(id)
    372.         bHasJetPack[id] = false
    373.         set_pev(id, pev_viewmodel2, "models/v_knife.mdl")
    374.         set_pev(id, pev_weaponmodel2, "models/p_knife.mdl")
    375.         return PLUGIN_HANDLED;
    376.     }
    377.    
    378.     return PLUGIN_CONTINUE;
    379. }
    380.  
    381. ReplaceModel(id)
    382. {
    383.     set_pev(id, pev_viewmodel2, ModelVJetPack)
    384.     set_pev(id, pev_weaponmodel2, ModelPJetPack)
    385. }
    386.  
    387. DropJetPack(id)
    388. {
    389.     new ent = create_entity(ClassInfoTarget)
    390.     if(!ent) return;
    391.    
    392.     engfunc(EngFunc_SetModel, ent, ModelWJetPack)
    393.     engfunc(EngFunc_SetSize, ent, Float:{-8.0, -8.0, -8.0}, Float:{8.0, 8.0, 8.0})
    394.     new Float:fOrigin[3]
    395.     pev(id, pev_origin, fOrigin)
    396.     fOrigin[2] += 16.0
    397.     engfunc(EngFunc_SetOrigin, ent, fOrigin)
    398.     set_pev(ent, pev_classname, ClassnameJetPack)
    399.     velocity_by_aim(id, 800, fOrigin) //if it too far then reduce it
    400.     set_pev(ent, pev_velocity, fOrigin)
    401.     set_pev(ent, pev_movetype, MOVETYPE_TOSS)
    402.     set_pev(ent, pev_effects, EF_LIGHT)
    403.     set_pev(ent, pev_iuser4, 11111)
    404.     set_pev(ent, pev_solid, SOLID_TRIGGER)
    405.     set_pev(ent, pev_flTimeStepSound, 200)
    406.     set_pev(ent, pev_nextthink, get_gametime()+2.0) // prevent drop/pickup exploit
    407. }
    408.  
    409. RemoveAllJetPack()
    410. {
    411.     new ent = engfunc(EngFunc_FindEntityByString, -1, "classname", ClassnameJetPack)
    412.     while(ent > 0)
    413.     {
    414.         engfunc(EngFunc_RemoveEntity, ent)
    415.         ent = engfunc(EngFunc_FindEntityByString, -1, "classname", ClassnameJetPack)
    416.     }
    417. }
    418.  
    419. ResetValues(id)
    420. {
    421.     bHasJetPack[id] = false
    422.     fJetpackFuel[id] = CMaxFuel
    423. }
Weapons menu:
    1. #include <zombie_escape>
    2. #include <ze_levels>
    3.  
    4. native give_golden_m3(id);
    5. native give_golden_mp5(id);
    6. native give_golden_m4a1(id);
    7. native give_golden_ak47(id);
    8. native ze_give_jetpack(id);
    9.  
    10. // Setting File
    11. new const ZE_SETTING_RESOURCES[] = "zombie_escape.ini"
    12.  
    13. // Keys
    14. const KEYSMENU = MENU_KEY_1|MENU_KEY_2|MENU_KEY_3|MENU_KEY_4|MENU_KEY_5|MENU_KEY_6|MENU_KEY_7|MENU_KEY_8|MENU_KEY_9|MENU_KEY_0
    15. const OFFSET_CSMENUCODE = 205
    16.  
    17. // Primary Weapons Entities [Default Values]
    18. new const szPrimaryWeaponEnt[][] =
    19. {
    20.     "weapon_xm1014",  // Level 0
    21.     "weapon_ump45",   // Level 0
    22.     "weapon_m3",      // Level 1
    23.     "weapon_mp5navy", // Level 2
    24.     "weapon_p90",     // Level 3
    25.     "weapon_galil",   // Level 4
    26.     "weapon_famas",   // Level 5
    27.     "weapon_sg550",   // Level 6
    28.     "weapon_g3sg1",   // Level 7
    29.     "weapon_m249",    // Level 8
    30.     "weapon_sg552",   // Level 9
    31.     "weapon_aug",     // Level 10
    32.     "weapon_m4a1",    // Level 11
    33.     "weapon_ak47"     // Level 12
    34. }
    35.  
    36. // Secondary Weapons Entities [Default Values]
    37. new const szSecondaryWeaponEnt[][]=
    38. {
    39.     "weapon_usp",         // Level 0
    40.     "weapon_p228",        // Level 0
    41.     "weapon_glock18",     // Level 1
    42.     "weapon_fiveseven",   // Level 2
    43.     "weapon_deagle",      // Level 3
    44.     "weapon_elite"        // Level 4
    45. }
    46.  
    47. // Primary and Secondary Weapons Names [Default Values]
    48. new const szWeaponNames[][] =
    49. {
    50.     "",
    51.     "P228",
    52.     "",
    53.     "Scout",
    54.     "HE Grenade",
    55.     "XM1014",
    56.     "",
    57.     "MAC-10",
    58.     "AUG",
    59.     "Smoke Grenade",
    60.     "Dual Elite",
    61.     "Five Seven",
    62.     "UMP 45",
    63.     "SG-550",
    64.     "Galil",
    65.     "Famas",
    66.     "USP",
    67.     "Glock",
    68.     "AWP",
    69.     "MP5",
    70.     "M249",
    71.     "M3",
    72.     "M4A1",
    73.     "TMP",
    74.     "G3SG1",
    75.     "Flashbang",
    76.     "Desert Eagle",
    77.     "SG-552",
    78.     "AK-47",
    79.     "",
    80.     "P90"
    81. }
    82.  
    83. // Max Back Clip Ammo (Change it From here if you need)
    84. new const szMaxBPAmmo[] =
    85. {
    86.     -1,
    87.     52,
    88.     -1,
    89.     90,
    90.     1,
    91.     32,
    92.     1,
    93.     100,
    94.     90,
    95.     1,
    96.     120,
    97.     100,
    98.     100,
    99.     90,
    100.     90,
    101.     90,
    102.     100,
    103.     120,
    104.     30,
    105.     120,
    106.     200,
    107.     32,
    108.     90,
    109.     120,
    110.     90,
    111.     2,
    112.     35,
    113.     90,
    114.     90,
    115.     -1,
    116.     100
    117. }
    118.  
    119. // Menu selections
    120. const MENU_KEY_AUTOSELECT = 7
    121. const MENU_KEY_BACK = 7
    122. const MENU_KEY_NEXT = 8
    123. const MENU_KEY_EXIT = 9
    124.  
    125. // Variables
    126. new Array:g_szPrimaryWeapons, Array:g_szSecondaryWeapons
    127.  
    128. new g_iMenuData[33][4],
    129.     Float:g_fBuyTimeStart[33],
    130.     bool:g_bBoughtPrimary[33],
    131.     bool:g_bBoughtSecondary[33],
    132.     WPN_MAXIDS[33]
    133.  
    134. // Define
    135. #define WPN_STARTID g_iMenuData[id][0]
    136. #define WPN_SELECTION (g_iMenuData[id][0]+key)
    137. #define WPN_AUTO_ON g_iMenuData[id][1]
    138. #define WPN_AUTO_PRI g_iMenuData[id][2]
    139. #define WPN_AUTO_SEC g_iMenuData[id][3]
    140.  
    141. // Cvars
    142. new g_pCvarBuyTime,
    143.     g_pCvarHeGrenade,
    144.     g_pCvarSmokeGrenade,
    145.     g_pCvarFlashGrenade,
    146.     g_pCvarBlockWeapLowLevel
    147.  
    148. public plugin_natives()
    149. {
    150.     register_native("ze_show_weapon_menu", "native_ze_show_weapon_menu", 1)
    151.     register_native("ze_is_auto_buy_enabled", "native_ze_is_auto_buy_enabled", 1)
    152.     register_native("ze_disable_auto_buy", "native_ze_disable_auto_buy", 1)
    153. }
    154.  
    155. public plugin_precache()
    156. {
    157.     // Initialize arrays (32 is the max length of Weapon Entity like: weapon_ak47)
    158.     g_szPrimaryWeapons = ArrayCreate(32, 1)
    159.     g_szSecondaryWeapons = ArrayCreate(32, 1)
    160.    
    161.     // Load from external file
    162.     amx_load_setting_string_arr(ZE_SETTING_RESOURCES, "Weapons Menu", "PRIMARY", g_szPrimaryWeapons)
    163.     amx_load_setting_string_arr(ZE_SETTING_RESOURCES, "Weapons Menu", "SECONDARY", g_szSecondaryWeapons)
    164.    
    165.     // If we couldn't load from file, use and save default ones
    166.    
    167.     new iIndex
    168.    
    169.     if (ArraySize(g_szPrimaryWeapons) == 0)
    170.     {
    171.         for (iIndex = 0; iIndex < sizeof szPrimaryWeaponEnt; iIndex++)
    172.             ArrayPushString(g_szPrimaryWeapons, szPrimaryWeaponEnt[iIndex])
    173.        
    174.         // If not found .ini File Create it and save default values in it
    175.         amx_save_setting_string_arr(ZE_SETTING_RESOURCES, "Weapons Menu", "PRIMARY", g_szPrimaryWeapons)
    176.     }
    177.    
    178.     if (ArraySize(g_szSecondaryWeapons) == 0)
    179.     {
    180.         for (iIndex = 0; iIndex < sizeof szSecondaryWeaponEnt; iIndex++)
    181.             ArrayPushString(g_szSecondaryWeapons, szSecondaryWeaponEnt[iIndex])
    182.        
    183.         // If not found .ini File Create it and save default values in it
    184.         amx_save_setting_string_arr(ZE_SETTING_RESOURCES, "Weapons Menu", "SECONDARY", g_szSecondaryWeapons)
    185.     }
    186. }
    187.  
    188. public plugin_init()
    189. {
    190.     register_plugin("[ZE] Levels Weapons Menu", "1.1", "Raheem")
    191.    
    192.     // Commands
    193.     register_clcmd("guns", "Cmd_Buy")
    194.     register_clcmd("say /enable", "Cmd_Enable")
    195.     register_clcmd("say_team /enable", "Cmd_Enable")
    196.    
    197.     // Cvars
    198.     g_pCvarBuyTime = register_cvar("ze_buy_time", "60")
    199.     g_pCvarHeGrenade = register_cvar("ze_give_HE_nade", "1") // 0 Nothing || 1 Give HE
    200.     g_pCvarSmokeGrenade = register_cvar("ze_give_SM_nade", "1")
    201.     g_pCvarFlashGrenade = register_cvar("ze_give_FB_nade", "1")
    202.     g_pCvarBlockWeapLowLevel = register_cvar("ze_block_weapons_lowlvl", "1")
    203.    
    204.     // Menus
    205.     register_menu("Primary Weapons", KEYSMENU, "Menu_Buy_Primary")
    206.     register_menu("Secondary Weapons", KEYSMENU, "Menu_Buy_Secondary")
    207.    
    208.     // Hams
    209.     RegisterHam(Ham_Touch, "weaponbox", "Fw_TouchWeapon_Pre", 0)
    210.     RegisterHam(Ham_Touch, "armoury_entity", "Fw_TouchWeapon_Pre", 0)
    211. }
    212.  
    213. public client_disconnected(id)
    214. {
    215.     WPN_AUTO_ON = 0
    216.     WPN_STARTID = 0
    217. }
    218.  
    219. public Cmd_Enable(id)
    220. {
    221.     if (WPN_AUTO_ON)
    222.     {
    223.         ze_colored_print(id, "%L", LANG_PLAYER, "BUY_ENABLED")
    224.         WPN_AUTO_ON = 0
    225.     }
    226. }
    227.  
    228. public Cmd_Buy(id)
    229. {
    230.     // Player Zombie
    231.     if (ze_is_user_zombie(id))
    232.     {
    233.         ze_colored_print(id, "%L", LANG_PLAYER, "NO_BUY_ZOMBIE")
    234.         return
    235.     }
    236.    
    237.     // Player Dead
    238.     if (!is_user_alive(id))
    239.     {
    240.         ze_colored_print(id, "%L", LANG_PLAYER, "DEAD_CANT_BUY_WEAPON")
    241.         return
    242.     }
    243.    
    244.     // Already bought
    245.     if (g_bBoughtPrimary[id] && g_bBoughtSecondary[id])
    246.     {
    247.         ze_colored_print(id, "%L", LANG_PLAYER, "ALREADY_BOUGHT")
    248.     }
    249.    
    250.     Show_Available_Buy_Menus(id)
    251. }
    252.  
    253. public ze_user_humanized(id)
    254. {
    255.     // Static Values
    256.     switch (ze_get_user_level(id))
    257.     {
    258.         case 0: WPN_MAXIDS[id] = 2
    259.         case 1: WPN_MAXIDS[id] = 3
    260.         case 2: WPN_MAXIDS[id] = 4
    261.         case 3: WPN_MAXIDS[id] = 5
    262.         case 4: WPN_MAXIDS[id] = 6
    263.         case 5: WPN_MAXIDS[id] = 7
    264.         case 6: WPN_MAXIDS[id] = 8
    265.         case 7: WPN_MAXIDS[id] = 9
    266.         case 8: WPN_MAXIDS[id] = 10
    267.         case 9: WPN_MAXIDS[id] = 11
    268.         case 10: WPN_MAXIDS[id] = 12
    269.         case 11: WPN_MAXIDS[id] = 13
    270.         case 12..14: WPN_MAXIDS[id] = 14
    271.         case 15..19: WPN_MAXIDS[id] = 15 // Golden m3
    272.         case 20..24: WPN_MAXIDS[id] = 16 // Golden MP5
    273.         case 25..29: WPN_MAXIDS[id] = 17 // Golden M4A1
    274.         case 30..39: WPN_MAXIDS[id] = 18 // Golden AK47
    275.         case 40: WPN_MAXIDS[id] = 19    // JatPack
    276.     }
    277.    
    278.     if (ze_get_user_level(id) > 40)
    279.     {
    280.         WPN_MAXIDS[id] = 19
    281.     }
    282.  
    283.     // Buyzone time starts when player is set to human
    284.     g_fBuyTimeStart[id] = get_gametime()
    285.    
    286.     g_bBoughtPrimary[id] = false
    287.     g_bBoughtSecondary[id] = false
    288.    
    289.     // Player dead or zombie
    290.     if (!is_user_alive(id) || ze_is_user_zombie(id))
    291.         return
    292.    
    293.     if (WPN_AUTO_ON)
    294.     {
    295.         ze_colored_print(id, "%L", LANG_PLAYER, "RE_ENABLE_MENU")
    296.         Buy_Primary_Weapon(id, WPN_AUTO_PRI)
    297.         Buy_Secondary_Weapon(id, WPN_AUTO_SEC)
    298.     }
    299.    
    300.     // Open available buy menus
    301.     Show_Available_Buy_Menus(id)
    302.    
    303.     // Give HE Grenade
    304.     if (get_pcvar_num(g_pCvarHeGrenade) != 0)
    305.         rg_give_item(id, "weapon_hegrenade")
    306.    
    307.     // Give Smoke Grenade
    308.     if (get_pcvar_num(g_pCvarSmokeGrenade) != 0)
    309.         rg_give_item(id, "weapon_smokegrenade")
    310.    
    311.     // Give Flashbang Grenade
    312.     if (get_pcvar_num(g_pCvarFlashGrenade) != 0)
    313.         rg_give_item(id, "weapon_flashbang")
    314. }
    315.  
    316. public Show_Available_Buy_Menus(id)
    317. {
    318.     // Already Bought
    319.     if (g_bBoughtPrimary[id] && g_bBoughtSecondary[id])
    320.         return
    321.    
    322.     // Here we use if and else if so we make sure that Primary weapon come first then secondary
    323.     if (!g_bBoughtPrimary[id])
    324.     {
    325.         // Primary     
    326.         Show_Menu_Buy_Primary(id)
    327.     }
    328.     else if (!g_bBoughtSecondary[id])
    329.     {
    330.         // Secondary
    331.         Show_Menu_Buy_Secondary(id)
    332.     }
    333. }
    334.  
    335. public Show_Menu_Buy_Primary(id)
    336. {
    337.     new iMenuTime = floatround(g_fBuyTimeStart[id] + get_pcvar_float(g_pCvarBuyTime) - get_gametime())
    338.    
    339.     if (iMenuTime <= 0)
    340.     {
    341.         ze_colored_print(id, "%L", id, "BUY_MENU_TIME_EXPIRED")
    342.         return
    343.     }
    344.    
    345.     static szMenu[300], szWeaponName[32]
    346.     new iLen, iIndex, iMaxLoops = min(WPN_STARTID+7, WPN_MAXIDS[id])
    347.    
    348.     // Title
    349.     iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\y%L \w[\r%d\w-\r%d\w]^n^n", id, "MENU_PRIMARY_TITLE", WPN_STARTID+1, min(WPN_STARTID+7, WPN_MAXIDS[id]))
    350.    
    351.     // 1-7. Weapon List
    352.     for (iIndex = WPN_STARTID; iIndex < iMaxLoops; iIndex++)
    353.     {
    354.         if (ze_get_user_level(id) == 0 && iIndex >= 2||
    355.         ze_get_user_level(id) == 1 && iIndex >= 3 ||
    356.         ze_get_user_level(id) == 2 && iIndex >= 4 ||
    357.         ze_get_user_level(id) == 3 && iIndex >= 5 ||
    358.         ze_get_user_level(id) == 4 && iIndex >= 6 ||
    359.         ze_get_user_level(id) == 5 && iIndex >= 7 ||
    360.         ze_get_user_level(id) == 6 && iIndex >= 8 ||
    361.         ze_get_user_level(id) == 7 && iIndex >= 9 ||
    362.         ze_get_user_level(id) == 8 && iIndex >= 10 ||
    363.         ze_get_user_level(id) == 9 && iIndex >= 11 ||
    364.         ze_get_user_level(id) == 10 && iIndex >= 12 ||
    365.         ze_get_user_level(id) == 11 && iIndex >= 13 ||
    366.         ze_get_user_level(id) == 12 && iIndex >= 14)
    367.         {
    368.             break
    369.         }
    370.        
    371.         /*
    372.         *  Note that WPN_MAXIDS start from 1 but iIndex start from 0.
    373.         */
    374.        
    375.         // Golden M3
    376.         if (ze_get_user_level(id) >= 15 && ze_get_user_level(id) < 20)
    377.         {
    378.             if (iIndex == 14)
    379.             {
    380.                 iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\w%d.\y %s^n", iIndex-WPN_STARTID+1, "Golden M3")
    381.                 break;
    382.             }
    383.         }
    384.        
    385.         // Golden MP5
    386.         if (ze_get_user_level(id) >= 20 && ze_get_user_level(id) < 25)
    387.         {
    388.             if (iIndex == 14)
    389.             {
    390.                 iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\w%d.\y %s^n", iIndex-WPN_STARTID+1, "Golden M3")
    391.             }
    392.            
    393.             if (iIndex == 15)
    394.             {
    395.                 iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\w%d.\y %s^n", iIndex-WPN_STARTID+1, "Golden MP5")
    396.                 break;
    397.             }
    398.         }
    399.        
    400.         // Golden M4A1
    401.         if (ze_get_user_level(id) >= 25 && ze_get_user_level(id) < 30)
    402.         {
    403.             if (iIndex == 14)
    404.             {
    405.                 iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\w%d.\y %s^n", iIndex-WPN_STARTID+1, "Golden M3")
    406.             }
    407.            
    408.             if (iIndex == 15)
    409.             {
    410.                 iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\w%d.\y %s^n", iIndex-WPN_STARTID+1, "Golden MP5")
    411.             }
    412.            
    413.             if (iIndex == 16)
    414.             {
    415.                 iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\w%d.\y %s^n", iIndex-WPN_STARTID+1, "Golden M4A1")
    416.                 break;
    417.             }
    418.         }
    419.        
    420.         // Golden AK47
    421.         if (ze_get_user_level(id) >= 30)
    422.         {
    423.             if (iIndex == 14)
    424.             {
    425.                 iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\w%d.\y %s^n", iIndex-WPN_STARTID+1, "Golden M3")
    426.             }
    427.            
    428.             if (iIndex == 15)
    429.             {
    430.                 iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\w%d.\y %s^n", iIndex-WPN_STARTID+1, "Golden MP5")
    431.             }
    432.            
    433.             if (iIndex == 16)
    434.             {
    435.                 iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\w%d.\y %s^n", iIndex-WPN_STARTID+1, "Golden M4A1")
    436.             }
    437.            
    438.             if (iIndex == 17)
    439.             {
    440.                 iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\w%d.\y %s^n", iIndex-WPN_STARTID+1, "Golden AK-47")
    441.                 break;
    442.             }
    443.         }
    444.        
    445.         // JetPack
    446.         if (ze_get_user_level(id) >= 40)
    447.         {
    448.             if (iIndex == 14)
    449.             {
    450.                 iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\w%d.\y %s^n", iIndex-WPN_STARTID+1, "Golden M3")
    451.             }
    452.            
    453.             if (iIndex == 15)
    454.             {
    455.                 iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\w%d.\y %s^n", iIndex-WPN_STARTID+1, "Golden MP5")
    456.             }
    457.            
    458.             if (iIndex == 16)
    459.             {
    460.                 iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\w%d.\y %s^n", iIndex-WPN_STARTID+1, "Golden M4A1")
    461.             }
    462.            
    463.             if (iIndex == 17)
    464.             {
    465.                 iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\w%d.\y %s^n", iIndex-WPN_STARTID+1, "Golden AK-47")
    466.             }
    467.            
    468.             if (iIndex == 18)
    469.             {
    470.                 iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\w%d.\y %s^n", iIndex-WPN_STARTID+1, "JetPack")
    471.                 break;
    472.             }
    473.         }
    474.        
    475.         // Must check if iIndex < 14 means max is AK47
    476.         if (iIndex < 14)
    477.         {
    478.             ArrayGetString(g_szPrimaryWeapons, iIndex, szWeaponName, charsmax(szWeaponName))
    479.             iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\w%d.\y %s^n", iIndex-WPN_STARTID+1, szWeaponNames[get_weaponid(szWeaponName)])
    480.         }
    481.     }
    482.    
    483.     if (iIndex < 7)
    484.     {
    485.         ArrayGetString(g_szPrimaryWeapons, iIndex, szWeaponName, charsmax(szWeaponName))
    486.         iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "^n\r Next Level Unlock\w: \y%s^n", szWeaponNames[get_weaponid(szWeaponName)])
    487.     }
    488.    
    489.     if (ze_get_user_level(id) == 5)
    490.     {
    491.         ArrayGetString(g_szPrimaryWeapons, 7, szWeaponName, charsmax(szWeaponName))
    492.         iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "^n\r Next Level Unlock\w: \y%s^n", szWeaponNames[get_weaponid(szWeaponName)])
    493.     }
    494.     else if (ze_get_user_level(id) == 6)
    495.     {
    496.         ArrayGetString(g_szPrimaryWeapons, 8, szWeaponName, charsmax(szWeaponName))
    497.         iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "^n\r Next Level Unlock\w: \y%s^n", szWeaponNames[get_weaponid(szWeaponName)])
    498.     }
    499.     else if (ze_get_user_level(id) == 7)
    500.     {
    501.         ArrayGetString(g_szPrimaryWeapons, 9, szWeaponName, charsmax(szWeaponName))
    502.         iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "^n\r Next Level Unlock\w: \y%s^n", szWeaponNames[get_weaponid(szWeaponName)])
    503.     }
    504.     else if (ze_get_user_level(id) == 8)
    505.     {
    506.         ArrayGetString(g_szPrimaryWeapons, 10, szWeaponName, charsmax(szWeaponName))
    507.         iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "^n\r Next Level Unlock\w: \y%s^n", szWeaponNames[get_weaponid(szWeaponName)])
    508.     }
    509.     else if (ze_get_user_level(id) == 9)
    510.     {
    511.         ArrayGetString(g_szPrimaryWeapons, 11, szWeaponName, charsmax(szWeaponName))
    512.         iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "^n\r Next Level Unlock\w: \y%s^n", szWeaponNames[get_weaponid(szWeaponName)])
    513.     }
    514.     else if (ze_get_user_level(id) == 10)
    515.     {
    516.         ArrayGetString(g_szPrimaryWeapons, 12, szWeaponName, charsmax(szWeaponName))
    517.         iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "^n\r Next Level Unlock\w: \y%s^n", szWeaponNames[get_weaponid(szWeaponName)])
    518.     }
    519.     else if (ze_get_user_level(id) == 11)
    520.     {
    521.         ArrayGetString(g_szPrimaryWeapons, 13, szWeaponName, charsmax(szWeaponName))
    522.         iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "^n\r Next Level Unlock\w: \y%s^n", szWeaponNames[get_weaponid(szWeaponName)])
    523.     }
    524.     else if (ze_get_user_level(id) >= 12 && ze_get_user_level(id) < 15) // Golden M3
    525.     {
    526.         iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "^n\r Level 15 Unlock\w: \yGolden M3^n")
    527.     }
    528.     else if (ze_get_user_level(id) >= 15 && ze_get_user_level(id) < 20) // Golden MP5
    529.     {
    530.         iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "^n\r Level 20 Unlock\w: \yGolden MP5^n")
    531.     }
    532.     else if (ze_get_user_level(id) >= 20 && ze_get_user_level(id) < 25) // Golden M4A1
    533.     {
    534.         iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "^n\r Level 25 Unlock\w: \yGolden M4A1^n")
    535.     }
    536.     else if (ze_get_user_level(id) >= 25 && ze_get_user_level(id) < 30) // Golden Ak-47
    537.     {
    538.         iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "^n\r Level 30 Unlock\w: \yGolden AK-47^n")
    539.     }
    540.     else if (ze_get_user_level(id) >= 30 && ze_get_user_level(id) < 40) // JetPack
    541.     {
    542.         iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "^n\r Level 40 Unlock\w: \yJetPack^n")
    543.     }
    544.  
    545.     // 8. Auto Select
    546.     iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "^n\w8.\y %L \w[\r%L\w]", id, "MENU_AUTOSELECT", id, (WPN_AUTO_ON) ? "SAVE_YES" : "SAVE_NO")
    547.    
    548.     // 9. Next/Back - 0. Exit
    549.     iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "^n^n\y9.\r %L \w/ \r%L^n^n\w0.\y %L", id, "NEXT", id, "BACK", id, "EXIT")
    550.    
    551.     // Fix for AMXX custom menus
    552.     set_pdata_int(id, OFFSET_CSMENUCODE, 0)
    553.     show_menu(id, KEYSMENU, szMenu, iMenuTime, "Primary Weapons")
    554. }
    555.  
    556. public Show_Menu_Buy_Secondary(id)
    557. {
    558.     new iMenuTime = floatround(g_fBuyTimeStart[id] + get_pcvar_float(g_pCvarBuyTime) - get_gametime())
    559.    
    560.     if (iMenuTime <= 0)
    561.     {
    562.         ze_colored_print(id, "%L", id, "BUY_MENU_TIME_EXPIRED")
    563.         return
    564.     }
    565.    
    566.     static szMenu[250], szWeaponName[32]
    567.     new iLen, iIndex, iMaxLoops = ArraySize(g_szSecondaryWeapons)
    568.    
    569.     // Title
    570.     iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\y%L^n", id, "MENU_SECONDARY_TITLE")
    571.    
    572.     // 1-6. Weapon List
    573.     for (iIndex = 0; iIndex < iMaxLoops; iIndex++)
    574.     {
    575.         if (ze_get_user_level(id) == 0 && iIndex >= 2 ||
    576.         ze_get_user_level(id) == 1 && iIndex >= 3 ||
    577.         ze_get_user_level(id) == 2 && iIndex >= 4 ||
    578.         ze_get_user_level(id) == 3 && iIndex >= 5 ||
    579.         ze_get_user_level(id) == 4 && iIndex >= 6)
    580.         {
    581.             break
    582.         }
    583.        
    584.         ArrayGetString(g_szSecondaryWeapons, iIndex, szWeaponName, charsmax(szWeaponName))
    585.         iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "^n\w%d.\y %s", iIndex+1, szWeaponNames[get_weaponid(szWeaponName)])
    586.     }
    587.    
    588.     if (iIndex < ArraySize(g_szSecondaryWeapons))
    589.     {
    590.         ArrayGetString(g_szSecondaryWeapons, iIndex, szWeaponName, charsmax(szWeaponName))
    591.         iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "^n^n\r Next Level Unlock\w: \y%s", szWeaponNames[get_weaponid(szWeaponName)])
    592.     }
    593.    
    594.     // 8. Auto Select
    595.     iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "^n^n\w8.\y %L \w[\r%L\w]", id, "MENU_AUTOSELECT", id, (WPN_AUTO_ON) ? "SAVE_YES" : "SAVE_NO")
    596.    
    597.     // 0. Exit
    598.     iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "^n^n\w0.\y %L", id, "EXIT")
    599.    
    600.     // Fix for AMXX custom menus
    601.     set_pdata_int(id, OFFSET_CSMENUCODE, 0)
    602.     show_menu(id, KEYSMENU, szMenu, iMenuTime, "Secondary Weapons")
    603. }
    604.  
    605. public Menu_Buy_Primary(id, key)
    606. {
    607.     // Player dead or zombie or already bought primary
    608.     if (!is_user_alive(id) || ze_is_user_zombie(id) || g_bBoughtPrimary[id])
    609.         return PLUGIN_HANDLED
    610.    
    611.     // Special keys / weapon list exceeded
    612.     if (key >= MENU_KEY_AUTOSELECT || WPN_SELECTION >= WPN_MAXIDS[id])
    613.     {
    614.         switch (key)
    615.         {
    616.             case MENU_KEY_AUTOSELECT: // toggle auto select
    617.             {
    618.                 WPN_AUTO_ON = 1 - WPN_AUTO_ON
    619.             }
    620.             case MENU_KEY_NEXT: // next/back
    621.             {
    622.                 if (WPN_STARTID+7 < WPN_MAXIDS[id])
    623.                     WPN_STARTID += 7
    624.                 else
    625.                     WPN_STARTID = 0
    626.             }
    627.             case MENU_KEY_EXIT: // exit
    628.             {
    629.                 return PLUGIN_HANDLED
    630.             }
    631.         }
    632.        
    633.         // Show buy menu again
    634.         Show_Menu_Buy_Primary(id)
    635.         return PLUGIN_HANDLED
    636.     }
    637.    
    638.     // Store selected weapon id
    639.     WPN_AUTO_PRI = WPN_SELECTION
    640.    
    641.     // Buy primary weapon
    642.     Buy_Primary_Weapon(id, WPN_AUTO_PRI)
    643.    
    644.     // Show Secondary Weapons
    645.     Show_Available_Buy_Menus(id)
    646.    
    647.     return PLUGIN_HANDLED
    648. }
    649.  
    650. public Buy_Primary_Weapon(id, selection)
    651. {
    652.     if (selection == 14) // Golden M3
    653.     {
    654.         give_golden_m3(id)
    655.         g_bBoughtPrimary[id] = true
    656.         return true;
    657.     }
    658.     else if (selection == 15) // Golden MP5
    659.     {
    660.         give_golden_mp5(id)
    661.         g_bBoughtPrimary[id] = true
    662.         return true;
    663.     }
    664.     else if (selection == 16) // Golden M4A1
    665.     {
    666.         give_golden_m4a1(id)
    667.         g_bBoughtPrimary[id] = true
    668.         return true;
    669.     }
    670.     else if (selection == 17) // Golden AK47
    671.     {
    672.         give_golden_ak47(id)
    673.         g_bBoughtPrimary[id] = true
    674.         return true;
    675.     }
    676.     else if (selection == 18) // JetPack
    677.     {
    678.         ze_give_jetpack(id)
    679.         g_bBoughtPrimary[id] = true
    680.         return true;
    681.     }
    682.    
    683.     static szWeaponName[32]
    684.     ArrayGetString(g_szPrimaryWeapons, selection, szWeaponName, charsmax(szWeaponName))
    685.     new iWeaponId = get_weaponid(szWeaponName)
    686.    
    687.     // Strip and Give Full Weapon
    688.     rg_give_item(id, szWeaponName, GT_REPLACE)
    689.     rg_set_user_bpammo(id, WeaponIdType:iWeaponId, szMaxBPAmmo[iWeaponId])
    690.    
    691.     // Primary bought
    692.     g_bBoughtPrimary[id] = true
    693.     return true;
    694. }
    695.  
    696. public Menu_Buy_Secondary(id, key)
    697. {
    698.     // Player dead or zombie or already bought secondary
    699.     if (!is_user_alive(id) || ze_is_user_zombie(id) || g_bBoughtSecondary[id])
    700.         return PLUGIN_HANDLED
    701.    
    702.     // Special keys / weapon list exceeded
    703.     if (key >= ArraySize(g_szSecondaryWeapons))
    704.     {
    705.         // Toggle autoselect
    706.         if (key == MENU_KEY_AUTOSELECT)
    707.             WPN_AUTO_ON = 1 - WPN_AUTO_ON
    708.        
    709.         // Reshow menu unless user exited
    710.         if (key != MENU_KEY_EXIT)
    711.             Show_Menu_Buy_Secondary(id)
    712.        
    713.         return PLUGIN_HANDLED
    714.     }
    715.    
    716.     // Store selected weapon id
    717.     WPN_AUTO_SEC = key
    718.    
    719.     // Buy secondary weapon
    720.     Buy_Secondary_Weapon(id, key)
    721.    
    722.     return PLUGIN_HANDLED
    723. }
    724.  
    725. public Buy_Secondary_Weapon(id, selection)
    726. {
    727.     if ( ((selection == 2) && (ze_get_user_level(id) < 1)) ||
    728.     ((selection == 3) && (ze_get_user_level(id) < 2)) ||
    729.     ((selection == 4) && (ze_get_user_level(id) < 3)) ||
    730.     ((selection == 5) && (ze_get_user_level(id) < 4)) )
    731.     {
    732.         Show_Menu_Buy_Secondary(id)
    733.         return;
    734.     }
    735.  
    736.     static szWeaponName[32]
    737.     ArrayGetString(g_szSecondaryWeapons, selection, szWeaponName, charsmax(szWeaponName))
    738.     new iWeaponId = get_weaponid(szWeaponName)
    739.    
    740.     // Strip and Give Full Weapon
    741.     rg_give_item(id, szWeaponName, GT_REPLACE)
    742.     rg_set_user_bpammo(id, WeaponIdType:iWeaponId, szMaxBPAmmo[iWeaponId])
    743.    
    744.     // Secondary bought
    745.     g_bBoughtSecondary[id] = true
    746. }
    747.  
    748. public Fw_TouchWeapon_Pre(iEnt, id)
    749. {
    750.     if (get_pcvar_num(g_pCvarBlockWeapLowLevel) == 0)
    751.         return HAM_IGNORED;
    752.    
    753.     // Not alive or Not Valid Weapon?
    754.     if(!is_user_alive(id) || !pev_valid(iEnt))
    755.         return HAM_IGNORED;
    756.    
    757.     // Get Weapon Model
    758.     new szWeapModel[32]
    759.     pev(iEnt, pev_model, szWeapModel, charsmax(szWeapModel))
    760.    
    761.     // Remove "models/w_" and ".mdl"
    762.     copyc(szWeapModel, charsmax(szWeapModel), szWeapModel[contain(szWeapModel, "_" ) + 1], '.')
    763.    
    764.     // Set for mp5 to be same as "weapon_mp5navy"
    765.     if(szWeapModel[1] == 'p' && szWeapModel[2] == '5')
    766.         szWeapModel = "mp5navy"
    767.    
    768.     // Add "weapon_" to all model names
    769.     static szWeaponEnt[32]
    770.     formatex(szWeaponEnt, charsmax(szWeaponEnt), "weapon_%s", szWeapModel)
    771.  
    772.     // Get it's index in Weapon Array
    773.     new iIndex, i
    774.    
    775.     // I won't explain the blew code if you need to understand ask me in Escapers-Zone.XYZ
    776.     for (i = 0; i < ArraySize(g_szPrimaryWeapons); i++)
    777.     {
    778.         new szPrimaryWeapon[32]
    779.         ArrayGetString(g_szPrimaryWeapons, i, szPrimaryWeapon, charsmax(szPrimaryWeapon))
    780.        
    781.         if (equali(szWeaponEnt, szPrimaryWeapon))
    782.             iIndex = i
    783.     }
    784.    
    785.     if (ze_get_user_level(id) == 0 && iIndex > 1)
    786.     {
    787.         return HAM_SUPERCEDE;
    788.     }
    789.    
    790.     for (i = 1; i <= 11; i++)
    791.     {
    792.         if ((ze_get_user_level(id) == i) && iIndex > i+1)
    793.         {
    794.             return HAM_SUPERCEDE;
    795.         }
    796.     }
    797.    
    798.     return HAM_IGNORED;
    799. }
    800.  
    801. // Natives
    802. public native_ze_show_weapon_menu(id)
    803. {
    804.     if (!is_user_connected(id))
    805.     {
    806.         log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player (%d)", id)
    807.         return false
    808.     }
    809.    
    810.     Cmd_Buy(id)
    811.     return true
    812. }
    813.  
    814. public native_ze_is_auto_buy_enabled(id)
    815. {
    816.     if (!is_user_connected(id))
    817.     {
    818.         log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player (%d)", id)
    819.         return -1;
    820.     }
    821.    
    822.     return WPN_AUTO_ON;
    823. }
    824.  
    825. public native_ze_disable_auto_buy(id)
    826. {
    827.     if (!is_user_connected(id))
    828.     {
    829.         log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player (%d)", id)
    830.         return false
    831.     }
    832.    
    833.     WPN_AUTO_ON = 0;
    834.     return true
    835. }
Note that if you exceeded the page number 3 there will be special edit needed, if you stuck in this please let me know and i'll help you go out ;)
You don't know? Learn and you will know.

czirimbolo
Veteran Member
Veteran Member
Poland
Posts: 416
Joined: 1 Year Ago
Has thanked: 15 times
Been thanked: 1 time
Contact:

#6

Post by czirimbolo » 3 Weeks Ago

I think I will exceed the page nr 3, because I would like add abour 6-7 guns
Image

User avatar
Raheem
Mod Developer
Mod Developer
Egypt
Posts: 1702
Joined: 1 Year Ago
Location: Egypt
Has thanked: 28 times
Been thanked: 74 times
Age: 20
Contact:

#7

Post by Raheem » 3 Weeks Ago

When you reach current page max, post your .sma and i'll add you another page.

One more thing if you don't know how to add native and remove the weapon from extra-items you can post it in public requests and it's easy for anyone to help you.
You don't know? Learn and you will know.

czirimbolo
Veteran Member
Veteran Member
Poland
Posts: 416
Joined: 1 Year Ago
Has thanked: 15 times
Been thanked: 1 time
Contact:

#8

Post by czirimbolo » 3 Weeks Ago

Raheem, I added this jetpack to my weapon list, but page 3rd is full with golden guns so I cant see jetpack because there is no 4th page. Can you make next page?

edit:
3rd page is full because of duplicated goldens, see the screen. By the way, you can delete M3 golden and mp5 GOLDEN, I won't be using them.
Attachments
ss.PNG
ss.PNG (133.24 KiB) Viewed 183 times
ss.PNG
ss.PNG (133.24 KiB) Viewed 183 times
Image

User avatar
Raheem
Mod Developer
Mod Developer
Egypt
Posts: 1702
Joined: 1 Year Ago
Location: Egypt
Has thanked: 28 times
Been thanked: 74 times
Age: 20
Contact:

#9

Post by Raheem » 3 Weeks Ago

I forget small check:
    1. #include <zombie_escape>
    2. #include <ze_levels>
    3.  
    4. native give_golden_m3(id);
    5. native give_golden_mp5(id);
    6. native give_golden_m4a1(id);
    7. native give_golden_ak47(id);
    8. native ze_give_jetpack(id);
    9.  
    10. // Setting File
    11. new const ZE_SETTING_RESOURCES[] = "zombie_escape.ini"
    12.  
    13. // Keys
    14. const KEYSMENU = MENU_KEY_1|MENU_KEY_2|MENU_KEY_3|MENU_KEY_4|MENU_KEY_5|MENU_KEY_6|MENU_KEY_7|MENU_KEY_8|MENU_KEY_9|MENU_KEY_0
    15. const OFFSET_CSMENUCODE = 205
    16.  
    17. // Primary Weapons Entities [Default Values]
    18. new const szPrimaryWeaponEnt[][] =
    19. {
    20.     "weapon_xm1014",  // Level 0
    21.     "weapon_ump45",   // Level 0
    22.     "weapon_m3",      // Level 1
    23.     "weapon_mp5navy", // Level 2
    24.     "weapon_p90",     // Level 3
    25.     "weapon_galil",   // Level 4
    26.     "weapon_famas",   // Level 5
    27.     "weapon_sg550",   // Level 6
    28.     "weapon_g3sg1",   // Level 7
    29.     "weapon_m249",    // Level 8
    30.     "weapon_sg552",   // Level 9
    31.     "weapon_aug",     // Level 10
    32.     "weapon_m4a1",    // Level 11
    33.     "weapon_ak47"     // Level 12
    34. }
    35.  
    36. // Secondary Weapons Entities [Default Values]
    37. new const szSecondaryWeaponEnt[][]=
    38. {
    39.     "weapon_usp",         // Level 0
    40.     "weapon_p228",        // Level 0
    41.     "weapon_glock18",     // Level 1
    42.     "weapon_fiveseven",   // Level 2
    43.     "weapon_deagle",      // Level 3
    44.     "weapon_elite"        // Level 4
    45. }
    46.  
    47. // Primary and Secondary Weapons Names [Default Values]
    48. new const szWeaponNames[][] =
    49. {
    50.     "",
    51.     "P228",
    52.     "",
    53.     "Scout",
    54.     "HE Grenade",
    55.     "XM1014",
    56.     "",
    57.     "MAC-10",
    58.     "AUG",
    59.     "Smoke Grenade",
    60.     "Dual Elite",
    61.     "Five Seven",
    62.     "UMP 45",
    63.     "SG-550",
    64.     "Galil",
    65.     "Famas",
    66.     "USP",
    67.     "Glock",
    68.     "AWP",
    69.     "MP5",
    70.     "M249",
    71.     "M3",
    72.     "M4A1",
    73.     "TMP",
    74.     "G3SG1",
    75.     "Flashbang",
    76.     "Desert Eagle",
    77.     "SG-552",
    78.     "AK-47",
    79.     "",
    80.     "P90"
    81. }
    82.  
    83. // Max Back Clip Ammo (Change it From here if you need)
    84. new const szMaxBPAmmo[] =
    85. {
    86.     -1,
    87.     52,
    88.     -1,
    89.     90,
    90.     1,
    91.     32,
    92.     1,
    93.     100,
    94.     90,
    95.     1,
    96.     120,
    97.     100,
    98.     100,
    99.     90,
    100.     90,
    101.     90,
    102.     100,
    103.     120,
    104.     30,
    105.     120,
    106.     200,
    107.     32,
    108.     90,
    109.     120,
    110.     90,
    111.     2,
    112.     35,
    113.     90,
    114.     90,
    115.     -1,
    116.     100
    117. }
    118.  
    119. // Menu selections
    120. const MENU_KEY_AUTOSELECT = 7
    121. const MENU_KEY_BACK = 7
    122. const MENU_KEY_NEXT = 8
    123. const MENU_KEY_EXIT = 9
    124.  
    125. // Variables
    126. new Array:g_szPrimaryWeapons, Array:g_szSecondaryWeapons
    127.  
    128. new g_iMenuData[33][4],
    129.     Float:g_fBuyTimeStart[33],
    130.     bool:g_bBoughtPrimary[33],
    131.     bool:g_bBoughtSecondary[33],
    132.     WPN_MAXIDS[33]
    133.  
    134. // Define
    135. #define WPN_STARTID g_iMenuData[id][0]
    136. #define WPN_SELECTION (g_iMenuData[id][0]+key)
    137. #define WPN_AUTO_ON g_iMenuData[id][1]
    138. #define WPN_AUTO_PRI g_iMenuData[id][2]
    139. #define WPN_AUTO_SEC g_iMenuData[id][3]
    140.  
    141. // Cvars
    142. new g_pCvarBuyTime,
    143.     g_pCvarHeGrenade,
    144.     g_pCvarSmokeGrenade,
    145.     g_pCvarFlashGrenade,
    146.     g_pCvarBlockWeapLowLevel
    147.  
    148. public plugin_natives()
    149. {
    150.     register_native("ze_show_weapon_menu", "native_ze_show_weapon_menu", 1)
    151.     register_native("ze_is_auto_buy_enabled", "native_ze_is_auto_buy_enabled", 1)
    152.     register_native("ze_disable_auto_buy", "native_ze_disable_auto_buy", 1)
    153. }
    154.  
    155. public plugin_precache()
    156. {
    157.     // Initialize arrays (32 is the max length of Weapon Entity like: weapon_ak47)
    158.     g_szPrimaryWeapons = ArrayCreate(32, 1)
    159.     g_szSecondaryWeapons = ArrayCreate(32, 1)
    160.    
    161.     // Load from external file
    162.     amx_load_setting_string_arr(ZE_SETTING_RESOURCES, "Weapons Menu", "PRIMARY", g_szPrimaryWeapons)
    163.     amx_load_setting_string_arr(ZE_SETTING_RESOURCES, "Weapons Menu", "SECONDARY", g_szSecondaryWeapons)
    164.    
    165.     // If we couldn't load from file, use and save default ones
    166.    
    167.     new iIndex
    168.    
    169.     if (ArraySize(g_szPrimaryWeapons) == 0)
    170.     {
    171.         for (iIndex = 0; iIndex < sizeof szPrimaryWeaponEnt; iIndex++)
    172.             ArrayPushString(g_szPrimaryWeapons, szPrimaryWeaponEnt[iIndex])
    173.        
    174.         // If not found .ini File Create it and save default values in it
    175.         amx_save_setting_string_arr(ZE_SETTING_RESOURCES, "Weapons Menu", "PRIMARY", g_szPrimaryWeapons)
    176.     }
    177.    
    178.     if (ArraySize(g_szSecondaryWeapons) == 0)
    179.     {
    180.         for (iIndex = 0; iIndex < sizeof szSecondaryWeaponEnt; iIndex++)
    181.             ArrayPushString(g_szSecondaryWeapons, szSecondaryWeaponEnt[iIndex])
    182.        
    183.         // If not found .ini File Create it and save default values in it
    184.         amx_save_setting_string_arr(ZE_SETTING_RESOURCES, "Weapons Menu", "SECONDARY", g_szSecondaryWeapons)
    185.     }
    186. }
    187.  
    188. public plugin_init()
    189. {
    190.     register_plugin("[ZE] Levels Weapons Menu", "1.1", "Raheem")
    191.    
    192.     // Commands
    193.     register_clcmd("guns", "Cmd_Buy")
    194.     register_clcmd("say /enable", "Cmd_Enable")
    195.     register_clcmd("say_team /enable", "Cmd_Enable")
    196.    
    197.     // Cvars
    198.     g_pCvarBuyTime = register_cvar("ze_buy_time", "60")
    199.     g_pCvarHeGrenade = register_cvar("ze_give_HE_nade", "1") // 0 Nothing || 1 Give HE
    200.     g_pCvarSmokeGrenade = register_cvar("ze_give_SM_nade", "1")
    201.     g_pCvarFlashGrenade = register_cvar("ze_give_FB_nade", "1")
    202.     g_pCvarBlockWeapLowLevel = register_cvar("ze_block_weapons_lowlvl", "1")
    203.    
    204.     // Menus
    205.     register_menu("Primary Weapons", KEYSMENU, "Menu_Buy_Primary")
    206.     register_menu("Secondary Weapons", KEYSMENU, "Menu_Buy_Secondary")
    207.    
    208.     // Hams
    209.     RegisterHam(Ham_Touch, "weaponbox", "Fw_TouchWeapon_Pre", 0)
    210.     RegisterHam(Ham_Touch, "armoury_entity", "Fw_TouchWeapon_Pre", 0)
    211. }
    212.  
    213. public client_disconnected(id)
    214. {
    215.     WPN_AUTO_ON = 0
    216.     WPN_STARTID = 0
    217. }
    218.  
    219. public Cmd_Enable(id)
    220. {
    221.     if (WPN_AUTO_ON)
    222.     {
    223.         ze_colored_print(id, "%L", LANG_PLAYER, "BUY_ENABLED")
    224.         WPN_AUTO_ON = 0
    225.     }
    226. }
    227.  
    228. public Cmd_Buy(id)
    229. {
    230.     // Player Zombie
    231.     if (ze_is_user_zombie(id))
    232.     {
    233.         ze_colored_print(id, "%L", LANG_PLAYER, "NO_BUY_ZOMBIE")
    234.         return
    235.     }
    236.    
    237.     // Player Dead
    238.     if (!is_user_alive(id))
    239.     {
    240.         ze_colored_print(id, "%L", LANG_PLAYER, "DEAD_CANT_BUY_WEAPON")
    241.         return
    242.     }
    243.    
    244.     // Already bought
    245.     if (g_bBoughtPrimary[id] && g_bBoughtSecondary[id])
    246.     {
    247.         ze_colored_print(id, "%L", LANG_PLAYER, "ALREADY_BOUGHT")
    248.     }
    249.    
    250.     Show_Available_Buy_Menus(id)
    251. }
    252.  
    253. public ze_user_humanized(id)
    254. {
    255.     // Static Values
    256.     switch (ze_get_user_level(id))
    257.     {
    258.         case 0: WPN_MAXIDS[id] = 2
    259.         case 1: WPN_MAXIDS[id] = 3
    260.         case 2: WPN_MAXIDS[id] = 4
    261.         case 3: WPN_MAXIDS[id] = 5
    262.         case 4: WPN_MAXIDS[id] = 6
    263.         case 5: WPN_MAXIDS[id] = 7
    264.         case 6: WPN_MAXIDS[id] = 8
    265.         case 7: WPN_MAXIDS[id] = 9
    266.         case 8: WPN_MAXIDS[id] = 10
    267.         case 9: WPN_MAXIDS[id] = 11
    268.         case 10: WPN_MAXIDS[id] = 12
    269.         case 11: WPN_MAXIDS[id] = 13
    270.         case 12..14: WPN_MAXIDS[id] = 14
    271.         case 15..19: WPN_MAXIDS[id] = 15 // Golden m3
    272.         case 20..24: WPN_MAXIDS[id] = 16 // Golden MP5
    273.         case 25..29: WPN_MAXIDS[id] = 17 // Golden M4A1
    274.         case 30..39: WPN_MAXIDS[id] = 18 // Golden AK47
    275.         case 40: WPN_MAXIDS[id] = 19    // JatPack
    276.     }
    277.    
    278.     if (ze_get_user_level(id) > 40)
    279.     {
    280.         WPN_MAXIDS[id] = 19
    281.     }
    282.  
    283.     // Buyzone time starts when player is set to human
    284.     g_fBuyTimeStart[id] = get_gametime()
    285.    
    286.     g_bBoughtPrimary[id] = false
    287.     g_bBoughtSecondary[id] = false
    288.    
    289.     // Player dead or zombie
    290.     if (!is_user_alive(id) || ze_is_user_zombie(id))
    291.         return
    292.    
    293.     if (WPN_AUTO_ON)
    294.     {
    295.         ze_colored_print(id, "%L", LANG_PLAYER, "RE_ENABLE_MENU")
    296.         Buy_Primary_Weapon(id, WPN_AUTO_PRI)
    297.         Buy_Secondary_Weapon(id, WPN_AUTO_SEC)
    298.     }
    299.    
    300.     // Open available buy menus
    301.     Show_Available_Buy_Menus(id)
    302.    
    303.     // Give HE Grenade
    304.     if (get_pcvar_num(g_pCvarHeGrenade) != 0)
    305.         rg_give_item(id, "weapon_hegrenade")
    306.    
    307.     // Give Smoke Grenade
    308.     if (get_pcvar_num(g_pCvarSmokeGrenade) != 0)
    309.         rg_give_item(id, "weapon_smokegrenade")
    310.    
    311.     // Give Flashbang Grenade
    312.     if (get_pcvar_num(g_pCvarFlashGrenade) != 0)
    313.         rg_give_item(id, "weapon_flashbang")
    314. }
    315.  
    316. public Show_Available_Buy_Menus(id)
    317. {
    318.     // Already Bought
    319.     if (g_bBoughtPrimary[id] && g_bBoughtSecondary[id])
    320.         return
    321.    
    322.     // Here we use if and else if so we make sure that Primary weapon come first then secondary
    323.     if (!g_bBoughtPrimary[id])
    324.     {
    325.         // Primary    
    326.         Show_Menu_Buy_Primary(id)
    327.     }
    328.     else if (!g_bBoughtSecondary[id])
    329.     {
    330.         // Secondary
    331.         Show_Menu_Buy_Secondary(id)
    332.     }
    333. }
    334.  
    335. public Show_Menu_Buy_Primary(id)
    336. {
    337.     new iMenuTime = floatround(g_fBuyTimeStart[id] + get_pcvar_float(g_pCvarBuyTime) - get_gametime())
    338.    
    339.     if (iMenuTime <= 0)
    340.     {
    341.         ze_colored_print(id, "%L", id, "BUY_MENU_TIME_EXPIRED")
    342.         return
    343.     }
    344.    
    345.     static szMenu[300], szWeaponName[32]
    346.     new iLen, iIndex, iMaxLoops = min(WPN_STARTID+7, WPN_MAXIDS[id])
    347.    
    348.     // Title
    349.     iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\y%L \w[\r%d\w-\r%d\w]^n^n", id, "MENU_PRIMARY_TITLE", WPN_STARTID+1, min(WPN_STARTID+7, WPN_MAXIDS[id]))
    350.    
    351.     // 1-7. Weapon List
    352.     for (iIndex = WPN_STARTID; iIndex < iMaxLoops; iIndex++)
    353.     {
    354.         if (ze_get_user_level(id) == 0 && iIndex >= 2||
    355.         ze_get_user_level(id) == 1 && iIndex >= 3 ||
    356.         ze_get_user_level(id) == 2 && iIndex >= 4 ||
    357.         ze_get_user_level(id) == 3 && iIndex >= 5 ||
    358.         ze_get_user_level(id) == 4 && iIndex >= 6 ||
    359.         ze_get_user_level(id) == 5 && iIndex >= 7 ||
    360.         ze_get_user_level(id) == 6 && iIndex >= 8 ||
    361.         ze_get_user_level(id) == 7 && iIndex >= 9 ||
    362.         ze_get_user_level(id) == 8 && iIndex >= 10 ||
    363.         ze_get_user_level(id) == 9 && iIndex >= 11 ||
    364.         ze_get_user_level(id) == 10 && iIndex >= 12 ||
    365.         ze_get_user_level(id) == 11 && iIndex >= 13 ||
    366.         ze_get_user_level(id) == 12 && iIndex >= 14)
    367.         {
    368.             break
    369.         }
    370.        
    371.         /*
    372.         *  Note that WPN_MAXIDS start from 1 but iIndex start from 0.
    373.         */
    374.        
    375.         // Golden M3
    376.         if (ze_get_user_level(id) >= 15 && ze_get_user_level(id) < 20)
    377.         {
    378.             if (iIndex == 14)
    379.             {
    380.                 iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\w%d.\y %s^n", iIndex-WPN_STARTID+1, "Golden M3")
    381.                 break;
    382.             }
    383.         }
    384.        
    385.         // Golden MP5
    386.         if (ze_get_user_level(id) >= 20 && ze_get_user_level(id) < 25)
    387.         {
    388.             if (iIndex == 14)
    389.             {
    390.                 iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\w%d.\y %s^n", iIndex-WPN_STARTID+1, "Golden M3")
    391.             }
    392.            
    393.             if (iIndex == 15)
    394.             {
    395.                 iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\w%d.\y %s^n", iIndex-WPN_STARTID+1, "Golden MP5")
    396.                 break;
    397.             }
    398.         }
    399.        
    400.         // Golden M4A1
    401.         if (ze_get_user_level(id) >= 25 && ze_get_user_level(id) < 30)
    402.         {
    403.             if (iIndex == 14)
    404.             {
    405.                 iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\w%d.\y %s^n", iIndex-WPN_STARTID+1, "Golden M3")
    406.             }
    407.            
    408.             if (iIndex == 15)
    409.             {
    410.                 iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\w%d.\y %s^n", iIndex-WPN_STARTID+1, "Golden MP5")
    411.             }
    412.            
    413.             if (iIndex == 16)
    414.             {
    415.                 iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\w%d.\y %s^n", iIndex-WPN_STARTID+1, "Golden M4A1")
    416.                 break;
    417.             }
    418.         }
    419.        
    420.         // Golden AK47
    421.         if (ze_get_user_level(id) >= 30 && ze_get_user_level(id) < 40)
    422.         {
    423.             if (iIndex == 14)
    424.             {
    425.                 iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\w%d.\y %s^n", iIndex-WPN_STARTID+1, "Golden M3")
    426.             }
    427.            
    428.             if (iIndex == 15)
    429.             {
    430.                 iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\w%d.\y %s^n", iIndex-WPN_STARTID+1, "Golden MP5")
    431.             }
    432.            
    433.             if (iIndex == 16)
    434.             {
    435.                 iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\w%d.\y %s^n", iIndex-WPN_STARTID+1, "Golden M4A1")
    436.             }
    437.            
    438.             if (iIndex == 17)
    439.             {
    440.                 iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\w%d.\y %s^n", iIndex-WPN_STARTID+1, "Golden AK-47")
    441.                 break;
    442.             }
    443.         }
    444.        
    445.         // JetPack
    446.         if (ze_get_user_level(id) >= 40)
    447.         {
    448.             if (iIndex == 14)
    449.             {
    450.                 iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\w%d.\y %s^n", iIndex-WPN_STARTID+1, "Golden M3")
    451.             }
    452.            
    453.             if (iIndex == 15)
    454.             {
    455.                 iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\w%d.\y %s^n", iIndex-WPN_STARTID+1, "Golden MP5")
    456.             }
    457.            
    458.             if (iIndex == 16)
    459.             {
    460.                 iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\w%d.\y %s^n", iIndex-WPN_STARTID+1, "Golden M4A1")
    461.             }
    462.            
    463.             if (iIndex == 17)
    464.             {
    465.                 iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\w%d.\y %s^n", iIndex-WPN_STARTID+1, "Golden AK-47")
    466.             }
    467.            
    468.             if (iIndex == 18)
    469.             {
    470.                 iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\w%d.\y %s^n", iIndex-WPN_STARTID+1, "JetPack")
    471.                 break;
    472.             }
    473.         }
    474.        
    475.         // Must check if iIndex < 14 means max is AK47
    476.         if (iIndex < 14)
    477.         {
    478.             ArrayGetString(g_szPrimaryWeapons, iIndex, szWeaponName, charsmax(szWeaponName))
    479.             iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\w%d.\y %s^n", iIndex-WPN_STARTID+1, szWeaponNames[get_weaponid(szWeaponName)])
    480.         }
    481.     }
    482.    
    483.     if (iIndex < 7)
    484.     {
    485.         ArrayGetString(g_szPrimaryWeapons, iIndex, szWeaponName, charsmax(szWeaponName))
    486.         iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "^n\r Next Level Unlock\w: \y%s^n", szWeaponNames[get_weaponid(szWeaponName)])
    487.     }
    488.    
    489.     if (ze_get_user_level(id) == 5)
    490.     {
    491.         ArrayGetString(g_szPrimaryWeapons, 7, szWeaponName, charsmax(szWeaponName))
    492.         iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "^n\r Next Level Unlock\w: \y%s^n", szWeaponNames[get_weaponid(szWeaponName)])
    493.     }
    494.     else if (ze_get_user_level(id) == 6)
    495.     {
    496.         ArrayGetString(g_szPrimaryWeapons, 8, szWeaponName, charsmax(szWeaponName))
    497.         iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "^n\r Next Level Unlock\w: \y%s^n", szWeaponNames[get_weaponid(szWeaponName)])
    498.     }
    499.     else if (ze_get_user_level(id) == 7)
    500.     {
    501.         ArrayGetString(g_szPrimaryWeapons, 9, szWeaponName, charsmax(szWeaponName))
    502.         iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "^n\r Next Level Unlock\w: \y%s^n", szWeaponNames[get_weaponid(szWeaponName)])
    503.     }
    504.     else if (ze_get_user_level(id) == 8)
    505.     {
    506.         ArrayGetString(g_szPrimaryWeapons, 10, szWeaponName, charsmax(szWeaponName))
    507.         iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "^n\r Next Level Unlock\w: \y%s^n", szWeaponNames[get_weaponid(szWeaponName)])
    508.     }
    509.     else if (ze_get_user_level(id) == 9)
    510.     {
    511.         ArrayGetString(g_szPrimaryWeapons, 11, szWeaponName, charsmax(szWeaponName))
    512.         iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "^n\r Next Level Unlock\w: \y%s^n", szWeaponNames[get_weaponid(szWeaponName)])
    513.     }
    514.     else if (ze_get_user_level(id) == 10)
    515.     {
    516.         ArrayGetString(g_szPrimaryWeapons, 12, szWeaponName, charsmax(szWeaponName))
    517.         iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "^n\r Next Level Unlock\w: \y%s^n", szWeaponNames[get_weaponid(szWeaponName)])
    518.     }
    519.     else if (ze_get_user_level(id) == 11)
    520.     {
    521.         ArrayGetString(g_szPrimaryWeapons, 13, szWeaponName, charsmax(szWeaponName))
    522.         iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "^n\r Next Level Unlock\w: \y%s^n", szWeaponNames[get_weaponid(szWeaponName)])
    523.     }
    524.     else if (ze_get_user_level(id) >= 12 && ze_get_user_level(id) < 15) // Golden M3
    525.     {
    526.         iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "^n\r Level 15 Unlock\w: \yGolden M3^n")
    527.     }
    528.     else if (ze_get_user_level(id) >= 15 && ze_get_user_level(id) < 20) // Golden MP5
    529.     {
    530.         iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "^n\r Level 20 Unlock\w: \yGolden MP5^n")
    531.     }
    532.     else if (ze_get_user_level(id) >= 20 && ze_get_user_level(id) < 25) // Golden M4A1
    533.     {
    534.         iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "^n\r Level 25 Unlock\w: \yGolden M4A1^n")
    535.     }
    536.     else if (ze_get_user_level(id) >= 25 && ze_get_user_level(id) < 30) // Golden Ak-47
    537.     {
    538.         iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "^n\r Level 30 Unlock\w: \yGolden AK-47^n")
    539.     }
    540.     else if (ze_get_user_level(id) >= 30 && ze_get_user_level(id) < 40) // JetPack
    541.     {
    542.         iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "^n\r Level 40 Unlock\w: \yJetPack^n")
    543.     }
    544.  
    545.     // 8. Auto Select
    546.     iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "^n\w8.\y %L \w[\r%L\w]", id, "MENU_AUTOSELECT", id, (WPN_AUTO_ON) ? "SAVE_YES" : "SAVE_NO")
    547.    
    548.     // 9. Next/Back - 0. Exit
    549.     iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "^n^n\y9.\r %L \w/ \r%L^n^n\w0.\y %L", id, "NEXT", id, "BACK", id, "EXIT")
    550.    
    551.     // Fix for AMXX custom menus
    552.     set_pdata_int(id, OFFSET_CSMENUCODE, 0)
    553.     show_menu(id, KEYSMENU, szMenu, iMenuTime, "Primary Weapons")
    554. }
    555.  
    556. public Show_Menu_Buy_Secondary(id)
    557. {
    558.     new iMenuTime = floatround(g_fBuyTimeStart[id] + get_pcvar_float(g_pCvarBuyTime) - get_gametime())
    559.    
    560.     if (iMenuTime <= 0)
    561.     {
    562.         ze_colored_print(id, "%L", id, "BUY_MENU_TIME_EXPIRED")
    563.         return
    564.     }
    565.    
    566.     static szMenu[250], szWeaponName[32]
    567.     new iLen, iIndex, iMaxLoops = ArraySize(g_szSecondaryWeapons)
    568.    
    569.     // Title
    570.     iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\y%L^n", id, "MENU_SECONDARY_TITLE")
    571.    
    572.     // 1-6. Weapon List
    573.     for (iIndex = 0; iIndex < iMaxLoops; iIndex++)
    574.     {
    575.         if (ze_get_user_level(id) == 0 && iIndex >= 2 ||
    576.         ze_get_user_level(id) == 1 && iIndex >= 3 ||
    577.         ze_get_user_level(id) == 2 && iIndex >= 4 ||
    578.         ze_get_user_level(id) == 3 && iIndex >= 5 ||
    579.         ze_get_user_level(id) == 4 && iIndex >= 6)
    580.         {
    581.             break
    582.         }
    583.        
    584.         ArrayGetString(g_szSecondaryWeapons, iIndex, szWeaponName, charsmax(szWeaponName))
    585.         iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "^n\w%d.\y %s", iIndex+1, szWeaponNames[get_weaponid(szWeaponName)])
    586.     }
    587.    
    588.     if (iIndex < ArraySize(g_szSecondaryWeapons))
    589.     {
    590.         ArrayGetString(g_szSecondaryWeapons, iIndex, szWeaponName, charsmax(szWeaponName))
    591.         iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "^n^n\r Next Level Unlock\w: \y%s", szWeaponNames[get_weaponid(szWeaponName)])
    592.     }
    593.    
    594.     // 8. Auto Select
    595.     iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "^n^n\w8.\y %L \w[\r%L\w]", id, "MENU_AUTOSELECT", id, (WPN_AUTO_ON) ? "SAVE_YES" : "SAVE_NO")
    596.    
    597.     // 0. Exit
    598.     iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "^n^n\w0.\y %L", id, "EXIT")
    599.    
    600.     // Fix for AMXX custom menus
    601.     set_pdata_int(id, OFFSET_CSMENUCODE, 0)
    602.     show_menu(id, KEYSMENU, szMenu, iMenuTime, "Secondary Weapons")
    603. }
    604.  
    605. public Menu_Buy_Primary(id, key)
    606. {
    607.     // Player dead or zombie or already bought primary
    608.     if (!is_user_alive(id) || ze_is_user_zombie(id) || g_bBoughtPrimary[id])
    609.         return PLUGIN_HANDLED
    610.    
    611.     // Special keys / weapon list exceeded
    612.     if (key >= MENU_KEY_AUTOSELECT || WPN_SELECTION >= WPN_MAXIDS[id])
    613.     {
    614.         switch (key)
    615.         {
    616.             case MENU_KEY_AUTOSELECT: // toggle auto select
    617.             {
    618.                 WPN_AUTO_ON = 1 - WPN_AUTO_ON
    619.             }
    620.             case MENU_KEY_NEXT: // next/back
    621.             {
    622.                 if (WPN_STARTID+7 < WPN_MAXIDS[id])
    623.                     WPN_STARTID += 7
    624.                 else
    625.                     WPN_STARTID = 0
    626.             }
    627.             case MENU_KEY_EXIT: // exit
    628.             {
    629.                 return PLUGIN_HANDLED
    630.             }
    631.         }
    632.        
    633.         // Show buy menu again
    634.         Show_Menu_Buy_Primary(id)
    635.         return PLUGIN_HANDLED
    636.     }
    637.    
    638.     // Store selected weapon id
    639.     WPN_AUTO_PRI = WPN_SELECTION
    640.    
    641.     // Buy primary weapon
    642.     Buy_Primary_Weapon(id, WPN_AUTO_PRI)
    643.    
    644.     // Show Secondary Weapons
    645.     Show_Available_Buy_Menus(id)
    646.    
    647.     return PLUGIN_HANDLED
    648. }
    649.  
    650. public Buy_Primary_Weapon(id, selection)
    651. {
    652.     if (selection == 14) // Golden M3
    653.     {
    654.         give_golden_m3(id)
    655.         g_bBoughtPrimary[id] = true
    656.         return true;
    657.     }
    658.     else if (selection == 15) // Golden MP5
    659.     {
    660.         give_golden_mp5(id)
    661.         g_bBoughtPrimary[id] = true
    662.         return true;
    663.     }
    664.     else if (selection == 16) // Golden M4A1
    665.     {
    666.         give_golden_m4a1(id)
    667.         g_bBoughtPrimary[id] = true
    668.         return true;
    669.     }
    670.     else if (selection == 17) // Golden AK47
    671.     {
    672.         give_golden_ak47(id)
    673.         g_bBoughtPrimary[id] = true
    674.         return true;
    675.     }
    676.     else if (selection == 18) // JetPack
    677.     {
    678.         ze_give_jetpack(id)
    679.         g_bBoughtPrimary[id] = true
    680.         return true;
    681.     }
    682.    
    683.     static szWeaponName[32]
    684.     ArrayGetString(g_szPrimaryWeapons, selection, szWeaponName, charsmax(szWeaponName))
    685.     new iWeaponId = get_weaponid(szWeaponName)
    686.    
    687.     // Strip and Give Full Weapon
    688.     rg_give_item(id, szWeaponName, GT_REPLACE)
    689.     rg_set_user_bpammo(id, WeaponIdType:iWeaponId, szMaxBPAmmo[iWeaponId])
    690.    
    691.     // Primary bought
    692.     g_bBoughtPrimary[id] = true
    693.     return true;
    694. }
    695.  
    696. public Menu_Buy_Secondary(id, key)
    697. {
    698.     // Player dead or zombie or already bought secondary
    699.     if (!is_user_alive(id) || ze_is_user_zombie(id) || g_bBoughtSecondary[id])
    700.         return PLUGIN_HANDLED
    701.    
    702.     // Special keys / weapon list exceeded
    703.     if (key >= ArraySize(g_szSecondaryWeapons))
    704.     {
    705.         // Toggle autoselect
    706.         if (key == MENU_KEY_AUTOSELECT)
    707.             WPN_AUTO_ON = 1 - WPN_AUTO_ON
    708.        
    709.         // Reshow menu unless user exited
    710.         if (key != MENU_KEY_EXIT)
    711.             Show_Menu_Buy_Secondary(id)
    712.        
    713.         return PLUGIN_HANDLED
    714.     }
    715.    
    716.     // Store selected weapon id
    717.     WPN_AUTO_SEC = key
    718.    
    719.     // Buy secondary weapon
    720.     Buy_Secondary_Weapon(id, key)
    721.    
    722.     return PLUGIN_HANDLED
    723. }
    724.  
    725. public Buy_Secondary_Weapon(id, selection)
    726. {
    727.     if ( ((selection == 2) && (ze_get_user_level(id) < 1)) ||
    728.     ((selection == 3) && (ze_get_user_level(id) < 2)) ||
    729.     ((selection == 4) && (ze_get_user_level(id) < 3)) ||
    730.     ((selection == 5) && (ze_get_user_level(id) < 4)) )
    731.     {
    732.         Show_Menu_Buy_Secondary(id)
    733.         return;
    734.     }
    735.  
    736.     static szWeaponName[32]
    737.     ArrayGetString(g_szSecondaryWeapons, selection, szWeaponName, charsmax(szWeaponName))
    738.     new iWeaponId = get_weaponid(szWeaponName)
    739.    
    740.     // Strip and Give Full Weapon
    741.     rg_give_item(id, szWeaponName, GT_REPLACE)
    742.     rg_set_user_bpammo(id, WeaponIdType:iWeaponId, szMaxBPAmmo[iWeaponId])
    743.    
    744.     // Secondary bought
    745.     g_bBoughtSecondary[id] = true
    746. }
    747.  
    748. public Fw_TouchWeapon_Pre(iEnt, id)
    749. {
    750.     if (get_pcvar_num(g_pCvarBlockWeapLowLevel) == 0)
    751.         return HAM_IGNORED;
    752.    
    753.     // Not alive or Not Valid Weapon?
    754.     if(!is_user_alive(id) || !pev_valid(iEnt))
    755.         return HAM_IGNORED;
    756.    
    757.     // Get Weapon Model
    758.     new szWeapModel[32]
    759.     pev(iEnt, pev_model, szWeapModel, charsmax(szWeapModel))
    760.    
    761.     // Remove "models/w_" and ".mdl"
    762.     copyc(szWeapModel, charsmax(szWeapModel), szWeapModel[contain(szWeapModel, "_" ) + 1], '.')
    763.    
    764.     // Set for mp5 to be same as "weapon_mp5navy"
    765.     if(szWeapModel[1] == 'p' && szWeapModel[2] == '5')
    766.         szWeapModel = "mp5navy"
    767.    
    768.     // Add "weapon_" to all model names
    769.     static szWeaponEnt[32]
    770.     formatex(szWeaponEnt, charsmax(szWeaponEnt), "weapon_%s", szWeapModel)
    771.  
    772.     // Get it's index in Weapon Array
    773.     new iIndex, i
    774.    
    775.     // I won't explain the blew code if you need to understand ask me in Escapers-Zone.XYZ
    776.     for (i = 0; i < ArraySize(g_szPrimaryWeapons); i++)
    777.     {
    778.         new szPrimaryWeapon[32]
    779.         ArrayGetString(g_szPrimaryWeapons, i, szPrimaryWeapon, charsmax(szPrimaryWeapon))
    780.        
    781.         if (equali(szWeaponEnt, szPrimaryWeapon))
    782.             iIndex = i
    783.     }
    784.    
    785.     if (ze_get_user_level(id) == 0 && iIndex > 1)
    786.     {
    787.         return HAM_SUPERCEDE;
    788.     }
    789.    
    790.     for (i = 1; i <= 11; i++)
    791.     {
    792.         if ((ze_get_user_level(id) == i) && iIndex > i+1)
    793.         {
    794.             return HAM_SUPERCEDE;
    795.         }
    796.     }
    797.    
    798.     return HAM_IGNORED;
    799. }
    800.  
    801. // Natives
    802. public native_ze_show_weapon_menu(id)
    803. {
    804.     if (!is_user_connected(id))
    805.     {
    806.         log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player (%d)", id)
    807.         return false
    808.     }
    809.    
    810.     Cmd_Buy(id)
    811.     return true
    812. }
    813.  
    814. public native_ze_is_auto_buy_enabled(id)
    815. {
    816.     if (!is_user_connected(id))
    817.     {
    818.         log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player (%d)", id)
    819.         return -1;
    820.     }
    821.    
    822.     return WPN_AUTO_ON;
    823. }
    824.  
    825. public native_ze_disable_auto_buy(id)
    826. {
    827.     if (!is_user_connected(id))
    828.     {
    829.         log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player (%d)", id)
    830.         return false
    831.     }
    832.    
    833.     WPN_AUTO_ON = 0;
    834.     return true
    835. }
You don't know? Learn and you will know.

czirimbolo
Veteran Member
Veteran Member
Poland
Posts: 416
Joined: 1 Year Ago
Has thanked: 15 times
Been thanked: 1 time
Contact:

#10

Post by czirimbolo » 3 Weeks Ago

Can you also remove Golden m3 and golden mp50 and add this gun for 30 level?

Code: Select all

/* Plugin generated by AMXX-Studio */

#pragma compress 1

#include <zombie_escape>
#include <fakemeta_util>
#include <fun>
#include <cstrike>
#include <xs>
#include <engine>

#define PLUGIN "Dual Sword Phantom Slayer"
#define VERSION "1.0"
#define AUTHOR "Bim Bim Cay"
#define VIP_FLAG "VIP_A"

#define v_model "models/v_dualsword.mdl"
#define v_modelfx "models/v_dualswordfx.mdl"

#define p_modela "models/p_dualsword_a.mdl"
#define p_modelb "models/p_dualsword_b.mdl"

#define skill_model "models/dualsword_skill.mdl"
#define blueblade_model "models/dualsword_skillfx2.mdl"
#define goldblade_model "models/dualsword_skillfx1.mdl"

//Blue Blade
#define spr_leaf1 "sprites/leaf01_dualsword.spr"
#define spr_leaf2 "sprites/leaf02_dualsword.spr"

//Gold Blade
#define spr_petal1 "sprites/petal01_dualsword.spr"
#define spr_petal2 "sprites/petal02_dualsword.spr"

//Ef Spr (Sorry, I think only csbte can do it)
#define spr_efleft "sprites/ef_dualsword_left.spr" 
#define spr_efright "sprites/ef_dualsword_right.spr" 

new const SwordsSounds[15][] = 
{
	"weapons/dualsword_fly1.wav",
	"weapons/dualsword_fly2.wav",
	"weapons/dualsword_fly3.wav",
	"weapons/dualsword_fly4.wav",
	"weapons/dualsword_fly5.wav",
	"weapons/dualsword_hit1.wav",
	"weapons/dualsword_hit2.wav",
	"weapons/dualsword_hit3.wav",
	"weapons/dualsword_skill_start.wav",
	"weapons/dualsword_skill_end.wav",
	"weapons/dualsword_stab1_hit.wav",
	"weapons/dualsword_stab2_hit.wav",
	"weapons/katana_hitwall.wav",
	"weapons/dualsword_slash_4_1.wav",
	"weapons/dualsword_slash_4_2.wav"
}

//Other Sounds
/*
dualsword_idle_a.wav
dualsword_idle_b.wav
dualsword_slash_1.wav
dualsword_slash_2.wav
dualsword_slash_3.wav
dualsword_slash_4.wav
dualsword_slash_4-1.wav
dualsword_slash_4-2.wav
dualsword_slash_end.wav
dualsword_stab1.wav 
dualsword_stab2.wav 
*/

//Animations
//Blades
#define ANIM_IDLEA		0
#define ANIM_SLASH1		1
#define ANIM_SLASH2		2
#define ANIM_SLASH3		3
#define ANIM_SLASH4		4
#define ANIM_SLASHEND		5
#define ANIM_DRAWA		6
#define ANIM_IDLEB		7
#define ANIM_STAB1		8
#define ANIM_STAB2		9
#define ANIM_STABEND		10
#define ANIM_DRAWB		11
#define ANIM_SWABA		12
#define ANIM_SWABB		13
#define ANIM_SKILLSTART		14
#define ANIM_SKILLLOOP		15

//Effects
#define ANIM_EFSLASH1		0
#define ANIM_EFSLASH2		1
#define ANIM_EFSLASH3		2
#define ANIM_EFSLASH4		3

//Config
#define DRAW_TIME 		0.233	
#define SWAB_TIME		0.366

//SLASH
#define SLASH_NEXTATTACK	0.1
#define SLASH4_NEXTATTACK	0.7
#define SLASH_NEXTIDLE     	1.0
#define SLASHEND_NEXTIDLE  	2.0
#define SLASH_DAMAGE 		150.0
#define SLASH_RANGE		175.0
#define SLASH_ANGLE		60.0

//STAB
#define STAB_DELAY1		0.06
#define STAB_DELAY2		0.4
#define STAB_NEXTATTACK1	0.43
#define STAB_NEXTATTACK2	0.86
#define STAB_NEXTIDLE1		0.7
#define STAB_NEXTIDLE2		0.93
#define STABEND_NEXTIDLE  	1.43
#define STAB_DAMAGE1 		200.0
#define STAB_RANGE1		200.0
#define STAB_ANGLE1		30.0
#define STAB_DAMAGE2 		1000.0
#define STAB_RANGE2		200.0
#define STAB_ANGLE2		45.0

//Skill
#define SKILL_STARTTIME		1.0
#define SKILL_TIME		11.36
#define SKILL_DAMAGE		200.0

//Entities 
#define ATK2_CLASSNAME		"Sugar"
#define EF_CLASSNAME		"1000Swords"
#define SWORD1_CLASSNAME	"Vinegar"
#define SWORD2_CLASSNAME	"Chilli"

//Hit
#define	HIT_NOTHING 			0
#define	HIT_ENEMY			1
#define	HIT_WALL			2

// MACROS
#define Get_BitVar(%1,%2) (%1 & (1 << (%2 & 31)))
#define Set_BitVar(%1,%2) %1 |= (1 << (%2 & 31))
#define UnSet_BitVar(%1,%2) %1 &= ~(1 << (%2 & 31))
#define MaskEnt(%0) (1<<(%0 & 31))

new g_had_dps, is_mode2, is_attacked
new PlayerAttack[33][11], Mode[33], Power[33] , Float:AttackDelay[33], AttackType[33]
new spr_blood_spray, spr_blood_drop, sprleaf1, sprleaf2, sprpetal1, sprpetal2
new dsp

new const Key[11] = 
{
	0,2,3,4,5,0,1,2,3,4,5
}

new const Float:Float1[42] = 
{ 
  50.0, -50.0, 60.0, -60.0, 70.0, -70.0, 80.0, -80.0, 90.0, -90.0, 100.0, -100.0, 110.0, -110.0, 120.0, -120.0, 130.0, -130.0, 140.0,-140.0,
  150.0, -150.0, 160.0, -160.0, 170.0, -170.0, 180.0, -180.0, 190.0, -190.0, 200.0, -200.0, 210.0, -210.0, 220.0, -220.0, 230.0, -230.0, 
  240.0, -240.0, 250.0, -250.0
}

new const Float:Float2[16] =
{
  -16.0, -15.0, -10.0, 0.0, 10.0, 20.0, 30.0, 40.0, 50.0, 60.0, 70.0, 80.0, 90.0, 100.0, 110.0, 120.0
}

new const Float:Float3[41] = 
{ 
  0.0, 10.0, -10.0, 20.0, -20.0, 30.0, -30.0, 40.0, -40.0, 50.0, -50.0, 60.0, -60.0, 70.0, -70.0, 80.0, -80.0, 90.0, -90.0, 100.0, -100.0, 110.0, -110.0, 120.0, -120.0, 130.0, -130.0, 140.0,-140.0,
  150.0, -150.0, 160.0, -160.0, 170.0, -170.0, 180.0, -180.0, 190.0, -190.0, 200.0, -200.0
}
	
public plugin_init() 
{
	register_plugin(PLUGIN, VERSION, AUTHOR)
	
	register_forward(FM_UpdateClientData, "fw_UpdateClientData_Post", 1)
	register_forward(FM_AddToFullPack, "fw_AddToFullPack_Post", 1)
	
	register_think(ATK2_CLASSNAME, "Atk2_Think")
	register_think(EF_CLASSNAME, "Ef_Think")
	register_think(SWORD1_CLASSNAME, "Sword1_Think")
	register_think(SWORD2_CLASSNAME, "Sword2_Think")
	
	register_touch(SWORD1_CLASSNAME, "*", "Sword1_Touch")
	
	RegisterHam(Ham_Item_Deploy,"weapon_knife", "fw_Item_Deploy_Post", 1)
	RegisterHam(Ham_Item_Holster, "weapon_knife", "fw_Item_Holster_Post", 1)
	RegisterHam(Ham_Weapon_WeaponIdle,"weapon_knife", "fw_Weapon_WeaponIdle_Post", 1)
	
	RegisterHam(Ham_Weapon_PrimaryAttack, "weapon_knife", "fw_Weapon_PrimaryAttack")
	RegisterHam(Ham_Weapon_SecondaryAttack, "weapon_knife", "fw_Weapon_SecondaryAttack")
	RegisterHam(Ham_Item_PostFrame, "weapon_knife", "fw_Item_PostFrame")
	
	dsp = ze_register_item("Dual Sword Phantom Slayer", 150, 0)
	ze_set_item_vip(dsp, VIP_FLAG)
	register_clcmd("get_dsp", "get_dsp")
}

public plugin_precache()
{
	precache_model(v_model)
	precache_model(v_modelfx)
	precache_model(p_modela)
	precache_model(p_modelb)
	precache_model(skill_model)
	precache_model(blueblade_model)
	precache_model(goldblade_model)
	
	for(new i = 0; i < sizeof(SwordsSounds); i++)
		precache_sound(SwordsSounds[i])
	
	sprleaf1 = precache_model(spr_leaf1)
	sprleaf2 = precache_model(spr_leaf2)
	sprpetal1 = precache_model(spr_petal1)
	sprpetal2 = precache_model(spr_petal2)
	spr_blood_spray = precache_model("sprites/bloodspray.spr")
	spr_blood_drop = precache_model("sprites/blood.spr")
}

public ze_user_infected(iVictim)
{
    RemoveWeapon(iVictim)
}	
public ze_select_item_pre(id, itemid)
{
	// If it is not the gun the player is willing to buy then just make it available.
	// g_iItemID is the handler you made it before.
	// You can name itemid whatever you like but just not the same handler name.
	
	if (itemid != dsp)
		return ZE_ITEM_AVAILABLE
		
	// In this item we are working on, it will be for humans only so we need to hide it for zombies so they do not get it.
	//If you want it to be for zombies, you need to add the not operator "!" before the native so it's gonna be like this:
	// if (!ze_is_user_zombie(id))
	// If you want an item to be for zombies & humans then just don't add the next code.
	
	if (ze_is_user_zombie(id))
		return ZE_ITEM_DONT_SHOW
		
	// Here we need to return a value so you don't get a warning on compiling.
	return ZE_ITEM_AVAILABLE
}

public ze_select_item_post(id, itemid)
{
	// Here we just block buying the gun if it is not the gun the player is willing to buy so we just add return without values.
	if (itemid != dsp)
		return
	
	GetWeapon(id, itemid)
}
	
public GetWeapon(id, item)
{
	if(item == dsp) get_dsp(id)
}

public RemoveWeapon(id)
{
	remove_dsp(id)
}
	
public get_dsp(id)
{
	if(!is_user_alive(id))
		return
	
	if(Get_BitVar(g_had_dps, id))
		return
	
	Set_BitVar(g_had_dps, id)
	UnSet_BitVar(is_mode2, id)
	UnSet_BitVar(is_attacked, id)
	AttackType[id] = 0
	Power[id] = 0
	Mode[id] = 0

	static Ent; Ent = fm_get_user_weapon_entity(id, CSW_KNIFE)
	
	if(!pev_valid(Ent)) 
		return
	
	if(get_pdata_cbase(id, 373) != Ent) 
		return
	
	ExecuteHamB(Ham_Item_Deploy, Ent)
}

public remove_dsp(id)
{
	UnSet_BitVar(g_had_dps, id)
	UnSet_BitVar(is_mode2, id)
	UnSet_BitVar(is_attacked, id)
	AttackType[id] = 0
	Power[id] = 0
	Mode[id] = 0
}

public fw_UpdateClientData_Post(id, sendweapons, cd_handle)
{
	if(!is_user_alive(id))
		return FMRES_IGNORED	
	if(get_user_weapon(id) == CSW_KNIFE && Get_BitVar(g_had_dps, id))
		set_cd(cd_handle, CD_flNextAttack, get_gametime() + 0.001) 
	
	return FMRES_HANDLED
}	
//Too much CPU but I don't have other choices now
public fw_AddToFullPack_Post(esState, iE, iEnt, iHost, iHostFlags, iPlayer, pSet)
{
	if(!pev_valid(iEnt))
		return
	
	static classname[12]; pev(iEnt, pev_classname, classname, charsmax(classname))
	
	if(equali(classname, ATK2_CLASSNAME))
	{
		static Owner; Owner = pev(iEnt, pev_owner)
		
		if(iHost != Owner)
		{
			set_es(esState, ES_RenderAmt, 0.0)
		}
	} 
}

public fw_Item_Deploy_Post(Ent)
{
	static Id; Id = get_pdata_cbase(Ent, 41, 4)
	
	if(!Get_BitVar(g_had_dps, Id))
		return
	
	set_pev(Id, pev_viewmodel2, v_model)
	
	if(Get_BitVar(is_mode2, Id))
	{
		set_pev(Id, pev_weaponmodel2, p_modela)
		Set_WeaponAnim(Id, ANIM_DRAWA)
	}
	else
	{
		set_pev(Id, pev_weaponmodel2, p_modelb)
		Set_WeaponAnim(Id, ANIM_DRAWB)
	}
}

public fw_Item_Holster_Post(Ent)
{
	static Id; Id = get_pdata_cbase(Ent, 41, 4)
	
	if(!Get_BitVar(g_had_dps, Id))
		return
	
	UnSet_BitVar(is_attacked, Id)
	Mode[Id] = 0
	Power[Id] = 0
	AttackType[Id] = 0
}

public fw_Weapon_WeaponIdle_Post(Ent)
{
	static Id; Id = get_pdata_cbase(Ent, 41, 4)
	
	if(!Get_BitVar(g_had_dps, Id))
		return
		
	if(get_pdata_float(Ent, 48, 4) <= 0.25)
	{
		if(Get_BitVar(is_attacked, Id))
		{
			if(Get_BitVar(is_mode2, Id))
			{
				Set_WeaponAnim(Id, ANIM_SLASHEND)
				set_pdata_float(Ent, 48, SLASHEND_NEXTIDLE + 0.5, 4)
			}
			else
			{
				Set_WeaponAnim(Id, ANIM_STABEND)
				set_pdata_float(Ent, 48, STABEND_NEXTIDLE + 0.5, 4)
			}
			
			UnSet_BitVar(is_attacked, Id)
		}
		else
		{
			if(Mode[Id]) Mode[Id] = 0
			if(Power[Id]) Power[Id] = 0
			
			if(Get_BitVar(is_mode2, Id))
			{
				Set_WeaponAnim(Id, ANIM_IDLEA)
			}
			else
			{
				Set_WeaponAnim(Id, ANIM_IDLEB)
			}
			
			set_pdata_float(Ent, 48, 20.0, 4)
		}
	}
}

public fw_Item_PostFrame(Ent)
{
	static id; id = pev(Ent, pev_owner)
	
	if(!Get_BitVar(g_had_dps, id))
		return HAM_IGNORED	
	
	if(AttackType[id] && AttackDelay[id] < get_gametime())
	{
		if(AttackType[id] == 1) Attack1(id)
		else if(AttackType[id] == 2) Attack2(id)
		
		AttackType[id] = 0
	}
	
	if(!(pev(id, pev_button) & IN_ATTACK2) && Get_BitVar(is_mode2, id) && Mode[id]) Mode[id] = 0
	
	return HAM_IGNORED
}

public fw_Weapon_PrimaryAttack(Ent) 
{
	static id; id = pev(Ent, pev_owner)
	
	if(!Get_BitVar(g_had_dps, id))
		return HAM_IGNORED
	
	if(Get_BitVar(is_mode2, id))
	{
		UnSet_BitVar(is_mode2, id)
		UnSet_BitVar(is_attacked, id)
		
		Mode[id] = 0
		
		Set_WeaponAnim(id, ANIM_SWABA)
		
		set_pdata_float(Ent, 46, 0.1, 4)
		set_pdata_float(Ent, 47, 0.1, 4)
		set_pdata_float(Ent, 48, SWAB_TIME + 0.5, 4)
		
		set_pev(id, pev_weaponmodel2, p_modelb)
		
		return HAM_SUPERCEDE
	}
	
	Set_BitVar(is_attacked, id)
	
	switch(Mode[id])
	{
		case 0: 
		{
			Mode[id] = 1
			
			AttackType[id] = 1
			AttackDelay[id] = get_gametime() + STAB_DELAY1
			
			Set_WeaponAnim(id, ANIM_STAB1)
			
			set_pdata_float(Ent, 46, STAB_NEXTATTACK1, 4)
			set_pdata_float(Ent, 47, STAB_NEXTATTACK1, 4)
			set_pdata_float(Ent, 48, STAB_NEXTIDLE1 + 0.5, 4)
			
			PlayerAttack[id][Power[id]] = 0
			CheckCode(id)
		}
		case 1: 
		{
			Mode[id] = 0
			
			AttackType[id] = 2
			AttackDelay[id] = get_gametime() + STAB_DELAY2
			
			Set_WeaponAnim(id, ANIM_STAB2)
			
			set_pdata_float(Ent, 46, STAB_NEXTATTACK2, 4)
			set_pdata_float(Ent, 47, STAB_NEXTATTACK2, 4)
			set_pdata_float(Ent, 48, STAB_NEXTIDLE2 + 0.5, 4)
			
			PlayerAttack[id][Power[id]] = 1
			CheckCode(id)
		}
	}
	
	return HAM_SUPERCEDE
}

public fw_Weapon_SecondaryAttack(Ent) 
{
	static id; id = pev(Ent, pev_owner)
	
	if(!Get_BitVar(g_had_dps, id))
		return HAM_IGNORED
	
	if(!Get_BitVar(is_mode2, id))
	{
		Set_BitVar(is_mode2, id)
		UnSet_BitVar(is_attacked, id)
		
		Mode[id] = 0
		
		Set_WeaponAnim(id, ANIM_SWABB)
		
		set_pdata_float(Ent, 46, 0.1, 4)
		set_pdata_float(Ent, 47, 0.1, 4)
		set_pdata_float(Ent, 48, SWAB_TIME + 0.5, 4)
		
		set_pev(id, pev_weaponmodel2, p_modela)
		
		return HAM_SUPERCEDE
	}
	
	Set_BitVar(is_attacked, id)
	
	switch(Mode[id])
	{
		case 0: 
		{
			Mode[id] = 1
			
			Set_WeaponAnim(id, ANIM_SLASH1)
			Create_FakeEnt(id, 0, 0)
			
			set_pdata_float(Ent, 46, SLASH_NEXTATTACK, 4)
			set_pdata_float(Ent, 47, SLASH_NEXTATTACK, 4)
			set_pdata_float(Ent, 48, SLASH_NEXTIDLE + 0.5, 4)
			
			PlayerAttack[id][Power[id]] = 2
			CheckCode(id)
		}
		case 1: 
		{
			Mode[id] = 2
			
			Set_WeaponAnim(id, ANIM_SLASH2)
			Create_FakeEnt(id, 1, 0)
			
			set_pdata_float(Ent, 46, SLASH_NEXTATTACK, 4)
			set_pdata_float(Ent, 47, SLASH_NEXTATTACK, 4)
			set_pdata_float(Ent, 48, SLASH_NEXTIDLE  + 0.5, 4)
			
			PlayerAttack[id][Power[id]] = 3
			CheckCode(id)
		}
		case 2: 
		{
			Mode[id] = 3
			
			Set_WeaponAnim(id, ANIM_SLASH3)
			Create_FakeEnt(id, 2, 0)
			
			set_pdata_float(Ent, 46, SLASH_NEXTATTACK, 4)
			set_pdata_float(Ent, 47, SLASH_NEXTATTACK, 4)
			set_pdata_float(Ent, 48, SLASH_NEXTIDLE + 0.5, 4)
			
			PlayerAttack[id][Power[id]] = 4
			CheckCode(id)
		}
		case 3: 
		{
			Mode[id] = 0
			
			Set_WeaponAnim(id, ANIM_SLASH4)
			
			set_pdata_float(Ent, 46, SLASH4_NEXTATTACK, 4)
			set_pdata_float(Ent, 47, SLASH4_NEXTATTACK, 4)
			set_pdata_float(Ent, 48, SLASH_NEXTIDLE + 0.5, 4)
			
			PlayerAttack[id][Power[id]] = 5
			static Skill; Skill = CheckCode(id)
			Create_FakeEnt(id, 3, Skill)
		}
	}
	
	Attack3(id)
	
	return HAM_SUPERCEDE
}

public CheckCode(id)
{
	if(PlayerAttack[id][Power[id]] == Key[Power[id]])
	{
		Power[id]++
		if(Power[id] >= 11)
		{
			Power[id] = 0
			return 1
		}
	}
	else
	{
		Power[id] = 0
	}
	
	return 0
}

public Create_FakeEnt(id, Anim, HavePower)
{
	static Ent; Ent = engfunc(EngFunc_CreateNamedEntity, engfunc(EngFunc_AllocString, "info_target")) 
	
	set_pev(Ent, pev_classname, ATK2_CLASSNAME)
	set_pev(Ent, pev_movetype, MOVETYPE_FLY)
	engfunc(EngFunc_SetModel, Ent, v_modelfx)
	set_pev(Ent, pev_owner, id)
	
	if(Anim == 3)
	{
		set_pev(Ent, pev_fuser4, get_gametime() + 0.5)
		set_pev(Ent, pev_iuser4, 1)
		set_pev(Ent, pev_iuser3, HavePower)
	}
	
	fm_set_rendering(Ent, kRenderNormal, 255, 255, 255, kRenderTransAdd, 255)
	
	set_pev(Ent, pev_sequence, Anim)
	set_pev(Ent, pev_framerate , 1.0)
	
	set_pev(Ent, pev_solid, SOLID_NOT)
	set_pev(Ent, pev_nextthink, get_gametime() + 0.01)
}

public Atk2_Think(Ent)
{
	if(!pev_valid(Ent))
		return

	static Owner; Owner = pev(Ent, pev_owner)
	
	if(!is_user_alive(Owner))
	{
		set_pev(Ent, pev_flags, FL_KILLME)
		return
	}
	
	if(get_user_weapon(Owner) != CSW_KNIFE || !Get_BitVar(g_had_dps, Owner) || !Get_BitVar(is_mode2, Owner))
	{
		set_pev(Ent, pev_flags, FL_KILLME)
		return
	}
	
	static Float:Light; pev(Ent, pev_renderamt, Light)
	
	Light -= 4.0
	//Light -= 20.0
	Light = floatmax(Light, 0.0)
	set_pev(Ent, pev_renderamt, Light)
	
	if(!Light)
	{
		set_pev(Ent, pev_flags, FL_KILLME)
		return
	}
	
	if(pev(Ent, pev_iuser4))
	{
		if(pev(Ent, pev_fuser4) < get_gametime())
		{
			set_pev(Ent, pev_iuser4, 0)
			if(pev(Ent, pev_iuser3))
			{
				Create_Skill(Owner)
				engfunc(EngFunc_EmitSound, Owner, CHAN_WEAPON, SwordsSounds[14], VOL_NORM, ATTN_NORM, 0, PITCH_NORM)
				set_pev(Ent, pev_flags, FL_KILLME)
			}
			else
			{
				engfunc(EngFunc_EmitSound, Owner, CHAN_WEAPON, SwordsSounds[13], VOL_NORM, ATTN_NORM, 0, PITCH_NORM)
			}
		}
	}
	
	static Float:vOrigin[3], Float:vUp[3], Float:Angles[3]
	
	pev(Owner, pev_origin, vOrigin)
	pev(Owner, pev_view_ofs,vUp)
	xs_vec_add(vOrigin, vUp, vOrigin)
	
	pev(Owner, pev_v_angle, Angles)
	angle_vector(Angles, ANGLEVECTOR_FORWARD, Angles)
	vector_to_angle(Angles, Angles)
	
	set_pev(Ent, pev_origin, vOrigin)
	set_pev(Ent, pev_angles, Angles)
	
	set_pev(Ent, pev_nextthink, get_gametime() + 0.01)
}

public Create_Skill(id)
{
	Set_WeaponAnim(id, ANIM_SKILLSTART)
	Set_WeaponIdleTime(id, CSW_KNIFE, SKILL_STARTTIME + 0.5)
	Set_PlayerNextAttack(id, SKILL_STARTTIME)
	
	UnSet_BitVar(is_attacked, id)
	Mode[id] = 0
	AttackType[id] = 0
	
	static Float:Origin[3]
	pev(id, pev_origin, Origin)
	
	static Ent; Ent = engfunc(EngFunc_CreateNamedEntity, engfunc(EngFunc_AllocString, "info_target"))
	
	set_pev(Ent, pev_classname, EF_CLASSNAME)
	engfunc(EngFunc_SetModel, Ent, skill_model)
	set_pev(Ent, pev_origin, Origin)
	set_pev(Ent, pev_movetype, MOVETYPE_FLY)
	set_pev(Ent, pev_owner, id)

	set_pev(Ent, pev_fuser4, get_gametime())
	set_pev(Ent, pev_fuser3, get_gametime())
	set_pev(Ent, pev_fuser2, get_gametime())
	set_pev(Ent, pev_fuser1, get_gametime())
	set_pev(Ent, pev_iuser4, 0)
	
	set_pev(Ent, pev_animtime, get_gametime())
	set_pev(Ent, pev_frame, 0)
	set_pev(Ent, pev_framerate , 1.0)
	set_pev(Ent, pev_sequence, 0)
	
	set_pev(Ent, pev_nextthink, get_gametime() + 0.01)
}

public Ef_Think(Ent)
{
	if(!pev_valid(Ent))
		return
	
	static Owner; Owner = pev(Ent, pev_owner)
	
	if(!is_user_alive(Owner))
	{
		set_pev(Ent, pev_flags, FL_KILLME)
		return
	}
		
	if(get_user_weapon(Owner) != CSW_KNIFE || !Get_BitVar(g_had_dps, Owner) || !Get_BitVar(is_mode2, Owner))
	{
		set_pev(Ent, pev_flags, FL_KILLME)
		return
	}
	
	static Float:Origin[3], Float:Angles[3]
	pev(Owner, pev_origin, Origin)
	pev(Owner, pev_angles, Angles)
	
	Stock_Hook_Ent(Ent, Origin, 1000.0)
	set_pev(Ent, pev_angles, Angles)
	
	static Mode; Mode = pev(Ent, pev_iuser4)
	static Float: Time; pev(Ent, pev_fuser4, Time)
	static Float: AttackTime1; pev(Ent, pev_fuser3, AttackTime1)
	static Float: AttackTime2; pev(Ent, pev_fuser2, AttackTime2)
	static Float: AttackTime3; pev(Ent, pev_fuser1, AttackTime3)
	
	if(Mode == 0)
	{
		if(get_gametime() - 1.0 > Time)
		{
			set_pev(Ent, pev_fuser4, get_gametime())
			set_pev(Ent, pev_iuser4, 1)
			
			Set_WeaponAnim(Owner, ANIM_SKILLLOOP)
			Set_WeaponIdleTime(Owner, CSW_KNIFE, SKILL_TIME + 0.5)
			Set_PlayerNextAttack(Owner, SKILL_TIME)
			
			set_pev(Ent, pev_origin, Origin)
			set_pev(Ent, pev_effects, pev(Ent, pev_effects) | EF_NODRAW) 
		}
	}
	else if(Mode == 1)
	{
		if(get_gametime() - 10.25 > Time)
		{
			set_pev(Ent, pev_fuser4, get_gametime())
			set_pev(Ent, pev_iuser4, 2)
				
			set_pev(Ent, pev_origin, Origin)
			set_pev(Ent, pev_effects, pev(Ent, pev_effects) &~ EF_NODRAW) 
			
			set_pev(Ent, pev_animtime, get_gametime())
			set_pev(Ent, pev_frame, 0)
			set_pev(Ent, pev_framerate , 1.0)
			set_pev(Ent, pev_sequence, 1)
		}
		if(get_gametime() - 0.15 > AttackTime1)
		{
			set_pev(Ent, pev_fuser3, get_gametime())
			DealDamage(Owner)
		}
		if(get_gametime() - 0.1 > AttackTime2)
		{
			set_pev(Ent, pev_fuser2, get_gametime())
			GoldSword(Owner)
		}
		if(get_gametime() - 0.05 > AttackTime3)
		{
			set_pev(Ent, pev_fuser1, get_gametime())
			BlueSword(Owner)
		}
	}
	else 
	{
		if(get_gametime() - 1.5 > Time)
		{
		 	set_pev(Ent, pev_flags, FL_KILLME)
			return
		}
	}
	
	set_pev(Ent, pev_nextthink, get_gametime() + 0.01)
}

public DealDamage(id)
{
	static Ent, Float:Origin[3]
	
	Ent = FM_NULLENT
	pev(id, pev_origin, Origin)
	
	while((Ent = engfunc(EngFunc_FindEntityInSphere, Ent, Origin, 250.0)) != 0)
	{
		if(!pev_valid(Ent))
			continue
		
		if(pev(Ent, pev_takedamage) == DAMAGE_NO)
			continue
			
		if(is_user_alive(Ent) && get_user_team(Ent) == get_user_team(id))
			continue
	
		ExecuteHamB(Ham_TakeDamage, Ent, id, id, SKILL_DAMAGE, DMG_BULLET)
		
		static Float:VicOrigin[3]
		pev(Ent, pev_origin, VicOrigin)
		
		SpawnBlood(VicOrigin, 247, 255)
	}
}
////////////////////////////////////////////////////////////////////////////////////////////////////
public BlueSword(id)
{
	static Float:Origin[3], Float:StartPoint[3], Float:EndPoint[3]
	static Float:FloatX, Float:FloatY, Float:FloatZ	
	
	pev(id, pev_origin, Origin)
	
	switch(random_num(0, 1))
	{
		case 0:
		{
			FloatX = Float1[random_num(0, 41)]
			FloatY = Float1[random_num(40, 41)]
			FloatZ = Float2[random_num(0, 15)]
		}
		case 1:
		{
			FloatX = Float1[random_num(40, 41)]
			FloatY = Float1[random_num(0, 41)]
			FloatZ = Float2[random_num(0, 15)]
		}
	}
	
	xs_vec_set(StartPoint, Origin[0] + FloatX, Origin[1] + FloatY, Origin[2] + FloatZ)
	
	engfunc(EngFunc_TraceLine, Origin, StartPoint, IGNORE_MONSTERS, 0, 0)
	get_tr2(0, TR_vecEndPos, StartPoint)
	
	xs_vec_set(EndPoint, Origin[0] + random_float(-150.0, 150.0), Origin[1] + random_float(-150.0, 150.0), Origin[2] + random_float(-18.0, 125.0))
	
	Create_BlueSword(id, StartPoint, EndPoint)
}

public Create_BlueSword(id, Float:Start[3], Float:End[3])
{
	static Ent, Float:Angles[3], Float:Velocity[3]
	
	xs_vec_sub(End, Start, Angles)
	vector_to_angle(Angles, Angles)
	get_speed_vector(Start, End, 1750.0, Velocity)
	
	Ent = engfunc(EngFunc_CreateNamedEntity, engfunc(EngFunc_AllocString, "info_target"))
	
	set_pev(Ent, pev_classname, SWORD1_CLASSNAME)
	set_pev(Ent, pev_movetype, MOVETYPE_FLY)
	set_pev(Ent, pev_solid, SOLID_TRIGGER)
	set_pev(Ent, pev_origin, Start)
	set_pev(Ent, pev_angles, Angles)
	
	set_pev(Ent, pev_owner, id)
	set_pev(Ent, pev_iuser3, get_user_team(id))
	
	engfunc(EngFunc_SetModel, Ent, blueblade_model)
	fm_set_rendering(Ent, kRenderNormal, 255, 255, 255, kRenderTransAdd, 255)
	
	set_pev(Ent, pev_animtime, get_gametime())
	set_pev(Ent, pev_frame, 0)
	set_pev(Ent, pev_framerate , 1.0)
	set_pev(Ent, pev_sequence, 0)
	
	// Create Velocity
	set_pev(Ent, pev_velocity, Velocity)
	
	emit_sound(Ent, CHAN_BODY, SwordsSounds[random_num(0, 4)], 1.0, ATTN_NORM, 0, PITCH_NORM)
	
	set_pev(Ent, pev_nextthink, get_gametime() + 0.25)
}

public Sword1_Think(Ent)
{
	if(!pev_valid(Ent))
		return
	
	set_pev(Ent, pev_flags, FL_KILLME)
}

public Sword1_Touch(Ent, Touch)
{
	if(!pev_valid(Ent))
		return
	
	if(!is_user_alive(Touch))
	{
		static Classname[32]
		pev(Touch, pev_classname, Classname, charsmax(Classname))
		
		if(equali(Classname, SWORD1_CLASSNAME))
			return
	
		set_pev(Ent, pev_flags, FL_KILLME)
	}
	else
	{
		static Team; Team = pev(Ent, pev_iuser3)
		
		if(get_user_team(Touch) == Team)
			return
		
		static Float:Origin[3]
		pev(Ent, pev_origin, Origin)
		
		SpawnBlood(Origin, 247, 255)
	}
}
////////////////////////////////////////////////////////////////////////////////////////////////////
public GoldSword(id)
{
	static Float:Origin[3], Float:Point[3], Float:Angles[3]
	static Float:FloatX, Float:FloatY, Float:FloatZ 
	
	FloatX = Float3[random_num(0, 40)]
	FloatY = Float3[random_num(0, 40)]
	FloatZ = random_float(0.0, 75.0)
	
	pev(id, pev_origin, Origin)
	xs_vec_set(Point, Origin[0] + FloatX, Origin[1] + FloatY, Origin[2] + FloatZ)
	
	engfunc(EngFunc_TraceLine, Origin, Point, IGNORE_MONSTERS, 0, 0)
	get_tr2(0, TR_vecEndPos, Point)
	
	xs_vec_set(Angles, 0.0, random_float(-180.0, 180.0), 0.0)
	
	Create_GoldSword(id, Point, Angles)
	
	for(new i = 1; i <= get_playersnum(); i++)
	{
		if(!is_user_alive(i))	
			continue
			
		if(get_user_team(i) == get_user_team(id))
			continue
			
		if(fm_entity_range(i, id) > 100.0)
			continue
	
		static Float:VicOrigin[3]
		pev(i, pev_origin, VicOrigin)
		
		SpawnBlood(VicOrigin, 247, 255)
	}
}

public Create_GoldSword(id, Float:Origin[3], Float:Angles[3])
{
	static Ent
	
	Ent = engfunc(EngFunc_CreateNamedEntity, engfunc(EngFunc_AllocString, "env_sprite"))
	
	set_pev(Ent, pev_classname, SWORD2_CLASSNAME)
	set_pev(Ent, pev_movetype, MOVETYPE_FLY)
	set_pev(Ent, pev_origin, Origin)
	set_pev(Ent, pev_angles, Angles)
	
	set_pev(Ent, pev_owner, id)
	
	engfunc(EngFunc_SetModel, Ent, goldblade_model)
	fm_set_rendering(Ent, kRenderNormal, 255, 255, 255, kRenderTransAdd, 255)
	
	set_pev(Ent, pev_fuser4, get_gametime() + 0.1)
	set_pev(Ent, pev_iuser4, 1)
	
	set_pev(Ent, pev_animtime, get_gametime())
	set_pev(Ent, pev_frame, 0)
	set_pev(Ent, pev_framerate , 1.0)
	set_pev(Ent, pev_sequence, random_num(0, 2))
	
	set_pev(Ent, pev_nextthink, get_gametime() + 0.01)
}

public Sword2_Think(Ent)
{
	if(!pev_valid(Ent))
		return
	
	if(pev(Ent, pev_iuser4))
	{
		static Float:Time; pev(Ent, pev_fuser4, Time)
		if(Time < get_gametime())
		{
			set_pev(Ent, pev_iuser4, 0)
		}
	}
	else
	{
		static Float:Light; pev(Ent, pev_renderamt, Light)
	
		Light -= 10.0
		Light = floatmax(Light, 0.0)
		set_pev(Ent, pev_renderamt, Light)
	
		if(!Light)
		{
			set_pev(Ent, pev_flags, FL_KILLME)
			return
		}
	}
	
	set_pev(Ent, pev_nextthink, get_gametime() + 0.01)
}
////////////////////////////////////////////////////////////////////////////////////////////////////
public Attack1(id)
{
	static iHitResult2
	
	iHitResult2 = Knife_Damage(id, STAB_RANGE1, STAB_ANGLE1, STAB_DAMAGE1, 0)
	switch(iHitResult2)
	{
		case HIT_ENEMY:
		{
			engfunc(EngFunc_EmitSound, id, CHAN_WEAPON, SwordsSounds[random_num(10, 11)], VOL_NORM, ATTN_NORM, 0, PITCH_NORM)
		}
		case HIT_WALL:
		{
			engfunc(EngFunc_EmitSound, id, CHAN_WEAPON, SwordsSounds[12], VOL_NORM, ATTN_NORM, 0, PITCH_NORM)
		}
	}
}

public Attack2(id)
{
	static iHitResult2
	
	iHitResult2 = Knife_Damage(id, STAB_RANGE2, STAB_ANGLE2, STAB_DAMAGE2, 0)
	switch(iHitResult2)
	{
		case HIT_ENEMY:
		{
			engfunc(EngFunc_EmitSound, id, CHAN_WEAPON, SwordsSounds[random_num(10, 11)], VOL_NORM, ATTN_NORM, 0, PITCH_NORM)
		}
		case HIT_WALL:
		{
			engfunc(EngFunc_EmitSound, id, CHAN_WEAPON, SwordsSounds[12], VOL_NORM, ATTN_NORM, 0, PITCH_NORM)
		}
	}
}

public Attack3(id)
{
	static iHitResult2
	
	iHitResult2 = Knife_Damage(id, SLASH_RANGE, SLASH_ANGLE, SLASH_DAMAGE, 1)
	switch(iHitResult2)
	{
		case HIT_ENEMY:
		{
			engfunc(EngFunc_EmitSound, id, CHAN_WEAPON, SwordsSounds[random_num(5, 7)], VOL_NORM, ATTN_NORM, 0, PITCH_NORM)
		}
		case HIT_WALL:
		{
			engfunc(EngFunc_EmitSound, id, CHAN_WEAPON, SwordsSounds[12], VOL_NORM, ATTN_NORM, 0, PITCH_NORM)
		}
	}	
}

public Knife_Damage(id, Float:flRange, Float:fAngle, Float:flDamage, Mode)
{
	new iHitResult = HIT_NOTHING
	new Float:vecOrigin[3], Float:vecScr[3], Float:vecEnd[3], Float:V_Angle[3], Float:vecForward[3]
	pev(id, pev_origin, vecOrigin)
	GetGunPosition(id, vecScr)
	pev(id, pev_v_angle, V_Angle)
	engfunc(EngFunc_MakeVectors, V_Angle)
	global_get(glb_v_forward, vecForward)
	xs_vec_mul_scalar(vecForward, flRange, vecForward)
	xs_vec_add(vecScr, vecForward, vecEnd)

	new tr = create_tr2()
	engfunc(EngFunc_TraceLine, vecScr, vecEnd, 0, id, tr)
	new Float:flFraction
	get_tr2(tr, TR_flFraction, flFraction)
	
	if(flFraction < 1.0) 
	{
		iHitResult = HIT_WALL
		
		new Float:EndPos2[3]
		get_tr2(tr, TR_vecEndPos, EndPos2)
		if(Mode) Make_Effect2(EndPos2)
		else Make_Effect1(EndPos2)
	}

	new Float:vecEndZ = vecEnd[2]
	new pEntity = -1
	
	while((pEntity = engfunc(EngFunc_FindEntityInSphere, pEntity, vecOrigin, flRange)) != 0)
	{
		if(!pev_valid(pEntity))
		continue

		if(!IsAlive(pEntity))
		continue

		if(fAngle < 120.0 && !CheckAngle(id, pEntity, fAngle))
		continue

		GetGunPosition(id, vecScr)
		Stock_Get_Origin(pEntity, vecEnd)
		vecEnd[2] = vecScr[2] + (vecEndZ - vecScr[2]) * (get_distance_f(vecScr, vecEnd) / flRange)
		
		engfunc(EngFunc_TraceLine, vecScr, vecEnd, 0, id, tr)
		get_tr2(tr, TR_flFraction, flFraction)

		if(flFraction >= 1.0) engfunc(EngFunc_TraceHull, vecScr, vecEnd, 0, 3, id, tr)
		
		get_tr2(tr, TR_flFraction, flFraction)
		new pHit = get_tr2(tr, TR_pHit)
		
		if(flFraction < 1.0)
		{
			new Float:EndPos[3]
			get_tr2(tr, TR_vecEndPos, EndPos)
			if(IsPlayer(pEntity) || IsHostage(pEntity))
			{
				iHitResult = HIT_ENEMY
				if(CheckBack(id, pEntity)) flDamage *= 3.0
				
				if(Mode) Make_Effect2(EndPos)
				else Make_Effect1(EndPos)
			}
		
			if(pev_valid(pEntity) && pHit == pEntity && id != pEntity && !(pev(pEntity, pev_spawnflags) & SF_BREAK_TRIGGER_ONLY))
			{
				Native_ExecuteAttack(id, pEntity, id, Float:flDamage, 1, DMG_NEVERGIB)
			}
		}
		free_tr2(tr)
	}
	return iHitResult
}

public Native_ExecuteAttack(iAttacker, iVictim, iEntity, Float:fDamage, iHeadShot, iDamageBit)
{
	if (pev(iVictim, pev_takedamage) <= 0.0)
	return 0

	new Float:fOrigin[3], Float:fEnd[3], iTarget, iBody, Float:fMultifDamage
	pev(iAttacker, pev_origin, fOrigin)
	get_user_aiming(iAttacker, iTarget, iBody)
	fm_get_aim_origin(iAttacker, fEnd)
	new ptr = create_tr2()
	new iHitGroup = get_tr2(ptr, TR_iHitgroup)
	if (iTarget == iVictim) iHitGroup = iBody
	else pev(iVictim, pev_origin, fEnd)
	engfunc(EngFunc_TraceLine, fOrigin, fEnd, DONT_IGNORE_MONSTERS, iAttacker, ptr)
	if (iHitGroup == HIT_HEAD && !iHeadShot) iHitGroup = HIT_CHEST

	set_pdata_int(iVictim, 75, iHitGroup, 4)
	switch(iHitGroup)
	{
		case HIT_HEAD: fMultifDamage  = 4.0
		case HIT_CHEST: fMultifDamage  = 1.0
		case 3: fMultifDamage  = 1.25
		case 4,5,6,7: fMultifDamage  = 0.75
		default: fMultifDamage  = 1.0
	}
	fDamage *= fMultifDamage

	if (get_cvar_num("mp_friendlyfire") || (!get_cvar_num("mp_friendlyfire") && get_pdata_int(iAttacker, 114) != get_pdata_int(iVictim, 114)))
	{
		if (is_user_alive(iVictim)) SpawnBlood(fEnd, 247, floatround(fDamage))
	}

	ExecuteHamB(Ham_TakeDamage, iVictim, iEntity, iAttacker, fDamage, iDamageBit)
	free_tr2(ptr)
	return 1
}

stock IsPlayer(pEntity) return is_user_connected(pEntity)

stock IsHostage(pEntity)
{
	new classname[32]; pev(pEntity, pev_classname, classname, charsmax(classname))
	return equal(classname, "hostage_entity")
}

stock IsAlive(pEntity)
{
	if (pEntity < 1) return 0
	return (pev(pEntity, pev_deadflag) == DEAD_NO && pev(pEntity, pev_health) > 0)
}

stock GetGunPosition(id, Float:vecScr[3])
{
	new Float:vecViewOfs[3]
	pev(id, pev_origin, vecScr)
	pev(id, pev_view_ofs, vecViewOfs)
	xs_vec_add(vecScr, vecViewOfs, vecScr)
}

stock CheckBack(iEnemy,id)
{
	new Float:anglea[3], Float:anglev[3]
	pev(iEnemy, pev_v_angle, anglea)
	pev(id, pev_v_angle, anglev)
	new Float:angle = anglea[1] - anglev[1] 
	if (angle < -180.0) angle += 360.0
	if (angle <= 45.0 && angle >= -45.0) return 1
	return 0
}

stock CheckAngle(iAttacker, iVictim, Float:fAngle)  return(Stock_CheckAngle(iAttacker, iVictim) > floatcos(fAngle,degrees))

stock Float:Stock_CheckAngle(id,iTarget)
{
	new Float:vOricross[2],Float:fRad,Float:vId_ori[3],Float:vTar_ori[3],Float:vId_ang[3],Float:fLength,Float:vForward[3]
	Stock_Get_Origin(id, vId_ori)
	Stock_Get_Origin(iTarget, vTar_ori)
	
	pev(id,pev_angles,vId_ang)
	for(new i=0;i<2;i++) vOricross[i] = vTar_ori[i] - vId_ori[i]
	
	fLength = floatsqroot(vOricross[0]*vOricross[0] + vOricross[1]*vOricross[1])
	
	if (fLength<=0.0)
	{
		vOricross[0]=0.0
		vOricross[1]=0.0
	} else {
		vOricross[0]=vOricross[0]*(1.0/fLength)
		vOricross[1]=vOricross[1]*(1.0/fLength)
	}
	
	engfunc(EngFunc_MakeVectors,vId_ang)
	global_get(glb_v_forward,vForward)
	
	fRad = vOricross[0]*vForward[0]+vOricross[1]*vForward[1]
	
	return fRad   //->   RAD 90' = 0.5rad
}

stock Stock_Get_Origin(id, Float:origin[3])
{
	new Float:maxs[3],Float:mins[3]
	if (pev(id, pev_solid) == SOLID_BSP)
	{
		pev(id,pev_maxs,maxs)
		pev(id,pev_mins,mins)
		origin[0] = (maxs[0] - mins[0]) / 2 + mins[0]
		origin[1] = (maxs[1] - mins[1]) / 2 + mins[1]
		origin[2] = (maxs[2] - mins[2]) / 2 + mins[2]
	} else pev(id, pev_origin, origin)
}

stock SpawnBlood(const Float:vecOrigin[3], iColor, iAmount)
{
	if(iAmount == 0)
	return

	if(!iColor)
	return

	iAmount *= 2
	if(iAmount > 255) iAmount = 255
	engfunc(EngFunc_MessageBegin, MSG_PVS, SVC_TEMPENTITY, vecOrigin)
	write_byte(TE_BLOODSPRITE)
	engfunc(EngFunc_WriteCoord, vecOrigin[0])
	engfunc(EngFunc_WriteCoord, vecOrigin[1])
	engfunc(EngFunc_WriteCoord, vecOrigin[2])
	write_short(spr_blood_spray)
	write_short(spr_blood_drop)
	write_byte(iColor)
	write_byte(min(max(3, iAmount / 10), 16))
	message_end()
}

stock Make_Effect1(Float:Origin[3])
{
	engfunc(EngFunc_MessageBegin, MSG_PVS, SVC_TEMPENTITY, Origin)
	write_byte(TE_BLOODSPRITE)
	engfunc(EngFunc_WriteCoord, Origin[0])
	engfunc(EngFunc_WriteCoord, Origin[1])
	engfunc(EngFunc_WriteCoord, Origin[2])
	write_short(sprleaf1)
	write_short(sprleaf1)
	write_byte(230)
	write_byte(3)
	message_end()
	
	engfunc(EngFunc_MessageBegin, MSG_PVS, SVC_TEMPENTITY, Origin)
	write_byte(TE_BLOODSPRITE)
	engfunc(EngFunc_WriteCoord, Origin[0])
	engfunc(EngFunc_WriteCoord, Origin[1])
	engfunc(EngFunc_WriteCoord, Origin[2])
	write_short(sprleaf2)
	write_short(sprleaf2)
	write_byte(71)
	write_byte(3)
	message_end()
}

stock Make_Effect2(Float:Origin[3])
{
	engfunc(EngFunc_MessageBegin, MSG_PVS, SVC_TEMPENTITY, Origin)
	write_byte(TE_BLOODSPRITE)
	engfunc(EngFunc_WriteCoord, Origin[0])
	engfunc(EngFunc_WriteCoord, Origin[1])
	engfunc(EngFunc_WriteCoord, Origin[2])
	write_short(sprpetal1)
	write_short(sprpetal1)
	write_byte(144)
	write_byte(3)
	message_end()
	
	engfunc(EngFunc_MessageBegin, MSG_PVS, SVC_TEMPENTITY, Origin)
	write_byte(TE_BLOODSPRITE)
	engfunc(EngFunc_WriteCoord, Origin[0])
	engfunc(EngFunc_WriteCoord, Origin[1])
	engfunc(EngFunc_WriteCoord, Origin[2])
	write_short(sprpetal2)
	write_short(sprpetal2)
	write_byte(150)
	write_byte(3)
	message_end()
}

stock Set_WeaponAnim(id, anim)
{
	set_pev(id, pev_weaponanim, anim)
	
	message_begin(MSG_ONE_UNRELIABLE, SVC_WEAPONANIM, {0, 0, 0}, id)
	write_byte(anim)
	write_byte(pev(id, pev_body))
	message_end()
}

stock get_angle_to_target(id, const Float:fTarget[3], Float:TargetSize = 0.0)
{
	static Float:fOrigin[3], iAimOrigin[3], Float:fAimOrigin[3], Float:fV1[3]
	pev(id, pev_origin, fOrigin)
	get_user_origin(id, iAimOrigin, 3) // end position from eyes
	IVecFVec(iAimOrigin, fAimOrigin)
	xs_vec_sub(fAimOrigin, fOrigin, fV1)
	
	static Float:fV2[3]
	xs_vec_sub(fTarget, fOrigin, fV2)
	
	static iResult; iResult = get_angle_between_vectors(fV1, fV2)
	
	if (TargetSize > 0.0)
	{
		static Float:fTan; fTan = TargetSize / get_distance_f(fOrigin, fTarget)
		static fAngleToTargetSize; fAngleToTargetSize = floatround( floatatan(fTan, degrees) )
		iResult -= (iResult > 0) ? fAngleToTargetSize : -fAngleToTargetSize
	}
	
	return iResult
}

stock get_angle_between_vectors(const Float:fV1[3], const Float:fV2[3])
{
	static Float:fA1[3], Float:fA2[3]
	engfunc(EngFunc_VecToAngles, fV1, fA1)
	engfunc(EngFunc_VecToAngles, fV2, fA2)
	
	static iResult; iResult = floatround(fA1[1] - fA2[1])
	iResult = iResult % 360
	iResult = (iResult > 180) ? (iResult - 360) : iResult
	
	return iResult
}	

stock get_position(id,Float:forw, Float:right, Float:up, Float:vStart[])
{
	new Float:vOrigin[3], Float:vAngle[3], Float:vForward[3], Float:vRight[3], Float:vUp[3]
	
	pev(id, pev_origin, vOrigin)
	pev(id, pev_view_ofs,vUp) //for player
	xs_vec_add(vOrigin,vUp,vOrigin)
	pev(id, pev_v_angle, vAngle) // if normal entity ,use pev_angles
	
	angle_vector(vAngle,ANGLEVECTOR_FORWARD,vForward) //or use EngFunc_AngleVectors
	angle_vector(vAngle,ANGLEVECTOR_RIGHT,vRight)
	angle_vector(vAngle,ANGLEVECTOR_UP,vUp)
	
	vStart[0] = vOrigin[0] + vForward[0] * forw + vRight[0] * right + vUp[0] * up
	vStart[1] = vOrigin[1] + vForward[1] * forw + vRight[1] * right + vUp[1] * up
	vStart[2] = vOrigin[2] + vForward[2] * forw + vRight[2] * right + vUp[2] * up
}

stock Set_WeaponIdleTime(id, WeaponId ,Float:TimeIdle)
{
	static entwpn; entwpn = fm_get_user_weapon_entity(id, WeaponId)
	if(!pev_valid(entwpn)) 
		return
		
	set_pdata_float(entwpn, 48, TimeIdle + 0.5, 4)
}

stock Set_PlayerNextAttack(id, Float:nexttime)
{
	set_pdata_float(id, 83, nexttime, 5)
}

stock Stock_Hook_Ent(ent, Float:TargetOrigin[3], Float:Speed)
{
	static Float:fl_Velocity[3], Float:EntOrigin[3], Float:distance_f, Float:fl_Time
	pev(ent, pev_origin, EntOrigin)
	
	distance_f = get_distance_f(EntOrigin, TargetOrigin)
	fl_Time = distance_f / Speed
	
	if(distance_f > 0.1)
	{
		fl_Velocity[0] = (TargetOrigin[0] - EntOrigin[0]) / fl_Time
		fl_Velocity[1] = (TargetOrigin[1] - EntOrigin[1]) / fl_Time
		fl_Velocity[2] = (TargetOrigin[2] - EntOrigin[2]) / fl_Time
	}
	else
	{
		fl_Velocity[0] = 0.0
		fl_Velocity[1] = 0.0
		fl_Velocity[2] = 0.0
	}

	set_pev(ent, pev_velocity, fl_Velocity)
}

stock get_speed_vector(const Float:origin1[3],const Float:origin2[3],Float:speed, Float:new_velocity[3])
{
	new_velocity[0] = origin2[0] - origin1[0]
	new_velocity[1] = origin2[1] - origin1[1]
	new_velocity[2] = origin2[2] - origin1[2]
	new Float:num = floatsqroot(speed*speed / (new_velocity[0]*new_velocity[0] + new_velocity[1]*new_velocity[1] + new_velocity[2]*new_velocity[2]))
	new_velocity[0] *= num
	new_velocity[1] *= num
	new_velocity[2] *= num
	
	return 1;
}
Image

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests