Avoiding death with a player switch.

Started by Pixelton, Sun 25/04/2010 23:25:36

Previous topic - Next topic

Pixelton

Hey guys I've hit a wall with my scripting in that I can't get the thing to do what I want it to do. Now Scripting is a real weakness of mine and I really wish I was better at it so hopefully this will help me out and I also learn a few things.

I have a broken gas pipe in my level, when the player colides with it he dies and it displays a GUI, when the player switches to a different character he can pass under the gas safely but its causing problems; so I'll get to my scrpt.

The gas Script:
Code: ags
function room_RepExec()
{
    if (cJohnny.IsCollidingWithObject(oGasleak)) {
    cJohnny.ChangeView(34);
    cJohnny.Animate(0, 3, eOnce, eBlock, eForwards);
    Wait(60);
    Display("You step under the sub-zero cloud, the Trigenon vapour turning you into a petrified, crystal statue: a monument to stupidity.");
    gDeathWindow.Visible = true;
    }
}


On the Room Load function
Code: ags
function room_Load()
{
    if (cJohnny.PreviousRoom == 5) {
    cJohnny.Walk(110, 155, eBlock, eWalkableAreas);
  }
    
  if (cStorebot.PreviousRoom == 5) {
    cStorebot.Walk(105, 150, eBlock, eWalkableAreas);
  }
}


Now I thought that because the gasleak is looking for a player called cJohnny then the death effects would be ignored once the player was now the storebot but it doesnt and I get an error: The character Johnny could not be displayed because there were no frames in loop 2 of view 34......This is also strange as I've never used that loop (which is empty)

So I thought I'd try this:
Code: ags
function room_RepExec()
{
    if (player.Name == "Johnny") {
    cJohnny.IsCollidingWithObject(oGasleak);
    cJohnny.ChangeView(34);
    cJohnny.Animate(0, 3, eOnce, eBlock, eForwards);
    Wait(60);
    Display("You step under the sub-zero cloud, the Trigenon vapour turning you into a petrified, crystal statue: a monument to stupidity.");
    gDeathWindow.Visible = true;
    }
}


Now the death sequence is ignored when the bot passes through the gasleak but when Johnny enters the room the screen fades to black through the room transition but it remains black and the room doesn't load (I get no errors here).

I know I'm giving off the concept of a puzzle here which is in the game but I have no other option :( I've tried to solve this problem in a number of ways before posting here.

Any help is much appreciated!
Please follow our progress on IndieDB!

<a href="http://www.indiedb.com/games/dustbowl-a-wasteland-adventure" title="View Dustbowl - A Wasteland Adventure on Indie DB" target="_blank">Dustbowl - A Wasteland Adventure</a>

Khris

You are using blocking walks in room_Load which is executed before the fadein.
To move characters around, you can simply set their .x and .y.

Also, you can test for the player character using
  if (player == cJohnny)

Pixelton

Thanks Khris

That doesnt fix my problem but it cleans up my little script and now I know better about player checks

Cheers man :)
Please follow our progress on IndieDB!

<a href="http://www.indiedb.com/games/dustbowl-a-wasteland-adventure" title="View Dustbowl - A Wasteland Adventure on Indie DB" target="_blank">Dustbowl - A Wasteland Adventure</a>

Khris

Right, the problem seems to be that you're using Character.ChangeView(). For short animations, use .LockView().

Pixelton

#4
Someone once tried to explain the difference between LockView and ChangeView and I kind of understood it and also kind of didn't.

When would it be correct to use ChangeView over LockView and does UnlockView() restore the character's view to the previous state? I hope these questions are good ones, I'm kind of guessing my way through AGS scripting at the moment, its quite frustrating.
Please follow our progress on IndieDB!

<a href="http://www.indiedb.com/games/dustbowl-a-wasteland-adventure" title="View Dustbowl - A Wasteland Adventure on Indie DB" target="_blank">Dustbowl - A Wasteland Adventure</a>

Khris

Quote from: Mark Borg on Mon 26/04/2010 15:25:55
Someone once tried to explain the difference between LockView and ChangeView and I kind of understood it and also kind of didn't.

I think that was CJ when he wrote the manual ;)

ChangeView permanently changes the player's view. Say he puts on a trenchcoat at one point and there's a second view of him, walkcycles in all directions, wearing it.

LockView is meant for short animations, usually those use one loop only. Say the player hops over a fence or something like that. You'll make him walk there, face the fence, then play a single animation, then go back to the normal view. Usually you'd call .UnlockView right after .Animate to return control to AGS as in switching back to the standard walking view.

Pixelton

Please follow our progress on IndieDB!

<a href="http://www.indiedb.com/games/dustbowl-a-wasteland-adventure" title="View Dustbowl - A Wasteland Adventure on Indie DB" target="_blank">Dustbowl - A Wasteland Adventure</a>

Pixelton

I've looked through the manual and I'm abit stuck with an idea.

Say I have this nasty broken gas pipe thats spraying death, and I have a shut off valve in another room, what would be the best way to switch off the gass animation view using a switch outside of the room? I guess I'd need to make some kinf of function for this in the global script. In leyman's terms how would I go about doing this?

For some reason I'm alittle scared of diving into the global script file as theres alot of stuff going on in it, I also have no idea how you'd go about setting up a function without hitting that little Lightening bolt button on an object in the editor :p

Any help is much appreciated - so far I've really learnt alot and I know I'm getting better at this stuff :)
Please follow our progress on IndieDB!

<a href="http://www.indiedb.com/games/dustbowl-a-wasteland-adventure" title="View Dustbowl - A Wasteland Adventure on Indie DB" target="_blank">Dustbowl - A Wasteland Adventure</a>

Matti

You could simply change a (global) variable and turn the gas pipe's animation off in the room_load when it's done.

Pixelton

But how would a beginner like me go about creating a function in the global script that can switch the gass field off?

I have been reading up on the manual and I've found that I could create a function in the gloab script like this:

function Gas_Leak (parameter);
{
 
}

But I haven't the foggiest on what goes into the parameter field and what I'd add within the brackets.

Also  I'm not sure how I would use this to change an object inside a room, I read that there is an:
import function but I'm not sure if I'd use this....I am an utter noob at all this.
Please follow our progress on IndieDB!

<a href="http://www.indiedb.com/games/dustbowl-a-wasteland-adventure" title="View Dustbowl - A Wasteland Adventure on Indie DB" target="_blank">Dustbowl - A Wasteland Adventure</a>

Khris

You don't really need a function.
In the Global variables pane, add a bool, say "pipe_leaking", initial value "true".

In the valve's code, simply set the variable to false:
  pipe_leaking = false;
Then add the before fadein event to the room with the pipe and in there, turn on the animation:
Code: ags
function room_Load() {
  oLeak.Clickable = false;
  if (pipe_leaking) {
    oLeak.Visible = true;
    oLeak.Animate(...);
  }
  else oLeak.Visible = false;
}

Pixelton

Ah cool

I've never used the global variables pane, so thats the thing that allows you to do cross room events. Out of curiosity, why have you set the actual gas leak object's clickable as false?
Please follow our progress on IndieDB!

<a href="http://www.indiedb.com/games/dustbowl-a-wasteland-adventure" title="View Dustbowl - A Wasteland Adventure on Indie DB" target="_blank">Dustbowl - A Wasteland Adventure</a>

Khris

You don't have to, it's fine to name it deadly steam or something and have it show up as interactable hotspot.
I just thought you wanted to use it only to display the animation.

Pixelton

#13
Thanks Khris, you have been so patient with me and I do appreciate it more than you know.

On a side note I have actually managed to script my initial idea and get that working (switcing players to get past a wall of death). If anyone is interested I'll explain how I did this. As my scripting knowledge is very basic and I'm abit rubbish I usually have to be very inventive about how I make things work.

In the level I have two Gas leak clouds, oGasleak and oGas_leak2. oGasleak is the thing that kills the player while the other gas_leak object does nothing and is none solid.

Here is the script.
Code: ags
function room_RepExec()
{
  
if (cJohnny.IsCollidingWithObject(oGasleak)) {
    cJohnny.LockView(34);
    cJohnny.Animate(0, 3, eOnce, eBlock, eForwards);
    Display("You are Dead!");
    Wait(50);
    gDeathWindow.Visible = true;
    oGasleak.Visible = false;
    oGas_leak2.Visible = true;
  }
  
  else if (cStorebot.IsCollidingWithObject(oGasleak)) {
  oGasleak.Visible = false;
  oGas_leak2.Visible = true;
  }
}


To avoid the whole script to replay again and again when Johnny is in contact with the cloud I switch fro the killer cloud to the none-killer cloud and as for the player switch that can survive the trap, thats fairly straight forward.

cJohnny.LockView(34); is the death animation the player switches to.


gDeathWindow is my custom window that is displayed when the player kicks the bucket.

This works perfectly fine and gets the desired effect I'm after. I thought I'd conclude this incase someone else eventually wants to do something similar. I'm sure theres a more efficiant way hehe.
Please follow our progress on IndieDB!

<a href="http://www.indiedb.com/games/dustbowl-a-wasteland-adventure" title="View Dustbowl - A Wasteland Adventure on Indie DB" target="_blank">Dustbowl - A Wasteland Adventure</a>

Pixelton

#14
Hey, has anyone had this issue?

I'm trying to hide an object when the player interacts with it and for the life of me I have no idea why this isn't working. There are a few chunks of script that involve this object from being hidden and visible, these are:

Code: ags
function room_Load()
{
  if (cStorebot.PreviousRoom == 5) {
    oStore_Crate.Visible = false;
  }
  
    else if (cJohnny.PreviousRoom == 5) {
        oStore_Crate.Visible = true;
  }
}


Code: ags
function oStore_Crate_Interact()
{
      if (player.Name == "Storebot") {
      cJohnny.Walk(380, 332, eBlock, eWalkableAreas);
      cJohnny.Walk(390, 320, eBlock, eAnywhere);
      oStore_Crate.Visible = false;
      cJohnny.LockView(29);
      cJohnny.Animate(0, 5, eOnce, eBlock, eBackwards);
      cStorebot.Walk(356, 319, eBlock, eWalkableAreas);
      cStorebot.FaceCharacter(cJohnny);
      cStorebot.LockView(36);
      cStorebot.Animate(1, 4, eOnce, eBlock, eForwards);
      cStorebot.UnlockView();
      cStorebot.LockView(35);
      cJohnny.FollowCharacter(null);
      }
      
      
  else if (player.Name == "Johnny") {
    oStore_Crate.Visible = true;
    cJohnny.Walk(380, 332, eBlock, eWalkableAreas);
    cJohnny.Walk(390, 320, eBlock, eAnywhere);
    oStore_Crate.Visible = false;
    cJohnny.LockView(29);
    cJohnny.Animate(0, 5, eOnce, eBlock, eBackwards);
    Wait(40);
    Display("I really feel safe in here but I can't sit around forever");
    cJohnny.Animate(0, 5, eOnce, eBlock, eForwards);
    oStore_Crate.Visible = true;
    cJohnny.UnlockView();
    cJohnny.LockView(1);
  }
}


-----------
The "Else if" section of code works fine, there seems to be an issue with the initial if statement.

I've searched through my code and tried a few things but no luck...I'm hoping someone will spot something I'm doing wrong and any help is much appreciated.
Please follow our progress on IndieDB!

<a href="http://www.indiedb.com/games/dustbowl-a-wasteland-adventure" title="View Dustbowl - A Wasteland Adventure on Indie DB" target="_blank">Dustbowl - A Wasteland Adventure</a>

Khris

To identify the current player character, you can compare the pointer directly to the Character object:
  if (player == cJohnny) ...

Pixelton

AH cheers Khris

Thats really handy to know so thank you! I still cant get this crate to vanish for some reason...I might have to wait for my friend Def to come online so I can send him the files....I can't see any fault but I do think it has something to do with the player (Johnny) following the storebot when the player switch happens.

nevermind...these setbacks are here to try us.
Please follow our progress on IndieDB!

<a href="http://www.indiedb.com/games/dustbowl-a-wasteland-adventure" title="View Dustbowl - A Wasteland Adventure on Indie DB" target="_blank">Dustbowl - A Wasteland Adventure</a>

SMF spam blocked by CleanTalk