Newbie Posted July 4, 2012 Posted July 4, 2012 (edited) when i say a mod its more of just a small function What it does: checks users money and bank money and gives them respect based on the money they have function calcRespect($user=0) { global $db, $ir; if($user != 0) { $user_pull = $db->query("SELECT money, bankmoney FROM users WHERE userid = ".abs((int)$user)); $user = $db->fetch_row($user_pull); } else { $user = $ir; } $respect= (($user['money']+$user['bankmoney'])/1500*1)+5; return round($respect); } cant get it to work on the gangsters legend script it shows up as 5 respect as thats what they get when they start iam not to sure on the id and ($user['money']) Here is what i tried. function calcRespect($user=0) { if($user != 0) { $user_pull = mysql_query("SELECT money, bank FROM login WHERE id='" .mysql_real_escape_string($_SESSION["user_id"]). "'"); $user = mysql_fetch_object($user_pull); } else { $user = $ir; } $respect= (($user['money']+$user['bank'])/1500*1)+5; return round($respect); } Edited July 5, 2012 by Newbie Quote
Dayo Posted July 5, 2012 Posted July 5, 2012 (edited) What's the error ur getting? Plus you don't need to call global $db, $ir; and try changing MRES to abs(intval($user)) Edited July 5, 2012 by Dayo Quote
lucky3809 Posted July 5, 2012 Posted July 5, 2012 (edited) yep mres is for alpha fields not numeric... could be your problem change it to abs(intval()) maths can be the problem also $respect= (($user['money']+$user['bankmoney'])/1500*1)+5; a user that is new will have 0 money and bank money which would be 0 after dividing it and times it by 1 plus 5 would only give them 5 respect.... You also have it to round that number... Edited July 5, 2012 by lucky3809 Quote
Newbie Posted July 5, 2012 Author Posted July 5, 2012 (edited) [ATTACH=CONFIG]523[/ATTACH] There is no errors when im using it its just not giving them respect the way its set out is it should start out with 5 respect and gain 1 respect for every $1500 they make but it aint adding on the respect after they gain money i didn't think i would need the globals yep mres is for alpha fields not numeric... could be your problem change it to abs(intval()) maths can be the problem also $respect= (($user['money']+$user['bankmoney'])/1500*1)+5; a user that is new will have 0 money and bank money which would be 0 after dividing it and times it by 1 plus 5 would only give them 5 respect.... You also have it to round that number... when a user joins the game they start with $1500 this works fine on mccodes the way it is just because gl engine is coded differently Edited July 5, 2012 by Newbie Quote
Dayo Posted July 5, 2012 Posted July 5, 2012 I think it could be the SQL try removing the MRES and replace with abs(intval()) it would always show as 5 if the query is empty as the default values would be 0 Quote
Newbie Posted July 5, 2012 Author Posted July 5, 2012 there is no sql file needed for this as i said it works fine on mccodes v2 as thats what i paid for it to be codded for but i took a interest in the gl engine again and want to have it here what do you mean take out the mres? thanks for reply's steve Quote
Seker Posted July 5, 2012 Posted July 5, 2012 there is no sql file needed for this as i said it works fine on mccodes v2 as thats what i paid for it to be codded for but i took a interest in the gl engine again and want to have it here what do you mean take out the mres? thanks for reply's steve Change: mysql_real_escape_string($_SESSION["user_id"]) To: abs(intval($_SESSION["user_id"]) Since MRES does nothing for numbers. Quote
Newbie Posted July 5, 2012 Author Posted July 5, 2012 alright done that still no change heres what i got so far function calcRespect($user=0) { if($user != 0) { $user_pull = mysql_query("SELECT money, bank FROM login WHERE id='" .abs(intval($_SESSION["user_id"])). "'"); $user = mysql_fetch_object($user_pull); } else { $user = $ir; } $respect= (($user['money']+$user['bank'])/1500*1)+5; return round($respect); } since the globals bit has been taken out what would this be changed to $user = $ir; Quote
Seker Posted July 5, 2012 Posted July 5, 2012 alright done that still no change heres what i got so far function calcRespect($user=0) { if($user != 0) { $user_pull = mysql_query("SELECT money, bank FROM login WHERE id='" .abs(intval($_SESSION["user_id"])). "'"); $user = mysql_fetch_object($user_pull); } else { $user = $ir; } $respect= (($user['money']+$user['bank'])/1500*1)+5; return round($respect); } since the globals bit has been taken out what would this be changed to $user = $ir; From the looks of it, you're not even using it. Seems like you could take out that line completely and just change $user to whatever GL's call to the user info is. (As in, $ir is the user info call for MCCodes) I could be mistaken, though. Just a thought. Quote
Newbie Posted July 5, 2012 Author Posted July 5, 2012 Sounds right but still no luck finding it will keep looking Quote
Newbie Posted July 6, 2012 Author Posted July 6, 2012 (edited) Should cover all issues; function calcRespect($user = false) { if (isset($user) && ctype_digit($user)) { // Initial return (ret) value as false. $ret = false; $sql = "SELECT `money`, `bank` FROM `login` WHERE `id` = '{$user}'"; // Run SQL. On error: Output error. (Should be removed before made live. // Infact, delete line above this line, this line and the line below and below the one below, // then uncomment the next one down, after testing :P $run = mysql_query($sql) or die('Error in query: ' . htmlspecialchars($sql)); //$run = mysql_query($sql); if (mysql_num_rows($run) == 1) { $res = mysql_fetch_assoc($run); $ret = floor(($res['money'] + $res['bank']) / 1500) + 5; } return $ret; } // If the whole function fails. return false; } And of course, call the function :P calcRespect($whatever_defines_users_id_here); Suspected usage; $respect = calcRespect($this->_user); $sql = "UPDATE TABLE `table_name` SET `respect_row` = `respect_row` + '{$respect}' WHERE `id` = '{$this-_user}'"; mysql_query($sql); echo 'You gained ' . number_format($respect) . ' respect. blah. blah. blah.'; works like a charm thanks alot SRB and everyone else who helped :) It worked when i added ($_SESSION['user_id']) but it gave everyone the same respect as you said will need to find the proper way to get the id just go through every file untill i see it Edited July 6, 2012 by Newbie Quote
Newbie Posted July 6, 2012 Author Posted July 6, 2012 (edited) it was giving everyone the same respect as me. i got it fixed now i went through the files again and found the id was simple actually surprised i never tried it $id is what i used and it works now tested with 2 accounts Edited July 6, 2012 by Newbie ops forgot thanks again eveyone been big help Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.