(Solved) Checking where a object is to pick it up

Started by BlueAngel, Fri 11/02/2011 13:23:12

Previous topic - Next topic

BlueAngel

Help
I want the player to pick up something and I want the player to walk there to pick it up. But he can only pick it up if he can reach it.
What I’m I doing wrong here:  ???

Code: ags

function oCoconut_AnyClick()
{
  //LOOK AT
  if(UsedAction(eGA_LookAt)) {
    player.Say("It's a coconut");
    
  }
  // USE
  else if(UsedAction(eGA_Use)) {
    player.Say("I'd rather pick it up.");
  }
  // Push
  else if(UsedAction(eGA_Push)) {
    Unhandled();
  }
  // Pull
  else if(UsedAction(eGA_Pull)) {
    Unhandled();
  }  
  // PICKUP
  else if(UsedAction(eGA_PickUp)) {
          if(Object.GetAtScreenXY(525, 419)==oCoconut)
      {
        player.Say("Jummy");
        cEgo.Walk(525, 419, eNoBlock, eWalkableAreas);
    
        Hunger-=10;
     }
     else
     {
      player.Say("help");
      }
  }
  //USE INV
  else if(UsedAction(eGA_UseInv)) {
    Unhandled();
  }
  // don't forget this
  else Unhandled();
}


I also have this in the room:
Code: ags

function room_Load()
{
  short waveX = oWave.X;
  short waveY = oWave.Y;
  float duration = 3.0;
  oWave2.Transparency=20;
  oWave.IgnoreScaling = false;
  oWave.TweenPosition(duration,85, 639, eLinearTween, eRepeatTween);
  oWave2.TweenPosition(duration, 483, 411, eLinearTween, eRepeatTween);
  oCoconut.TweenPosition(10.0, 513, 384, eEaseOutTween,  eReverseRepeatTween);
  
    
}

Khris

You're using the 9verb template, right? There should be a function called MovePlayer you're supposed to use like this:

Code: ags
function oCoconut_AnyClick()
{
  if (MovePlayer(525, 419)) {
    player.FaceDirection(eDirUp);
    //LOOK AT
    if(UsedAction(eGA_LookAt)) {
      player.Say("It's a coconut");
    }
    // USE
    else if(UsedAction(eGA_Use)) {
      player.Say("I'd rather pick it up.");
    }
    ...
  }
}


Now, there used to be a small bug in MovePlayer which caused it to return true even if the player was unable to reach the specified coordinates.
Don't know if that has been fixed, I'm at work so can't take a look right now.

BlueAngel

Ok, I will try that when I get back in.
Thanks for helping me!

BlueAngel

#3
No, it works but not as I want it to. cEgo walks to the coconut but can take it even when he shouldnt. Maybe I making this to hard. May I should just let the player have the coconut.  ::)

Is there any way else to check if a object is in a place beside this:
Code: ags

if(Object.GetAtScreenXY(525, 419)==oCoconut)

I have taken out the Tween moving so that not the problem as I thought..
Maybe I can do something with a timmer...


Solved it kind of:
Code: ags

// PICKUP
  else if(UsedAction(eGA_PickUp)) {
     if(Region.GetAtRoomXY(player.x, player.y)==region[1]&&oCoconut.Animating==false)
  {
    cEgo.FaceObject(oCoconut, eBlock);
    cEgo.AddInventory(iCoconut);
  }
    else if(Region.GetAtRoomXY(player.x, player.y)!=region[1]&&oCoconut.Animating==false)
    {
      player.Say("cant reach it");
    }


Now I just have to found another way to animate it without using Tween

BlueAngel

I must be stupid.
With this code the player can never reach it even if he on region 1. Any suggestions?

Code: ags

// PICKUP
  else if(UsedAction(eGA_PickUp)) {
     if(Region.GetAtRoomXY(player.x, player.y)==region[1]&&Object.GetAtScreenXY(525, 419)==oCoconut)
  {
    cEgo.FaceObject(oCoconut, eBlock);
    cEgo.AddInventory(iCoconut);
  }
    else if(Region.GetAtRoomXY(player.x, player.y)!=region[1]&&oCoconut.Moving==false)
    {
      player.Say("cant reach it");
    }
    else if(Region.GetAtRoomXY(player.x, player.y)==region[1]&&oCoconut.Moving==true)
    {
      player.Say("cant reach it");
    }
    else if(Region.GetAtRoomXY(player.x, player.y)!=region[1]&&oCoconut.Moving==true)
    {
      player.Say("cant reach it");
    }
    else if(Region.GetAtRoomXY(player.x, player.y)==region[1]&&Object.GetAtScreenXY(525, 419)!=oCoconut)
    {
      player.Say("cant reach it");
    }

BlueAngel

#5
This works the first time but after the nut has move one time, it stops working  ???
Code: ags

// PICKUP
  else if(UsedAction(eGA_PickUp)) {
     if(Region.GetAtRoomXY(player.x, player.y)==region[1]&&object[0].X==525)
  {
    cEgo.FaceObject(oCoconut, eBlock);
    cEgo.AddInventory(iCoconut);
  }
    else if(Region.GetAtRoomXY(player.x, player.y)!=region[1]&&oCoconut.Moving==false)
    {
      player.Say("cant reach it");
    }
    else if(Region.GetAtRoomXY(player.x, player.y)==region[1]&&oCoconut.Moving==true)
    {
      player.Say("cant reach it");
    }
    else if(Region.GetAtRoomXY(player.x, player.y)!=region[1]&&object[0].X!=525)
    {
      player.Say("cant reach it");
    }
    else if(Region.GetAtRoomXY(player.x, player.y)==region[1]&&object[0].X!=525)
    {
      player.Say("cant reach it");
    }
    
  }

but it should be at the same place after move
Code: ags

function room_RepExec()
{
    if(IsTimerExpired(1))
  {
    oCoconut.Move(513, 384, 80, eNoBlock, eAnywhere);
    SetTimer(1, 400);
  }
  if(IsTimerExpired(2))
  {
    oCoconut.Move(525, 419, 20, eNoBlock, eAnywhere);
    SetTimer(2, 400);
  }
}


Close this -I think my problem was that the start position and my end position were too close so the picture of the object was overlapping or something. As soon as I put the end further down it worked.

SMF spam blocked by CleanTalk