DragonPrime - LoGD Resource Community
Welcome Guest
  • Good evening, Guest.
    Please log in, or register.
  • December 14, 2017, 10:25:01 PM
Home Forums News Downloads Login Register Advanced Search
* * *
DragonPrime Menu
Login
 
 
Resource Pages
Search

Pages: [1]   Go Down
  Print  
Author Topic: Question About Item System  (Read 273 times)
0 Members and 1 Guest are viewing this topic.
TGTarheel
Captain of the Guard
***
Offline Offline

Posts: 189


View Profile
« 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?
Logged
Stephen.Kise
Codemeister
****
Offline Offline

Posts: 380


So meme'd up.


View Profile
« Reply #1 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);
}
Logged

Slowly progressing fork with PHP 7 support: https://github.com/stephenKise/Legend-of-the-Green-Dragon
Cheap VPS Hosting (10$ credit!): https://m.do.co/c/acde75b086c5
TGTarheel
Captain of the Guard
***
Offline Offline

Posts: 189


View Profile
« Reply #2 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.
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
14 Guests, 0 Users
Home Forums News Downloads Login Register Advanced Search