Jump to content
MakeWebGames

Property with random crystal drop


danman24

Recommended Posts

Hey evertone. ive been trying to make a property that will randomly drop crystals to the user as they play. i havnt had any luck messing around with it. is there anyone willing to help out? im not even sure how to go about doing it really. still new to coding. if youre not willing to help please dont leave smart (BLEEP) comments.

Link to comment
Share on other sites

Well, I'm not sure what you mean by property, but take a look at rand(); use that for the random number of crystals you would like to give. Then have a query which updates the users crystals and add on the random amount. So something like this:

 

// Will give a random number between 1-5
$random = rand(1, 5);

// The query to update the users, the field may not be called crystals (I'm not sure). Make sure you have the "WHERE" or you will update everyone.
$updateCrystals = $db->query("UPDATE `users` SET crystals=crystals+$random WHERE userid=$userid");

 

Other than that, I think you should know how to add you own things.

Link to comment
Share on other sites

sounds like you need something like a hourly rewards module. I don't really see why you would want houses to drop random crystals

 

# In case you want to set a different type of prices for houses 
if($ir['house'] > 1 && $ir['house'] < 10) {
# Lets set a chance so the user doesn't always get crystals
$chance = rand(1,1000); 
if($chance == 1) {
	# As kyle says sets a random amount of crystals from 5-10
	$amount = rand(5,10);
	$db->query("UPDATE `users` SET `crystals` = `crystals` + '$amount' WHERE `userid` = '$userid'");
} else if($chance == 25) {
	$amount = rand(1,2) {
	$db->query("UPDATE `users` SET `crystals` = `crystals` + '$amount' WHERE `userid` = '$userid'");
} else if($chance > 800) {
	$amount = rand(7,6) {
	$db->query("UPDATE `users` SET `crystals` = `crystals` + '$amount' WHERE `userid` = '$userid'");
}
} 
else if($ir['house'] > 9) {
# code goes here
}
Link to comment
Share on other sites

sounds like you need something like a hourly rewards module. I don't really see why you would want houses to drop random crystals

 

# In case you want to set a different type of prices for houses 
if($ir['house'] > 1 && $ir['house'] < 10) {
   # Lets set a chance so the user doesn't always get crystals
   $chance = rand(1,1000); 
   if($chance == 1) {
       # As kyle says sets a random amount of crystals from 5-10
       $amount = rand(5,10);
       $db->query("UPDATE `users` SET `crystals` = `crystals` + '$amount' WHERE `userid` = '$userid'");
   } else if($chance == 25) {
       $amount = rand(1,2) {
       $db->query("UPDATE `users` SET `crystals` = `crystals` + '$amount' WHERE `userid` = '$userid'");
   } else if($chance > 800) {
       $amount = rand(7,6) {
       $db->query("UPDATE `users` SET `crystals` = `crystals` + '$amount' WHERE `userid` = '$userid'");
   }
} 
else if($ir['house'] > 9) {
   # code goes here
}

Ummm......

Thats not me :p that would be [MENTION=69670]Script47[/MENTION]. Yes I know our avatars look exactly the same haha

Link to comment
Share on other sites

Not tested it but this in theory should work (just place it in your header.php somewhere I guess):

<?php
// ID of the property that gives the crystals
$property_id = X;

if($ir['house'] === $property_id) {
   // User has the property that has random drops
   //  generate two random numbers and check if they match
   $chance1 = mt_rand(1,10);
   $chance2 = mt_rand(1,10);
   $crystal_gain = 3;

   if($chance1 === $chance2) {
       // got the crystals so update user reccord
       $sql = sprintf("UPDATE `users` SET `crystals` = `crystals` + %u WHERE `userid` = %u;", $crystal_gain, $userid);
       $db->query($sql);  
   }
} 
?>
Link to comment
Share on other sites

Ive sent you my skype so if you require help with a few things im here.

http://makewebgames.io/showthread.php/40980-Hourly-Reward - A module by Newbie, simple but effective and is pretty much what you are asking for here.

If you want this to work with the propertys then it shouldn't be hard to insert.

Otherwise id suggest keep this module as it is but neaten it up a little.

Link to comment
Share on other sites

Ummm......

Thats not me :p that would be [MENTION=69670]Script47[/MENTION]. Yes I know our avatars look exactly the same haha

Yeah haha. Kyle has the smaller beard. :D

I would think instead of giving him full codes or links to other modules, people would encourage him to code it himself. So merely directing them in the right direction, just my opinion though.

Link to comment
Share on other sites

Ive sent you my skype so if you require help with a few things im here.

http://makewebgames.io/showthread.php/40980-Hourly-Reward - A module by Newbie, simple but effective and is pretty much what you are asking for here.

If you want this to work with the property then it shouldn't be hard to insert.

Otherwise id suggest keep this module as it is but neaten it up a little.

ah you found my old module yep its pretty basic if my memory serves me correctly someone did a recoded version of it

Link to comment
Share on other sites

nice guys! ive always tried coding things on my own i was just having trouble with this one. i was trying to use {$ir['maxwill']} and couldnt get it to work the way i wanted it to. im not looking for full codes at all just more guidance. also i think giving the user a chance to NOT get random drops was eluding me. im really new to random functions. Also the reason i want random crystal drops for a property is because its for my game's top property which will be a donation items. :) I thank you all for your assistance. This website has lived up to its reputation for great people.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...