User Control Panel
Advertisements

HELP US, HELP YOU!

Subtracting

 
Post new topic   Reply to topic    Bot Depot Forum Index -> Perl
View unanswered posts
Author Message
X-Worm
Newbie
Newbie


Joined: 12 May 2005
Posts: 36

Reputation: 35.7Reputation: 35.7Reputation: 35.7Reputation: 35.7

PostPosted: Sat Dec 03, 2005 10:41 am    Post subject: Subtracting Reply with quote

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... Razz
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
The Merovingian


Joined: 18 Apr 2004
Posts: 2557
Location: London, England
Reputation: 39.3Reputation: 39.3Reputation: 39.3Reputation: 39.3
votes: 7

PostPosted: Sat Dec 03, 2005 3:14 pm    Post subject: Reply with quote

$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
Newbie


Joined: 12 May 2005
Posts: 36

Reputation: 35.7Reputation: 35.7Reputation: 35.7Reputation: 35.7

PostPosted: Sat Dec 03, 2005 4:33 pm    Post subject: Reply with quote

Oh, just like that. Thanks. Very Happy
Back to top
X-Worm
Newbie
Newbie


Joined: 12 May 2005
Posts: 36

Reputation: 35.7Reputation: 35.7Reputation: 35.7Reputation: 35.7

PostPosted: Wed Jan 04, 2006 11:17 am    Post subject: New problems Reply with quote

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
Upgraded Agent


Joined: 03 Feb 2004
Posts: 3776
Location: Michigan
Reputation: 146.9
votes: 4

PostPosted: Wed Jan 04, 2006 12:42 pm    Post subject: Reply with quote

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
Newbie


Joined: 12 May 2005
Posts: 36

Reputation: 35.7Reputation: 35.7Reputation: 35.7Reputation: 35.7

PostPosted: Wed Jan 04, 2006 4:18 pm    Post subject: Reply with quote

Oh, I know that. Just didn't thought of using it. Thanks. Razz
Back to top
alienz
Almost An Agent
Almost An Agent


Joined: 22 Mar 2004
Posts: 1436
Location: Mars
Reputation: 55.7

PostPosted: Wed Jan 04, 2006 6:07 pm    Post subject: Reply with quote

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
Display posts from previous:   
Post new topic   Reply to topic    Bot Depot Forum Index -> Perl All times are GMT
Page 1 of 1

 



Protected by phpBB Security phpBB-TweakS
phpBB Security Has Blocked 9 Exploit Attempts.
Antispam Captcha Mod by phpbb-security.com
Powered by phpBB © 2001, 2005 phpBB Group