AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Solved Weapon Register Array Problem (https://forums.alliedmods.net/showthread.php?t=329216)

AnimalMonster 12-13-2020 08:21

Weapon Register Array Problem
 
PHP Code:

#include <amxmodx>
#include <amxmisc>
#include <fakemeta>
#include <cstrike>
#include <zombie_theheroex>

#define PLUGIN "Weapon Addon"
#define VERSION "1.0"
#define AUTHOR "DeclineD"

new Forwards[2], g_iRet
new Array:WPN_Name, Array:WPN_Type, Array:WPN_BasedOn, Array:WPN_Cost
new g_Selected[3], g_weapons
new g_UnlockedWeapon[33][99]

public 
plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
Forwards[0] = CreateMultiForward("zbheroex_weapon_bought"ET_IGNOREFP_CELLFP_CELL)
    
Forwards[1] = CreateMultiForward("zbheroex_weapon_remove"ET_IGNOREFP_CELLFP_CELL)
    
    
WPN_Name ArrayCreate(641)
    
WPN_Type ArrayCreate(11)
    
WPN_BasedOn ArrayCreate(11)
    
WPN_Cost ArrayCreate(11)
}

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

public 
client_putinserver(id)
{
    for(new 
0g_weaponsi++)
    {
        if(
ArrayGetCell(WPN_Typei) == WEAPON_PRIMARY)
        
g_Selected[0] = i
        
break;
    }
    
    for(new 
0g_weaponsi++)
    {
        if(
ArrayGetCell(WPN_Typei) == WEAPON_SECONDARY)
        
g_Selected[1] = i
        
break;
    }
    
    for(new 
0g_weaponsi++)
    {
        if(
ArrayGetCell(WPN_Typei) == WEAPON_MELEE)
        
g_Selected[2] = i
        
break;
    }
}

public 
native_register(Weapon_Name[], TypeBasedOnCost)
{
    
param_convert(1)
    
    
ArrayPushString(WPN_NameWeapon_Name)
    
ArrayPushCell(WPN_TypeType)
    
ArrayPushCell(WPN_BasedOnBasedOn)
    
ArrayPushCell(WPN_CostCost)
    
    
g_weapons++
    
    return 
g_weapons-1
}

public 
zbheroex_user_spawned(idZombie)
{
    if(
Zombie) return;
    if(!
is_user_connected(id)) return;

    
ExecuteForward(Forwards[1], g_iRetidg_Selected[0])
    
ExecuteForward(Forwards[1], g_iRetidg_Selected[1])
    
ExecuteForward(Forwards[1], g_iRetidg_Selected[2])
    
    
Open_WeaponMenu(id)
}

public 
Open_WeaponMenu(id)
{
    new 
MenuWeapons menu_create("Select Your Weapon""WeaponHandeler")
    
    new 
szBuffer[100], PrimName[64], SecoName[64], MeleeName[64]
    
    
ArrayGetString(WPN_Nameg_Selected[0], PrimNamecharsmax(PrimName))
    
    
formatex(szBuffercharsmax(szBuffer), "Primary Weapons [ %s ]"PrimName)
    
menu_additem(MenuWeaponsszBuffer)
    
    
ArrayGetString(WPN_Nameg_Selected[1], SecoNamecharsmax(SecoName))

    
formatex(szBuffercharsmax(szBuffer), "Secondary Weapons [ %s ]"SecoName)
    
menu_additem(MenuWeaponsszBuffer)
    
    
ArrayGetString(WPN_Nameg_Selected[2], MeleeNamecharsmax(MeleeName))

    
formatex(szBuffercharsmax(szBuffer), "Melee Weapons [ %s ]"MeleeName)
    
menu_additem(MenuWeaponsszBuffer)
    
formatex(szBuffercharsmax(szBuffer), "Recive Weapons")
    
menu_additem(MenuWeaponsszBuffer)
    
    
menu_display(idMenuWeapons)
}

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

public 
Show_WeaponMenu(idType)
{
    new 
szBuffer2[100], szBuffer3[100], szWeapons[64], Weapon[6]

    if(
Type == WEAPON_PRIMARYformatex(szBuffer2charsmax(szBuffer2), "Select Primary Weapon")
    else if(
Type == WEAPON_SECONDARYformatex(szBuffer2charsmax(szBuffer2), "Select Secondary Weapon")
    else if(
Type == WEAPON_MELEEformatex(szBuffer2charsmax(szBuffer2), "Select Melee Weapon")
    
    new 
MenuID menu_create(szBuffer2"WeaponSelected")
    
    for(new 
0g_weaponsi++)
    {
        
ArrayGetString(WPN_NameiszWeaponscharsmax(szWeapons))
        
        if(
ArrayGetCell(WPN_Typei) == Type || is_user_connected(id))
        {
            if(
g_UnlockedWeapon[id][i] == || ArrayGetCell(WPN_Costi) <= 0)
            {
                
formatex(szBuffer3charsmax(szBuffer3), "\y%s"szWeapons)
            }
            else if(
cs_get_user_money(id) >= ArrayGetCell(WPN_Costi))
            {
                
formatex(szBuffer3charsmax(szBuffer3), "%s \y-> \w%i"szWeaponsArrayGetCell(WPN_Costi))
            }
            else 
formatex(szBuffer3charsmax(szBuffer3), "%s \r-> \w%i"szWeapons)
            
            
format(Weaponcharsmax(Weapon), "%i"i)
            
            
menu_additem(MenuIDszBuffer3Weapon)
        }
    }
    
menu_display(idMenuID)
}

public 
WeaponSelected(idMenuIDitem)
{
    new 
_accessWeaponID[6], Name[64]
    
menu_item_getinfo(MenuIDitem_accessWeaponIDcharsmax(WeaponID), Namecharsmax(Name), _)
    
    new 
WeaponCost ArrayGetCell(WPN_Coststr_to_num(WeaponID))
    new 
WeaponType ArrayGetCell(WPN_Typestr_to_num(WeaponID))
    
    if(
g_UnlockedWeapon[id][str_to_num(WeaponID)] == || WeaponCost <= 0)
    {
        if(
WeaponType == WEAPON_PRIMARY)
        
g_Selected[0] = str_to_num(WeaponID)
        else if(
WeaponType == WEAPON_SECONDARY)
        
g_Selected[1] = str_to_num(WeaponID)
        else if(
WeaponType == WEAPON_MELEE)
        
g_Selected[2] = str_to_num(WeaponID)
        
Open_WeaponMenu(id)
    }
    else if(
cs_get_user_money(id) >= WeaponCost)
    {
        if(
WeaponType == WEAPON_PRIMARY)
        
g_Selected[0] = str_to_num(WeaponID)
        else if(
WeaponType == WEAPON_SECONDARY)
        
g_Selected[1] = str_to_num(WeaponID)
        else if(
WeaponType == WEAPON_MELEE)
        
g_Selected[2] = str_to_num(WeaponID)
        
        
cs_set_user_money(idcs_get_user_money(id) - WeaponCost1)
        
Open_WeaponMenu(id)
    }
    else 
Open_WeaponMenu(id)
}

public 
ReciveWeapons(id)
{
    
ExecuteForward(Forwards[0], g_iRetidg_Selected[0])
    
ExecuteForward(Forwards[0], g_iRetidg_Selected[1])
    
ExecuteForward(Forwards[0], g_iRetidg_Selected[2])


PHP Code:

public native_register(Weapon_Name[], TypeBasedOnCost)
{
    
param_convert(1)
    
    
ArrayPushString(WPN_NameWeapon_Name)
    
ArrayPushCell(WPN_TypeType)
    
ArrayPushCell(WPN_BasedOnBasedOn)
    
ArrayPushCell(WPN_CostCost)
    
    
g_weapons++
    
    return 
g_weapons-1


Run Time Error 10: Native Error (native "ArrayPushString")
Unhandled dynamic native error

PHP Code:

public Open_WeaponMenu(id)
{
    new 
MenuWeapons menu_create("Select Your Weapon""WeaponHandeler")
    
    new 
szBuffer[100], PrimName[64], SecoName[64], MeleeName[64]
    
    
ArrayGetString(WPN_Nameg_Selected[0], PrimNamecharsmax(PrimName))
    
    
formatex(szBuffercharsmax(szBuffer), "Primary Weapons [ %s ]"PrimName)
    
menu_additem(MenuWeaponsszBuffer)
    
    
ArrayGetString(WPN_Nameg_Selected[1], SecoNamecharsmax(SecoName))

    
formatex(szBuffercharsmax(szBuffer), "Secondary Weapons [ %s ]"SecoName)
    
menu_additem(MenuWeaponsszBuffer)
    
    
ArrayGetString(WPN_Nameg_Selected[2], MeleeNamecharsmax(MeleeName))

    
formatex(szBuffercharsmax(szBuffer), "Melee Weapons [ %s ]"MeleeName)
    
menu_additem(MenuWeaponsszBuffer)
    
formatex(szBuffercharsmax(szBuffer), "Recive Weapons")
    
menu_additem(MenuWeaponsszBuffer)
    
    
menu_display(idMenuWeapons)


Run TimeError 10:
native error (native "ArrayGetString")

Hey, i tried to rewrite this plugin of dias because i tried to edit something and didn't work but i met these runtime problems....
Can someone help me? Please?
Thanks in advance

fysiks 12-13-2020 17:21

Re: Weapon Register Array Problem
 
Did the original plugin work without errors? What did you change?

AnimalMonster 12-17-2020 14:36

Re: Weapon Register Array Problem
 
Quote:

Originally Posted by fysiks (Post 2728706)
Did the original plugin work without errors? What did you change?

No but i forgot to put it as Solved since i tried again to edit the original and tried to use my brain properly to make it work:)


All times are GMT -4. The time now is 14:12.

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