DragonPrime - LoGD Resource Community
Welcome Guest
  • Good morning, Guest.
    Please log in, or register.
  • July 25, 2017, 09:32:31 AM
Home Forums News Downloads Login Register Advanced Search
* * *
DragonPrime Menu
Login
 
 
Resource Pages
Search

Pages: [1]   Go Down
  Print  
Author Topic: Anyone want to help with my Luck system?  (Read 144 times)
0 Members and 1 Guest are viewing this topic.
Dax
Member

Offline Offline

Posts: 2


View Profile
« on: July 13, 2017, 05:23:08 PM »

So I'm (slowly and brokenly) building a Luck system for my server. So far the only thing that is (what I consider to be) complete is the core, luck.php (based off, you guessed it, the Alignment Core). I tried to use the 'Find and Replace' method, but I kept getting confused lol. What I ended up doing was opening a blank file and alignment.php side-by-side and copying line-by line, and making my modifications when I needed to. It ended up working pretty well, I think.

Save as luck.php if you want to try it out, but as it is it only hooks into mounts and creatures to increase and decrease the stat.
Code:
<?php
function luck_getmoduleinfo(){
$info = array(
"name"=>"Luck",
"version"=>"1.0",
"author"=>"`!David Murray</br>`0 based on Chris Vorndran's Alignment Core</br>`6Original Script by: `QWebPixie",
                
"download"=>"N/a",
"category"=>"Stat Display",
"settings"=>array(
"Luck Settings,title",
"goodluck"=>"Good luck begin,int|50",
"Numbers in between will be neutral,note",
"badluck"=>"Bad luck begin,int|-50",
"Luck Display Settings,title",
"shead"=>"What stat heading should this go under?,text|Vital Info",
"show-luck"=>"Display luck as integer?,bool|0",
"sbio"=>"Should luck be displayed in bio?,bool|0",
),
"prefs-mounts"=>array(
"Mount Luck Settings,title",
"ml"=>"How much does having this mount affect a player's luck?,int|0",
),
"prefs-creatures"=>array(
"Creature Luck Settings,title",
"cl"=>"How much does killing this creature affect player's luck?,int|0",
),
"prefs"=>array(
"Luck User Preferences,title",
"luck"=>"Current luck,int|0",
),
);
return $info;
}

function 
luck_install(){
module_addhook("charstats");
module_addhook("newday");
module_addhook("biostat");
module_addhook("battle-victory");
    return 
true;
}

function 
luck_uninstall(){
return true;
}

function 
luck($val,$user=FALSE){

$val = (int)$val;
$hook modulehook('luck-val-adjust', array('modifier'=>1));
if (!isset($hook['modifier']))
$modifier 1;
else
$modifier $hook['modifier'];
$newval round($val $modifier,0);
increment_module_pref('luck',$newval,'luck',$user);
}

function 
get_luck($user=false){
$val get_module_pref('luck','luck',$user);
return $val;
}

function 
set_luck($val,$user=false){
set_module_pref('luck',$val,'luck',$user);
}

function 
luck_dohook($hookname,$args){
global $session,$badguy,$options;
$stat translate_inline("Fortune");
$goodluck get_module_setting("goodluck");
$badluck get_module_setting("badluck");
$lucky translate_inline("`@Lucky");
$unlucky translate_inline("`\$Unlucky");
$meh translate_inline("`0Meh");

switch($hookname){
case "charstats":
$val get_module_pref("luck");
$loc get_module_setting("shead");
$nval "";
if (get_module_setting("show-luck")) $nval "(`b$val`b)";
if($val >= $goodluck){
$newval sprintf("`b%s`b %s",$lucky,$nval);
}
if ($val <= $badluck){
$newval sprintf("`b%s`b %s",$unlucky,$nval);
}
if ($val $goodluck && $val $badluck){
$newval sprintf("`b%s`b %s",$meh,$nval);
}
setcharstat($loc$stat$newval);
break;
case "newday":
$id $session['user']['hashorse'];
if ($id){
$ml get_module_objpref("mounts",$id,"ml");
if ($ml != 0){
luck($ml);
}
}
break;
case "biostat";
$userluck get_luck($args['acctid']);
if (get_module_setting("sbio")) {
if ($userluck >= $goodluckoutput("`^Fortune: %s`n",$lucky);
if ($userluck <= $badluckoutput("`^Fortune: %s`n",$unlucky);
if ($userluck $badluck && $userluck $goodluckoutput("`^Fortune: %s`n",$meh);
}
break;
case "battle-victory":
if ($options['type'] == 'forest' || $options['type'] == 'travel'){
//debug($options);
//debug($badguy);
$id $badguy['creatureid'];
$cl get_module_objpref("creatures",$id,"cl");
if ($cl != ""){
 luck($cl);
}
}
break;
}
return $args;
}

function 
luck_run(){

}
?>

If anyone has any suggestions how this could be improved, I'm completely open. Also, if I didn't change enough to reverse the author field and of course I'll fix it.

Two additional files I'm working on to compliment this budding Luck system are goldenmonkey.php and luckyornot.php - the former being a pet, the latter being forest/village events.

I'm having a little problem setting a variable raw chance with the goldenmonkey though. This is what I have:

Code:
function goldenmonkey_dohook($hookname,$args){
...
case "header-village":
$monkeygift = get_module_setting("monkeygift","goldenmonkey");
if(!$haspet){
module_addeventhook("village", "return 0;");
}else{
module_addeventhook("village", "return $monkeygift;");
}
break;

But I'm sure there's a more efficient way to do this, right? This adds the eventhook every page load, which seems like it's gonna slow my server down once it's open to the public.
« Last Edit: July 13, 2017, 05:33:53 PM by Dax » Logged
TGTarheel
Militia
**
Offline Offline

Posts: 81


View Profile
« Reply #1 on: July 13, 2017, 09:28:30 PM »

Hummm...I did something similar, but as core and module alterations.

I used Item System to create an Item called Felix Felicitas 9after harry Potter fame) and it gives you a day of better luck.

Perhaps you might wish to M me to see the actual script the Item uses, and it may assist you in this.  PM me if you want this.

I have Felix Felicitas checked for in several modukes, and your chances of a better outcome are improved if you have it.

You might be able to use my script for my Item in a similar way.
Logged
MarcTheSlayer
Mod God
*****
Offline Offline

Posts: 1738


View Profile
« Reply #2 on: July 14, 2017, 08:23:39 AM »

Nice module, a few pointers for you. Smiley

1. Your module is called luck, so all functions within the file must start with this. get_luck() or set_luck should be reversed. Also maybe change luck() to luck_add().

2. You need to hook into where mounts are bought and sold and add/remove luck there as needed.

Have you thought about luck just being used to stop a player from dying? Mounts/pets/events give luck up to 100%, but instead of dying, part of your luck is used up to save you, decided in the settings.

1. Mount gives you +50.
2. Pet gives you +15.
3. You find gold in the village, that was lucky +5
4. Wow, you find a gem in the forest +5.
5. A forest creature has a luck of 10, but only if it defeats you does it's luck get removed from the players to calculate if the player's lucky enough to not die.

Code:
<?php
$players_luck 
75;
$creatures_luck 10;

if( (
$players_luck-$creatures_luck) > rand(1100) )
{
    
// Player lives!!!!
    // Some luck was used up to save you, get value from settings.
}

6. Luck gets reset on a newday.

Regarding adding an event hook, these should be done in the install function and look something like,
Code:
<?php
module_addeventhook
("village","\$bought=get_module_pref(\"bought\", \"abigail\");return (\$bought?0:50);");

Smiley
Logged

Pages: [1]   Go Up
  Print  
 
Jump to:  


*
DragonPrime Notices
Play LoGD on Dragonprime

Support Us
No funds raised yet this year
Your help is greatly appreciated!
Recent Topics
DragonPrime LoGD
Who's Online
26 Guests, 0 Users
Home Forums News Downloads Login Register Advanced Search