|
| Author |
Message |
X-Worm Newbie

Joined: 12 May 2005 Posts: 36
    
|
Posted: Sat Dec 03, 2005 10:41 am Post subject: Subtracting |
|
|
I'm trying to do a small game, but got this problem. When a user attacks a monster, the HP should be subtracted by the attack strength. Don't really know how to do this...
| Quote: |
# This is the sub for doing damage on monsters.
sub DoDamage {
$msn->{$username}->{randomDamage} = int( rand($msn->{$username}->{attack1})) + $msn->{$username}->{attack2};
$msn->{$username}->{monster}->{newhealth} = $msn->{$username}->{monster}->{health} - $msn->{$username}->{randomDamage};
&send($self, "You attacked $msn->{$username}->{monster} with $msn->{$username}->{randomDamage} HP. $msn->{$username}->{monster} now has $msn->{$username}->{monster}->{newhealth} HP remaining.", $username);
}
# This is the sub that's used when the monsters hit you.
sub MonsterDoDamage {
$msn->{$username}->{monster}->{randomDamage} = int( rand($msn->{$username}->{monster}->{damage1})) + $msn->{$username}->{monster}->{damage2};
$msn->{$username}->{newhealth} = msn->{$username}->{health} - $msn->{$username}->{monster}->{randomDamage};
&send($self, "$msn->{$username}->{monster} attacked you with $msn->{$username}->{randomDamage} HP. You now have $msn->{$username}->{monster}->{health} HP remaining.", $username, Color => "0000ff");
}
|
As this just resets the HP after every attack. |
|
| Back to top |
|
 |
darkmonkey The Merovingian

Joined: 18 Apr 2004 Posts: 2557 Location: London, England
     votes: 7
|
Posted: Sat Dec 03, 2005 3:14 pm Post subject: |
|
|
$msn->{$username}->{monster}->{health} -= $msn->{$username}->{randomDamage};
Also, in the second one, you have "msn->{$username"...you forgot the $ on $msn. _________________ ~ Josh
[ Need bot hosting on a dedicated server? PM me. ] |
|
| Back to top |
|
 |
X-Worm Newbie

Joined: 12 May 2005 Posts: 36
    
|
Posted: Sat Dec 03, 2005 4:33 pm Post subject: |
|
|
Oh, just like that. Thanks.  |
|
| Back to top |
|
 |
X-Worm Newbie

Joined: 12 May 2005 Posts: 36
    
|
Posted: Wed Jan 04, 2006 11:17 am Post subject: New problems |
|
|
Ho-ho. Found the code on my hard-drive and tried to finish it, but a new problem came up.
| Quote: |
# Testing data.
$rpg->{$username}->{victim} = "Dude";
$rpg->{$username}->{victim}->{hp} = 100;
$rpg->{$username}->{victim}->{randattack} = 10;
$rpg->{$username}->{hp} = 100;
$rpg->{$username}->{randattack} = 20;
# Handlers.
sub DoDamage {
if ($rpg->{$username}->{status} = "dead") {
print ("You're already dead. \n");
} else {
$rpg->{$username}->{victim}->{hp} -= $rpg->{$username}->{randattack}; # victim->{HP} is now what's left after your "randattack".
print ("You attacked $rpg->{$username}->{victim} with $rpg->{$username}->{randattack} dmg HP, $rpg->{$username}->{victim} now has $rpg->{$username}->{victim}->{hp} HP left. \n");
if ($rpg->{$username}->{victim}->{hp} <=0) {
print ("You killed $rpg->{$username}->{victim}. \n");
$rpg->{$username}->{status} = "alive";
&CheckStatus;
}
}
}
sub TakeDamage {
if ($rpg->{$username}->{status} = "dead") {
print ("You're already dead. \n");
} else {
$rpg->{$username}->{hp} -= $rpg->{$username}->{victim}->{randattack}; # $username->{HP} is now what's left after the "randattack".
print ("$rpg->{$username}->{victim} attacked you with $rpg->{$username}->{victim}->{randattack} dmg HP, now you have $rpg->{$username}->{hp} HP left. \n");
if ($rpg->{$username}->{hp} <=0) {
print ("You died. \n");
$rpg->{$username}->{status} = "dead";
}
}
}
# Testing
$input = <STDIN>;
while ($input =~ /^!atc/i) {
$input = <STDIN>;
&DoDamage;
&TakeDamage;
}
|
... What I want is a code that checks wether the local user ($rpg->{$username}) is dead or now (if the HP have reached 0 once), and in that case the user should'nt be able to use the command !atc. |
|
| Back to top |
|
 |
Cer Upgraded Agent

Joined: 03 Feb 2004 Posts: 3776 Location: Michigan
  votes: 4
|
Posted: Wed Jan 04, 2006 12:42 pm Post subject: |
|
|
Find a basic Perl tutorial, you'll want to use operators...
| Code: | if ($rpg->{$username}->{hp} <= 0) {
print "You have no HP left.\n";
} |
For Numbers
< less than
> greater than
<= less than or equal to
>= greater than or equal to
== equal to
For Strings
eq equal to
ne not equal to _________________ Current Site (2008) http://www.cuvou.com/ |
|
| Back to top |
|
 |
X-Worm Newbie

Joined: 12 May 2005 Posts: 36
    
|
Posted: Wed Jan 04, 2006 4:18 pm Post subject: |
|
|
Oh, I know that. Just didn't thought of using it. Thanks.  |
|
| Back to top |
|
 |
alienz Almost An Agent

Joined: 22 Mar 2004 Posts: 1436 Location: Mars
 
|
Posted: Wed Jan 04, 2006 6:07 pm Post subject: |
|
|
What else would you use if you're trying to work with numbers and arithmetic in Perl??? _________________ Check out Botworld! A dev resource for things bot.
Downloads, articles, news, fourm and more.
http://botworld.marzopolis.com |
|
| Back to top |
|
 |
|