DragonPrime - LoGD Resource Community
Welcome Guest
  • Good afternoon, Guest.
    Please log in, or register.
  • May 19, 2013, 02:13:02 PM
Home Forums News Links Downloads Login Register Advanced Search
* * *
DragonPrime Menu
Login
 
 
Resource Pages
IRC Channels
Search

Pages: [1]   Go Down
  Print  
Author Topic: Adding a stat in forest fights  (Read 1969 times)
0 Members and 1 Guest are viewing this topic.
CavemanJoe
Mod God
*****
Offline Offline

Posts: 555


Opener of WormCans


View Profile WWW
« on: January 29, 2008, 10:13:54 AM »

Hi!  I'd like to start coding a module, but being a noob I need some inspiration first.  The module will award "Glory" points for participating in interesting battles.  The idea is that the more epic your battles become, the more Glory you have, the more air time you get (my server is Reality TV themed, as well as other silliness) and the more the Network rewards you.
What I'd like my module to do is this:

Upon fighting a monster or another player, Glory is awarded.  In the first round of combat:
glory+=(foeHP-playerHP)

In subsequent rounds of combat:
glory+=(((playerMAXHP-playerHP)+foeHP)*RoundsThatTheFightHasLastedThusFar)

Glory is awarded at every round of combat, not just after the fight.  To the viewers at home, it matters not who wins, as long as the fight is bloody and epic.

Basically the idea is that the player is encouraged to live dangerously, taking on monsters bigger than (s)he, encouraging fights to go on for as long as possible and healing as infrequently as they can.  I'd also like to have a HOF entry for this, and a system whereby Glory can convert to Charm (or Requisition, my server's equivalent of gold) on newday, possibly by establishing whether the player is above or below the average Glory for their level and adding or removing a single Charm point (or paying a Requisition stipend) accordingly.

Now, what I could do with before I get started is a module to dissect and examine.  Are there any modules currently existing that perform a similar function in terms of adding a stat to the player info table, incrementing a counter with each round of combat and awarding something to the player (or simply just modifying a stat) while still engaged in combat?  This will be my first module, so any personalised advice that you guys can give specifically for making this module would be much appreciated and credited when I release it.

Many, many thanks!
Logged

ThricebornPhoenix
Codemeister
****
Offline Offline

Posts: 368


Dying is the easy part.


View Profile
« Reply #1 on: February 02, 2008, 10:02:17 AM »

incrementing a counter with each round of combat and awarding something to the player (or simply just modifying a stat) while still engaged in combat?

I believe that can only be done via creature A.I. script (which executes every round), unless you write your own battle script. If you're using 1.1.1, you can find out more at the A.I. scripts forum. If I'm wrong, I'd love to hear how else it could be done Smiley
Logged

"I'm no hand at casuistry, but I can't break my word to a modern pessimist. It's like breaking one's word to a child." ~ The Man Who Was Thursday, G. K. Chesterton
Iori
Mod God
*****
Offline Offline

Posts: 832


View Profile WWW
« Reply #2 on: February 02, 2008, 10:47:09 AM »

In 1.1.1, battle scripts are probably the easiest way to accomplish something like this. You can do it like this:
1. Prepare your a.i. script ($yourpreparedscript)
2. make a simple module that hooks onto creatureencounter, and set $args['creatureaiscript'] = $yourpreparedscript; This should give that script to every creature in the forest battle. The game engine will then automatically run the script every round for each creature alive that has it as its script.

The downside is, you will run into trouble with creatures that already have their own scripts with this approach.

------------------------------------------------------------------
However, if you run 1.1.0 or lower, this should still be doable with a module with a different approach.

modulehook "creatureencounter":
sets modulepref "combat_rounds"to 0.
sets modulepref "tempglory" to 0.

modulehook "battle":
increment "combat_rounds" modulepref by 1 and run your formula for glory points. Increment the result obtained to the modulepref "tempglory".

modulehook "battle-victory" / "battle-defeat":
display a message reflecting the total value of "tempglory", and increment that value to a "glory" modulepref storing the total amount of glory points the player has.

It's not pretty, but it should work.
Logged

CavemanJoe
Mod God
*****
Offline Offline

Posts: 555


Opener of WormCans


View Profile WWW
« Reply #3 on: February 03, 2008, 12:40:31 PM »

I'm on 1.1.1.  Aye, looks like the creature AI script would probably be the best way to go...  I don't have any other creatures with AI scripts at the moment, but I guess I could simply include the glory-related bits into whatever other scripts I end up using, and then just apply the script to all the creatures via PHPMyAdmin.
Logged

seekey
Codemeister
****
Offline Offline

Posts: 475


Demon to some but Angel to others


View Profile WWW
« Reply #4 on: February 03, 2008, 12:48:56 PM »

Hmmmmmmm Maybe there is a way to do this with a buff, like an specialty. It's just a thought of mine.

Insert a permanent buff via module which give out a message every round. I don't think that you have to edit any core files, beacause you can hook into the battle-buffs. You can allow it in playerfights and insert a setting into the module,  to  collect the glory points.

I am very busy the next time, but if I have some space I can test this and find out if it could work like I think.

Is an A.I. script working at pvp?
« Last Edit: February 03, 2008, 12:51:04 PM by seekey » Logged
CavemanJoe
Mod God
*****
Offline Offline

Posts: 555


Opener of WormCans


View Profile WWW
« Reply #5 on: February 03, 2008, 12:51:54 PM »

Agh.  That'd be the crunch.  It'd have to work in PVP, and I'd actually like it to award more glory in that case...
I like the idea of making it work via a buff, though.  It'd be no problem for me to build this into the race files, since all my races are custom-built anyway (and yes, I'll release them as soon as I'm satisfied they're properly balanced...).
Logged

Velle
Guest
« Reply #6 on: February 03, 2008, 02:24:35 PM »

You can edit a buff to work in PvP as well as in leveling against a master if you wanted that.  Not sure if this code is up to date with 1.1.1 though, but it might be worth a try.

Quote
Allow in PvP

Example:

"allowinpvp"=>1,

Explanation: "Allow in PvP" (Player vs. Player) is a bool that indicates if a player can use this buff in a pvp; hence is only useful if it is set to 1. The main type of buffs that have generally been accepted in pvp are race buffs. Most buffs are NOT "allowed in PvP" in order to preserve game balance.

~~~~~~~~~~~~~~~~~~~~~~
Allow in Training

Example:

"allowintrain"=>1,

Explanation: "Allow in Training" is a bool that indicates if a player can use this buff in training, i.e. when they are fighting their master to increase their level. The main type of buffs that have generally been accepted for in training are race buffs. Most buffs are NOT "allowed in training" in order to preserve game balance.

Hope it helps. I do agree that writing it in as a module instead of into your core might be the best way to go, so that as you test it you can uninstall without screwing the site up if it isn't working proper.  Just a thought.

« Last Edit: February 03, 2008, 02:26:20 PM by Velle » Logged
Iori
Mod God
*****
Offline Offline

Posts: 832


View Profile WWW
« Reply #7 on: February 03, 2008, 07:51:41 PM »

Hmmmmmmm Maybe there is a way to do this with a buff, like an specialty. It's just a thought of mine.

Insert a permanent buff via module which give out a message every round. I don't think that you have to edit any core files, beacause you can hook into the battle-buffs. You can allow it in playerfights and insert a setting into the module,  to  collect the glory points.

I am very busy the next time, but if I have some space I can test this and find out if it could work like I think.

Is an A.I. script working at pvp?

Yes, A.I scripts can work in any battle. Afterall, in PvP, your opponent still functions the same way as forest creatures.

Doing this via a buff is not a good idea for multiple monsters, because buffs cannot keep tracks of all creatures, whereas you can through A.I scripts (each creature can have their own script, even if the scripts are identical). In fact, there is nothing you cannot do with an A.I. script that you can with a buff (since you can even apply buffs from scripts, as well as use functions such as increment_module_pref(), etc). The opposite is not true, however.
Logged

CavemanJoe
Mod God
*****
Offline Offline

Posts: 555


Opener of WormCans


View Profile WWW
« Reply #8 on: April 06, 2008, 07:16:09 PM »

Yup, realised another reason to do it via an AI script - you can only hook into "battle" once per click.  It disregards how many rounds of combat have actually occurred in that one click.  Observe my crappy, first-hour coding:

Code:
<?php

function glory_getmoduleinfo(){
$info = array(
"name"=>"Glory Tracking",
"version"=>"0.1",
"author"=>"Dan Hall",
"category"=>"General",
"download"=>"",
"prefs"=>array(
"glory"=>"Glory points of this player,int|0",
"tempglory"=>"Temporary Glory points,int|0",
"combat_rounds"=>"Rounds of combat,int|0",
),
);
return $info;
}
function 
glory_install(){
module_addhook("battle");
module_addhook("battle-victory");
module_addhook("creatureencounter");
return true;
}
function 
glory_uninstall(){
return true;
}
function 
glory_dohook($hookname,$args){
global $session$badguy;
switch($hookname){
case "creatureencounter":
set_module_pref("tempglory",0);
set_module_pref("combat_rounds",0);
apply_buff('glory', array(
"atkmod"=>1,
"minioncount"=>1,
"rounds"=>1000,
));
break;
case "battle":
// Evaluate the number of rounds that the battle has lasted thus far.  Because this is only called once per click, and the user can choose to play five rounds, ten rounds or to the end of the fight, we've got to get the number of rounds by looking at the remaining rounds left in the buff we set up at newday.
$roundsplayed = (1000-$session['bufflist']['glory']['rounds']);
$roundglory = ((($session['user']['maxhitpoints']-$session['user']['hitpoints'])+$badguy['creaturehealth'])*$roundsplayed);
set_module_pref("combat_rounds"$roundsplayed);
set_module_pref("tempglory"get_module_pref("tempglory")+$roundglory);
output("You have fought for %s rounds.`n",get_module_pref("combat_rounds"));
output("Glory for this round: %s`n",$roundglory);
output("Glory for this fight: %s`n",get_module_pref("tempglory"));
break;
}
return $args;
}
?>

You can probably tell that I wrote the bit to increment combat_rounds first, then came up with a workaround when it didn't do its thing, then - LIKE A MORON - did the same mistake again, going right ahead and writing my glory calculations and then going "Oh, wait, that only happens once per mouse-click."

So, now what?  Is there anything I can hook into that executes with every round of combat, should I set up a loop to check how many rounds were executed and then run the calculations for that number of rounds (and if so how?) or am I really, definitely, positively and without a doubt going to have to do this via an AI script?

And if I do this via an AI script, am I to assume that said AI script would reference variables stored in these moduleprefs when it executes?
Logged

Nevhiliel
Guest
« Reply #9 on: April 06, 2008, 10:33:48 PM »

Maybe you could actually hook into the everyhit-loggedin and then controll via httpget( 'op' ) == 'fight' if you're in a fight or not.
This won't be optimal, but I think it will work.
Logged
Iori
Mod God
*****
Offline Offline

Posts: 832


View Profile WWW
« Reply #10 on: April 06, 2008, 11:27:53 PM »

Maybe you could actually hook into the everyhit-loggedin and then controll via httpget( 'op' ) == 'fight' if you're in a fight or not.
This won't be optimal, but I think it will work.

No, it isn't very optimal at all. CavemanJoe, you might want to see how the Mana module (by Aeriswind) gets around the problem of the hook only executing once per mouseclick. It should be available in the downloads section.
Logged

CavemanJoe
Mod God
*****
Offline Offline

Posts: 555


Opener of WormCans


View Profile WWW
« Reply #11 on: April 07, 2008, 01:00:13 AM »

Well, I had a little think about the way the formula is calculated, and I think I came up with an acceptable compromise.  Now, rather than Glory being awarded with each round of combat, it's only awarded after a successful kill.  The importance of starting a fight with fewer hitpoints is now more emphasized, and I've added a "Streak" value that increments with each fight and resets at death.  Code-in-progress:

Code:
<?php

function glory_getmoduleinfo(){
$info = array(
"name"=>"Glory Tracking",
"version"=>"0.1",
"author"=>"Dan Hall",
"category"=>"General",
"download"=>"",
"prefs"=>array(
"glory"=>"Glory points of this player,int|0",
"tempglory"=>"Temporary Glory points,int|0",
"combat_rounds"=>"Rounds of combat,int|0",
"streak"=>"Number of successive combat rounds,int|1",
"startinghitpoints"=>"Starting hit points,int|1",
"endinghitpoints"=>"Ending hit points,int|1",
),
);
return $info;
}
function 
glory_install(){
module_addhook("battle");
module_addhook("battle-victory");
module_addhook("battle-defeat");
module_addhook("creatureencounter");
module_addhook("charstats");
return true;
}
function 
glory_uninstall(){
return true;
}
function 
glory_dohook($hookname,$args){
global $session$badguy;
switch($hookname){
case "creatureencounter":
set_module_pref("tempglory",0);
set_module_pref("combat_rounds",0);
set_module_pref("streak",get_module_pref("streak")+1);
set_module_pref("startinghitpoints",(1+$session['user']['maxhitpoints']-$session['user']['hitpoints']));
apply_buff('glory', array(
"atkmod"=>1,
"minioncount"=>1,
"rounds"=>1000,
));
break;
case "battle":
// Evaluate the number of rounds that the battle has lasted thus far.  Because this is only called once per click, and the user can choose to play five rounds, ten rounds or to the end of the fight, we've got to get the number of rounds by looking at the remaining rounds left in the buff we set up at newday.
if (has_buff("glory")) {
$roundsplayed = (1000-$session['bufflist']['glory']['rounds']);
set_module_pref("combat_rounds"$roundsplayed);
}
break;
case "battle-victory":
if (has_buff("glory")) {
$endinghitpoints 1+$session['user']['maxhitpoints']-$session['user']['hitpoints'];
$startinghitpoints get_module_pref("startinghitpoints");
$streak get_module_pref("streak");
$combat_rounds get_module_pref("combat_rounds");
$tempglory = ($startinghitpoints $endinghitpoints $combat_rounds $streak);
output("`n`bGlory Point Calculation`b`n");
output("Starting damage: `4`b%s`0`b`n",$startinghitpoints);
output("Ending damage: `4`b%s`0`b`n",$endinghitpoints);
output("Combat Rounds: `4`b%s`0`b`n",$combat_rounds);
output("Successive Successes: `4`b%s`0`b`n",$streak);
output("`bTotal Glory Points awarded for this fight: `4%s`0`b`n`n",$tempglory);
set_module_pref("glory",get_module_pref("glory")+$tempglory);
}
break;
case "battle-defeat":
set_module_pref("streak",0);
break;
case "charstats":
$ccode "`^";
$stat "Glory";
$new $ccode get_module_pref("glory");
setcharstat("Vital Info"$stat$new);
break;
}
return $args;
}
?>

Now, I've just got to figure out under what criteria Glory should reset, and then set up a HOF for it - possibly by figuring out the player's Average Glory Per Fight.  Eventually I'd like to make some other modules (or maybe write some into this) that will reference the Glory stat and Do Things accordingly.

I'll take a look at the Mana system, see if it'll provide any inspiration. Smiley  Thanks for the heads-up.

EDIT: What I could really do with now, since the numbers are so large, is a way to insert thousands seperators.  IE to format 3102345 as 3,102,345.  I'm sure I saw a forum post about this, but I can't for the life of me find it, no matter how I search.  Anyone remember it?
« Last Edit: April 07, 2008, 01:02:42 AM by CavemanJoe » Logged

Sichae
iMod God
SVN Users
Mod God
*
Offline Offline

Posts: 3458


If ya didn't get it by now... you're hopeless...


View Profile WWW
« Reply #12 on: April 07, 2008, 05:11:58 AM »

EDIT: What I could really do with now, since the numbers are so large, is a way to insert thousands seperators.  IE to format 3102345 as 3,102,345.  I'm sure I saw a forum post about this, but I can't for the life of me find it, no matter how I search.  Anyone remember it?

Code:
$number = "10000000";
$number = number_format($number);
output("I have %s dollars.",$number);
Logged

If you didn't understand anything in the above post, don't try to attempt anything suggested.

CavemanJoe
Mod God
*****
Offline Offline

Posts: 555


Opener of WormCans


View Profile WWW
« Reply #13 on: April 08, 2008, 03:22:37 PM »

Fantastic, thankyou. Smiley
Logged

Pages: [1]   Go Up
  Print  
 
Jump to:  


*
DragonPrime Notices
Please take the time to read the FAQ and browse the DragonPedia

Support Us
$100 raised this year
Your help is greatly appreciated!
Who's Online
23 Guests, 0 Users
DragonPrime LoGD
Recent Topics
Home Forums News Links Downloads Login Register Advanced Search