Jump to content

[SOLVED] Slight Coding Help.


SoireeExtreme

Recommended Posts

Hi, I have created a very simple attack scripted for an online game I'm working on. But there is a little problem with it. And I've been trying to figure out how to fix it but I can't. See my problem is I need the script to deny a player a fight if the a player tries to fight themselves. If anyone could help me that would be great. Here is my code..... Thanks in advance.

 

Everything here seems to be working pretty well so far. Just need help with what I said about thanks.

<?php
if (isset($_SESSION['player'])) 
  {
    $player=$_SESSION['player'];
    $userstats="SELECT * from ac_users where playername='$player'";
    $userstats2=mysql_query($userstats) or die("Could not get user stats");
    $userstats3=mysql_fetch_array($userstats2);

$atk1=$userstats3['attack']+$userstats3['attack'];

if (!isset($_GET['ID'])) {
  print "No player was selected to attack.<br>";
} else {
  $playerID = $_GET['ID'];
}

$playertwo="SELECT * from ac_users where ID='$playerID'";
$playertwo2=mysql_query($playertwo) or die("Blah");
$playertwo3=mysql_fetch_array($playertwo2);

$atk2=$playertwo3['defence']+$playertwo3['defence'];

echo "<u>Player Challenge</u><P>";

echo "$userstats3[playername] VS $playertwo3[playername]";

$update=$userstats3['attack']/4;
$update2=$playertwo3['attack']/4;

if($userstats3[playername] =$playertwo3[playername])
{
echo "<br>THis needs to be where a player can't attack themselves ";
}
else
if($atk1>$atk2)
{
echo "<br>You Won!";

$skill="update ac_users set experience=experience+'$update'  where playername='$player'";
mysql_query($skill);

$skill2="update ac_users set experience=experience+'$update2'  where ID='$playerID'";
mysql_query($skill2);

}
else
if($atk2>$atk1)
{
echo "<br>You Lose! ";
}
else
if($atk1=$atk2)
{
echo "<br>Its a Draw. ";
}
}
else
{
print "Nope";
}

?>

Link to comment
Share on other sites

I don't see anywhere you have tried.

The user who is logged in, their ID should be in here:

<?php $userstats3=mysql_fetch_array($userstats2); ?>

Then do

<?php

if($userID == $playerID){

}

?>

 

You might want to use a better name than $playerID, like $attackedPlayerID or something descriptive, since $player is the username of the logged in player, yes?

Link to comment
Share on other sites

You do not under any circumstances do not want to try a game with procedural. You are going to want to rewrite it using OOP.  I can't even imagine trying to quickly add features into an ever-growing game having to cut through procedural.  YOu need to handle all of those things with OOP functions. You would have a function for attack inside your class.

 

class Basics extends Core {

 function attack () {

 

 }

}

 

Your going to want to redo most of that in OOP if you try to cut through that code to update/change/enhance code you'll notice later on down the road that you will have 4-5 times the amount of time to enhance it as opposed to OOP.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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

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

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.