AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Solved weapon names (https://forums.alliedmods.net/showthread.php?t=332260)

kww 05-02-2021 11:51

weapon names
 
Hi! Is it good way to show weapon name in every 0.1 second repeating task?
I'm using @ConnorMcLeod's slightly edited by me (for my needs) "Spectator Hud Information" https://forums.alliedmods.net/showthread.php?t=157028
PHP Code:

//creating vars
new g_szCurWeapon[MAX_PLAYERS 1][32/*number of rows, length of rows*/

new const /*maybe const or not, doesnt matter i guess*/ g_weapons[33][32] = { /*number of rows, length of rows*/
    
"",                 // nothing             0
    
"P250",             // CSW_P228         1
    
"",                 //                  2
    
"Steyr Scout",         // CSW_SCOUT         3
    
"HE Grenade",         // CSW_HEGRENADE     4
    
"XM1014",             // CSW_XM1014         5
    
"C4 Explosive",     // CSW_C4             6
    
"MAC-10",             // CSW_MAC10         7
    
"AUG",                 // CSW_AUG             8
    
"Smoke Grenade",     // CSW_SMOKEGRENADE 9
    
"Dual Berettas",     // CSW_ELITE         10
    
"Five-SeveN",         // CSW_FIVESEVEN     11
    
"UMP-45",             // CSW_UMP45         12
    
"SCAR-20",             // CSW_SG550         13
    
"Galil AR",         // CSW_GALIL         14
    
"FAMAS",             // CSW_FAMAS         15
    
"USP-S",             // CSW_USP             16
    
"Glock-18",         // CSW_GLOCK18         17
    
"AWP",                 // CSW_AWP             18
    
"MP5",                 // CSW_MP5NAVY         19
    
"M249",             // CSW_M249         20
    
"M3",                 // CSW_M3             21
    
"M4A1-S",             // CSW_M4A1         22
    
"Steyr TMP",         // CSW_TMP             23
    
"G3SG1",             // CSW_G3SG1         24
    
"Flashbang",         // CSW_FLASHBANG     25
    
"Desert Eagle",     // CSW_DEAGLE         26
    
"SG 552",             // CSW_SG552         27
    
"AK47",             // CSW_AK47         28
    
"Classic Knife",     // CSW_KNIFE         29
    
"P90",                 // CSW_P90             30
    // can't be obtained
    
"vest",             // CSW_VEST         31
    
"vest + helmet"     // CSW_VESTHELM     32
}

//get weapon name to show it in hud_showmessage()
public Event_CurWeapon(id)
{
    
g_szCurWeapon[id] = g_weapons[read_data(2)]



LondoN 05-03-2021 17:33

Re: weapon names
 
Code:

stock weapon_name( id )
{
        new szWpName[ 40 ];
        get_weaponname( get_user_weapon( id ) , szWpName, charsmax( szWpName ) );

        replace( szWpName, charsmax( szWpName ), "weapon_", "" );
        ucfirst( szWpName );

        return szWpName;
}

This is not my code, i recommend re-write to pass by reference.

This is how it looks
https://hermes.extreamcs.com/camo/ap...5861772e706e67

kww 05-03-2021 19:41

Re: weapon names
 
Quote:

Originally Posted by LondoN (Post 2745825)
Code:

stock weapon_name( id )
{
        new szWpName[ 40 ];
        get_weaponname( get_user_weapon( id ) , szWpName, charsmax( szWpName ) );

        replace( szWpName, charsmax( szWpName ), "weapon_", "" );
        ucfirst( szWpName );

        return szWpName;
}

]

But if i want custom (predefined or even changed on the fly by cvars or commands) names for weapons? Thanks for the snippet tho. It may be useful

iceeedr 05-03-2021 21:14

Re: weapon names
 
Very poorly written, for reference only

PHP Code:

#include <amxmodx>
#include <amxmisc>
#include <cstrike>
// #include <engine>
#include <fakemeta>
#include <hamsandwich>
// #include <fun>
// #include <xs>
// #include <sqlx>

#define PLUGIN  "New Plug-In"
#define VERSION "1.0"
#define AUTHOR  "Author"

#define IsPlayer(%0)    ( 1 <= (%0) <= MaxClients)

new Trie:TrieGuns

public plugin_init()
{
        
register_plugin(PLUGINVERSIONAUTHOR)

        
register_event("CurWeapon""CurWeapon""be""1=1")

        
TrieGuns TrieCreate()
        
TrieSetCell(TrieGuns"weapon_p228"register_cvar("weapon_p228""P250"))
        
TrieSetCell(TrieGuns"weapon_scout"            register_cvar("weapon_scout""Steyr Scout"))
        
TrieSetCell(TrieGuns"weapon_hegrenade"   register_cvar("weapon_hegrenade""HE Grenade"))
        
TrieSetCell(TrieGuns"weapon_xm1014"      register_cvar("weapon_xm1014" "XM1014"))
        
TrieSetCell(TrieGuns"weapon_c4"      register_cvar("weapon_c4"        "C4 Explosive"))
        
TrieSetCell(TrieGuns"weapon_mac10"   register_cvar("weapon_mac10"        "MAC-10"))
        
TrieSetCell(TrieGuns"weapon_aug"      register_cvar("weapon_aug"   "AUG"))
        
TrieSetCell(TrieGuns"weapon_smokegrenade"    register_cvar("weapon_smokegrenade"  "Smoke Grenade"))
        
TrieSetCell(TrieGuns"weapon_elite" register_cvar("weapon_elite"   "Dual Berettas"))
        
TrieSetCell(TrieGuns"weapon_fiveseven"    register_cvar("weapon_fiveseven"   "Five-SeveN"))
        
TrieSetCell(TrieGuns"weapon_ump45"      register_cvar("weapon_ump45" "UMP-45"))
        
TrieSetCell(TrieGuns"weapon_sg550"   register_cvar("weapon_sg550"  "SCAR-20"))
        
TrieSetCell(TrieGuns"weapon_galil"         register_cvar("weapon_galil"   "Galil AR"))
        
TrieSetCell(TrieGuns"weapon_famas"   register_cvar("weapon_famas"      "FAMAS"))
        
TrieSetCell(TrieGuns"weapon_usp"  register_cvar("weapon_usp"    "USP-S"))
        
TrieSetCell(TrieGuns"weapon_glock18"   register_cvar("weapon_glock18"    "Glock-18"))
        
TrieSetCell(TrieGuns"weapon_awp"      register_cvar("weapon_awp"  "AWP"))
        
TrieSetCell(TrieGuns"weapon_mp5navy"   register_cvar("weapon_mp5navy"    "MP5"))
        
TrieSetCell(TrieGuns"weapon_m249"      register_cvar("weapon_m249"  "M249"))
        
TrieSetCell(TrieGuns"weapon_m3"        register_cvar("weapon_m3" "M3"))
        
TrieSetCell(TrieGuns"weapon_m4a1"         register_cvar("weapon_m4a1"        "M4A1-S"))
        
TrieSetCell(TrieGuns"weapon_tmp"      register_cvar("weapon_tmp" "Steyr TMP"))
        
TrieSetCell(TrieGuns"weapon_g3sg1"      register_cvar("weapon_g3sg1" "G3SG1"))
        
TrieSetCell(TrieGuns"weapon_flashbang"      register_cvar("weapon_flashbang" "Flashbang"))
        
TrieSetCell(TrieGuns"weapon_deagle"      register_cvar("weapon_deagle" "Desert Eagle"))
        
TrieSetCell(TrieGuns"weapon_sg552"      register_cvar("weapon_sg552" "SG 552"))
        
TrieSetCell(TrieGuns"weapon_ak47"      register_cvar("weapon_ak47" "AK47"))
        
TrieSetCell(TrieGuns"weapon_knife"      register_cvar("weapon_knife" "Classic Knife"))
        
TrieSetCell(TrieGuns"weapon_p90"      register_cvar("weapon_p90" "P90"))

        
RegisterHam(Ham_Spawn"player""OnPlayerSpawn"1)
}

new 
g_szCurWeapon[MAX_PLAYERS 1][32/*number of rows, length of rows*/

public OnPlayerSpawn(id)
{
        if(
is_user_alive(id))
        {
                
set_task(1.0"test"id, .flags "b")
        }
}

public 
test(id)
{
        
server_print("%s weapon name"g_szCurWeapon[id])
}

public 
CurWeapon(id)
{
        if(!
is_user_alive(id) || !IsPlayer(id))
        {
                return 
PLUGIN_HANDLED
        
}

        new 
szWpName40 ]
        static 
handleCvar
        get_weaponname
get_user_weaponid ) , szWpNamecharsmaxszWpName ) )

        if(
TrieGetCell(TrieGunsszWpNamehandleCvar) && get_pcvar_string(handleCvarszWpNamecharsmax(szWpName)))
        {
                
copy(g_szCurWeapon[id], charsmax(g_szCurWeapon[]), szWpName)
        }
        return 
PLUGIN_HANDLED



kww 05-04-2021 10:20

Re: weapon names
 
Quote:

Originally Posted by iceeedr (Post 2745841)
Very poorly written, for reference only

code

ooh.... it's very complex :\

iceeedr 05-08-2021 10:03

Re: weapon names
 
Quote:

Originally Posted by kww (Post 2745893)
ooh.... it's very complex :\

What exactly do you need?

Bugsy 05-08-2021 11:21

Re: weapon names
 
This will allow you to have a standard and custom weapon name.

GetWeaponName() allows you to retrieve either the standard or custom name. If you ask for the custom name and the custom name is not defined, it will return the standard name instead.

You can build a function to populate this array with a weapon name as needed:
PHP Code:

copyg_weaponsCSW_M4A1 ][ CustomName ] , charsmaxg_weapons[][] ) , "M4A-One" ); 

PHP Code:


#include <amxmodx>

enum WeaponNameTypes
{
    
StandardName,
    
CustomName
}

new 
g_weapons[33][ WeaponNameTypes ][32] = 

    { 
"""" },
    { 
"P250""" }, 
    { 
"""" }, 
    { 
"Steyr Scout""" }, 
    { 
"HE Grenade""" }, 
    { 
"XM1014""" }, 
    { 
"C4 Explosive""" }, 
    { 
"MAC-10""" }, 
    { 
"AUG""" }, 
    { 
"Smoke Grenade""" }, 
    { 
"Dual Berettas""" }, 
    { 
"Five-SeveN""" }, 
    { 
"UMP-45""" }, 
    { 
"SCAR-20""" }, 
    { 
"Galil AR""" }, 
    { 
"FAMAS""" }, 
    { 
"USP-S""" }, 
    { 
"Glock-18""" }, 
    { 
"AWP""" }, 
    { 
"MP5""" }, 
    { 
"M249""" }, 
    { 
"M3""" }, 
    { 
"M4A1-S""" }, 
    { 
"Steyr TMP""" }, 
    { 
"G3SG1""" }, 
    { 
"Flashbang""" }, 
    { 
"Desert Eagle""" }, 
    { 
"SG 552""" }, 
    { 
"AK47""" }, 
    { 
"Classic Knife""" }, 
    { 
"P90""" }, 
    { 
"vest""" }, 
    { 
"vest + helmet" "" }
}


public 
plugin_init() 
{
    new 
szTemp32 ];
    
    
GetWeaponNameCSW_M4A1 CustomName szTemp charsmaxszTemp ) );
    
    
server_printszTemp );
}

GetWeaponNameWeaponID WeaponNameTypes:wnType szBuffer32 ] , maxchars )
{
    new 
WeaponNameTypes:wnWeaponNameType = ( ( wnType == CustomName ) && ( g_weaponsWeaponID ][ wnType ][ ] != EOS ) ) ? CustomName StandardName;
    
    return 
copyszBuffer maxchars g_weaponsWeaponID ][ wnWeaponNameType ] );



kww 05-08-2021 12:39

Re: weapon names
 
woo thanks


All times are GMT -4. The time now is 02:30.

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