Hello. Can someone tell me how to make a plugin to be disabled/unavailable during a certain game mode?
In this case, I want gifts (bonus boxes) to be available
only during normal infection round, and to never be available during armageddon mode, swarm mode, multiple infection mode, sniper mode, assassin mode, or any mode that is not normal infection mode.
I already know how to make the boxes to be not available during certain modes, like Sniper vs Assassin mode, by adding checks for classes like Sniper and Assassin, for example: "
zp_get_user_sniper(id)" - I add this check in the "return" section, meaning that if the player is a sniper, the function that allows the player to get a box, will be returned and the player won't get the box.
Let me give you more details about the problem.
I added checks for sniper and assassin. Now, during Sniper mode, the player who is a sniper is unable to get boxes, but zombies can get boxes as they can do it during a normal infection round. Some boxes contain antidote, meaning during Sniper mode, zombies can be turned into humans, which will ruin the gameplay in Sniper mode.
During assassin mode, the player who is an assassin is unable to get the boxes, because I added a check that returns the function that allows snipers to get boxes. However, the players who are humans are able to get boxes. Since some boxes contain T-Virus, some players who are humans will be turned into zombies, during the assassin round, which will ruin the assassin round.
I fixed this issue for Sniper vs Assassin round, by adding checks for sniper and assassin. Since there are
ONLY snipers and assassins during Sniper vs Assassin round, and there are checks that prevent assassins and snipers from getting boxes, no one can get boxes during Sniper vs Assassin round.
During nemesis mode, the nemesis is unable to get boxes. However, players who are humans are able to get boxes. Since some boxes contain T-Virus, some players who are humans will be turned into zombies, which will ruin the nemesis round.
During survivor mode, the survivor is unable to get boxes. However, players who are zombies are able to get boxes. Since some boxes contain antidote, some players who are zombies will be turned into humans, which will ruin the survivor round.
The main idea of the bonus box plugin is to allow
ONLY humans and zombies to get boxes during normal infection round, while no one is able to get boxes during any other round, that isn't a normal infection round, regardless whether or not the player is a zombie or a human.
In a nutshell, i know how to add checks that prevent snipers, nemesis, and assassins from getting the boxes. However, since the plugin is designed to give boxes to zombies and humans, zombies and humans can get the boxes by default. Since there are zombies and humans during game modes like multiple infection mode or swarm mode, zombies and humans can still get boxes during such game mode rounds. Some boxes contain T-Viruses and antidotes, and this is what will ruin the game mode rounds I'm talking about. Because zombies and humans are not supposed to get T-Virus or antidote during these rounds.
There are only two solutions. One is to remove the T-Virus box and the antidote box. I know how to do it, but I don't want to remove the T-Virus box or the antidote box. The second solution is to make the bonus box plugin to be active
only during normal infection mode, and to never be active during any game mode that is not normal infection mode.
I prefer to keep the boxes, and to make the bonus box plugin to be disabled during any game mode that isn't normal infection mode.
I tried to make the plugin to be disabled during a certain game mode, but i got error, meaning i did something wrong.
So, let say i want the box plugin to be completely disabled during nemesis mode, so humans can't get any boxes, including the T-Virus box.
Here is what i did.
I opened the source code of the plugin:
PHP Code:
/*
---------------------------------------------------------
# # # #=== ### ## #
# ## #=== # # # #
# # #=== ### ## #
---------------------------------------------------------
[ZP] Addon: Present Spawner by <VeCo> 1.4
Plugin made by <VeCo>
Special thanks to:
- marto874 : for testing and ideas.
- remotiv : for the idea for zp_ps_spawn_presents_time CVAR.
If you modify the code, please DO NOT change the author!
---------------------------------------------------------
Contacts:
e-mail: removed to avoid violation of spam policies
skype: removed to avoid violations of spam policies
---------------------------------------------------------
Changes log:
-> v 1.0 = First release!
-> v 1.1 = Added CVAR zp_ps_spawn_presents_time.
-> v 1.2 = Fixed bug in the new round task.
-> v 1.3 = Fixed bugs with some items.
-> v 1.4 = Fixed bug whit the present limit.
---------------------------------------------------------
Don't forget to visit removed to avoid violations of spam policies
---------------------------------------------------------
*/
#include <amxmodx>
#include <amxmisc>
#include <cstrike>
#include <fakemeta>
#include <engine>
#include <fun>
#include <zombieplague>
#define ADMIN_PRESENT_SPAWN ADMIN_RCON // access level for zp_ps_spawn command
#define ADMIN_PRESENT_REMOVE ADMIN_BAN // access level for zp_ps_remove command
#define ADMIN_PRESENT_STOP ADMIN_RCON // access level for zp_ps_stop command
#define ADMIN_PRESENT_START ADMIN_RCON // access level for zp_ps_start command
#define PRESENT_LIMIT 20 // maximum amount of presents
new const present_model[] = "models/zp_ps_present.mdl" // present model
/*START - From colorchat.inc by Numb */
enum Color {
NORMAL = 1,
GREEN,
TEAM_COLOR,
GREY,
RED,
BLUE,
}
new TeamName[][] = {
"",
"TERRORIST",
"CT",
"SPECTATOR"
}
/*END - From colorchat.inc by Numb */
new file[78],total_presents, Float:present_data[PRESENT_LIMIT + 1][3],
present_glow,present_light,present_light_radius,present_rot,
spawn_time,min_presents,max_presents,
value_ap,value_armor,value_hp_h,value_hp_z
public plugin_precache()
{
precache_model(present_model)
precache_sound("items/suitchargeok1.wav")
precache_sound("weapons/electro4.wav")
}
public plugin_init() {
register_plugin("[ZP] Addon: Present Spawner by <VeCo>", "1.4", "<VeCo>")
register_cvar("zp_addon_present_spawner_version","1.4",FCVAR_SERVER | FCVAR_SPONLY)
register_logevent("round_end",2,"1=Round_End")
register_logevent("round_start",2,"1=Round_Start")
present_glow = register_cvar("zp_ps_present_glow","1")
present_light = register_cvar("zp_ps_present_light","1")
present_light_radius = register_cvar("zp_ps_present_light_radius","10")
present_rot = register_cvar("zp_ps_present_rotate","1")
spawn_time = register_cvar("zp_ps_spawn_presents_time","10.0")
min_presents = register_cvar("zp_ps_min_spawn_presents","1")
max_presents = register_cvar("zp_ps_max_spawn_presents","3")
value_ap = register_cvar("zp_ps_present_ammo_pack_value","30")
value_armor = register_cvar("zp_ps_present_armour_value","100")
value_hp_h = register_cvar("zp_ps_present_human_health_value","35")
value_hp_z = register_cvar("zp_ps_present_zombie_health_value","200")
register_concmd("zp_ps_spawn","admin_present_spawn",ADMIN_PRESENT_SPAWN)
register_concmd("zp_ps_remove","admin_present_remove",ADMIN_PRESENT_REMOVE)
register_concmd("zp_ps_stop","admin_present_stop",ADMIN_PRESENT_STOP)
register_concmd("zp_ps_start","admin_present_start",ADMIN_PRESENT_START)
register_touch("info_present","player","present_touch")
register_think("info_present","present_think")
new mapname[32]
get_mapname(mapname,31)
format(file,77,"addons/amxmodx/configs/zp_present_spawner/%s.ini",mapname)
load_presents()
}
public admin_present_spawn(id,level,cid)
{
if(!cmd_access(id,level,cid,1)) return PLUGIN_HANDLED
if(total_presents == PRESENT_LIMIT)
{
console_print(id,"[ZP] Present limit exceeded! Maximum amount of presents is %i.",PRESENT_LIMIT)
return PLUGIN_HANDLED
}
new Float:origin[3]
entity_get_vector(id,EV_VEC_origin,origin)
origin[2] -= 30.0
save_present(id,origin)
return PLUGIN_HANDLED
}
public admin_present_remove(id,level,cid)
{
if(!cmd_access(id,level,cid,1)) return PLUGIN_HANDLED
remove_all_presents()
console_print(id,"[ZP] All presents were removed for this round.")
return PLUGIN_HANDLED
}
public admin_present_stop(id,level,cid)
{
if(!cmd_access(id,level,cid,1)) return PLUGIN_HANDLED
remove_all_presents()
total_presents = 0
console_print(id,"[ZP] All presents were removed for this map.")
return PLUGIN_HANDLED
{
if(!total_presents) return
remove_all_presents()
}
public round_start()
{
if(!total_presents) return
remove_task(1337)
set_task(get_pcvar_float(spawn_time),"spawn_random_presents",1337)
}
public spawn_random_presents()
{
new data[PRESENT_LIMIT]
new rand, n, j, x
x = random_num(get_pcvar_num(min_presents), get_pcvar_num(max_presents))
if(x == 0) return
n = 0
j = 0
while(n <= total_presents)
{
if(n == total_presents)
break
rand = random_num(0, total_presents - 1)
if(!data[rand])
{
data[rand] = 1
if(j > x)
break
}
return
}
public present_touch(ent,id)
{
if(zp_get_user_nemesis(id) || zp_get_user_survivor(id)) return
give_random_present(ent,id)
}
public give_random_present(ent,id)
{
new num = random_num(1,12)
switch(num)
{
case 1:
{
ColorChat(id,GREEN,"[ZP]^x01 You won^x04 %i^x01 ammo packs!",get_pcvar_num(value_ap))
zp_set_user_ammo_packs(id,zp_get_usr_num(value_ap))
}
case 2:
{
if(zp_get_user_zombie(id))
{
give_random_present(ent,id)
} else {
if(get_user_armor(id) >= 100)
{
give_random_present(ent,id)
} else {
ColorChat(id,GREEN,"[ZP]^x01 You won^x04 %i^x01 armor!",get_pcvar_num(value_armor))
cs_set_user_armor(id,get_palue_armor),CS_ARMOR_KEVLAR)
}
}
}
case 3:
{
if(zp_get_user_zombie(id) || zp_get_user_nightvision(id))
{
give_random_present(ent,id)
} else {
ColorChat(id,GREEN,"[ZP]^x01 You won a nightvision!")
zp_set_user_nightvision(id,1)
}
}
case 4:
{ if(user_has_weapon(id,CSW_HEGRENADE))
{
give_random_present(ent,id)
} else {
if(zp_get_user_zombie(id))
{
ColorChat(id,GREEN,"[ZP]^x01 You won an infection grenade!")
} else {
ColorChat(id,GREEN,"[ZP]^x01 You won a fire grenade!")
}
give_item(id,"weapon_hegrenade")
}
}
case 5:
{
if(zp_get_user_zombie(id))
{
give_random_present(ent,id)
} else {
if(user_has_weapon(id,CSW_FLASHBANG))
{
give_random_present(ent,id)
} else {
ColorChat(id,GREEN,"[ZP]^x01 You won a frost grenade!")
give_item(id,"weapon_flashbang")
}
}
}
case 6:
{
if(zp_get_user_zombie(id))
{
give_random_present(ent,id)
} else {
if(user_has_weapon(id,CSW_SMOKEGRENADE))
{
give_random_present(ent,id)
} else {
ColorChat(id,GREEN,"[ZP]^x01 You won a flare!")
give_item(id,"weapon_smokegrenade")
}
}
}
case 7:
{
if(zp_get_user_last_zombie(id) || zp_get_user_last_human(id))
{
give_random_present(ent,id)
} else {
if(zp_get_user_zombie(id))
{
ColorChat(id,GREEN,"[ZP]^x01 You won an antidote!")
zp_disinfect_user(id)
} else {
ColorChat(id,GREEN,"[ZP]^x01 You won an infection!")
zp_infect_user(id)
}
}
}
case 8:
{
if(zp_get_user_zombie(id))
{
ColorChat(id,GREEN,"[ZP]^x01 You won^x04 %i^x01 health!",get_pcvar_num(value_hp_z))
set_user_health(id,get_user_health(id) + get_pcvar_num(value_hp_z))
} else {
ColorChat(id,GREEN,"[ZP]^x01 You won^x04 %i^x01 health!",get_pcvar_num(value_hp_h))
set_user_health(id,get_user_health(id) + get_pcvar_num(value_hp_h))
}
}
case 9:
{
if(zp_get_user_zombie(id))
{
give_random_present(ent,id)
} else {
ColorChat(id,GREEN,"[ZP]^x01 You won a weapon -^x04 m249^x01!")
give_item(id,"weapon_m249")
cs_set_user_bpammo(id,CSW_M249,100)
}
}
case 10:
{
if(zp_get_user_zombie(id))
{
give_random_present(ent,id)
} else {
ColorChat(id,GREEN,"[ZP]^x01 You won a weapon -^x04 sg550^x01!")
give_item(id,"weapon_sg550")
cs_set_user_bpammo(id,CSW_SG550,30)
}
}
case 11:
{
if(zp_get_user_zombie(id))
{
give_random_present(ent,id)
} else {
ColorChat(id,GREEN,"[ZP]^x01 You won a weapon -^x04 g3sg1^x01!")
give_item(id,"weapon_g3sg1")
cs_set_user_bpammo(id,CSW_G3SG1,20)
}
}
case 12:
{
if(zp_get_user_zombie(id))
{
give_random_present(ent,id)
} else {
ColorChat(id,GREEN,"[ZP]^x01 You won a weapon -^x04 awp^x01!")
give_item(id,"weapon_awp")
cs_set_user_bpammo(id,CSW_AWP,10)
}
}
}
emit_sound(ent,CHAN_AUTO,"items/suitchargeok1.wav",VOL_NORM,ATTN_NORM,0,PITCH_NORM)
remove_entity(ent)
}
public present_think(ent)
{
if(get_pcvar_num(present_light))
{
static Float:origin[3]
entity_get_vector(ent,EV_VEC_origin,origin)
engfunc(EngFunc_MessageBegin, MSG_PVS, SVC_TEMPENTITY, origin, 0)
write_byte(TE_DLIGHT)
engfunc(EngFunc_WriteCoord, origin[0])
engfunc(EngFunc_WriteCoord, origin[1])
engfunc(EngFunc_WriteCoord, origin[2])
write_byte(get_pcvar_num(present_light_radius))
write_byte(entity_get_int(ent,EV_INT_iuser1))
write_byte(entity_get_int(ent,EV_INT_iuser2))
write_byte(entity_get_int(ent,EV_INT_iuser3))
write_byte(2)
write_byte(0)
message_end()
}
if(get_pcvar_num(present_rot))
{
static Float:angles[3]
entity_get_vector(ent,EV_VEC_angles,angles)
angles[1]--
entity_set_vector(ent,EV_VEC_angles,angles)
}
entity_set_float(ent,EV_FL_nextthink,halflife_time() + 0.01)
}
public remts() remove_entity_name("info_present")
public load_presents()
{
total_presents = 0
new buffer[128], x[12],y[12],z[12]
if(file_exists(file))
{
new save = fopen(file,"rt")
if(!save) return
while(!feof(save))
{
fgets(save,buffer,127)
if(buffer[0] == ';' || !buffer[0]) continue
if(total_presents == PRESENT_LIMIT) break
parse(buffer, x,11, y,11, z,11)
present_desents][1] = str_to_float(y)
present_data[total_presents][2] = str_to_float(z)
total_presents++
}
fclose(save)
}
}
public spawn_present(param)
{
new ent = create_entity("info_target")
if(ent)
{
entity_set_string(ent,EV_SZ_classname,"info_present")
entity_set_model(ent,present_model)
entity_set_int(ent,EV_INT_solid,SOLID_TRIGGER)
entity_set_int(ent,EV_INT_movetype,MOVETYPE_TOSS)
entity_set_float(ent,EV_FL_gravity,1.0)
if(get_pcvar_num(present_glow))
{
entity_set_int(ent,EV_INT_iuser1,random(255))
entity_set_int(ent,EV_INT_iuser2,random(255))
entity_set_int(ent,EV_INT_iuser3,random(255))
set_rendering(ent,kRenderFxGlowShell,entity_get_int(ent,EV_INT_iuser1),entity_get_int(ent,EV_INT_iuser2),entity_get_int(ent,EV_INT_iuser3),kRenderNormal,60)
}
entity_set_esent_data[param])
entity_set_FL_nextthink,halflife_time() + 0.01)
emit_sound(eO,"weapons/electro4.wav",VOL_NORM,ATTN_NORM,0,PITCH_NORM)
}
}
public save_present(id,Float:origin[3])
{
new save = fopen(file,"at")
if(save)
{
fprintf(save,"%.2f %.2f %.2f^n",origin[0],origin[1],origin[2])
fclose(save)
console_print(id,"[ZP] Present Spawn: successfully added at x:y:z(%.2f : %.2f : %.2f).",origin[0],origin[1],origin[2])
load_presents()
}
}
/*START - From colorchat.inc by Numb */
ColorChat(id, Color:type, const msg[], {Float, Sql, Result,_}:...) {
new message[256]
switch(type) {
case NORMAL: message[0] = 0x01
case GRe[0] = 0x04
default: message[0] = 0x03
}
vformat(message[1], 251, msg, 4)
message[192] = '^0'
new team, Coloe, indexSG_Type
if(id) {
MSG_Type = MSG_ONE
index = id
} else {
index = FindPlayer()
MSG_Type = MSG_ALL
}
team = get_user_team(index)
ColorChange = Con(index, MSG_Type, type)
ShowColorMessage(iSG_Type, message)
if(ColorChange)
Team_Info(index_Type, TeamName[team])
}
ShowColorMessage(id, typage[]) {
static bool:saytext_used
static get_user_msgiaytext
if(!saytext_used) {
get_user_msgid_saytext = get_user_msgid("SayText")
saytext_used = true
}
message_begin(type, get_user_msgid_saytext, _, id)
write_byte(id)
write_string(message)
message_end()
}
Team_Info(id, type, team[]) {
static bool:tnfo_used
static get_ussgid_teaminfo
if(!teaminsed) {
get_usergid_teaminfo = get_user_msgid("TeamInfo")
teaminfo_used = true
}
message_n(type, get_user_msgid_teaminfo, _, id)
write_byte(id)
write_steam)
messagend()
return 1
}
ColorSelection(index, type, Color:Type) {
switch(Type) {
case RED: return Team_Info(index, type, TeamName[1])
case BLUE: return Tnfo(index, type, TeamName[2])
case GREY: _Info(index, type, TeamName[0])
}
return 0
}
Findyer() {
nw i = -1
while(i <maxplayers()) {
if(is_user_connected(++i))
return i
}
return -1
}
/*END - From colorchat.inc by Numb */
I replaced this:
#include <zombieplague>
with this:
#include <zombie_plague_advance>
I added "#define zp_game_mode_nemesis" at the top of the code, where the other "#DEFINEs" are placed. I did this, otherwise, i will get this error:
"error 017: undefined symbol "zp_game_mode_nemesis"
Then i added this "
zp_get_user_nemesis(id)" here:
Code:
public present_touc,id)
{
if(zp_get_user_nemesis(id) || zp_get_user_survivor(id) || zp_game_mode_nemesis(id)) return
give_random_present(ent,id)
}
The compiler didn't show any errors after i made the changes. However, although no errors were shown during the compiling process, the changes i introduced created a bug that prevents anyone from getting boxes. It doesn't matter what the round is, what the game mode is, no one can get boxes. So, this method didn't work.
Here is the second method i tried.
I found this code:
Code:
public present_touch(ent,id)
{
if(zp_get_user_nemesis(id) || zp_get_user_survivor(id)) return
give_random_present(ent,id)
}
Then, i added the following check
(marked in red):
Code:
public present_touch(ent,id)
{
if(zp_get_user_nemesis(id) || zp_get_user_survivor(id)) return
give_random_present(ent,id)
if(zp_game_mode_nemesis(id))
return PLUGIN_HANDLED
}
This method didn't work, too. I got the following errors:
// C:\Mod\cstrike\addons\amxmodx\scripting\zp_ad don_box.sma(220) : warning 209: function "present_touch" should return a value
// C:\Mod\cstrike\addons\amxmodx\scripting\zp_ad don_box.sma(222) : warning 217: loose indentation
// C:\Mod\cstrike\addons\amxmodx\scripting\zp_ad don_box.sma(223) : error 078: function uses both "return" and "return <value>"
Line 220:
PHP Code:
give_random_present(ent,id)
Line 222:
PHP Code:
if(zp_game_mode_nemesis(id))
Line 223:
PHP Code:
return PLUGIN_HANDLED
The whole code:
PHP Code:
public present_touch(ent,id)
{
if(zp_get_user_nemesis(id) || zp_get_user_survivor(id)) return
give_random_present(ent,id)
if(zp_game_mode_nemesis(id))
return PLUGIN_HANDLED
}
I know how to fix the warning, but i don't know how to fix the 2 errors. So, i tried another method.
I added the following code to the source code of the bonus box plugin:
PHP Code:
public client_PreThink(id)
{
if(!zp_game_mode_nemesis(id)
return PLUGIN_HANDLED
}
This method didn't work, too. I got the following errors:
// C:\Mod\cstrike\addons\amxmodx\scripting\zp_ad don_box.sma(226) : error 001: expected token: ")", but found "return"
// C:\Mod\cstrike\addons\amxmodx\scripting\zp_ad don_box.sma(227) : warning 209: function "client_PreThink" should return a value
Line 226:
Code:
return PLUGIN_HANDLED
Line 227:
The whole code:
PHP Code:
public client_PreThink(id)
{
if(!zp_game_mode_nemesis(id)
return PLUGIN_HANDLED
}
So, i want the boxes to be available only during normal infection mode, while unavailable during any other mode that isn't normal infection mode. I don't know how to do this.
In a nutshell, i need a code (check) that detects what the game mode is, and then disables the bonus box plugin, if the detected game mode is considered a mode during which the bonus box plugin must be disabled. If it's impossible to create a code that disables the whole plugin, then i need a code that at least makes boxes to be impossible to get, meaning players can go on the box, but the box will stay there and the player won't be able to get the box.
Can someone help me to do it?
Thanks.