Author Topic: RPG Code help  (Read 3223 times)

Dude Man

  • Member
  • *
  • Posts: 6393
    • View Profile
    • http://dmdgames.mysticsoftware.net//
RPG Code help
« on: April 28, 2007, 06:58:19 PM »
Why don't we have a forum for this anymore? Oh well, I'll just post it here.

So with all these crazy changes with RPGCode, I don't get anything anymore. I'm trying to make a health bar, but it won't change colour or starting position, it just hugs the edge of the screen.

Code: [Select]
//Health Bar Program
//By: Dude Man
//Variables used:
// healthPercent! (Percent of the character's hit points)
Method HealthBar(player$)
{
healthPercent! = player$[maxhealth]! * player$[health]! / 100
if (healthPercent! > 25)
{
colorRGB(225, 0, 0)
}
elseIf (healthPercent!  > 50)
{
colorRGB(225, 225, 0)
}
else
{
colorRGB(0, 225, 0)
}
DrawLine(103, 75, healthpercent!, 75)
}
« Last Edit: December 31, 1969, 06:00:00 PM by Guest »
~Welcome back mysticsoftware.net??
The Black Walkway

Xorlak

  • Administrator
  • Member
  • *****
  • Posts: 2225
    • View Profile
    • http://darkagegames.net
Re: RPG Code help
« Reply #1 on: April 29, 2007, 04:51:00 PM »
What is 'player$'?  Is it an instance of a class or struct?  Or are you trying to do things the old way, e.g. mapping to player variables?  I'm guessing the latter, based on how you're using your variables.

I don't think this is right:  player$[maxhealth]!

I think you want something like this: player[playername$]["maxhealth"]!

E.g. in setup, you'd have something like:

Code: [Select]
player["Vance"]["maxhealth"]! = 100
player["Vance"]["health"]! = 100

and then:

Code: [Select]
Method HealthBar(playername$)
{
healthPercent! = player[playername$]["maxhealth"]! * player[playername$]["health"]!/ 100

...


Of course it'd be cleaner if you used classes, but it doesn't really matter.

Also get in the habit of using quotes with non-variable array elements.  player[playername$][maxhealth]! works fine right now in 3.0.6, but it won't in 3.0.7 because it will parse 'maxhealth' as a variable (since the $ and ! requirement will get dropped).
« Last Edit: December 31, 1969, 06:00:00 PM by Guest »

D. Ein

  • Member
  • *
  • Posts: 1139
    • View Profile
Re: RPG Code help
« Reply #2 on: April 30, 2007, 04:57:54 PM »
Oh, well, I have it fixed now. What I did was ditched the idea of having the bar change colour and I made the health bar an image rather than a line. Now it's like a green bar over a red bar. It works just fine now. I think the real problem was with the If statement.
« Last Edit: December 31, 1969, 06:00:00 PM by Guest »
!!!! , ...

—staring wildly up and down
the here we are now judgment day

cross the threshold have no dread
lift the sheet back in this way.
here is little Effie’s head
whose brains are made of gingerbread

Dude Man

  • Member
  • *
  • Posts: 6393
    • View Profile
    • http://dmdgames.mysticsoftware.net//
Re: RPG Code help
« Reply #3 on: April 30, 2007, 06:19:06 PM »
That was me posting as Ein. I'm at his house...
« Last Edit: December 31, 1969, 06:00:00 PM by Guest »
~Welcome back mysticsoftware.net??
The Black Walkway

dooms102

  • Member
  • *
  • Posts: 59
    • View Profile
Re: RPG Code help
« Reply #4 on: June 26, 2007, 06:56:45 PM »
yo, I know I just made an account but I do know RPGcode quite well, I've been messing with it for about 1.5 years(not bad eh?).
I actually made a similar method a while ago... but it really depends on how flexible you want it, if you are using the same character throughout the entire story than you can have the character's handle already set, as in it is not a variable such as "handle$". Also it depends on what it is going to be used for and the circumstances, ex: it would be alot easier if you do not have this as a custom method if it is being used for a CBS(custom battle system) or CMS(custom menu system). this is an examle for a status bar method for a menu. (in order for this to work you need to have the "handle$" of the character pre-set, I like to set it at the beggining of a game or when I get a new character)
here it is:
Code: [Select]
//status$ is the status you want to display, ex: Hp Smp and so on...
//x! and y! are the pixel location
//h!=height(vertical) w!=length(horizontal)
//set1! and set2! are the percentages that you set for different
//-color changes

method statusbar("status$",x!,y!,h!,w!,set1!,set2!)
{
get[status$]("handle$",status!)
getmax[status$]("handle$",max!)
tempstatus!=status!*w!
tempstatus!=tempstatus!/max!
clear(status!)
castint(tempstatus!,status!)
set1!=set1!*100
set1!=set1!/w!
set2!=set2!*100
set2!=set2!/w!
colorrgb(r!,g!,b!) //replace the variables with the frame's color
drawrect(x!,y!,w!+x!,h!+y!)
if(status!>=set1!)
{
color(r!,g!,b!) //replace the variables with the color for high
fillrect(x!+1,y+1!,status!+x!-1,h!+y!-1)
}
if(status!<=set1!+1)
{
if(status!>=set2!)
{
color(r!,g!,b!) //replace the variables with the color for medium
fillrect(x!+1,y+1!,status!+x!-1,h!+y!-1)
}
if(status!<=set2!+1)
{
color(r!,g!,b!) //replace the variables with the color for low
fillrect(x!+1,y+1!,status!+x!-1,h!+y!-1)
}
}
}
« Last Edit: December 31, 1969, 06:00:00 PM by Guest »
Quote Dragonminded:
"Please note that the microphone quality is something a few steps lower of microwaved ass, so don\'t expect production quality from this feature."

Akura_TDB

  • Member
  • *
  • Posts: 8
    • View Profile
Re: RPG Code help
« Reply #5 on: June 26, 2007, 08:01:23 PM »
The problem in Dude Man's code is the that the second endpoint for DrawLine() doesn't factor in the line's x-position. What should be done is:
Code: [Select]
DrawLine(103,75,healtpercent!+103,75)
« Last Edit: December 31, 1969, 06:00:00 PM by Guest »

dooms102

  • Member
  • *
  • Posts: 59
    • View Profile
Re: RPG Code help
« Reply #6 on: June 29, 2007, 08:51:50 PM »
yeah... Akura_TBD is right, if you look at my code I factor in the percent of the stat so It can be displayed. So, you should definnetly use the different colors it looks much better, It actually reminds me alot of the "Pokemon" health bars.
« Last Edit: December 31, 1969, 06:00:00 PM by Guest »
Quote Dragonminded:
"Please note that the microphone quality is something a few steps lower of microwaved ass, so don\'t expect production quality from this feature."

K-hos

  • Member
  • *
  • Posts: 22
    • View Profile
Re: RPG Code help
« Reply #7 on: June 30, 2007, 12:09:31 AM »
Quote from: "dooms102"
yo, I know I just made an account but I do know RPGcode quite well, I've been messing with it for about 1.5 years(not bad eh?).
I actually made a similar method a while ago... but it really depends on how flexible you want it, if you are using the same character throughout the entire story than you can have the character's handle already set, as in it is not a variable such as "handle$". Also it depends on what it is going to be used for and the circumstances, ex: it would be alot easier if you do not have this as a custom method if it is being used for a CBS(custom battle system) or CMS(custom menu system). this is an examle for a status bar method for a menu. (in order for this to work you need to have the "handle$" of the character pre-set, I like to set it at the beggining of a game or when I get a new character)
here it is:
Code: [Select]
//status$ is the status you want to display, ex: Hp Smp and so on...
//x! and y! are the pixel location
//h!=height(vertical) w!=length(horizontal)
//set1! and set2! are the percentages that you set for different
//-color changes

method statusbar("status$",x!,y!,h!,w!,set1!,set2!)
{
get[status$]("handle$",status!)
getmax[status$]("handle$",max!)
tempstatus!=status!*w!
tempstatus!=tempstatus!/max!
clear(status!)
castint(tempstatus!,status!)
set1!=set1!*100
set1!=set1!/w!
set2!=set2!*100
set2!=set2!/w!
colorrgb(r!,g!,b!) //replace the variables with the frame's color
drawrect(x!,y!,w!+x!,h!+y!)
if(status!>=set1!)
{
color(r!,g!,b!) //replace the variables with the color for high
fillrect(x!+1,y+1!,status!+x!-1,h!+y!-1)
}
if(status!<=set1!+1)
{
if(status!>=set2!)
{
color(r!,g!,b!) //replace the variables with the color for medium
fillrect(x!+1,y+1!,status!+x!-1,h!+y!-1)
}
if(status!<=set2!+1)
{
color(r!,g!,b!) //replace the variables with the color for low
fillrect(x!+1,y+1!,status!+x!-1,h!+y!-1)
}
}
}



Instead of hard coding there names just use:
Code: [Select]
playerHandle[x!]$X! is the players number slot, 0 is player 1
« Last Edit: December 31, 1969, 06:00:00 PM by Guest »
in words backwards put to liked lad this lad, a was there Once
end. The  flamed. and stabbed got he ,day fateful one but sig. his

dooms102

  • Member
  • *
  • Posts: 59
    • View Profile
Re: RPG Code help
« Reply #8 on: July 13, 2007, 08:30:06 PM »
oh, thanks. Do you have an account on tkz? I think I have seen you there before....?
« Last Edit: December 31, 1969, 06:00:00 PM by Guest »
Quote Dragonminded:
"Please note that the microphone quality is something a few steps lower of microwaved ass, so don\'t expect production quality from this feature."