Help with dagger throw code please

Started by Construed, Tue 14/02/2012 01:37:34

Previous topic - Next topic

Construed

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...
Code: ags


//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.
I felt sorry for myself because I had no shoes.
Then I met the man with no feet.

Creator

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:

Code: ags

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


Hope this helps you.

R4L

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?"

Construed

Yea search hasnt been working for me either  ???

But this is what i have so far.
Code: ags

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.
I felt sorry for myself because I had no shoes.
Then I met the man with no feet.

Creator

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).

Code: ags

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:

Code: ags

cdag.FollowCharacter(null);

Construed

Thank you my good man, Duely noted.
Going to play with this a bit and see what i come up with :D
I felt sorry for myself because I had no shoes.
Then I met the man with no feet.

Construed

#6
ok, i've been toying with this and using this:
Code: ags

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 ???
I felt sorry for myself because I had no shoes.
Then I met the man with no feet.

Khris

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:

Code: ags
// 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.

SMF spam blocked by CleanTalk