Jump to content
MakeWebGames

Recommended Posts

Posted

I'm finally trying my first mod from scratch. I don't think it's anything too special, but I am trying my best.

What this is supposed to do, is, give the option of exacting revenge on the player who attacked you. It's definitely not complete, and I'm sure there is a lot I could do cleaner/more efficient. I'm not all too worried about that right this second.

At the moment, I'm at the point where I'm trying to add the option in the user's event to attempt a revenge kill. I just have no idea how to do this so it picks up the user who attacked you. Would I pull it from the attack log (If V1 has one :/)? I'm just at a loss. Could anyone just point me in the right direction?

Here is revenge.php (So far. Not complete.)

<?php
session_start();
require "global_func.php";
if($_SESSION['loggedin']==0) { header("Location: login.php");exit; }
$userid=$_SESSION['userid'];
require "header.php";
$h = new headers;
$h->startheaders();
include "mysql.php";
global $c;
$is=mysql_query("SELECT u.*,us.* FROM users u LEFT JOIN userstats us ON u.userid=us.userid WHERE u.userid=$userid",$c) or die(mysql_error());
$ir=mysql_fetch_array($is);
check_level();
$fm=money_formatter($ir['money']);
$cm=money_formatter($ir['crystals'],'');
$lv=date('F j, Y, g:i a',$ir['laston']);
$h->userdata($ir,$lv,$fm,$cm);
$h->menuarea();

$limit = mysql_query("SELECT drevkills FROM users WHERE userid={$ir['userid']}", $c);
$od = mysql_query("SELECT * FROM users WHERE userid={$r['userid']}", $c);
if (mysql_num_rows($od))
{
   $r = mysql_fetch_array($od);
   if ($r['hospital'] >= 1)
   {
       print "<a href='viewuser.php?u={$r['userid']}'>{$r['username']}</a> is already in the hospital!";
   }
}
else if($limit = 10)
{
print "You have exacted all the revenge you can today! Try again tomorrow!</ br>
<a href='index.php'>> Back</a>";

else
{
$revsucc = rand(1,4)
			if($revsucc = 1)
			{
			$expgain = 200;
			mysql_query("UPDATE users SET revkills=revkills+1,drevkills=drevkills+1 WHERE userid={$ir['userid']}",$c);
			mysql_query("UPDATE users SET hp=1,hospital=hospital+30,hospreason='Killed for revenge' WHERE userid={$r['userid']}",$c);
			event_add($r['userid'],
				"<a href='viewuser.php?u={$ir['userid']}'>{$ir['username']}</a> exacted their revenge! You've been hospitalized for {$r['hospital']}!",
				$c);
			print "You exacted your revenge on <a href='viewuser.php?u={$r['userid']}'>{$r['username']}</a>! You've earned 200 experience!"
			mysql_query(
					"UPDATE users SET exp=exp+$expgain WHERE userid={$ir['userid']}",
					$c);
			$warq =
               mysql_query(
                       "SELECT * FROM gangwars WHERE (warDECLARER={$ir['gang']} AND warDECLARED={$r['gang']}) OR (warDECLARED={$ir['gang']} AND warDECLARER={$r['gang']})",
                       $c);
				if (mysql_num_rows($warq) > 0)
				{
				$war = mysql_fetch_array($warq);
				mysql_query(
						"UPDATE gangs SET gangRESPECT=gangRESPECT-10 WHERE gangID={$r['gang']}",
						$c);
				mysql_query(
						"UPDATE gangs SET gangRESPECT=gangRESPECT+5 WHERE gangID={$ir['gang']}",
						$c);
				print "<br />You also earned 5 respect for your gang!";
				}
			}
			else
			{
			$expgain = 500;
			mysql_query("UPDATE users SET revfails=revfails+1,hp=1,hospital=hospital+30,hospreason='Failed to take revenge' WHERE userid={$ir['userid']}",$c);
			event_add($r['userid'],
				"<a href='viewuser.php?u={$ir['userid']}'>{$ir['username']}</a> failed to exact their revenge! You have gained 500 experience, and {$ir['username']} has been hospitalized for {$ir['hospital']}",
				$c);
			print "You have failed to exact your revenge! You have been hospitalized for {$ir['hospital']}!"
			mysql_query(
					"UPDATE users SET exp=exp+$expgain WHERE userid={$r['userid']}",
					$c);
			$warq =
               mysql_query(
                       "SELECT * FROM gangwars WHERE (warDECLARER={$ir['gang']} AND warDECLARED={$r['gang']}) OR (warDECLARED={$ir['gang']} AND warDECLARER={$r['gang']})",
                       $c);
				if (mysql_num_rows($warq) > 0)
				{
				$war = mysql_fetch_array($warq);
				mysql_query(
						"UPDATE gangs SET gangRESPECT=gangRESPECT-5 WHERE gangID={$ir['gang']}",
						$c);
				mysql_query(
						"UPDATE gangs SET gangRESPECT=gangRESPECT+10 WHERE gangID={$r['gang']}",
						$c);
				print "<br />You also lost 5 respect for your gang!";
				}
			}
}

$h->endpage();
?>
Posted

Why not do the following;

  1. Add a column in `users`, lastAttackedBy
  2. After the attack is done, change the value of lastAttackedBy in the victims row, with the attackers ID
  3. When they go to attack, check to see if the user id (_GET) matches lastAttackedBy, and if it does, treat it as a revenge kill.
Posted
Why not do the following;
  1. Add a column in `users`, lastAttackedBy
  2. After the attack is done, change the value of lastAttackedBy in the victims row, with the attackers ID
  3. When they go to attack, check to see if the user id (_GET) matches lastAttackedBy, and if it does, treat it as a revenge kill.

Ah once again, sniko, you've enlightened me. That does make sense. Thank you for the response!

Posted

No worries at all :)

For further issues you may have, step away, clear your mind and re-build the solution from the ground up, disregarding what you've already done. I take this process when I have problems, and it works like a charm. Remember, the computer is stupid and only does what you tell it, so, write down what you've got to do, to solve the problem, in a format, like I've done above ;)

Posted
No worries at all :)

For further issues you may have, step away, clear your mind and re-build the solution from the ground up, disregarding what you've already done. I take this process when I have problems, and it works like a charm. Remember, the computer is stupid and only does what you tell it, so, write down what you've got to do, to solve the problem, in a format, like I've done above ;)

Though, I just had a thought. Say, I wanted to have a link in the "You were hospitalize by blah blah.." event to exact revenge. If you're attacked five times by five different people, it would still only be calling the last attacker, right? That means if, say, someone is attacked by user Bob, and then attacked by user Fred, if they click revenge on Bob, it would still be calling Fred. Any ideas on how to get around this?

Posted

Yeah, that's where you'd create another table of recent attacks, something like the following;

revengeAttacks

  1. attacker
  2. victim
  3. time

 

Then, after each attack, do something along the following

INSERT INTO `revengeAttacks` (`attacker`,`victim`,`time`) VALUES ($attacker, $victim, unix_timestamp())

Then, modify step 3, and look in the revengeAttacks table, and see if the attacker is equal to the _GET user id, and if it is, treat it as a revenge attack.

Once the attack is done, remove the correct records from the table, and insert a new one

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