Welcome
Welcome to the Official<strong>World of Phaos</strong>Forums.

You are currently viewing our boards as a guest, which gives you limited access to view most discussions and access our other features. By joining the World of Phaos community for free, you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content, and access many other special features. Registration is fast, simple, and absolutely free, so please, <a href="/profile.php?mode=register">join the World of Phaos community today</a>!

Not so random monsters.

Updated or created a new script or part of WoP and you think the world should know, post it here and you may well see it in the next release of Phaos.
(Remember to keep all code clean and readable)

Moderators: zeke, Aradan

Not so random monsters.

Postby mccragge » Tue Jun 02, 2009 5:18 am

The trick to getting monsters to spawn with specific attributes is actually a lot easier then it looks.

First open the class.characters.php file, look for this block of code around line 1058

Code: Select all
class np_character_from_blueprint extends character {
   function np_character_from_blueprint($blueprint,$level=1,$username='phaos_npc'){
        $this->level= intval($level);
        if($level<0){
            $level= 1;
            echo "<p>bad level input for npc!</p>";
        }

      //define main vars
      $this->id= -1;
      $this->name=$blueprint["name"];
      $this->user= $username;
      $this->cclass=$blueprint["class"];
      $this->race=$blueprint["race"];
      $this->sex= rand(0,1)?'Female':'Male';
      $this->image=$blueprint["image_path"];
      $this->age=$this->level*$this->level;
      $this->location= 0;
      //define attribute vars
      $this->strength = (int)($blueprint["min_damage"]+3*($this->level-1));
       $this->dexterity = (int)($blueprint["max_damage"]-$blueprint["min_damage"]+2*$this->level+2);
        $this->wisdom = (int)($blueprint["xp_given"]/2+$this->level);
        //define changeable vars( well except constitution )
        $this->hit_points = $blueprint["hit_points"]+rand(0,$this->level*3);
        $this->constitution = (int)(($this->hit_points+10)/6);
        $this->stamina_points= ($this->constitution+$this->strength)*5;
        $this->level = $this->level;

        //This are the most significant changes from 0.90
        $ac_left= fairInt( $blueprint['AC']*sqrt($this->level*0.25) );
        $this->xp   = fairInt( $blueprint["xp_given"]*(0.50+sqrt($this->level*0.25)) );
        $this->gold = fairInt( $blueprint["gold_given"]*(0.50+sqrt($this->level*0.25)) );

        $this->stat_points = 0;

        //skills
        $this->fight = 4+$this->level;
        $this->defence = (int)($blueprint['AC']/4+$this->level-1);
        $this->lockpick = 1+ (int)($this->wisdom/4);
        $this->traps = 1 + (int)($this->wisdom/2);

        //define equipment vars
        $this->weapon = 0;
        $this->armor = 0;
        $this->boots = 0;
        $this->shield = 0;
        $this->gloves = 0;
        $this->helm = 0;

        //FIXME: we need natural armor to clothe e.g. dragons
        //FIXME: armor class needs to be spent more evenly among armor types
        if($ac_left>0) {
            $armors= fetch_all("select id, armor_class from phaos_armor where armor_class<=$ac_left order by armor_class DESC LIMIT 1");
            if(count($armors)>0){
                $this->armor= $armors[0]['id'];
                $this->armor_ac= $armors[0]['armor_class'];
                $ac_left -= $this->armor_ac;
            }
        }

        if($ac_left>0) {
            $boots= fetch_all("select id, armor_class from phaos_boots where armor_class<=$ac_left order by armor_class DESC LIMIT 1");
            if(count($boots)>0){
                $this->boots= $boots[0]['id'];
                $this->boots_ac= $boots[0]['armor_class'];
                $ac_left -= $this->boots_ac;
            }
        }

        //fill weapon:
        $blueprint['avg_damage']= (int)(($blueprint["min_damage"]+$blueprint["max_damage"])*0.5);
        $weapons= fetch_all("select * from phaos_weapons where min_damage<=$blueprint[min_damage] and $blueprint[avg_damage]<= 2*max_damage order by RAND() LIMIT 1");
        if(count($weapons)>0){
            $this->weapon= $weapons[0]['id'];
            $this->weapon_min = $weapons[0]['min_damage'];
            $this->weapon_max = $weapons[0]['max_damage'];
            $this->weapon_name = $weapons[0]['name'];
        }else{
            $this->weapon_min = 0;
            $this->weapon_max = 0;
            $this->weapon_name = "natural weapon";
        }
        $this->weaponless = $blueprint['avg_damage']+ 2*(int)($this->level);

        //calculated stuff
        $this->available_points = $this->strength+$this->dexterity+$this->wisdom+$this->constitution;
        $this->max_hp = $this->constitution*6;
        $this->max_stamina = ($this->constitution+$this->strength)*10;
        $this->max_rep = 7;

        if($this->hit_points>$this->max_hp){
            $this->max_hp= $this->hit_points;
        }
        if($this->stamina_points>$this->max_stamina){
            $this->max_stamina= $this->stamina_points;
        }

        //other stuff
        $actTime=time();
        $this->regen_time = $actTime;
        $this->stamina_time = $actTime;
        $this->rep_time = $actTime;
        $this->no_regen_hp = $blueprint["hit_points"];
        //regeneration
        $this->time_since_regen = $actTime-$this->regen_time;
        $this->stamina_time_since_regen = $actTime-$this->stamina_time;
        $this->rep_time_since_regen = $actTime-$this->rep_time;
        //reputation
        $this->rep_points = rand(0,$this->level-1);
        $this->rep_helpfull = rand(0,$this->level-1);
        $this->rep_generious = rand(0,$this->level-1);
        $this->rep_combat = rand(0,$this->level-1);
        //weapon & fight Calculation

        $this->max_inventory=$this->strength*5;

       if( !$this->image ) {
            $this->image = "images/monster/forest_troll.gif";
        }
    }

}


All you have to do now is modify all the different stats you don't want to be random with the following:

$this->old_stat = $blueprint["old_stat"];

Once done there edit your admin panel that controls creating and editing monsters adding entries for the stats you want to include in your monster.

Once you have all the monsters edited to your liking, you have to purge the character database to get rid of the old monsters and then the new monsters will start to generate on their own using your modified blueprint and with the stats you told it to have and not some random craziness. (especially with gold and xp give outs)

Hope that helps

McCragge
mccragge
Level 4
 
Posts: 82
Joined: Mon Nov 10, 2008 5:46 am

Return to Scripts

Who is online

Users browsing this forum: No registered users and 0 guests

cron