Hello I wonder what is wrong with this, and I wonder how do you read
from a cfg file? My version (read_from_file) has a few leaks (LOL).
Code:
#include <amxmodx>
#include <fun>
new cvar
public plugin_init()
{
register_plugin("Spelltime", "1.0", "MaTTe")
cvar = register_cvar("amx_spelltime", "1")
register_clcmd("say /spelltime", "cmd_spelltime")
register_clcmd("say_team /spelltime", "cmd_spelltime")
new basedir[64]
new cfgfile[64]
format(cfgfile, 63, "%s/addons/amxmodx/configs/spelltime/spelltime.cfg", basedir)
if(file_exists(cfgfile))
{
log_amx("[Spelltime] Loading cfgfile [spelltime.cfg]...")
server_cmd("exec %s", cfgfile)
log_amx("[Spelltime] Cfgfile loaded successfully.")
}else{
log_amx("[Spelltime] Cfgfile not found. [Pausing plugin]")
server_cmd("amxx pause spelltime")
}
return PLUGIN_CONTINUE
}
public cmd_spelltime(id)
{
if(!get_pcvar_num(cvar))
return PLUGIN_HANDLED
new sound = read_from_file(cfgfile)
new sound2 = read_from_file(cfgfile)
new sound3 = read_from_file(cfgfile)
new sound4 = read_from_file(cfgfile)
new sound5 = read_from_file(cfgfile)
new rand = random_num(1, 5)
switch(rand)
{
case 1:
{
client_cmd(id, "play spelltime/%s.wav", sound)
}
case 2:
{
client_cmd(id, "play spelltime/%s.wav", sound2)
}
case 3:
{
client_cmd(id, "play spelltime/%s.wav", sound3)
}
case 4:
{
client_cmd(id, "play spelltime/%s.wav", sound4)
}
case 5:
{
client_cmd(id, "play spelltime/%s.wav", sound5)
}
}
new text[200]
read_args(text, 199)
if(rand==1)
{
if(containi(text, "i guess it is %s", sound)==1)
{
client_print(id, print_chat, "You guessed right! +5 health")
set_user_health(id, get_user_health(id)+5)
}else{
client_print(id, print_chat, "You guessed wrong! -5 health")
set_user_health(id, get_user_health(id)-5)
}
} else if(rand==2)
{
if(containi(text, "i guess it is %s", sound2)==1)
{
client_print(id, print_chat, "You guessed right! +5 health")
set_user_health(id, get_user_health(id)+5)
}else{
client_print(id, print_chat, "You guessed wrong! -5 health")
set_user_health(id, get_user_health(id)-5)
}
} else if(rand==3)
{
if(containi(text, "i guess it is %s", sound3)==1)
{
client_print(id, print_chat, "You guessed right! +5 health")
set_user_health(id, get_user_health(id)+5)
}else{
client_print(id, print_chat, "You guessed wrong! -5 health")
set_user_health(id, get_user_health(id)-5)
}
} else if(rand==4)
{
if(containi(text, "i guess it is %s", sound4)==1)
{
client_print(id, print_chat, "You guessed right! +5 health")
set_user_health(id, get_user_health(id)+5)
}else{
client_print(id, print_chat, "You guessed wrong! -5 health")
set_user_health(id, get_user_health(id)-5)
}
} else if(rand==5)
{
if(containi(text, "i guess it is %s", sound5)==1)
{
client_print(id, print_chat, "You guessed right! +5 health")
set_user_health(id, get_user_health(id)+5)
}else{
client_print(id, print_chat, "You guessed wrong! -5 health")
set_user_health(id, get_user_health(id)-5)
}
}
return PLUGIN_CONTINUE
}