Topic:   Need Help with weapon system   (Read 9336 times)


0 Members and 1 Guest are viewing this topic.

Gnome


  • GMG Extraordinaire

  • ***


  • Posts: 1073
Need Help with weapon system
« on: February 25, 2008, 05:09:11 PM »
The damage dosen't change... ???

Player Attack Button Script
playerhit = RANDOM 7
IF playerweapon$ = "ironsword" THEN playerhit = playerhit + 5
IF playerweapon$ = "steelsword" THEN playerhit = playerhit + 20
IF playerweapon$ = "dragonsword" THEN playerhit = playerhit + 50
monsterHP = monsterHP - playerhit
CLEAR TEXT
PRINT enemyHP: $monsterHP$
PRINT yourHP: $youHP$
ALERT You hit the $monstername$$ for $x$ damage.
 ' if monster isn't dead, he hits you for up to y points
  y = RANDOM 5
  youHP = youHP - y
CLEAR TEXT
PRINT enemyHP: $monsterHP$
PRINT yourHP: $youHP$
  ALERT The $monstername$$ hits you for $y$ damage.
  IF monsterHP < 1 THEN
playerEXP = playerEXP + RANDOM 12
 ALERT YERRRARGH!!!!
  GOTOCARD 19
ELSE
   IF youHP < 1 THEN
    ALERT You have died.
    GOTOCARD 2
 END IF
END IF

Battle CARD script


IF playerweapon = "ironsword" THEN playerhit = playerhit + 5
IF playerweapon = "steelsword" THEN playerhit = playerhit + 20
IF playerweapon = "dragonsword" THEN playerhit = playerhit + 50

x = 1
IF x = 1 THEN monsterName$ = "theif"



monsterHP = 17
PRINT Enemy HP: $monsterHP$
PRINT YourHP: $youHP$

Please Help!!! :o
This Cannot be, NOOOOOOOO!!!!

-Gnomes Cry when the McRib was discontinued again.

GMG Tim


  • Administrator

  • GMG-er

  • *****


  • Posts: 465
Re: Need Help with weapon system
« Reply #1 on: February 25, 2008, 08:35:37 PM »
First, did you declare 'monsterHP' earlier? I don't see it declared in that code, and so you can't possibly subtract from it in the line:

monsterHP = monsterHP - playerhit

Also, this is the wrong forum, this should be in the "Game Time" forum, but you might find you'll get more help at the SilverCreator forums or the GameMaker forums, depending on which system you're using.

GameMaker: http://gmforums.macintoshdevelopers.net/
SilverCreator: http://www.silvernetworks.net/cgi-bin/yabb/YaBB.pl

- Ghost
« Last Edit: February 25, 2008, 08:41:59 PM by admin »

Silverwind


  • ^ This guy is amazing.

  • ****


  • Posts: 2805

  • For the glory of my maker
Re: Need Help with weapon system
« Reply #2 on: February 26, 2008, 02:07:46 PM »
That's some pretty nifty code there Gnome. Apart from what Ghost pointed out I don't see anything immediately wrong with it. Here's a simple engine I wrote that might be able to help you, quoted straight from my RPG making guide:
Quote
The battle engine is a great place to start. Let's say that the goal for your first battle engine is to have a player character and an enemy, each with their own HP, (Hit Points) and an Attack button that makes them attack each other. Ok, so create a new game in Mac GameMaker (GM as we'll now refer to it) and select a Card layout that includes a text field. In the button script of the Begin Game button on Card 1, create variables for both the player and the enemy's HP. Like this:

playerHP = 30
enemyHP = 25

Now go to Card 2 and enter this in the Card script:

CLEAR TEXT
PRINT Player HP: $playerHP$
PRINT Enemy HP: $enemyHP$

(the "CLEAR TEXT" line isn't necessary because the text field will usually be blank when the card loads, but I add it anyway incase I leave a note to myself in the text field in the editor) So now when Card 2 loads the screen should read "PlayerHP: 30 EnemyHP: 25". What's that I hear you say? "Cool"? You're right, it is cool, but what good are HP if you can't do anything with them? Let's create an Attack button so that the player and the enemy can damage each other! Create a button and call it "Attack" or "Fight" or whatever you want, and put the following code in it:

damage = RANDOM 5
enemyHP = enemyHP - damage

That will make the player attack the enemy, so lets add a bit more code and make the enemy attack the player afterwards.

damage = RANDOM 5
playerHP = playerHP - damage

Now that damage has been done to the HP of both the player and the enemy, lets tell the computer to print the updated values of their HP.

CLEAR TEXT
PRINT Player HP: $playerHP$
PRINT Enemy HP: $enemyHP$

Coolaboola! Now when you click the Attack button the player and the enemy damage each other and the new HP are printed! Awesome!!! But wait... uh oh, look at what happens if you click the Attack button over and over again: the HP drop to a value below 0! Not a problem, we'll add a few lines of code to tell the computer that if the HP of a character reaches 0 we want that character to die! (Nothing personal, but we can't have a load of "less then 0 HP" people running around in our game) Ok, here's what to do. Under the line that says "enemyHP = enemyHP - damage" type:

IF enemyHP < 1 THEN
  ALERT You have defeated the enemy! Hurray!
  GOTOCARD 1
END IF

Now make a similar block of code and put it under the line that says "playerHP = playerHP - damage"

IF playerHP < 1 THEN
  ALERT You have been defeated...
  GOTOCARD 1
END IF

Take a moment to step back and gaze at your creation... gasp! You have achieved your goal! You have made a player character and an enemy BOTH with HP, and you can make them damage each other by clicking the Attack button! Congratulations, you've programmed a simple battle engine! By changing the values of "damage", "playerHP" and "enemyHP" you can make the player and enemy's attack stronger or weaker. Coooooool! When you're ready to build a slightly more flexible battle engine, move on to the next section.
You can download the Guide (which contains loads more handy tips, tutorials and code snippets) here: http://www.savefile.com/files/1133178

Hope that helps. :)
I survived the spammage of 2007

EqwanoX


  • Administrator

  • GMG Extraordinaire

  • *****


  • Posts: 1180
Re: Need Help with weapon system
« Reply #3 on: February 27, 2008, 04:42:49 AM »
 Â it says print "you hit monster for $x$ damage" when i dont see x set to anything, i think you meant to put "you hit monster for  $playerhit$ damage"

also it might be easier to set the weapons power when you purchase it, then you wouldnt have to have all the weapon stats in the attack code

purchase code

let weapon$="dagger"
let power=10

attack code

let playerhit=random 10
let playerhit=playerhit+power
« Last Edit: February 27, 2008, 04:47:10 AM by EqwanoX »

Gnome


  • GMG Extraordinaire

  • ***


  • Posts: 1073
Re: Need Help with weapon system
« Reply #4 on: February 27, 2008, 06:54:34 PM »
hmm. thanks guys i'll see if this works.
This Cannot be, NOOOOOOOO!!!!

-Gnomes Cry when the McRib was discontinued again.