| 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(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_desert, g_hclass_arctic, g_hclass_urban,
cvar_desert_nades, cvar_arctic_nades, cvar_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_name, hclass1_info, hclass1_model, hclass1_handmodel, hclass1_health, hclass1_speed, hclass1_gravity)
zpnm_register_human_class(hclass2_name, hclass2_info, hclass2_model, hclass2_handmodel, hclass2_health, hclass2_speed, hclass2_gravity)
zpnm_register_human_class(hclass3_name, hclass3_info, hclass3_model, hclass3_handmodel, hclass3_health, hclass3_speed, hclass3_gravity)
zpnm_register_human_class(hclass4_name, hclass4_info, hclass4_model, hclass4_handmodel, hclass4_health, hclass4_speed, hclass4_gravity)
g_hclass_desert = zpnm_register_human_class(hclass5_name, hclass5_info, hclass5_model, hclass5_handmodel, hclass5_health, hclass5_speed, hclass5_gravity)
g_hclass_arctic = zpnm_register_human_class(hclass6_name, hclass6_info, hclass6_model, hclass6_handmodel, hclass6_health, hclass6_speed, hclass6_gravity)
g_hclass_urban = zpnm_register_human_class(hclass7_name, hclass7_info, hclass7_model, hclass7_handmodel, hclass7_health, hclass7_speed, hclass7_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(id, CSW_HEGRENADE, FireNades[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(id, CSW_FLASHBANG, FrostNades[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(id, CSW_SMOKEGRENADE, LightNades[id])
}
// If the player isn't using any of our classes then exit the function
else
return;
}
stock give_grenades(id, weaponid, count)
{
static const iAmmoIDs[] = { 12, 11, 13 }
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_SMOKEGRENADE: iNadeType = 2;
default: return 0;
}
if (count < 1)
return 0;
new iFirstCount = cs_get_user_bpammo(id, weaponid)
if (!iFirstCount)
give_item(id, szNames[iNadeType])
if (iFirstCount)
{
cs_set_user_bpammo(id, weaponid, iFirstCount + count)
static AmmoPickup
if (AmmoPickup || (AmmoPickup = get_user_msgid("AmmoPickup")))
{
message_begin(MSG_ONE_UNRELIABLE, AmmoPickup, _, id)
write_byte(iAmmoIDs[iNadeType])
write_byte(count)
message_end()
}
emit_sound(id, CHAN_ITEM, g_szAmmoPickupSound, 1.0, ATTN_NORM, 0, PITCH_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", id, args, sizeof 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_id, msg_dest, msg_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) <= 1 : get_pcvar_num(cvar_infammo) <= 1
|| g_sniper[msg_entity] ? get_pcvar_num(cvar_sniperinfammo) <= 1 : 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(3, get_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(id, set)
{
// ZP disabled
if (!g_pluginenabled)
return -1;
if (!set)
g_infammo[id] = 0
else
switch (set)
{
case 1: g_infammo[id] = 1
case 2: g_infammo[id] = 2
default: g_infammo[id] = 1
}
return 1;
}
|