* Kendaer takes a look since he figures it's time to give people feedback on modules again.
$city = getsetting("villagename", LOCATION_FIELDS);
$capital = $session['user']['location']==$city;
$sqlpq="SELECT active FROM modules WHERE modulename='cities'";
$resultpq = db_query($sqlpq) or die(db_error(LINK));
$rowpq = db_fetch_assoc($resultpq);
if ($rowpq['active'] == 1 and $capital){
}else{
tlschema($args['schemas']['fightnav']);
addnav($args['fightnav']);
tlschema();
addnav("H?Healer's Hut","healer.php?return=village.php");
}
could be much better written as
$city = getsetting("villagename", LOCATION_FIELDS);
if ($session['user']['location'] == $city) {
// no healer in the capital since it's already added there by the
// multicity module, and shouldn't be there in single city.
} else {
tlschema($args['schemas']['fightnav']);
addnav($args['fightnav']);
tlschema();
addnav("H?Healer's Hut","healer.php?return=village.php");
}
There is no need for that extra SQL call there since the village hook will only be called for active villages.
You have some work to do for translation readyness.
output("`3Healing Potion`7 costs `6".round(100*$potioncost/100,0)." gold`7. You can carry up to 5 with you to heal yourself.`n`n");
should be
output("`3Healing Potion`7 costs `6%s gold`7. You can carry up to 5 with you to heal yourself.`n`n", round(100*$potioncost/100, 0));
Lastly, you do the following
function potions_runevent($type)
{
global $session;
$upotion = get_module_pref("potion");
if ($upotion<5 and $session['user']['dragonkills']<10){
output("Lucky Day! You find a healing potion!");
set_module_pref('potion', ++$upotion);
debuglog("found 1 Healing Potion in the forest");
}else{
redirect("forest.php?op=search");
}
}
While this would work, it would be *better* to make the event not fire at all if it wasn't legal, so instead, what you should do is modify the module_addeventhook("forest", "return 100;");
call as follows
module_addeventhook("forest", "require_once(\"modules/potions.php\"); return potions_chance();");
and then modify the code as follows
function potions_chance()
{
global $session;
// we need the modulename in the get here because we aren't in a
// module context at the time we call the event hooks for evaluation.
$upotion = get_module_pref("potion", "potions");
if ($upotion >= 5 || $session['user']['dragonkills'] >= 10)
return 0;
return 100;
}
function potions_runevent($type)
{
$upotion = get_module_pref("potion");
output("Lucky Day! You find a healing potion!");
set_module_pref('potion', ++$upotion);
debuglog("found 1 Healing Potion in the forest");
}
This is actually better because it doesn't require an extra page load which the redirect does require making it actually faster on a loaded server.