DragonPrime - LoGD Resource Community

Coding Support => Coding Support Desk => Topic started by: TGTarheel on November 02, 2017, 06:49:43 PM



Title: Question About Item System
Post by: TGTarheel on November 02, 2017, 06:49:43 PM
ok, you probably don't need to really know the Item System to do this...

There are settings that allow certain items to be destroyed on a dragon kill.  You have to set the chances for each item.

BUT...the hook for dragonkill looks like this
Code:
<?php
require_once(
"lib/itemhandler.php");
$inventory get_inventory();
$count=0;
while ($item db_fetch_assoc($inventory)) {
$destroyed 0;
for($c=0;$c<$item['quantity'];$c++) {
if($item['dkloosechance'] >= e_rand(1,100)) $destroyed++;

}
if ($destroyedremove_item((int)$item['itemid'], $destroyed);
$count+=$destroyed;
}
if ($count == 1) {
output("`n`2Shattered around you lie the remains of a once mighty item destroyed by the power of the dragon's flames. ");
} else if ($count 1) {
output("`n`2Shattered around you lie the remains of once mighty items destroyed by the power of the dragon's flames. ");
output("It seems `^%s items`2 have been destroyed."$count);
}
?>


Now...what I'd LIKE to do is make it so that ONLY if you are over 100 dragon kills could you have items destoryed.

SO....

If I wrapped an If around the entire thing...would that prevent those under 100 from having anything detroyed...like this...
Code:
<?php


if ($session['user']['dragonkills'] >= 100) {


require_once("lib/itemhandler.php");
$inventory get_inventory();
$count=0;
while ($item db_fetch_assoc($inventory)) {
$destroyed 0;
for($c=0;$c<$item['quantity'];$c++) {
if($item['dkloosechance'] >= e_rand(1,100)) $destroyed++;

}
if ($destroyedremove_item((int)$item['itemid'], $destroyed);
$count+=$destroyed;
}
if ($count == 1) {
output("`n`2Shattered around you lie the remains of a once mighty item destroyed by the power of the dragon's flames. ");
} else if ($count 1) {
output("`n`2Shattered around you lie the remains of once mighty items destroyed by the power of the dragon's flames. ");
output("It seems `^%s items`2 have been destroyed."$count);
}

} else {}


?>

Would that achieve what I am after...so that ONLY after 100 dragonkills...could items be destroyed by the dragon?


Title: Re: Question About Item System
Post by: Stephen.Kise on November 06, 2017, 04:35:58 AM
I have not looked at the item system module at all, and you did not provide a full snippet of the _dohook() function, so I am going to assume that this is in a switch case. It is better to just add a break for those under 100 Dragon kills - it will look a lot nicer in the code, rather than wrapping everything in an if statement.

Code:
<?php
        
global $session;
        if (
$session['user']['dragonkills'] <= 100) {
            break;
        }
require_once("lib/itemhandler.php");
$inventory get_inventory();
$count=0;
while ($item db_fetch_assoc($inventory)) {
$destroyed 0;
for($c=0;$c<$item['quantity'];$c++) {
if($item['dkloosechance'] >= e_rand(1,100)) $destroyed++;

}
if ($destroyedremove_item((int)$item['itemid'], $destroyed);
$count+=$destroyed;
}
if ($count == 1) {
output("`n`2Shattered around you lie the remains of a once mighty item destroyed by the power of the dragon's flames. ");
} else if ($count 1) {
output("`n`2Shattered around you lie the remains of once mighty items destroyed by the power of the dragon's flames. ");
output("It seems `^%s items`2 have been destroyed."$count);
}


Title: Re: Question About Item System
Post by: TGTarheel on November 06, 2017, 09:40:50 AM
I have not looked at the item system module at all, and you did not provide a full snippet of the _dohook() function, so I am going to assume that this is in a switch case. It is better to just add a break for those under 100 Dragon kills - it will look a lot nicer in the code, rather than wrapping everything in an if statement.

Code:
<?php
        
global $session;
        if (
$session['user']['dragonkills'] <= 100) {
            break;
        }
require_once("lib/itemhandler.php");
$inventory get_inventory();
$count=0;
while ($item db_fetch_assoc($inventory)) {
$destroyed 0;
for($c=0;$c<$item['quantity'];$c++) {
if($item['dkloosechance'] >= e_rand(1,100)) $destroyed++;

}
if ($destroyedremove_item((int)$item['itemid'], $destroyed);
$count+=$destroyed;
}
if ($count == 1) {
output("`n`2Shattered around you lie the remains of a once mighty item destroyed by the power of the dragon's flames. ");
} else if ($count 1) {
output("`n`2Shattered around you lie the remains of once mighty items destroyed by the power of the dragon's flames. ");
output("It seems `^%s items`2 have been destroyed."$count);
}

So it accomplished the same thing...
It just breaks the case if under 100 dragonkills, and allows it to continue if not.

Thanks.

Not sure really why that is cleaner...I guess I do not know a whole lot about standards and practices...I'm a pretty sloppy coder and always have just done what works, regardless of any standards or protocols, LOL.

Thanks for this, I will try it.

It seems like this would work, from what I know of the code.

Just trying to add a machanism in that balances the game a bit for the elite players, and helps the newbies.

© 2017 DragonPrime - LoGD Resource Community
Email Talisman: talisman -at- gmail.com
&oeXs)2U7=V BmܲV.U e=;p\}eG )Jj} C5EH7ˤH=j } mo|*Ŋw{drV_@IV>/- TFQJ׀̀Ve}l1,V O iNYx͘$e$;
Forums: Powered by SMF 1.1.21 | SMF © 2006-2007, Simple Machines