Raised This Month: $32 Target: $400
 8% 

Random Weapon


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
AnimalMonster
Senior Member
Join Date: May 2020
Old 12-17-2020 , 14:34   Random Weapon
Reply With Quote #1

Hey i've edited a plugin that is supposed to register weapons but i wanted to add support to bots, and i tried to make a random weapon system where bots would get melee weapons, primary weapons and secondary weapons random to use in their battle HvZ but the problem is that when executing the forward that gives the bot the random weapons is giving them like 3 primary weapons and 2 pistols, ofc they re thrown on the ground when Executing the forwards.
May i show the code? Or make a example of how i coded that thing?
AnimalMonster is offline
Napoleon_be
Veteran Member
Join Date: Jul 2011
Location: Belgium
Old 12-17-2020 , 17:00   Re: Random Weapon
Reply With Quote #2

Show your code already. You're probably doing something wrong in your loop.
__________________
Napoleon_be is offline
Send a message via Skype™ to Napoleon_be
AnimalMonster
Senior Member
Join Date: May 2020
Old 12-18-2020 , 06:02   Re: Random Weapon
Reply With Quote #3

PHP Code:
#include <amxmodx>
#include <amxmisc>
#include <fakemeta>
#include <fakemeta_util>
#include <hamsandwich>
#include <cstrike>
#include <zombie_theheroex>

#define PLUGIN "[ZBHeroEx] Addon: Weapon"
#define VERSION "1.0"
#define AUTHOR "Dias"

// Config File
#define LANG_FILE "zombie_theheroex.txt"
#define SETTING_FILE "zombie_theheroex.ini"


#define GAMENAME "Zombie: ExHero"
#define LANG_OFFICIAL LANG_PLAYER

// Forward
#define MAX_FORWARD 2
enum
{
    
FWD_WEAPON_BOUGHT 0,
    
FWD_WEAPON_REMOVE
}

new 
g_Forward[MAX_FORWARD], g_fwResult

// Array
new g_WeaponCountg_WeaponPriCountg_WeaponSecCountg_WeaponMeleeCount
new Array:WeaponName, Array:WeaponType, Array:WeaponBasedOn, Array:WeaponCost

// Main Var
#define MAX_WEAPON 32
#define TASK_RESELECT_WEAPON 1972

new g_PriSelected[33], g_SecSelected[33], g_MeleeSelected[33]
new 
g_UnlockedWeapon[33][MAX_WEAPON], g_CanGetWeapons

// Const
const PRIMARY_WEAPONS_BIT_SUM = (1<<CSW_SCOUT)|(1<<CSW_XM1014)|(1<<CSW_MAC10)|(1<<CSW_AUG)|(1<<CSW_UMP45)|(1<<CSW_SG550)|(1<<CSW_GALIL)|(1<<CSW_FAMAS)|(1<<CSW_AWP)|(1<<CSW_MP5NAVY)|(1<<CSW_M249)|(1<<CSW_M3)|(1<<CSW_M4A1)|(1<<CSW_TMP)|(1<<CSW_G3SG1)|(1<<CSW_SG552)|(1<<CSW_AK47)|(1<<CSW_P90)
const 
SECONDARY_WEAPONS_BIT_SUM = (1<<CSW_P228)|(1<<CSW_ELITE)|(1<<CSW_FIVESEVEN)|(1<<CSW_USP)|(1<<CSW_GLOCK18)|(1<<CSW_DEAGLE)
const 
NADE_WEAPONS_BIT_SUM = ((1<<CSW_HEGRENADE)|(1<<CSW_SMOKEGRENADE)|(1<<CSW_FLASHBANG))

// Temp Cache
new MenuTitle[64], WeaponNameS[32], WeaponTypeSWeaponBasedOnSWeaponCostSAddItemS[80], AddDescS[4]

// 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))

public plugin_init() 
{
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
g_Forward[FWD_WEAPON_BOUGHT] = CreateMultiForward("zbheroex_weapon_bought"ET_IGNOREFP_CELLFP_CELL)
    
g_Forward[FWD_WEAPON_REMOVE] = CreateMultiForward("zbheroex_weapon_remove"ET_IGNOREFP_CELLFP_CELL)
}

public 
plugin_precache()
{
    
register_dictionary(LANG_FILE)
    
    
WeaponName ArrayCreate(641)
    
WeaponType ArrayCreate(11)
    
WeaponBasedOn ArrayCreate(11)
    
WeaponCost ArrayCreate(11)
}

public 
plugin_natives()
{
    
register_native("zbheroex_register_weapon""Native_RegisterWeapon"1)
}

public 
Native_RegisterWeapon(const Name[], TypeBasedOnCost)
{
    
param_convert(1)
    
    
ArrayPushString(WeaponNameName)
    
ArrayPushCell(WeaponTypeType)
    
ArrayPushCell(WeaponBasedOnBasedOn)
    
ArrayPushCell(WeaponCostCost)
    
    
g_WeaponCount++
    
    if(
Type == WEAPON_PRIMARYg_WeaponPriCount++
    else if(
Type == WEAPON_SECONDARYg_WeaponSecCount++
    else if(
Type == WEAPON_MELEEg_WeaponMeleeCount++
    
    return 
g_WeaponCount 1
}

public 
client_putinserver(id)
{
    
ResetWeapon(id1)
    
    
g_PriSelected[id] = get_first_weapon(WEAPON_PRIMARY)
    
g_SecSelected[id] = get_first_weapon(WEAPON_SECONDARY)
    
g_MeleeSelected[id] = get_first_weapon(WEAPON_MELEE)
}

public 
zbheroex_user_spawned(idZombie)
{
    if(
Zombie) return
    
    
ResetWeapon(id0)
    
set_task(0.25"Delay_Spawn"id+TASK_RESELECT_WEAPON)
}

public 
zbheroex_user_infect(idInfectorInfection)
{
    
ResetWeapon(id0)
}

public 
Delay_Spawn(id)
{
    
id -= TASK_RESELECT_WEAPON
    
if(!is_user_alive(id))
        return
    
    if(!
is_user_bot(id))
    {
        
Set_BitVar(g_CanGetWeapons,  id)
        
Open_WeaponMenu(id)
    }
    else 
ReciveWeapons(id)
}

public 
Task_ReOpen(id)
{
    
id -= TASK_RESELECT_WEAPON
    Open_WeaponMenu
(id)
}
    
public 
Open_WeaponMenu(id)
{
    new 
weap menu_create("Select Your Weapon""Weaphandeler")
    new 
szBuffer[100]
    
    
format(szBuffercharsmax(szBuffer), "\rPrimary Weapon \w[ \y%s \w]"get_item_name(g_PriSelected[id]))
    
menu_additem(weapszBuffer)
    
format(szBuffercharsmax(szBuffer), "\rSecondary Weapon \w[ \y%s \w]"get_item_name(g_SecSelected[id]))
    
menu_additem(weapszBuffer)
    
format(szBuffercharsmax(szBuffer), "\rMelee Weapon \w[ \y%s \w]"get_item_name(g_MeleeSelected[id]))
    
menu_additem(weapszBuffer)
    
format(szBuffercharsmax(szBuffer), "\rRecive \yWeapons")
    
menu_additem(weapszBuffer)
    
    
menu_display(idweap)
}

public 
Weaphandeler(idweapitem)
{
    switch(
item)
    {
        case 
0Show_WeaponMenu(idWEAPON_PRIMARY)
        case 
1Show_WeaponMenu(idWEAPON_SECONDARY)
        case 
2Show_WeaponMenu(idWEAPON_MELEE)
        case 
3ReciveWeapons(id)
    }
}

public 
ResetWeapon(idNewPlayer)
{
    if(
NewPlayer)
    {
        for(new 
0MAX_WEAPONi++)
            
g_UnlockedWeapon[id][i] = 0
    
}
    
    for(new 
0MAX_WEAPONi++)
        
ExecuteForward(g_Forward[FWD_WEAPON_REMOVE], g_fwResultidi)
    
}

public 
Show_WeaponMenu(idType)
{
    if(
zbheroex_get_user_hero(id))
        return
    
    if(
Type == WEAPON_PRIMARYformatex(MenuTitlesizeof(MenuTitle), "%L"LANG_OFFICIAL"WEAPON_PRIMARY")
    else if(
Type == WEAPON_SECONDARYformatex(MenuTitlesizeof(MenuTitle), "%L"LANG_OFFICIAL"WEAPON_SECONDARY")
    else if(
Type == WEAPON_MELEEformatex(MenuTitlesizeof(MenuTitle), "%L"LANG_OFFICIAL"WEAPON_MELEE")
    
    static 
MenuMenu menu_create(MenuTitle"MenuHandle_Weapon")
    for(new 
0g_WeaponCounti++)
    {
        
WeaponTypeS ArrayGetCell(WeaponTypei)
        
        if(
WeaponTypeS != Type)
            continue
            
        
ArrayGetString(WeaponNameiWeaponNameSsizeof(WeaponNameS))
        
WeaponCostS ArrayGetCell(WeaponCosti)
        
        if(
g_UnlockedWeapon[id][i] || !WeaponCostS)
        {
            
formatex(AddItemSsizeof(AddItemS), "%s"WeaponNameS)
        } else {
            if(
cs_get_user_money(id) >= WeaponCostSformatex(AddItemSsizeof(AddItemS), "%s (\y$%i\w)"WeaponNameSWeaponCostS)
            else 
formatex(AddItemSsizeof(AddItemS), "\d%s\w (\r$%i\w)"WeaponNameSWeaponCostS)
        }
    
        
num_to_str(iAddDescSsizeof(AddDescS))
        
menu_additem(MenuAddItemSAddDescS)
    }
    
    
menu_display(idMenu0)
}

public 
zbheroex_game_start()
{
    for(new 
0get_maxplayers(); i++)
        if(
Get_BitVar(g_CanGetWeaponsi))
        {
            
ReciveWeapons(i)
            
menu_cancel(i)
        }
}

public 
MenuHandle_Weapon(idMenuItem)
{
    if(
Item == MENU_EXIT)
    {
        
menu_destroy(Menu)
        return
    }
    if(!
is_user_alive(id) || zbheroex_get_user_zombie(id))
    {
        
menu_destroy(Menu)
        return
    }
    if(
zbheroex_get_user_hero(id))
    {
        
menu_destroy(Menu)
        return
    }
    
    static 
Data[6], Name[64], ItemAccessItemCallback
    menu_item_getinfo
(MenuItemItemAccessDatacharsmax(Data), Namecharsmax(Name), ItemCallback)
    
    static 
WeaponIdWeaponId str_to_num(Data)
    
    
ArrayGetString(WeaponNameWeaponIdWeaponNameSsizeof(WeaponNameS))
    
WeaponCostS ArrayGetCell(WeaponCostWeaponId)
    
WeaponBasedOnS ArrayGetCell(WeaponBasedOnWeaponId)
    
WeaponTypeS ArrayGetCell(WeaponTypeWeaponId)
    
    if(
g_UnlockedWeapon[id][WeaponId] || !WeaponCostS)
    {
        if(
WeaponTypeS == WEAPON_MELEEg_MeleeSelected[id] = WeaponId
        
else if(WeaponTypeS == WEAPON_SECONDARY
        {
            
g_SecSelected[id] = WeaponId
        
} else if(WeaponTypeS == WEAPON_PRIMARY) {
            
g_PriSelected[id] = WeaponId
        
}    
        
        
g_UnlockedWeapon[id][WeaponId] = 1
        Open_WeaponMenu
(id)

        
menu_destroy(Menu)
        
        return
    } else {
        if(
cs_get_user_money(id) >= WeaponCostS
        {
            if(
WeaponTypeS == WEAPON_MELEEg_MeleeSelected[id] = WeaponId
            
else if(WeaponTypeS == WEAPON_SECONDARY
            {
                
g_SecSelected[id] = WeaponId
            
} else if(WeaponTypeS == WEAPON_PRIMARY) {
                
g_PriSelected[id] = WeaponId
            
}        
            
            
g_UnlockedWeapon[id][WeaponId] = 1
                
            cs_set_user_money
(idcs_get_user_money(id) - floatround(float(WeaponCostS) / 2.0))
                
            
client_print_color(idid"^4[%s]^1 %L"GAMENAMELANG_OFFICIAL"WEAPON_UNLOCKED"WeaponNameSWeaponCostS)
            
menu_destroy(Menu)
            
Open_WeaponMenu(id)
            
            return
        } else {
            
client_print_color(idid"^4[%s]^1 %L"GAMENAMELANG_OFFICIAL"WEAPON_NOMONEY"WeaponNameSWeaponCostS)
        
            
menu_destroy(Menu)
            
Open_WeaponMenu(id)
            
            return
        }
    }    
}

public 
ReciveWeapons(id)
{
    if(
is_user_bot(id))
    {
        
g_PriSelected[id] = get_randomweap(WEAPON_PRIMARY)
        
g_SecSelected[id] = get_randomweap(WEAPON_SECONDARY)
        
g_MeleeSelected[id] = get_randomweap(WEAPON_MELEE)
    }

    
drop_weapons(id1)
    
drop_weapons(id2)
    
ExecuteForward(g_Forward[FWD_WEAPON_BOUGHT], g_fwResultidg_PriSelected[id])
    
ExecuteForward(g_Forward[FWD_WEAPON_BOUGHT], g_fwResultidg_SecSelected[id])
    
ExecuteForward(g_Forward[FWD_WEAPON_BOUGHT], g_fwResultidg_MeleeSelected[id])
    
Give_FuckingAmmo(idArrayGetCell(WeaponBasedOng_PriSelected[id]))
    
Give_FuckingAmmo(idArrayGetCell(WeaponBasedOng_SecSelected[id]))
    
UnSet_BitVar(g_CanGetWeaponsid)
}

public 
Give_FuckingAmmo(idCSWID)
{
    static 
AmountMax
    
switch(CSWID)
    {
        case 
CSW_P228: {Amount 10Max 104;}
        case 
CSW_SCOUT: {Amount 6Max 180;}
        case 
CSW_XM1014: {Amount 8Max 64;}
        case 
CSW_MAC10: {Amount 16Max 200;}
        case 
CSW_AUG: {Amount 6Max 180;}
        case 
CSW_ELITE: {Amount 16Max 200;}
        case 
CSW_FIVESEVEN: {Amount 4Max 200;}
        case 
CSW_UMP45: {Amount 16Max 200;}
        case 
CSW_SG550: {Amount 6Max 180;}
        case 
CSW_GALIL: {Amount 6Max 180;}
        case 
CSW_FAMAS: {Amount 6Max 180;}
        case 
CSW_USP: {Amount 18Max 200;}
        case 
CSW_GLOCK18: {Amount 16Max 200;}
        case 
CSW_AWP: {Amount 6Max 60;}
        case 
CSW_MP5NAVY: {Amount 16Max 200;}
        case 
CSW_M249: {Amount 4Max 200;}
        case 
CSW_M3: {Amount 8Max 64;}
        case 
CSW_M4A1: {Amount 7Max 180;}
        case 
CSW_TMP: {Amount 7Max 200;}
        case 
CSW_G3SG1: {Amount 7Max 180;}
        case 
CSW_DEAGLE: {Amount 10Max 70;}
        case 
CSW_SG552: {Amount 7Max 180;}
        case 
CSW_AK47: {Amount 7Max 180;}
        case 
CSW_P90: {Amount 4Max 200;}
        default: {
Amount 3Max 200;}
    }

    for(new 
0Amounti++) give_ammo(id0CSWIDMax)
}

// Drop primary/secondary weapons
stock drop_weapons(iddropwhat)
{
    
// Get user weapons
    
static weapons[32], numiweaponid
    num 
// reset passed weapons count (bugfix)
    
get_user_weapons(idweaponsnum)
    
    
// Loop through them and drop primaries or secondaries
    
for (0numi++)
    {
        
// Prevent re-indexing the array
        
weaponid weapons[i]
        
        if ((
dropwhat == && ((1<<weaponid) & PRIMARY_WEAPONS_BIT_SUM)) || (dropwhat == && ((1<<weaponid) & SECONDARY_WEAPONS_BIT_SUM)))
        {
            
// Get weapon entity
            
static wname[32]; get_weaponname(weaponidwnamecharsmax(wname))
            
engclient_cmd(id"drop"wname)
        }
    }
}

public 
give_ammo(idsilentCSWIDMax)
{
    static 
AmountName[32]
        
    switch(
CSWID)
    {
        case 
CSW_P228: {Amount 13formatex(Namesizeof(Name), "357sig");}
        case 
CSW_SCOUT: {Amount 30formatex(Namesizeof(Name), "762nato");}
        case 
CSW_XM1014: {Amount 8formatex(Namesizeof(Name), "buckshot");}
        case 
CSW_MAC10: {Amount 12formatex(Namesizeof(Name), "45acp");}
        case 
CSW_AUG: {Amount 30formatex(Namesizeof(Name), "556nato");}
        case 
CSW_ELITE: {Amount 30formatex(Namesizeof(Name), "9mm");}
        case 
CSW_FIVESEVEN: {Amount 50formatex(Namesizeof(Name), "57mm");}
        case 
CSW_UMP45: {Amount 12formatex(Namesizeof(Name), "45acp");}
        case 
CSW_SG550: {Amount 30formatex(Namesizeof(Name), "556nato");}
        case 
CSW_GALIL: {Amount 30formatex(Namesizeof(Name), "556nato");}
        case 
CSW_FAMAS: {Amount 30formatex(Namesizeof(Name), "556nato");}
        case 
CSW_USP: {Amount 12formatex(Namesizeof(Name), "45acp");}
        case 
CSW_GLOCK18: {Amount 30formatex(Namesizeof(Name), "9mm");}
        case 
CSW_AWP: {Amount 10formatex(Namesizeof(Name), "338magnum");}
        case 
CSW_MP5NAVY: {Amount 30formatex(Namesizeof(Name), "9mm");}
        case 
CSW_M249: {Amount 30formatex(Namesizeof(Name), "556natobox");}
        case 
CSW_M3: {Amount 8formatex(Namesizeof(Name), "buckshot");}
        case 
CSW_M4A1: {Amount 30formatex(Namesizeof(Name), "556nato");}
        case 
CSW_TMP: {Amount 30formatex(Namesizeof(Name), "9mm");}
        case 
CSW_G3SG1: {Amount 30formatex(Namesizeof(Name), "762nato");}
        case 
CSW_DEAGLE: {Amount 7formatex(Namesizeof(Name), "50ae");}
        case 
CSW_SG552: {Amount 30formatex(Namesizeof(Name), "556nato");}
        case 
CSW_AK47: {Amount 30formatex(Namesizeof(Name), "762nato");}
        case 
CSW_P90: {Amount 50formatex(Namesizeof(Name), "57mm");}
    }
    
    if(!
silentemit_sound(idCHAN_ITEM"items/9mmclip1.wav"VOL_NORMATTN_NORM0PITCH_NORM)
    
ExecuteHamB(Ham_GiveAmmoidAmountNameMax)
}

stock get_item_name(item_id)
{
    static 
item_name[64]
    
ArrayGetString(WeaponNameitem_iditem_namecharsmax(item_name))
    
    return 
item_name;
}

stock get_first_weapon(type)
{
    for(new 
0g_WeaponCounti++)
    {
        if(
ArrayGetCell(WeaponTypei) == type)
        return 
i;
    }
    return 
PLUGIN_HANDLED;    
}

stock get_randomweap(type)
{
    new 
stop

    
while(!stop)
    {
        new 
rand random_num(0g_WeaponCount-1)
        new 
weaptype ArrayGetCell(WeaponTyperand)
        
        if(
weaptype == type)
        {
            return 
rand;
            
stop true
        
}
    }
    return 
PLUGIN_HANDLED

->
PHP Code:
stock get_randomweap(type)
{
    new 
stop

    
while(!stop)
    {
        new 
rand random_num(0g_WeaponCount-1)
        new 
weaptype ArrayGetCell(WeaponTyperand)
        
        if(
weaptype == type)
        {
            return 
rand;
            
stop true
        
}
    }
    return 
PLUGIN_HANDLED

This was my final try, i didn't know what to do... i assume it's not from here but from the one below
PHP Code:
public ReciveWeapons(id)
{
    if(
is_user_bot(id))
    {
        
g_PriSelected[id] = get_randomweap(WEAPON_PRIMARY)
        
g_SecSelected[id] = get_randomweap(WEAPON_SECONDARY)
        
g_MeleeSelected[id] = get_randomweap(WEAPON_MELEE)
    }

    
drop_weapons(id1)
    
drop_weapons(id2)
    
ExecuteForward(g_Forward[FWD_WEAPON_BOUGHT], g_fwResultidg_PriSelected[id])
    
ExecuteForward(g_Forward[FWD_WEAPON_BOUGHT], g_fwResultidg_SecSelected[id])
    
ExecuteForward(g_Forward[FWD_WEAPON_BOUGHT], g_fwResultidg_MeleeSelected[id])
    
Give_FuckingAmmo(idArrayGetCell(WeaponBasedOng_PriSelected[id]))
    
Give_FuckingAmmo(idArrayGetCell(WeaponBasedOng_SecSelected[id]))
    
UnSet_BitVar(g_CanGetWeaponsid)


Last edited by AnimalMonster; 12-18-2020 at 06:06.
AnimalMonster is offline
AnimalMonster
Senior Member
Join Date: May 2020
Old 12-25-2020 , 17:53   Re: Random Weapon
Reply With Quote #4

Bump, does anyone want to help?
AnimalMonster is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 22:10.


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