Jump to content
MakeWebGames

[mccode] Buy A House With Level Requirements !


ColdK
 Share

Recommended Posts

i was thinking of a code so if you arnt blah levle to buy the house required level you cannot buy it i was thing of this code in estate.php

 

if($ir['hLevel'] == $ir['level'] )
{
print "You Are Not The Level Required Yet";
}
else
{
$db->query("UPDATE users SET money=money-{$np['hPRICE']},will=0,maxwill={$np['hWILL']} WHERE userid=$userid");
print "You Baught  {$np['hNAME']} .";
}
}

if that would work i dont know and alter the houses tabe with a new row with hLevel

Please comment me and update it if it needs it thanks

Link to comment
Share on other sites

Re: Buy A House With Level Requirements !

 

ALTER TABLE `houses` ADD `hLEVEL` INT(2) NOT NULL default '0'

 

That should work for the SQL.

When i get my laptop back from repair i will post the staff_houses.php edit so you can add the hLEVEL via the panel unless someone else posts.

Until then you will have to edit via the phpmyadmin.

Link to comment
Share on other sites

Re: Buy A House With Level Requirements !

 

ALTER TABLE `houses` ADD `hLEVEL` INT(2) NOT NULL default '0'

 

That should work for the SQL.

When i get my laptop back from repair i will post the staff_houses.php edit so you can add the hLEVEL via the panel unless someone else posts.

Until then you will have to edit via the phpmyadmin.

FAAAAIIILLLL

This would make the max level to buy a house only two digits long meaning the max level would be 99 of course. What if people want an `hLEVEL` to be 125?. I don't see the point in messing with things, should have just left it at int(11). Also I don't think it would need a default, but it works either way I guess.

ALTER TABLE `houses` ADD `hLEVEL` INT(11) NOT NULL default '0'

 

Thank you, and good night !

Link to comment
Share on other sites

Re: [mccode] Buy A House With Level Requirements !

I will go ahead and post it anyway in here so its all together. This is the staff_houses edit that was needed

replace this

 

function addhouse()
{
global $db, $ir, $c, $h, $userid;
$price=abs((int) $_POST['price']);
$will=abs((int) $_POST['will']);
$name=$_POST['name'];
if($price and $will and $name)
{
$q=$db->query("SELECT * FROM houses WHERE hWILL={$will}");
if($db->num_rows($q))
{
print "Sorry, you cannot have two houses with the same maximum will.";
$h->endpage();
exit;
}
$db->query("INSERT INTO houses VALUES(NULL, '$name', '$price', '$will')");
print "House {$name} added to the game.";
stafflog_add("Created House $name");
}
else
{
print "<h3>Add House</h3><hr />
<form action='staff_houses.php?action=addhouse' method='post'>
Name: <input type='text' name='name' />

Price: <input type='text' name='price' />

Max Will: <input type='text' name='will' />

<input type='submit' value='Add House' /></form>";
}
}
function edithouse()
{
global $db, $ir, $c, $h, $userid;
switch($_POST['step'])
{
case "2":
$price=abs((int) $_POST['price']);
$will=abs((int) $_POST['will']);
$q=$db->query("SELECT * FROM houses WHERE hWILL={$will} AND hID!={$_POST['id']}");
if($db->num_rows($q))
{
print "Sorry, you cannot have two houses with the same maximum will.";
$h->endpage();
exit;
}
$name=$_POST['name'];
$q=$db->query("SELECT * FROM houses WHERE hID={$_POST['id']}");
$old=$db->fetch_row($q);
if($old['hWILL'] == 100 && $old['hWILL'] != $will)
{
die("Sorry, this house's will bar cannot be edited.");
}
$db->query("UPDATE houses SET hWILL=$will, hPRICE=$price, hNAME='$name' WHERE hID={$_POST['id']}");
$db->query("UPDATE users SET maxwill=$will WHERE maxwill={$old['hWILL']}");
$db->query("UPDATE users SET will=maxwill WHERE will > maxwill");
print "House $name was edited successfully.";
stafflog_add("Edited house $name");
break;
case "1":
$q=$db->query("SELECT * FROM houses WHERE hID={$_POST['house']}");
$old=$db->fetch_row($q);
print "<h3>Editing a House</h3><hr />
<form action='staff_houses.php?action=edithouse' method='post'>
<input type='hidden' name='step' value='2' />
<input type='hidden' name='id' value='{$_POST['house']}' />
Name: <input type='text' name='name' value='{$old['hNAME']}' />
Price: <input type='text' name='price' value='{$old['hPRICE']}' />

Max Will: <input type='text' name='will' value='{$old['hWILL']}' />

<input type='submit' value='Edit House' /></form>";
break;
default:
print "<h3>Editing a House</h3><hr />
<form action='staff_houses.php?action=edithouse' method='post'>
<input type='hidden' name='step' value='1' />
House: ".house_dropdown($c, "house")."

<input type='submit' value='Edit House' /></form>";
break;
}
}

 

with this

 

function addhouse()
{
global $db, $ir, $c, $h, $userid;
$price=abs((int) $_POST['price']);
$will=abs((int) $_POST['will']);
$level=abs((int) $_POST['level']);
$name=$_POST['name'];
if($price and $will and $name)
{
$q=$db->query("SELECT * FROM houses WHERE hWILL={$will}");
if($db->num_rows($q))
{
print "Sorry, you cannot have two houses with the same maximum will.";
$h->endpage();
exit;
}
$db->query("INSERT INTO houses VALUES(NULL, '$name', '$price', '$will', '$level' )");
print "House {$name} added to the game.";
stafflog_add("Created House $name");
}
else
{
print "<h3>Add House</h3><hr />
<form action='staff_houses.php?action=addhouse' method='post'>
Name: <input type='text' name='name' />

Price: <input type='text' name='price' />

Max Will: <input type='text' name='will' />

Required Level: <input type='text' name='level' />

<input type='submit' value='Add House' /></form>";
}
}
function edithouse()
{
global $db, $ir, $c, $h, $userid;
switch($_POST['step'])
{
case "2":
$price=abs((int) $_POST['price']);
$will=abs((int) $_POST['will']);
$level=abs((int) $_POST['level']);
$q=$db->query("SELECT * FROM houses WHERE hWILL={$will} AND hID!={$_POST['id']}");
if($db->num_rows($q))
{
print "Sorry, you cannot have two houses with the same maximum will.";
$h->endpage();
exit;
}
$name=$_POST['name'];
$q=$db->query("SELECT * FROM houses WHERE hID={$_POST['id']}");
$old=$db->fetch_row($q);
if($old['hWILL'] == 100 && $old['hWILL'] != $will)
{
die("Sorry, this house's will bar cannot be edited.");
}
$db->query("UPDATE houses SET hLEVEL=$level, hWILL=$will, hPRICE=$price, hNAME='$name' WHERE hID={$_POST['id']}");
$db->query("UPDATE users SET maxwill=$will WHERE maxwill={$old['hWILL']}");
$db->query("UPDATE users SET will=maxwill WHERE will > maxwill");
print "House $name was edited successfully.";
stafflog_add("Edited house $name");
break;
case "1":
$q=$db->query("SELECT * FROM houses WHERE hID={$_POST['house']}");
$old=$db->fetch_row($q);
print "<h3>Editing a House</h3><hr />
<form action='staff_houses.php?action=edithouse' method='post'>
<input type='hidden' name='step' value='2' />
<input type='hidden' name='id' value='{$_POST['house']}' />
Name: <input type='text' name='name' value='{$old['hNAME']}' />
Price: <input type='text' name='price' value='{$old['hPRICE']}' />

Max Will: <input type='text' name='will' value='{$old['hWILL']}' />

Required Level: <input type='text' name='level' value='{$old['hLEVEL']}' />

<input type='submit' value='Edit House' /></form>";
break;
default:
print "<h3>Editing a House</h3><hr />
<form action='staff_houses.php?action=edithouse' method='post'>
<input type='hidden' name='step' value='1' />
House: ".house_dropdown($c, "house")."

<input type='submit' value='Edit House' /></form>";
break;
}
}
Link to comment
Share on other sites

Re: Buy A House With Level Requirements !

 

ALTER TABLE `houses` ADD `hLEVEL` INT(2) NOT NULL default '0'

 

That should work for the SQL.

When i get my laptop back from repair i will post the staff_houses.php edit so you can add the hLEVEL via the panel unless someone else posts.

Until then you will have to edit via the phpmyadmin.

FAAAAIIILLLL

This would make the max level to buy a house only two digits long meaning the max level would be 99 of course. What if people want an `hLEVEL` to be 125?. I don't see the point in messing with things, should have just left it at int(11). Also I don't think it would need a default, but it works either way I guess.

ALTER TABLE `houses` ADD `hLEVEL` INT(11) NOT NULL default '0'

 

Thank you, and good night !

The sql works perfectly and i set it at 2 for a reason, sure your going to need ( 11,000,000,000) as the default for a house number. I use INT(2) in my own game, sure change it if you need it but that is not a fail as it works perfectly. OF course it needs a default, if you add a new house and the level isnt set its going to bring an error without the default.

Also i use INT(2) etc because everyone uses INT(11) because thats all they know. Why follow the others, be creaive and different.

Link to comment
Share on other sites

Re: Buy A House With Level Requirements !

 

ALTER TABLE `houses` ADD `hLEVEL` INT(2) NOT NULL default '0'

 

That should work for the SQL.

When i get my laptop back from repair i will post the staff_houses.php edit so you can add the hLEVEL via the panel unless someone else posts.

Until then you will have to edit via the phpmyadmin.

FAAAAIIILLLL

This would make the max level to buy a house only two digits long meaning the max level would be 99 of course. What if people want an `hLEVEL` to be 125?. I don't see the point in messing with things, should have just left it at int(11). Also I don't think it would need a default, but it works either way I guess.

ALTER TABLE `houses` ADD `hLEVEL` INT(11) NOT NULL default '0'

 

Thank you, and good night !

The sql works perfectly and i set it at 2 for a reason, sure your going to need ( 11,000,000,000) as the default for a house number. I use INT(2) in my own game, sure change it if you need it but that is not a fail as it works perfectly. OF course it needs a default, if you add a new house and the level isnt set its going to bring an error without the default.

Also i use INT(2) etc because everyone uses INT(11) because thats all they know. Why follow the others, be creaive and different.

*cough*

Jesus.

Like I said before, That ony allows people to have an "hLEVEL" of max 99 and min 1. So what if someone wanted an "hLEVEL" of 100? (rhetorical)

That is why it should just be left as it is. So what if everyone else has it that way? (also rhetorical)

It actually amazes me at how ignorant people are these days...

Link to comment
Share on other sites

Re: [mccode] Buy A House With Level Requirements !

*Ignorant he says*

Im finding that rather hypocrytical at the moment. You fail to understand that there are games that dont allow people over level 100, or they have slow level climbing ill call first to mind.

TORN CITY - Highest level is maybe 70 and thats over 1400 days.

If people want to have higher levels then put INT(11) its not that hard to comprehend dude. Ofcourse i dont use int(2) for everything but for things like this i do, whats the point as i say before for allowing levels such as (99,999,999,999) as max level for a house, i mean wtf?

And you call me ignorant when your blatent to the point of this subject.

I dont need your advice on what code i need for my forumlas on my game as i do not waste space, i choose the correct setting for each row in every table and if i used that, i would only need a 2.

So do not reply to this because it will be just another post with no concept or idea, just trying to prove yourself when there is nothing to prove accept your wrong in the circumstances im in.

Thats all

Link to comment
Share on other sites

  • 2 weeks later...

Re: [mccode] Buy A House With Level Requirements !

Hey, hope this isn't a newb post, but I found the code to add to estate.php to work good with:

else if($ir['hLevel'] < $ir['level'] ){

print "You Are Not The Level Required Yet.";}

For some reason the other didn't work for me.. anyway, just posting this in case it is helpful.

Link to comment
Share on other sites

Guest Anonymous

Re: [mccode] Buy A House With Level Requirements !

Lets just try a little test:

 

DROP TABLE IF EXISTS `Sample`;
CREATE TABLE IF NOT EXISTS `Sample`
(
 `id` int(10) unsigned NOT NULL,
 `value` int(2) unsigned NOT NULL
)
ENGINE=MyISAM;

INSERT INTO `Sample` (`id`, `value`) VALUES
(456, 456),
(123, 123);

SELECT * FROM `Sample`;
+-----+-------+
|  id | value |
+-----+-------+
| 456 |   456 |
| 123 |   123 |
+-----+-------+

 

Looks like restricting the field width with INT(2) just doesn't work anyway. How odd...

Link to comment
Share on other sites

Re: [mccode] Buy A House With Level Requirements !

 

Lets just try a little test:

 

DROP TABLE IF EXISTS `Sample`;
CREATE TABLE IF NOT EXISTS `Sample`
(
 `id` int(10) unsigned NOT NULL,
 `value` int(2) unsigned NOT NULL
)
ENGINE=MyISAM;

INSERT INTO `Sample` (`id`, `value`) VALUES
(456, 456),
(123, 123);

SELECT * FROM `Sample`;
+-----+-------+
|  id | value |
+-----+-------+
| 456 |   456 |
| 123 |   123 |
+-----+-------+

 

Looks like restricting the field width with INT(2) just doesn't work anyway. How odd...

Whats the point posting somthing hardly anyone understands.

Link to comment
Share on other sites

  • 2 weeks later...
Guest Anonymous

Re: [mccode] Buy A House With Level Requirements !

Hehe - It's is surprisingly basic stuff really. It's even in the manual! It's also a question that crops up from time to time here and in chat and people who actually try it and realize what the results mean usually end up having a better understanding of the language itself.

Link to comment
Share on other sites

  • 1 month later...

Re: [mccode] Buy A House With Level Requirements !

WOWOWOWO is it just me or is this totally wrong?

 

if($ir['hLevel'] == $ir['level'] )
{
print "You Are Not The Level Required Yet";
}
else
{
$db->query("UPDATE users SET money=money-{$np['hPRICE']},will=0,maxwill={$np['hWILL']} WHERE userid=$userid");
print "You Baught  {$np['hNAME']} .";
}
}

 

If the house level equals your level, you are NOT required level? I think you got it the wrong way round.

Link to comment
Share on other sites

Re: [mccode] Buy A House With Level Requirements !

 

if($ir['hLevel'] > $ir['level'] )
{
print "You Are Not The Level Required Yet";
}
else
{
$db->query("UPDATE users SET money=money-{$np['hPRICE']},will=0,maxwill={$np['hWILL']} WHERE userid=$userid");
print "You Baught  {$np['hNAME']} .";
}
}
Link to comment
Share on other sites

Re: [mccode] Buy A House With Level Requirements !

 

Lets just try a little test:

 

DROP TABLE IF EXISTS `Sample`;
CREATE TABLE IF NOT EXISTS `Sample`
(
 `id` int(10) unsigned NOT NULL,
 `value` int(2) unsigned NOT NULL
)
ENGINE=MyISAM;

INSERT INTO `Sample` (`id`, `value`) VALUES
(456, 456),
(123, 123);

SELECT * FROM `Sample`;
+-----+-------+
|  id | value |
+-----+-------+
| 456 |   456 |
| 123 |   123 |
+-----+-------+

 

Looks like restricting the field width with INT(2) just doesn't work anyway. How odd...

The answer is to use TINYINT right?

A signed TINYINT can go from -127 to +127 which is more than enough needed. If i am correct the number in brackets (e.g INT(11)) or "display width" is for returning the value, therefore the display width wouldn't restrict data held in the field.

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.

 Share

×
×
  • Create New...