Jump to content
MakeWebGames

need help transfering a small mod to gl engine


Newbie

Recommended Posts

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 by Newbie
Link to comment
Share on other sites

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 by lucky3809
Link to comment
Share on other sites

[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

screenshot.thumb.jpg.c6a4116bba2e465f6913287be7e10d69.jpg

Edited by Newbie
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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;
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 by Newbie
Link to comment
Share on other sites

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 by Newbie
ops forgot thanks again eveyone been big help
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...