Menu

Show posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Show posts Menu

Messages - thom0512

#1
Hello everyone.  I have read through the manual and performed numerous forum searches but haven't found anything that has helped me.

I want a non-playable character to follow the playable character, but I want it done in a fashion so that the NPC will be "following the leader" and matching their every move, but doing so a moment or two later (so no waiting around, no moving to a random location close by the playable character, etc).  FOLLOW_EXACTLY has sent me in the right direction, but it's still not helping because no matter what value I input, overlapping of characters still occurs.  I hope this makes sense; any help would be greatly appreciated.
#2
I checked, and I already had that line up above the function.  I'm not sure what I am missing.  If you don't mind, let me show you what I've got so far.

This is the code I have in the global script.

Code: ags

int ron_hp = 30;
DynamicSprite*ron_gauge;

function ron_gets_hit(int damage) 
{
  ron_hp -= damage;
  if (ron_hp < 0) ron_hp = 0;
  if (ron_hp > 30) ron_hp = 30;
  ron_gauge = DynamicSprite.CreateFromExistingSprite(btnHealth.NormalGraphic);
  DrawingSurface*ds = ron_gauge.GetDrawingSurface();
  ds.DrawingColor = 16; // black
  ds.DrawRectangle(0, 0, 99, 15);  // clear gauge
  ds.DrawingColor = Game.GetColorFromRGB(0,255,0); // green
  if (ron_hp > 0) ds.DrawRectangle(0, 0, ron_hp, 15); // draw health        only draw health if > 0
  ds.Release(); // end drawing
  btnHealth.NormalGraphic = ron_gauge.Graphic;
}


This is the code I have for a first-aid kit to recover health (with a sound playing when that happens).

Code: ags

function cRon_UseInv()
{
  if (cRon.ActiveInventory == iFirstaidkit) { // use first-aid kit on self
    PlaySound(19);
    ron_gets_hit(-20);
    cRon.LoseInventory(iFirstaidkit);
  }
}


...and here is an example of Ron taking damage from the first example I could find from my game (with the first code listed above shown at the top of the room script).

Code: ags

function hStove_Interact()
{
  cRon.Walk(269, 179, eBlock);
  cRon.LockView(15);
  cRon.Animate(2, 1, 0, eBlock);
  cRon.UnlockView();
  PlaySound(17);
  ron_gets_hit(15);
{
  if (ron_hp == 0){
    cRon.Say("&93 Uhh...");
    cJon.Say("Ron?");
    PlaySound(11);
    cJon.LockView(17);
    cRon.LockView(16);
    cJon.Animate(0, 0, eOnce);
    cRon.Animate(2, 1, 0, eBlock); // catch on fire
    cJon.UnlockView();
    cRon.UnlockView();
    cRon.ChangeRoom(17);} // obvious game-over
  if (ron_hp > 0){
    cRon.Say("&91 Ouch!");
    cRon.Say("&92 I know better than to touch a hot stove.");
    cJon.Say("Oh, c'mon Ron...");
    cJon.Say("That's so HOKEY!");
    cJon.Say("Getting burned by a stove?");
    cRon.FaceLocation(268, 0, eBlock);
    Wait(80);
    cRon.FaceLocation(268, 194, eBlock);
    } 
  }
}


The animation pretty much shows Ron catching on fire from the stove once his HP has reached zero, or at least, that's how I'd like it to work.  The same problem seems to be here: I touch the stove and lose 15 HP.  Using the first aid kit (recovering 20 HP, but really only going to 30 HP, the maximum) I touch the stove again and Ron loses all of his health instead of another 15 HP.  What am I missing?
#3
I tried your suggestion by adding the extra line of code where it was needed.  The change didn't seem to do anything, however...it just still stays the same as before. ???

And to clarify, I did get rid of that extra bit of code I had before, added the one line of code from your last post, and am inputing health as taking damage a negative value.  It still isn't working for me...
#4
I have one last question for the moment.  The health bar is up and running and it all works great.  I would like to include some inventory items in my game that if they are used with the character, Ron gains HP.  I have created a first-aid kit, and here is the code I have to have Ron recover health, rather than lose it.

Code:
function ron_heals(int amount) { // function used to have Ron recover health
  ron_hp += amount;
  if (ron_hp < 0) ron_hp = 0;
    btnHealth.Width = ron_hp;
    ron_gauge = DynamicSprite.CreateFromExistingSprite(btnHealth.NormalGraphic);
    DrawingSurface*ds = ron_gauge.GetDrawingSurface();
    ds.DrawingColor = 16; // black
    ds.DrawRectangle(0, 0, 99, 15);  // clear gauge
    ds.DrawingColor = Game.GetColorFromRGB(0,255,0); // green
    ds.DrawRectangle(0, 0, ron_hp, 15);
    ds.Release(); // end drawing
    btnHealth.NormalGraphic = ron_gauge.Graphic;
}

The problem that I am encountering is this: When I use the first-aid kit on the character, the bar adds more green, showing that he is recovering health.  But if he takes damage after this, the healing is almost "disregarded" -- the bar lowers as if a first-aid kit weren't even used.  (Take this, for example.  Ron has 10 HP out of 30 HP.  The first-aid kit is used on him to recover 20 HP, which shows on the bar, equaling 30/30 HP.  But if he is hit after this, let's say 5 HP worth of damage, all of this "recovered" green disappears, showing in the bar that he now has 5 HP out of 30 just from that one hit.)  I hope I'm making sense.  What's the problem here?

I would really appreciate any help regarding this issue. Thanks!
#5
All right...I'm about there.  I'm able to have a health bar that can decrease based on the number of hit points put in a specific part of the script.  It all works fine, but my last question for now is how I am able to have the health bar run out of HP and therefore end in a "game over."  The script just keeps a single hit point in the health bar, no matter how much damage Ron takes, and I'd like to change this.

By the way, KhrisMUC, the DynamicSprite and DrawingSurface functions have been extremely useful.  I knew there was a way from the start to have a button serve as a health bar, instead of the GUIs, but there have been so many examples explained on the forum I was lost as far as how to place that into the global script.  I really appreciate the help.
#6
Thanks, KhrisMUC, for your quick response.

I got rid of the GUI health bars except for one, where I put a button on it, called btnHealth.  I only want my character to start out with 30 HP, so I am assuming that a pixel is equivalent to a hit point in this case.  So I made the button 30 pixels wide and 5 high (a "landscape" health bar).

I copied and pasted the new code into the global script and, in some instances, the room script where the function was not recognized.  The game starts out okay, but whenever I run into:

ron_gets_hit(10);

...the game crashes.  It says that the error is "null pointer referenced" and that part of the problem is this:

DrawingSurface *ds = ron_gauge.GetDrawingSurface();

...which is part of the code that I tried out.  I searched the forum for what "null pointer referenced" means but didn't find anything that helped me with this situation.  What am I doing wrong?
#7
I have an RPG-related question regarding a battle I am working on.  I am creating it similar to what was used in the MOTHER series.  Again, I did research this issue before I asked, and I am sure there is a much easier way to script this than the way I did, but oh well.

When my character picks a specific dialog option, he will trigger a fight and will change rooms to the "battle screen" room.  I am using default display messages to let the player know of what goes on during the battle.  I have a GUI off to the side of my room, displaying different actions for the player to pick...attack, defend, run, etc.  I made the main character's and the enemy's health bars with 4 GUIs each: full, 2/3 full, 1/3 full, and empty.  So that totals eight.  The GUIs are marked as gVitals; 1-4 is for the main character, and 5-8 is for the enemy.  Here is the basic script I have so far regarding the battle, with only the main character (Ron) being able to take damage:

function gRobber1_OnClick(GUI *theGui, MouseButton button)
{
Display("Ron throws a punch!");{
int ran=Random(2);
if (ran==0) Display("Just misses!");
else if (ran==1) Display("The robber dodges out of the way quickly!");
else Display("10 HP damage dealt to the robber!");
}
Display("The robber charges at Ron!");{
int ran=Random(2);
if (ran==0) Display("Just misses!");
else if (ran==1) Display("Ron dodges out of the way quickly!");
else Display("10 HP damage given to Ron!");
}}


Display("10 HP damage given to Ron!");{
  if (gVitals1.Visible == true) {
  gVitals1.Visible=false;
  gVitals2.Visible=true;
}
else if (gVitals2.Visible == true) {
  gVitals2.Visible=false;
  gVitals3.Visible=true;
}
else if (gVitals3.Visible == true) {
  gVitals3.Visible=false;
  gVitals4.Visible=true;
  Display("Ron loses the fight.");
  cRon.ChangeRoom(17);
}}

I realize that the bottom portion of the script technically does not fit.  I just threw it in there to show what I want to happen only when a character is hit by an attack.

I am using random effects for the moment until I think of something better.  My problem is that I want the "gVitals" to change only when the main character or the enemy takes damage, or when it is displayed that "10 HP dealt to **", etc.  Right now it just gives Ron 10 HP damage every turn he gets during the battle, and I want to fix this.  Hopefully this makes sense.

Any help would be greatly appreciated.  If I am not clear, please let me know and I'll elaborate as best as I can.  Thank you!
#8
Ha ha, my mistake.  Thanks for catching that.
#9
Thanks so much.  I appreciate all of the help.  It answered my question, but unfortunately, more things came up as I was editing around with things.  I'll put those aside for now to see if I can work them out on my own.  Again, thank you!  I will mark this thread as solved.
#10
Hello, everyone.  I am new to AGS and have started working on my own game.  I have always made a consistent effort to search through the manual and on the forum to find answers to my questions before I ask, and up to now, that's what I have done.  I am stumped, however, on this certain portion I have been trying to complete in my game.

I have created a GUI of a keypad.  I would like for this keypad to be able to unlock a door in the same room once a six-digit code has been entered, which is "233524".  The GUI is composed of nine buttons, which contain the numbers 1-9, and a text box, which displays the numbers that have been punched in.  My dilemma is this: I am aware that, through the keyboard, you can manually enter characters in the text box.  However, I would like to include the option of utilizing the GUI's buttons and pushing the buttons to display numbers.  I have figured this out, but whenever I push a new number, it overrides the old number that was previously in the text box.  Obviously, I want to script this so that pressing buttons on the keypad will be the same as manually typing in the code on the keyboard.  This is the code that I have regarding the buttons so far, when the GUI is visible:

function Keypad1_OnClick(GUIControl *control, MouseButton button)
{
Keypadscreen.Text="1";
}

function Keypad2_OnClick(GUIControl *control, MouseButton button)
{
Keypadscreen.Text="2";
}

function Keypad3_OnClick(GUIControl *control, MouseButton button)
{
Keypadscreen.Text="3";
}

function Keypad4_OnClick(GUIControl *control, MouseButton button)
{
Keypadscreen.Text="4";
}

function Keypad5_OnClick(GUIControl *control, MouseButton button)
{
Keypadscreen.Text="5";
}

function Keypad6_OnClick(GUIControl *control, MouseButton button)
{
Keypadscreen.Text="6";
}

function Keypad7_OnClick(GUIControl *control, MouseButton button)
{
Keypadscreen.Text="7";
}

function Keypad8_OnClick(GUIControl *control, MouseButton button)
{
Keypadscreen.Text="8";
}

function Keypad9_OnClick(GUIControl *control, MouseButton button)
{
Keypadscreen.Text="9";
}

I have searched countless times in the manual and on the forum attempting to solve this.  I do apologize if this question has already been answered in a previous thread.  Again, I have been working on this game for a couple of months and have always looked up a question I have had.  This specific problem has just stumped me, though.  Any help would be greatly appreciated, and if I have been unclear in any way, please let me know and I'll try to elaborate.  Thanks!
SMF spam blocked by CleanTalk