Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: Construed on Tue 14/02/2012 01:37:34

Title: Help with dagger throw code please
Post by: Construed on Tue 14/02/2012 01:37:34
Wondering if anyone can help me improve this dagger throwing code.
My goal here is to make the dagger only be thrown within the walkable area so it appears to stop at walls etc..
I would like to be able to use the dagger gamewide and also use multiple daggers for multiple players.
Here's what i got so far...


//make dagger normally invisible
cdag.Transparency=100;
cdag.FollowCharacter(cA, 0, 0);


//button that activates dagger animation
function Button31_OnClick(GUIControl *control, MouseButton button)
{
 
  cdag.Transparency=0;
cdag.Walk(5, 182, eBlock);
  cdag.Transparency=100;
  Wait(30);
}

//open dagger gui
function Button19_OnClick(GUIControl *control, MouseButton button)
{

attacks.Visible=true;
   
}

function attacks_OnClick(GUI *theGui, MouseButton button)
{


}
//close dagger gui
function Button32_OnClick(GUIControl *control, MouseButton button)
{
attacks.Visible=false;
}


As you can see the dagger will only go to the area specified in the script. I would like it to go to mouses x,y coords but cant seem to find a function or variable capable of that.
This code is totally expieramental, for testing purposes.
Title: Re: Help with dagger throw code please
Post by: Creator on Tue 14/02/2012 04:58:46
I can help with the dagger going to the mouse coordinates, but I have no idea about stopping at walkable areas. Sorry.

For going to mouse X and Y:


cdag.Walk(mouse.x, mouse.y, eBlock);


Hope this helps you.
Title: Re: Help with dagger throw code please
Post by: R4L on Tue 14/02/2012 05:34:27
The forums aren't letting me search, but there are quite of bit of questions pertaining to this in the Tech Forum and Begginer's Tech forum. Maybe search in those for "How do I make a bullet?"
Title: Re: Help with dagger throw code please
Post by: Construed on Tue 14/02/2012 17:26:15
Yea search hasnt been working for me either  ???

But this is what i have so far.

function cdag_Interact()
{
player.AddInventory(dag);
cdag.Transparency=100;
cdag.FollowCharacter(cA, 0, 0);
}



function dag_UseInv()
{
cdag.Transparency=0; 
cdag.Walk(mouse.x, mouse.y, eBlock);
player.LoseInventory(dag);
cdag.StopMoving();

}


My issues with this are..

1.Cant find any way to make inventory items interact with anything but other inventory items and the ego himself.

2.Follow char doesnt seem to be stopping on command.
Title: Re: Help with dagger throw code please
Post by: Creator on Wed 15/02/2012 04:40:01
Quote from: GrimReapYou on Tue 14/02/2012 17:26:15
1.Cant find any way to make inventory items interact with anything but other inventory items and the ego himself.

2.Follow char doesnt seem to be stopping on command.

1. I'm pretty sure each character, object and hotspot has a "use inventory on x" option in their interaction pane (the lightning bolt menu).


function cRandomNPC_UseInv()
{
  if (player.ActiveInventory == iDagger) // If the player is using the dagger on cRandomNPC
  {
    //Some dagger code
  }
}


2. Using StopMoving will only make the character stop moving. If he's following another character, he'll resume moving once the command has moved on. If you want a character to stop following another, you have to use:


cdag.FollowCharacter(null);
Title: Re: Help with dagger throw code please
Post by: Construed on Wed 15/02/2012 16:11:16
Thank you my good man, Duely noted.
Going to play with this a bit and see what i come up with :D
Title: Re: Help with dagger throw code please
Post by: Construed on Fri 17/02/2012 00:37:22
ok, i've been toying with this and using this:

function cdag_Interact()
{
player.AddInventory(dag);
cdag.Transparency=100;
cdag.FollowCharacter(cA, 0, 0);
}



function cdag_UseInv()
{
 if (player.ActiveInventory == dag) // If the player is using the dagger on cRandomNPC
 {
   
cdag.Walk(mouse.x, mouse.y, eBlock);  
cdag.FollowCharacter(null);  
cdag.Transparency=0;  

player.LoseInventory(dag);

 }
}


The dagger has the behavior i want it to have with other functions, but (player.ActiveInventory == dag) seems to have no effect, perhaps i don't correctly understand this function, I would like the dagger to use the script located within that function when clicked anywhere on the screen.

Basically i need the active inventory item "dag" to just go wherever i click on the screen.
I would think cdag.Walk(mouse.x, mouse.y, eBlock);  located under the (player.ActiveInventory == dag) function would do so, but its not ???
Title: Re: Help with dagger throw code please
Post by: Khris on Fri 17/02/2012 08:57:46
cdag_UseInv() is called when the player uses a random inventory item on the dagger.

In other words, the code you used is only called if the dagger is used on itself. You need:

// inside on_mouse_click

  ...
  else if (button == eMouseLeft) {
    if (player.ActiveInventory == dag) {
      player.LoseInventory(dag);
      cdag.FollowCharacter(null);   
      cdag.Transparency = 0;
      cdag.Walk(mouse.x, mouse.y, eBlock);
    }
    else ProcessClick(mouse.x, mouse.y, mouse.Mode );
  }
  ...


Note that I changed the order. I stopped making it follow before telling it to walk, and I also turned it visible beforehand.
This should be obvious.