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 - Lewis

#2
Hi Khris! Thanks for adding your method. Can you clarify where this code would go? As mouse.position is read-only.

Cheers!
#3
Thanks! :)

Here's what I ended up doing. I may play around with a timer so that the mouse position doesn't necessarily update every single game loop.

Code: ags
function repeatedly_execute_always()
{
  int ran=Random(1);
  int ran2=Random(3);
  
  if (cPlayer.View==2) //This is the 'aiming' view that enables when the player selects the gun from their inventory.
  {
    if (ran2==0)
    {
      mouse.Update();
      mouse.SetPosition(mouse.x + ran, mouse.y + ran);
    }
    else if (ran2==1)
    {
      mouse.Update();
      mouse.SetPosition(mouse.x - ran, mouse.y - ran);
    }
    else if (ran2==2)
    {
      mouse.Update();
      mouse.SetPosition(mouse.x + ran, mouse.y - ran);
    }
    else
    {
      mouse.Update();
      mouse.SetPosition(mouse.x - ran, mouse.y + ran);
    }
  }
}


For the recoil, I just added this to the function where the player shoots the gun:

Code: ags
mouse.SetPosition(mouse.x, mouse.y-40);
#4
Yeah, that's pretty much it! I'd prefer a smoother movement but I'd settle for this. I'll have a play around with that method, thanks!
#5
I've been trying to fathom this one on my own but it turns out I really have no idea where to start.

For context, I've been working on a survival horror style game in AGS for a little while now. One thing that I'd like to incorporate is a sort of 'wobbly aiming' mechanic whereby when the player is aiming the reticule at an enemy, the cursor/reticule sort of wobbles around the point where the mouse is on screen as if your aiming is imperfect (for example, like with the sniper rifle in the Deus Ex games - watch from 13 secs:) https://youtu.be/W78OSUJZrBU

I'm also hoping to add a recoil effect whereby when the player shoots the enemy, the reticule/cursor snaps upward on the y axis.

The aiming/firing mechanic simply uses an inventory item (iPistol) which, while active, changes the mouse pointer to an aiming reticule. Clicking this on the enemy (cMonster) then triggers a bunch of script that isn't especially relevant here.

Can anyone give me some pointers (pun very much intended) as to how to approach this?
#6
Thanks both! Yeah, objects was gonna be my contingency plan. It's just very mildly fiddlier, so was hoping to avoid it, but no big deal. Thanks again!
#7
Question per the thread title, really.

I'm creating a zombie shooter engine within AGS because of course I am. Slowly but surely it's coming together.

When the player kills a zombie, I'm getting it to show a 'zombie death animation' then replace the zombie with a sprite drawn onto the background, so I'm not cluttering the screen up with characters, as there's no need to interact with zombie corpses (both in the game and in life in general). So I'm using this code:

Code: ags
DrawingSurface *surface = Room.GetDrawingSurfaceForBackground();
surface.DrawImage(cZombie.x-16, cZombie.y-48, 105); //weird quirk in AGS offsets the sprite coordinates from the character coordinates. No idea why, but offsetting the coordinates like this works.
surface.Release();


Of course, the issue is that if the zombie dies when behind a 'walk behind' area, the sprite is drawn over the top of it, because I'm simply drawing the sprite onto the background.

Anyone got any simple / elegant solutions for this?
#8
What specifically are you trying to do with this?
#9
Sounds like AGS doesn't know to edit dialog audio instructions out of options.

Remove the &1 from the option, uncheck the 'say' box next to it, and then have selecting that option simply make your character say that in the dialog script itself.

So your option would now be 'This is a line of dialog', with "show" checked but "say" unchecked.

And when you select that option, it sends you to:

Code: ags
Character: &1 This is a line of dialog.
#10
You always need something to 'trigger' a script to fire. You need to establish the conditions under which, if axe equals zero, the player changes rooms. Your if statement asks the game to check something - while the function you nest that statement within tells the game when to check it. That, in simple terms, is what your functions are for.

So let's say you want the player to change rooms when they click a hotspot, but only if axe is 0. You would bring up that hotspot's event table and select 'player interacts with hotspot' to add the relevant function to your room script, then add your script inside that function:

Code: ags
hotspot1_interact()
{
  if (axe == 0)
  {
    player.ChangeRoom(2)
  }
}


If you want the game to be constantly checking an if statement, and firing a script if it is true, then you need to put that script in releatedly_execute.

If you want this only to be the case when the player is in the current room, then in your room's events table, click repeatedly execute to add this function to your room script, then input exactly the script you wrote in your OP within it:

Code: ags
function repeatedly_execute()
{
  if (axe == 0)
  {
    player.ChangeRoom(2);
  }
}


If you wanted the game to constantly check throughout the game, you would instead add this to repeatedly_execute in the global script (and for best practice, check the player isn't already in the right room when this fires):

Code: ags
function repeatedly_execute()
{
  if ((player.Room != 2) && (axe == 0)) //checks player isn't already in room 2 and that axe==0
  {
    player.ChangeRoom(2);
  }
}
#11
Quote from: Cassiebsg on Mon 04/05/2020 16:02:22
Fedx, just place your sky object in a sky GUI instead, then make sure the z order is in front of the flashlight.  ;)

That is... much less convoluted than my method.  :grin:
#12
This might not be the best way but I'd do it slightly differently.

To avoid the GUI/mouse pointer issue, I'd make the mouse pointer invisible for that scene and combine the flashlight effect and black screen into one large object twice your game resolution. In the middle of your object sprite is the flashlight effect with transparency, which then turns to solid black as required.

I would then make the object follow my mouse pointer in repeatedly_execute_always by constantly setting the object coordinates to be commensurate to the mouse coordinates, with x and y offset according to the object size and your game resolution.

You could then make the sky another object and set this to be in front of your flashlight/darkness object.

I'm sure there is a cheaper and more technical way, but that's the inelegant solution I'd land on in your position.
#13
Thanks, I knew it would be something simple.

In fact, what I needed to do specifically was ensure that cZombie.StopMoving(); was only called once from repeatedly_execute - otherwise the zombie never actually moved anywhere, as no sooner had it been instructed to follow the player, it was instructed to stop moving again.

So, I decided to use a dummy 'state' that is quickly cycled through:

Code: ags
if (zombie_state==1)
    {
      cZombie.StopMoving();
      cZombie.FollowCharacter(cPlayer, 1, 1);
      zombie_state=2;
    }


This worked a treat.
#14
Apols for the third new thread in a few days - I'm trying something new!

So, I'm trying to create a simple real-time combat engine with some very basic AI logic.

There's a lot of code in lots of places in the global script, and most of it isn't relevant to this question, so I won't put it all here. In short, I have an enemy character (cZombie) that has three AI 'states': 0) Patrol, 1) Attack, and 2) Dead. These are all controlled by calling functions from when different conditions are met. Specifically, I check in rep_ex to see if the zombie is moving, and if it isn't, it walks (noblock) to a random place on the screen. I also check with a custom function (and call it from rep_ex) to see if the player is within a certain distance of the zombie and, if they are, then the zombie begins to follow the player and ultimately attack them if they get right up close.

And it almost works. The problem is, when "is the player within a certain distance" returns true, the zombie waits until it has reached its next randomly generated coordinates before it begins to follow the player. In other words, I'm struggling to find a way to 'interrupt' the noblock walk instruction so that the zombie begins to immediately follow the player.

Here's the relevant rep_ex snippet:
Code: ags
//Check distance from player for attacks
    if (cPlayer.Room == cZombie.Room)
    {
      check_zombie_distance();
    }
    
    //Zombie patrolling the area
    if (zombie_state==0)
    {
      if (cZombie.Moving==false)
      {
        cZombie.Walk(Random(1280), Random(720), eNoBlock, eWalkableAreas);
      }
    }
    //Zombie chasing player
    else if (zombie_state==1)
    {
      cZombie.FollowCharacter(cPlayer);
    }


And then I have a custom function for checking the distance:

Code: ags
function check_zombie_distance()
{
  //Check if a zombie is nearby and should therefore change to state 1
  
  if ((cZombie.x - cPlayer.x < 400) && (cZombie.x - cPlayer.x > -400) && (cZombie.y - cPlayer.y < 300) && (cZombie.y - cPlayer.y > -300))
  {
    zombie_state=1;
  }
  
  
    //Check if a zombie is close and should therefore attack
  
  if ((cZombie.x - cPlayer.x < 30) && (cZombie.x - cPlayer.x > -30) && (cZombie.y - cPlayer.y < 30) && (cZombie.y - cPlayer.y > -30))
    {
      zombie_attack();
    }
}


I've checked around the forums and found some ideas (including a module) on how to allow a click to interrupt the player's own walk, which is the most similar query I've found, but haven't been able to find anything to fix this particular issue. Any help or pointers appreciated!

I am also suddenly conscious that any blocking scripts that are fired will block the rep_ex functionality so I suspect I'll also have to move all this to rep_ex_always and then find a way for the zombie attack to interrupt what would normally be blocking actions by the player. Work still to be done!
#15
Edit: I've solved this myself.

Firstly, and most obviously, I had a brain fart and forgot to add brackets to my function imports. This fixed that problem.

I was then making the mistake of thinking char.FaceDirection could check, as well as set, the direction, but I was wrong. This error was fixed by checking which animation loop the characters are using.

As you were.


Hello, me again.

I know there is already a thread about this, but I couldn't figure out a way to apply it to this specific situation and I'm stumped.

I'm trying to create a pair of global functions that will allow the player to shoot another character, who then dies. This occurs repeatedly in various bits of the game, so I want to do this globally rather than one at a time, for efficiency.

I'm creating and importing two functions: shoot() and zombie_die(). shoot() handles the player shooting the zombie and associated variables, while zombie_die() handles the zombie's death animation and associated variables. shoot() will be called when the player interacts with the zombie with a gun inventory item equipped; the zombie_die() function is then called within shoot(), so I've made sure zombie_die() is above shoot() in the global script.

However, when I go to run the game, I get the error "Type of identifier differs from original description" pointing to the zombie_die() function in the global script.

The error still occurs if I comment out literally the entire section of code inside function, so it's definitely something to do with the function itself.

Header script:
Code: ags
import function zombie_die;
import function shoot;


Global script:
Code: ags
function zombie_die()
{
  if (cZombie.FaceDirection==eDirectionDown)
  {
    cZombie.ChangeView(12);
    cZombie.Animate(0, 5, eOnce, eBlock, eForwards);
    cZombie.FollowCharacter(null);
    zombie_dead=true;
  }
  else if (cZombie.FaceDirection==eDirectionLeft)
  {
    cZombie.ChangeView(12);
    cZombie.Animate(1, 5, eOnce, eBlock, eForwards);
    cZombie.FollowCharacter(null);
    zombie_dead=true;
  }
  else if (cZombie.FaceDirection==eDirectionRight)
  {
    cZombie.ChangeView(12);
    cZombie.Animate(2, 5, eOnce, eBlock, eForwards);
    cZombie.FollowCharacter(null);
    zombie_dead=true;
  }
  else
  {
    cZombie.ChangeView(12);
    cZombie.Animate(3, 5, eOnce, eBlock, eForwards);
    cZombie.FollowCharacter(null);
    zombie_dead=true;
}

function shoot()
{
  if (ammo<1)
  {
    SetSpeechStyle(eSpeechLucasarts);
    cPlayer.Say("I'm out of ammo!");
    SetSpeechStyle(eSpeechSierra);
  }
  else
  {
    cPlayer.FaceCharacter(cZombie);
    if (player.FaceDirection==eDirectionDown)
    {
      cPlayer.ChangeView(13);
      cPlayer.Animate(0, 3, eOnce, eBlock, eForwards);
      ammo=ammo-1;
      cPlayer.ChangeView(4);
      zombie_die();
      cZombie.FollowCharacter(null);
    }
    else if (player.FaceDirection==eDirectionLeft)
    {
      cPlayer.ChangeView(13);
      cPlayer.Animate(1, 3, eOnce, eBlock, eForwards);
      ammo=ammo-1;
      cPlayer.ChangeView(4);
      zombie_die();
      cZombie.FollowCharacter(null);
    }
    else if (player.FaceDirection==eDirectionRight)
    {
      cPlayer.ChangeView(13);
      cPlayer.Animate(2, 3, eOnce, eBlock, eForwards);
      ammo=ammo-1;
      cPlayer.ChangeView(4);
      zombie_die();
      cZombie.FollowCharacter(null);
    }
    else
    {
      cPlayer.ChangeView(13);
      cPlayer.Animate(3, 3, eOnce, eBlock, eForwards);
      ammo=ammo-1;
      cPlayer.ChangeView(4);
      zombie_die();
      cZombie.FollowCharacter(null);
    }
  }
}


I'm sure this isn't the most efficient code but I can't fathom any reason why it shouldn't work - so clearly I'm missing something blindingly obvious. Any help appreciated!
#16
Well I'll be damned, I had no idea that was added. Thanks!
#17
Right. So for a particular scene I need the camera to follow a 'character' (a moving vehicle) in the centre of a vertically scrolling screen. Easy enough.

Problem is, the vehicle sprite includes an effect coming out of the back of the vehicle - with the vehicle itself in the top half of the sprite and the trail effect a the bottom. Because the vehicle itself is at the top of the sprite, the screen isn't scrolling until the top of the vehicle nears the top of the screen, so it's continually off-centre vertically as it scrolls.

I figured I could resolve this by manually offsetting the viewport in repeatedly_execute_always, but there's a problem - the sprite now 'flickers' up and down by a few pixels with each game loop. I assume this is because the rep_ex is checking precisely one frame offset against the movement of the sprite.

The most annoying thing is that I know I've solved this problem before, many moons ago. But I've searched and searched and experimented and experimented and can't figure it out.

Here's the rep_ex_always code that results in the flicker effect:

Code: ags
SetViewport(cBuggy.x, cBuggy.y-400);


Any help very much appreciated!
#18
Hi! It's me! I'm back! I'm still working on this! Slowly but surely!

As proof / procrastination (you pick), I made a small new story teaser:

https://www.youtube.com/watch?v=-2T_YGJP0n4
#19
Quote from: ManicMatt on Fri 16/11/2018 21:39:11
wow you have voice acting already?! That's the last thing on my list! Sounds good though.

It normally would be for me, but I wanted to get a sense of how people reacted to the voices early, so I had chance to shake things up a bit based on feedback, before I commissioned the whole script out! :-)
#20
Might seem like an obvious question but: is your other audio playing fine?

File size of the imported audio? I accidentally imported a massive uncompressed audio file into the game once and only realised 'cause there was like a 10 second pause before it started playing.
SMF spam blocked by CleanTalk