AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   2 little problems (https://forums.alliedmods.net/showthread.php?t=153437)

georgik57 03-23-2011 13:09

2 little problems
 
please help me fix these codes
problem 1:
the stock is supposed to give grenades to a player
the problem is that(i think) it can't set the ammo above the cs limit(1 for HE, 2 for FB, 1 for SG) since only the Arctic class receives one extra grenade, already having 1.
PHP Code:

/*================================================================================
    
    -----------------------------------
    -*- [ZPNM] Default Human Classes -*-
    -----------------------------------
    
    ~~~~~~~~~~~~~~~
    - Description -
    ~~~~~~~~~~~~~~~
    
    This plugin adds the default human classes to Zombie Plague.
    Feel free to modify their attributes to your liking.
    
    Note: If human classes are disabled, the first registered class
    will be used for all players (by default, Normal Human).
    
================================================================================*/

#include <amxmodx>
#include <zombieplaguenm>

// Natives from cstrike.inc
native cs_get_user_bpammo(indexweapon);
native cs_set_user_bpammo(indexweaponamount);

// Native from fun.inc
native give_item(index, const item[]);

/*================================================================================
 [Plugin Customization]
=================================================================================*/

// Normal Human Attributes
new const hclass1_name[] = "Normal Human"
new const hclass1_info[] = "Average"
new const hclass1_model[] = "gsg9"
new const hclass1_handmodel[] = "v_knife.mdl"
const hclass1_health 100
const hclass1_speed 240
const Float:hclass1_gravity 1.0

// Speed Human Attributes
new const hclass2_name[] = "Speed Human"
new const hclass2_info[] = "Runs faster"
new const hclass2_model[] = "guerilla"
new const hclass2_handmodel[] = "v_knife.mdl"
const hclass2_health 100
const hclass2_speed 249
const Float:hclass2_gravity 1.0

// Gravity Human Attributes
new const hclass3_name[] = "Gravity Human"
new const hclass3_info[] = "Jumps Higher"
new const hclass3_model[] = "terror"
new const hclass3_handmodel[] = "v_knife.mdl"
const hclass3_health 100
const hclass3_speed 240
const Float:hclass3_gravity 0.75

// Slow Human Attributes
new const hclass4_name[] = "Slow Human"
new const hclass4_info[] = "Higher HP"
new const hclass4_model[] = "gign"
new const hclass4_handmodel[] = "v_knife.mdl"
const hclass4_health 150
const hclass4_speed 231
const Float:hclass4_gravity 1.0

// Desert Human Attributes
new const hclass5_name[] = "Desert Human"
new const hclass5_info[] = "Has more fire nades"
new const hclass5_model[] = "leet"
new const hclass5_handmodel[] = "v_knife.mdl"
const hclass5_health 100
const hclass5_speed 240
const Float:hclass5_gravity 1.0

// Arctic Human Attributes
new const hclass6_name[] = "Arctic Human"
new const hclass6_info[] = "Has more frost nades"
new const hclass6_model[] = "arctic"
new const hclass6_handmodel[] = "v_knife.mdl"
const hclass6_health 100
const hclass6_speed 240
const Float:hclass6_gravity 1.0

// Urban Human Attributes
new const hclass7_name[] = "Urban Human"
new const hclass7_info[] = "Has more light nades"
new const hclass7_model[] = "urban"
new const hclass7_handmodel[] = "v_knife.mdl"
const hclass7_health 100
const hclass7_speed 240
const Float:hclass7_gravity 1.0

/*============================================================================*/

// Class IDs
new g_hclass_desertg_hclass_arcticg_hclass_urban,
cvar_desert_nadescvar_arctic_nadescvar_urban_nades,
FireNades[33], FrostNades[33], LightNades[33]

// CS sounds
new const g_szAmmoPickupSound[] = "items/9mmclip1.wav"

public plugin_init()
{
    
register_plugin("[ZPNM] Default Human Classes""1.0""MeRcyLeZZ, 93()|29!/<, Exolent")
    
    
cvar_desert_nades register_cvar("zpnm_desert_nades""1")
    
cvar_arctic_nades register_cvar("zpnm_arctic_nades""1")
    
cvar_urban_nades register_cvar("zpnm_urban_nades""1")
}

// Human Classes MUST be registered on plugin_precache
public plugin_precache()
{
    
// Register all classes
    
zpnm_register_human_class(hclass1_namehclass1_infohclass1_modelhclass1_handmodelhclass1_healthhclass1_speedhclass1_gravity)
    
zpnm_register_human_class(hclass2_namehclass2_infohclass2_modelhclass2_handmodelhclass2_healthhclass2_speedhclass2_gravity)
    
zpnm_register_human_class(hclass3_namehclass3_infohclass3_modelhclass3_handmodelhclass3_healthhclass3_speedhclass3_gravity)
    
zpnm_register_human_class(hclass4_namehclass4_infohclass4_modelhclass4_handmodelhclass4_healthhclass4_speedhclass4_gravity)
    
g_hclass_desert zpnm_register_human_class(hclass5_namehclass5_infohclass5_modelhclass5_handmodelhclass5_healthhclass5_speedhclass5_gravity)
    
g_hclass_arctic zpnm_register_human_class(hclass6_namehclass6_infohclass6_modelhclass6_handmodelhclass6_healthhclass6_speedhclass6_gravity)
    
g_hclass_urban zpnm_register_human_class(hclass7_namehclass7_infohclass7_modelhclass7_handmodelhclass7_healthhclass7_speedhclass7_gravity)
    
    
precache_sound(g_szAmmoPickupSound)
}

// User got primary weapons forward
public zpnm_user_got_weapons1_post(id)
{
    
// Find out what human class our player is using
    
new hclass zpnm_get_user_human_class(id)
    
    
// Desert Human gets more fire grenades
    
if (hclass == g_hclass_desert)
    {
        if (
get_pcvar_num(cvar_desert_nades) < 1)
            
FireNades[id] = 1
        
else
            
FireNades[id] = get_pcvar_num(cvar_desert_nades)
        
        
give_grenades(idCSW_HEGRENADEFireNades[id])
    }
    
// Arctic Human gets more frost grenades
    
else if (hclass == g_hclass_arctic)
    {
        if (
get_pcvar_num(cvar_arctic_nades) < 1)
            
FrostNades[id] = 1
        
else
            
FrostNades[id] = get_pcvar_num(cvar_arctic_nades)
        
        
give_grenades(idCSW_FLASHBANGFrostNades[id])
    }
    
// Urban Human gets more light grenades
    
else if (hclass == g_hclass_urban)
    {
        if (
get_pcvar_num(cvar_urban_nades) < 1)
            
LightNades[id] = 1
        
else
            
LightNades[id] = get_pcvar_num(cvar_urban_nades)
        
        
give_grenades(idCSW_SMOKEGRENADELightNades[id])
    }
    
// If the player isn't using any of our classes then exit the function
    
else
        return;
}

stock give_grenades(idweaponidcount)
{
    static const 
iAmmoIDs[] = { 121113 }
    static const 
szNames[][] = { "weapon_hegrenade""weapon_flashbang""weapon_smokegrenade" }
    
    new 
iNadeType;
    switch (
weaponid)
    {
        case 
CSW_HEGRENADE:    iNadeType 0;
        case 
CSW_FLASHBANG:    iNadeType 1;
        case 
CSW_SMOKEGRENADEiNadeType 2;
        default: return 
0;
    }
    
    if (
count 1)
        return 
0;
    
    new 
iFirstCount cs_get_user_bpammo(idweaponid)
    
    if (!
iFirstCount)
        
give_item(idszNames[iNadeType])
    
    if (
iFirstCount)
    {
        
cs_set_user_bpammo(idweaponidiFirstCount count)
        
        static 
AmmoPickup
        
if (AmmoPickup || (AmmoPickup get_user_msgid("AmmoPickup")))
        {
            
message_begin(MSG_ONE_UNRELIABLEAmmoPickup_id)
            
write_byte(iAmmoIDs[iNadeType])
            
write_byte(count)
            
message_end()
        }
        
        
emit_sound(idCHAN_ITEMg_szAmmoPickupSound1.0ATTN_NORM0PITCH_NORM)
    }
    
    return 
1;


problem 2:
i'm trying to make a native in zp that will give/take away unlimited ammo to/from a player. the problem is that it affects the default values of the function
i will show you all the code i've added.
PHP Code:

new g_infammo[33// has unlimited ammo/clip 

the idea is g_infammo[id] = 1 means player has unlimited reloads and 2 means unlimited clip. so i did the following:
PHP Code:

public plugin_natives()
{
    
register_native("zpnm_get_user_unlimited_ammo""native_get_user_infammo"1)
    
register_native("zpnm_set_user_unlimited_ammo""native_set_user_infammo"1)


PHP Code:

// BP Ammo update
public event_ammo_x(id)
{
    
// Unlimited BP Ammo?
    
if (g_survivor[id] ? get_pcvar_num(cvar_survinfammo) : get_pcvar_num(cvar_infammo)
    || 
g_sniper[id] ? get_pcvar_num(cvar_sniperinfammo) : get_pcvar_num(cvar_infammo)
    || 
g_infammo[id] = 1)
    {
        if (
amount MAXBPAMMO[weapon])
        {
            
// The BP Ammo refill code causes the engine to send a message, but we
            // can't have that in this forward or we risk getting some recursion bugs.
            // For more info see: https://bugs.alliedmods.net/show_bug.cgi?id=3664
            
static args[1]
            
args[0] = weapon
            set_task
(0.1"refill_bpammo"idargssizeof args)
        }
    }


but if i do this i get a tag mismatch error on compilation. how to make it work?
also...
PHP Code:

// Current Weapon info
public message_cur_weapon(msg_idmsg_destmsg_entity)
{
    
// Not alive or zombie
    
if (!g_isalive[msg_entity] || g_zombie[msg_entity])
        return;
    
    
// Not an active weapon
    
if (get_msg_arg_int(1) != 1)
        return;
    
    
// Unlimited clip disabled for class
    
if (g_survivor[msg_entity] ? get_pcvar_num(cvar_survinfammo) <= get_pcvar_num(cvar_infammo) <= 1
    
|| g_sniper[msg_entity] ? get_pcvar_num(cvar_sniperinfammo) <= get_pcvar_num(cvar_infammo) <= 1
    
|| g_infammo[msg_entity] != 2)
        return;
    
    
// Get weapon's id
    
static weapon
    weapon 
get_msg_arg_int(2)
    
    
// Unlimited Clip Ammo for this weapon?
    
if (MAXBPAMMO[weapon] > 2)
    {
        
// Max out clip ammo
        
cs_set_weapon_ammo(fm_cs_get_current_weapon_ent(msg_entity), MAXCLIP[weapon])
        
        
// HUD should show full clip all the time
        
set_msg_arg_int(3get_msg_argtype(3), MAXCLIP[weapon])
    }


also is the way i'm checking for it correct?
PHP Code:

// Native: zpnm_get_user_unlimited_ammo
public native_get_user_infammo(id)
{
    
// ZP disabled
    
if (!g_pluginenabled)
        return -
1;
    
    if (
g_survivor[id])
    {
        switch (
get_pcvar_num(cvar_survinfammo))
        {
            case 
0: return g_infammo[id] = 0
            
case 1: return g_infammo[id] = 1
            
case 2: return g_infammo[id] = 2
        
}
    }
    else if (
g_sniper[id])
    {
        switch (
get_pcvar_num(cvar_sniperinfammo))
        {
            case 
0: return g_infammo[id] = 0
            
case 1: return g_infammo[id] = 1
            
case 2: return g_infammo[id] = 2
        
}
    }
    else
    {
        switch (
get_pcvar_num(cvar_infammo))
        {
            case 
0: return g_infammo[id] = 0
            
case 1: return g_infammo[id] = 1
            
case 2: return g_infammo[id] = 2
        
}
    }
    
    return 
1;
}

// Native: zpnm_set_user_unlimited_ammo
public native_set_user_infammo(idset)
{
    
// ZP disabled
    
if (!g_pluginenabled)
        return -
1;
    
    if (!
set)
        
g_infammo[id] = 0
    
else
        switch (
set)
        {
            case 
1g_infammo[id] = 1
            
case 2g_infammo[id] = 2
            
default: g_infammo[id] = 1
        
}
    
    return 
1;



schmurgel1983 03-23-2011 14:01

Re: 2 little problems
 
Quote:

Originally Posted by georgik57 (Post 1438174)
please help me fix these codes

problem 1:
add #include <cstrike>
add #include <fun>
delete native from file, fun dosen't autoload from zp so u must use include
code looks fine

problem 2:
PHP Code:

// BP Ammo update
g_infammo[id] == 

PHP Code:

// Current Weapon info
g_infammo[msg_entity] <= 

PHP Code:

// Native: zpnm_get_user_unlimited_ammo
public native_get_user_infammo(id)
{
    
// ZP disabled
    
if (!g_pluginenabled)
        return -
1;
    
    return 
g_infammo[id];


PHP Code:

// Native: zpnm_set_user_unlimited_ammo
public native_set_user_infammo(idset)
{
    
// ZP disabled
    
if (!g_pluginenabled)
        return -
1;
    
    switch (
set)
    {
        case 
1g_infammo[id] = 1;
        case 
2g_infammo[id] = 2;
        default: 
g_infammo[id] = 0;
    }
    
    return 
1;



georgik57 03-23-2011 14:10

Re: 2 little problems
 
problem 1: still not working
problem 2: still getting a tag mismatch error. i think it has to be in the format of the other 2 conditions

schmurgel1983 03-23-2011 18:02

Re: 2 little problems
 
Quote:

Originally Posted by georgik57 (Post 1438196)
problem 2: still getting a tag mismatch error. i think it has to be in the format of the other 2 conditions

post me the line

problem 1:
PHP Code:

// User got primary weapons forward
public zpnm_user_got_weapons1_post(id)
{
    
// Find out what human class our player is using
    
switch (zpnm_get_user_human_class(id))
    {
        case 
g_hclass_desert// Desert Human gets more fire grenades
        
{
            
FireNades[id] = get_pcvar_num(cvar_desert_nades)
            
give_grenades(id0FireNades[id])
        }
        case 
g_hclass_arctic// Arctic Human gets more frost grenades
        
{
            
FrostNades[id] = get_pcvar_num(cvar_arctic_nades)
            
give_grenades(id1FrostNades[id])
        }
        case 
g_hclass_urban// Urban Human gets more light grenades
        
{
            
LightNades[id] = get_pcvar_num(cvar_urban_nades)
            
give_grenades(id2LightNades[id])
        }
    }
}

give_grenades(idiNadeTypeiCount)
{
    if (!
iCount) return;
    
    static const 
iAmmoIDs[] = { 121113 }
    static const 
iWeaponIDs[] = { CSW_HEGRENADECSW_FLASHBANGCSW_SMOKEGRENADE }
    static const 
szNames[][] = { "weapon_hegrenade""weapon_flashbang""weapon_smokegrenade" }
    
    if (
iCount >= 2)
    {
        if (!
user_has_weapon(idiWeaponIDs[iNadeType]))
        {
            
give_item(idszNames[iNadeType])
            
iCount -= 1
        
}
        
        
cs_set_user_bpammo(idiWeaponIDs[iNadeType], cs_get_user_bpammo(idiWeaponIDs[iNadeType]) + iCount)
        
        static 
msgAmmoPickup
        
if (msgAmmoPickup || (msgAmmoPickup get_user_msgid("AmmoPickup")))
        {
            
message_begin(MSG_ONE_UNRELIABLEmsgAmmoPickup_id)
            
write_byte(iAmmoIDs[iNadeType])
            
write_byte(iCount)
            
message_end()
        }
        
        
emit_sound(idCHAN_ITEMg_szAmmoPickupSound1.0ATTN_NORM0PITCH_NORM)
    }
    else
    {
        
give_item(idszNames[iNadeType])
    }



georgik57 03-24-2011 14:13

Re: 2 little problems
 
problem 1: switch doesn't work with hclass id variables. will try your stock.
problem 2: lines 2445, 2446, 2447
EDIT: problem 1 not solved.
here's the script with your stock:
PHP Code:

/*================================================================================
    
    -----------------------------------
    -*- [ZPNM] Default Human Classes -*-
    -----------------------------------
    
    ~~~~~~~~~~~~~~~
    - Description -
    ~~~~~~~~~~~~~~~
    
    This plugin adds the default human classes to Zombie Plague.
    Feel free to modify their attributes to your liking.
    
    Note: If human classes are disabled, the first registered class
    will be used for all players (by default, Normal Human).
    
================================================================================*/

#include <amxmodx>
#include <fun>
#include <cstrike>
#include <zombieplaguenm>

// Natives from cstrike.inc
//native cs_get_user_bpammo(index, weapon);
//native cs_set_user_bpammo(index, weapon, amount);

// Native from fun.inc
//native give_item(index, const item[]);

/*================================================================================
 [Plugin Customization]
=================================================================================*/

// Normal Human Attributes
new const hclass1_name[] = "Normal Human"
new const hclass1_info[] = "Average"
new const hclass1_model[] = "gsg9"
new const hclass1_handmodel[] = "v_knife.mdl"
const hclass1_health 100
const hclass1_speed 240
const Float:hclass1_gravity 1.0

// Speed Human Attributes
new const hclass2_name[] = "Speed Human"
new const hclass2_info[] = "Runs faster"
new const hclass2_model[] = "guerilla"
new const hclass2_handmodel[] = "v_knife.mdl"
const hclass2_health 100
const hclass2_speed 249
const Float:hclass2_gravity 1.0

// Gravity Human Attributes
new const hclass3_name[] = "Gravity Human"
new const hclass3_info[] = "Jumps Higher"
new const hclass3_model[] = "terror"
new const hclass3_handmodel[] = "v_knife.mdl"
const hclass3_health 100
const hclass3_speed 240
const Float:hclass3_gravity 0.75

// Slow Human Attributes
new const hclass4_name[] = "Slow Human"
new const hclass4_info[] = "Higher HP"
new const hclass4_model[] = "gign"
new const hclass4_handmodel[] = "v_knife.mdl"
const hclass4_health 150
const hclass4_speed 231
const Float:hclass4_gravity 1.0

// Desert Human Attributes
new const hclass5_name[] = "Desert Human"
new const hclass5_info[] = "Has more fire nades"
new const hclass5_model[] = "leet"
new const hclass5_handmodel[] = "v_knife.mdl"
const hclass5_health 100
const hclass5_speed 240
const Float:hclass5_gravity 1.0

// Arctic Human Attributes
new const hclass6_name[] = "Arctic Human"
new const hclass6_info[] = "Has more frost nades"
new const hclass6_model[] = "arctic"
new const hclass6_handmodel[] = "v_knife.mdl"
const hclass6_health 100
const hclass6_speed 240
const Float:hclass6_gravity 1.0

// Urban Human Attributes
new const hclass7_name[] = "Urban Human"
new const hclass7_info[] = "Has more light nades"
new const hclass7_model[] = "urban"
new const hclass7_handmodel[] = "v_knife.mdl"
const hclass7_health 100
const hclass7_speed 240
const Float:hclass7_gravity 1.0

/*============================================================================*/

// Class IDs
new g_hclass_desertg_hclass_arcticg_hclass_urban,
cvar_desert_nadescvar_arctic_nadescvar_urban_nades,
FireNades[33], FrostNades[33], LightNades[33]

// CS sounds
new const g_szAmmoPickupSound[] = "items/9mmclip1.wav"

public plugin_init()
{
    
register_plugin("[ZPNM] Default Human Classes""1.0""MeRcyLeZZ, 93()|29!/<, Exolent")
    
    
cvar_desert_nades register_cvar("zpnm_desert_nades""1")
    
cvar_arctic_nades register_cvar("zpnm_arctic_nades""1")
    
cvar_urban_nades register_cvar("zpnm_urban_nades""1")
}

// Human Classes MUST be registered on plugin_precache
public plugin_precache()
{
    
// Register all classes
    
zpnm_register_human_class(hclass1_namehclass1_infohclass1_modelhclass1_handmodelhclass1_healthhclass1_speedhclass1_gravity)
    
zpnm_register_human_class(hclass2_namehclass2_infohclass2_modelhclass2_handmodelhclass2_healthhclass2_speedhclass2_gravity)
    
zpnm_register_human_class(hclass3_namehclass3_infohclass3_modelhclass3_handmodelhclass3_healthhclass3_speedhclass3_gravity)
    
zpnm_register_human_class(hclass4_namehclass4_infohclass4_modelhclass4_handmodelhclass4_healthhclass4_speedhclass4_gravity)
    
g_hclass_desert zpnm_register_human_class(hclass5_namehclass5_infohclass5_modelhclass5_handmodelhclass5_healthhclass5_speedhclass5_gravity)
    
g_hclass_arctic zpnm_register_human_class(hclass6_namehclass6_infohclass6_modelhclass6_handmodelhclass6_healthhclass6_speedhclass6_gravity)
    
g_hclass_urban zpnm_register_human_class(hclass7_namehclass7_infohclass7_modelhclass7_handmodelhclass7_healthhclass7_speedhclass7_gravity)
    
    
precache_sound(g_szAmmoPickupSound)
}

// User got primary weapons forward
public zpnm_user_got_weapons1_post(id)
{
    
// Find out what human class our player is using
    
new hclass zpnm_get_user_human_class(id)
    
    
// Desert Human gets more fire grenades
    
if (hclass == g_hclass_desert)
    {
        
FireNades[id] = get_pcvar_num(cvar_desert_nades)
        
        
give_grenades(id0FireNades[id])
    }
    
// Arctic Human gets more frost grenades
    
else if (hclass == g_hclass_arctic)
    {
        
FrostNades[id] = get_pcvar_num(cvar_arctic_nades)
        
        
give_grenades(id1FrostNades[id])
    }
    
// Urban Human gets more light grenades
    
else if (hclass == g_hclass_urban)
    {
        
LightNades[id] = get_pcvar_num(cvar_urban_nades)
        
        
give_grenades(id2LightNades[id])
    }
}

give_grenades(idiNadeTypeiCount)
{
    if (!
iCount) return;
    
    static const 
iAmmoIDs[] = { 121113 }
    static const 
iWeaponIDs[] = { CSW_HEGRENADECSW_FLASHBANGCSW_SMOKEGRENADE }
    static const 
szNames[][] = { "weapon_hegrenade""weapon_flashbang""weapon_smokegrenade" }
    
    if (
iCount >= 2)
    {
        if (!
user_has_weapon(idiWeaponIDs[iNadeType]))
        {
            
give_item(idszNames[iNadeType])
            
iCount -= 1
        
}
        
        
cs_set_user_bpammo(idiWeaponIDs[iNadeType], cs_get_user_bpammo(idiWeaponIDs[iNadeType]) + iCount)
        
        static 
msgAmmoPickup
        
if (msgAmmoPickup || (msgAmmoPickup get_user_msgid("AmmoPickup")))
        {
            
message_begin(MSG_ONE_UNRELIABLEmsgAmmoPickup_id)
            
write_byte(iAmmoIDs[iNadeType])
            
write_byte(iCount)
            
message_end()
        }
        
        
emit_sound(idCHAN_ITEMg_szAmmoPickupSound1.0ATTN_NORM0PITCH_NORM)
    }
    else
    {
        
give_item(idszNames[iNadeType])
    }



schmurgel1983 03-24-2011 17:24

Re: 2 little problems
 
problem 1: zpnm_register_human_class() return a value (classid) when yes u can use switch.

problem 2:
make sure
g_infammo[] do store only nums don't make a boolean on this, this get tag missmatch errors.

georgik57 03-25-2011 11:45

Re: 2 little problems
 
Quote:

Originally Posted by schmurgel1983 (Post 1438814)
problem 1: zpnm_register_human_class() return a value (classid) when yes u can use switch.


switch can be used only with constants
i tried to compile it with switch and i got that error
Quote:

Originally Posted by schmurgel1983 (Post 1438814)
problem 2:
make sure

Quote:

Originally Posted by schmurgel1983 (Post 1438814)
g_infammo[] do store only nums don't make a boolean on this, this get tag missmatch errors.

it's not a bool
and also this is hard to code
i think i will abandon it

schmurgel1983 03-25-2011 11:53

Re: 2 little problems
 
pm me the source


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

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