Jump to content
MakeWebGames

Getting the wrong NPC


Damond

Recommended Posts

Hello everyone,

So I'm fairly new to the PHP and MySQL scene and I know it is just something simple that I am over looking.

I am using a version of streets that allows you to attack the NPCs for experience. We have a rank system and want our players to be able to attack only the NPC of equal rank.

Here is my query:

 

else if($step['reward_type'] == 'npc'){
   $q=$db->query("SELECT cb.*,u.* FROM challengebots cb LEFT JOIN users u ON cb.cb_npcid=u.userid LEFT JOIN cities cy ON u.location=cy.cityid WHERE u.level <= {$ir['level']} LIMIT 1"); 
   $s=$db->fetch_row($q);
   print"While out prowling you run into {$s['username']}, they seem to be looking for a fight.<br />
   <a href='npc_attack.php?ID={$s['userid']}'>Fight them?</a><br/>";
}

For some reason it is always giving you the lowest level NPC not the one closest to your level without going over your level.

I added a second attack page called npc_attack.php so that I could take out the location restriction and you could fight any NPC for any town while in your streets.

As I said I know it is something simple that I am just over looking, but again I'm really new to using PHP and MySQL.

Thanks for any help.

Edited by KyleMassacre
Added code tags And fixed formatting
Link to comment
Share on other sites

[MENTION=65530]Coly010[/MENTION] Firstly no that's not right. One cb_level doesn't exist in the challengebots table, two he wants it to select closest to the users level but not above so if you have a bot that is level 100 and you're level 110 and the next bot above is level 150 then it selects the level 100 bot and not above or say the level 1 bot.

Link to comment
Share on other sites

Can you please use the code or php tags when you post code? It's makes it easy for us to read. Also, can you give us some stats of "your" level and the level of the NPC it should be selecting? Is there a NPC that would meet that criteria? Example:

Say you are level 20 and the lowest level NPC is 10 and the next level is 25, your query should run and give you the level 10 bot, is that a similar case that you have?

Link to comment
Share on other sites

Sorry about the code tags I'm new to a forum like this and trying to pick up on all the rules as quickly as I can. I will do my best to remember the code tags next time.

So my user level is level 90.

There is a bot at level 75 and then the next is at level 101. I should be calling to the level 75 bot until I reach level 101, but right now it is calling to the lowest level bot, that being the level 1 bot of course.

Link to comment
Share on other sites

[MENTION=65530]Coly010[/MENTION] Firstly no that's not right. One cb_level doesn't exist in the challengebots table, two he wants it to select closest to the users level but not above so if you have a bot that is level 100 and you're level 110 and the next bot above is level 150 then it selects the level 100 bot and not above or say the level 1 bot.

I have never seen the table, so I was assuming what there would be. However i should have stated that what I had posted wasn't an actual fix, but something to think about.

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...