Author Topic: Different creatures and Dragon, based on DK...  (Read 5302 times)

Alchemion

  • Guest
Different creatures and Dragon, based on DK...
« on: October 10, 2008, 09:28:14 am »
Hello, Nightborn,

I am getting busy again with my game implementation and I keep getting new ideas...

I stumbled upon a couple of days on Kala's module 'variedvillage', on Dragonprime, a module that changes encountered creatures based on DK, and I found it usefull for my themed game scenario.

I tried to adapt and get rid of unneeded code for my game and I got it to this :

Code: [Select]
<?php
function variedvillage_getmoduleinfo(){
$info=array(
"name"=>"Varied Villages",
"author" => "Alchemion with help from Nightborn, based on`4Kara Abbott's variedvillage",
"version"=>"1.0",
"download"=>"http://dragonprime.net/index.php?module=Downloads;sa=dlview;id=639",
"category"=>"Administrative",
"description"=>"Change creatures  and dragon names depending upon dk",
"settings"=>array(
"Varied Village Settings,title",
"dk"=>"First dk level?,int|",
"dk2"=>"Second dk level?,int|",
"dragon1"=>"First Dragon Name?,text|",
"dragon2"=>"Second Dragon Name?,text|",
),
"prefs-creatures"=>array(
"Varied Villages - Creature Settings,title",
"city1creature"=>"This monster may appear in the First Village?,bool|0",
"city2creature"=>"This monster may appear in the Second Village?,bool|0"
),
);
return $info;
}
function 
variedvillage_install(){
module_addhook("creatureencounter");
if (!is_module_installed('variedvillages')) {
foreach ($sql_statements as $intext => $outtext) {
$sql "INSERT INTO ".db_prefix("translations")." (intext, outtext, uri, language) VALUES ('".addslashes($intext)."', '".addslashes($outtext)."', 'module-variedvillages', 'en')";
db_query($sql);
}
}
return true;
}
function 
variedvillage_uninstall(){
return true;
}

function 
variedvillage_dohook($hookname,$args){
global $session;
$dk=$session['user']['dragonkills'];
$dkc=get_module_setting("dk");
$dkc2=get_module_setting("dk2");

switch($hookname){

case "creatureencounter":
if ($dk>=$dkc && $dk<$dkc2){
//first city creatures
$dragon=get_module_setting("dragon1");
preg_replace("Green Dragon","$dragon");
preg_replace("Dragon","$dragon");
$creatures db_prefix("creatures");
$module_objprefs db_prefix("module_objprefs");
$sql "SELECT c.creaturename AS creaturename, c.creatureweapon AS creatureweapon
FROM 
$creatures AS c
INNER JOIN 
$module_objprefs AS mo ON mo.objid = c.creatureid
WHERE mo.objtype='creatures'
AND mo.modulename='variedvillage'
AND mo.setting='city1creature'
AND mo.value=1
AND c.creaturelevel = 
{$args['creaturelevel']}
ORDER BY rand("
.e_rand().")
LIMIT 1"
;
$result db_query($sql);
if (db_num_rows($result)) {
$row db_fetch_assoc($result);
$args['creaturename'] = $row['creaturename'];
$args['creatureweapon'] = $row['creatureweapon'];
$args['creaturehealth'] = round($args['creaturehealth'] * (0.1 get_module_setting("expbonus")));
$args['creatureattack'] = round($args['creatureattack'] * (0.1 get_module_setting("expbonus")));
$args['creaturedefense'] = round($args['creaturedefense'] * (0.1 get_module_setting("expbonus")));
} else {
$args['creaturename'] = "`4Avenging Angel";
$args['creatureweapon'] = "`4Flames of Light";
}
}elseif($dk>=$dkc2){
//second cities creatures
$dragon=get_module_setting("dragon2");
preg_replace("Green Dragon","$dragon");
preg_replace("Dragon","$dragon");
$creatures db_prefix("creatures");
$module_objprefs db_prefix("module_objprefs");
$sql "SELECT c.creaturename AS creaturename, c.creatureweapon AS creatureweapon
FROM 
$creatures AS c
INNER JOIN 
$module_objprefs AS mo ON mo.objid = c.creatureid
WHERE mo.objtype='creatures'
AND mo.modulename='variedvillage'
AND mo.setting='city2creature'
AND mo.value=1
AND c.creaturelevel = 
{$args['creaturelevel']}
ORDER BY rand("
.e_rand().")
LIMIT 1"
;
$result db_query($sql);
if (db_num_rows($result)) {
$row db_fetch_assoc($result);
$args['creaturename'] = $row['creaturename'];
$args['creatureweapon'] = $row['creatureweapon'];
$args['creaturehealth'] = round($args['creaturehealth'] * (0.1 get_module_setting("expbonus")));
$args['creatureattack'] = round($args['creatureattack'] * (0.1 get_module_setting("expbonus")));
$args['creaturedefense'] = round($args['creaturedefense'] * (0.1 get_module_setting("expbonus")));
} else {
$args['creaturename'] = "`4Avenging Angel";
$args['creatureweapon'] = "`4Flames of Light";
}
}
break;
}
return $args;
}
?>

With the Kala's file, the dragon didn't change its name on encountering, and i remember something about the need to use translation engine to get the job done...

I thought of simplifying it, but still does not show the dragon name modified in battle...

Please, have a look on the upper code and point what is lacking so the code would work also for the Dragon name change ( to have the same effect as encountering different creatures on different dk's) ...

Regarding other hard coded "dragon" name in the game, i plan to replace it with a generic name that would not pose a problem with the specificity of this encounter... or maybe you would suggest something more efficient ... though you're the fan of modularizing changes...  :)

Thank you, very much.

« Last Edit: October 10, 2008, 09:47:06 am by Alchemion »

Nightborn

  • Administrator
  • Sr. Member
  • *****
  • Posts: 320
  • Karma: +20/-0
    • View Profile
    • Shinobilegends
Re: Different creatures and Dragon, based on DK...
« Reply #1 on: October 10, 2008, 03:12:13 pm »
         preg_replace("Green Dragon","$dragon");
         preg_replace("Dragon","$dragon");


<--- well, a bad hack.

she simply replaces all "Green Dragon" strings with the content of $dragon.... and then if t here is STILL a dragon, again.

if you have translated OR altered the green dragon to phantom wedgie - your module won't change a thing.
It should be fixed, but it won't be easy and it won't be fast. If you want
to help - wonderful. But keep in mind that it will take months of wading
through the ugliest code we have in the tree. If you've got a weak stomach -
stay out. I've been there and it's not a nice place.

   - Al Viro

Alchemion

  • Guest
Re: Different creatures and Dragon, based on DK...
« Reply #2 on: October 10, 2008, 03:56:41 pm »
And if i didn't translate the green dragon name to anything ?...

I have the core name for the dragon... but the dragon name does not change, while others creature works fine for different dk's...

What would be a more viable solution ?

Thank you.

Nightborn

  • Administrator
  • Sr. Member
  • *****
  • Posts: 320
  • Karma: +20/-0
    • View Profile
    • Shinobilegends
Re: Different creatures and Dragon, based on DK...
« Reply #3 on: October 10, 2008, 08:46:14 pm »
second the "bad hack"

... it does not do anything :) the return value is not assigned to anything.

does it do anything?


if you want to replace the dragon .... hook into this on

 $badguy = modulehook("buffdragon", $badguy);

<--- and change it there =)
It should be fixed, but it won't be easy and it won't be fast. If you want
to help - wonderful. But keep in mind that it will take months of wading
through the ugliest code we have in the tree. If you've got a weak stomach -
stay out. I've been there and it's not a nice place.

   - Al Viro

Alchemion

  • Guest
Re: Different creatures and Dragon, based on DK...
« Reply #4 on: October 12, 2008, 09:56:55 am »
I didn't understand the $badguy schema you suggested, but I took full advantage of the buffdragon hook...

So, the cleaned and neat working module that provides different creatures, including different dragons, based on dk range, is this  [variedvillage.php] :

Code: [Select]
<?php
function variedvillage_getmoduleinfo(){
$info=array(
"name"=>"Varied Villages",
"author" => "Alchemion with Nightborn's insight, based on`4Kara Abbott's variedvillage",
"version"=>"1.0",
"download"=>"http://dragonprime.net/index.php?module=Downloads;sa=dlview;id=639",
"category"=>"Administrative",
"description"=>"Change creatures  and dragon names depending upon dk",
"settings"=>array(
"Varied Village Settings,title",
"dk"=>"First dk level?,int|",
"dk2"=>"Second dk level?,int|",
"dragon1"=>"First Dragon Name?,text|",
"dragon2"=>"Second Dragon Name?,text|",
),
"prefs-creatures"=>array(
"Varied Villages - Creature Settings,title",
"city1creature"=>"This monster may appear in the First Village?,bool|0",
"city2creature"=>"This monster may appear in the Second Village?,bool|0"
),
);
return $info;
}
function 
variedvillage_install(){
module_addhook("creatureencounter");
module_addhook("buffdragon");
return true;
}
function 
variedvillage_uninstall(){
return true;
}

function 
variedvillage_dohook($hookname,$args){
global $session;
$dk=$session['user']['dragonkills'];
$dkc=get_module_setting("dk");
$dkc2=get_module_setting("dk2");

switch($hookname){

case "creatureencounter":
$creatures db_prefix("creatures");
$module_objprefs db_prefix("module_objprefs");
if ($dk>=$dkc && $dk<$dkc2){
//first dk band creatures
$sql "SELECT c.creaturename AS creaturename, c.creatureweapon AS creatureweapon
FROM 
$creatures AS c
INNER JOIN 
$module_objprefs AS mo ON mo.objid = c.creatureid
WHERE mo.objtype='creatures'
AND mo.modulename='variedvillage'
AND mo.setting='city1creature'
AND mo.value=1
AND c.creaturelevel = 
{$args['creaturelevel']}
ORDER BY rand("
.e_rand().")
LIMIT 1"
;
$result db_query($sql);
if (db_num_rows($result)) {
$row db_fetch_assoc($result);
$args['creaturename'] = $row['creaturename'];
$args['creatureweapon'] = $row['creatureweapon'];
$args['creaturehealth'] = round($args['creaturehealth'] * (0.1 get_module_setting("expbonus")));
$args['creatureattack'] = round($args['creatureattack'] * (0.1 get_module_setting("expbonus")));
$args['creaturedefense'] = round($args['creaturedefense'] * (0.1 get_module_setting("expbonus")));
} else {
$args['creaturename'] = "`4Avenging Angel";
$args['creatureweapon'] = "`4Flames of Light";
}
}elseif($dk>=$dkc2){
//second dk band creatures
$sql "SELECT c.creaturename AS creaturename, c.creatureweapon AS creatureweapon
FROM 
$creatures AS c
INNER JOIN 
$module_objprefs AS mo ON mo.objid = c.creatureid
WHERE mo.objtype='creatures'
AND mo.modulename='variedvillage'
AND mo.setting='city2creature'
AND mo.value=1
AND c.creaturelevel = 
{$args['creaturelevel']}
ORDER BY rand("
.e_rand().")
LIMIT 1"
;
$result db_query($sql);
if (db_num_rows($result)) {
$row db_fetch_assoc($result);
$args['creaturename'] = $row['creaturename'];
$args['creatureweapon'] = $row['creatureweapon'];
$args['creaturehealth'] = round($args['creaturehealth'] * (0.1 get_module_setting("expbonus")));
$args['creatureattack'] = round($args['creatureattack'] * (0.1 get_module_setting("expbonus")));
$args['creaturedefense'] = round($args['creaturedefense'] * (0.1 get_module_setting("expbonus")));
} else {
$args['creaturename'] = "`4Avenging Angel";
$args['creatureweapon'] = "`4Flames of Light";
}
}
break;

case 
"buffdragon":
global $options;
if ($dk>=$dkc && $dk<$dkc2){
//first dk band dragon
$dragon=get_module_setting("dragon1");
}elseif($dk>=$dkc2){
//second dk band dragon
$dragon=get_module_setting("dragon2");
}
$args['creaturename'] = $dragon;
break;
}
return $args;
}
//this modules takes into consideration 2 dk bands... for more dk bands, simply multiply the code above, accordingly ...
?>

Edit: The more correct module name would be "variedcreatures"... so, whoever is interested, thogh it does not affect the module, just replace the module name and inside the module, "variedvillage" with "variedcreatures"

Thank you very much, Nightborn, for the insight...
« Last Edit: October 12, 2008, 10:58:56 am by Alchemion »

Alchemion

  • Guest
Re: Different creatures and Dragon, based on DK...
« Reply #5 on: November 29, 2009, 08:01:06 pm »
Hi,

As I have restarted testing my old server, I have found out that only admin can encounter different creatures and dragons based on his dk range... the other players fight regular creatures and old green dragon...

Any idea why this happens ?

Thank you very much.
E.C.

Alchemion

  • Guest
Re: Different creatures and Dragon, based on DK...
« Reply #6 on: December 02, 2009, 10:16:29 am »
Hi, Nightborn,
Please some insight here...
Thank you.

Edit. Solution found out. I was in a hurry and messed up the conditions...

So, the first condition:
Code: [Select]
if ($dk>=$dkc && $dk<$dkc2){  I have modified to this:
Code: [Select]
if ($dk<$dkc){
and the second condition become the first and so on for the following dk ranges and creatures...

While the admin had tens of dks, obviously the new players wouldn't have been "seen" by the module...

Sorry for rushin' in  ;D

Cheers!
« Last Edit: December 02, 2009, 05:28:59 pm by Alchemion »