CraftBook 3

CraftBook 3

139k Downloads

Command-Items ENTITY_ARROW click type

LadyCailinBot opened this issue · 49 comments

commented

CRAFTBOOK-2927 - Reported by jjkrause

As discussed on the Youtube video, the Command-Item doesn't trigger the ENTITY_ARROW click type. I've tested it with a snowball and with a bow/arrow.

Also, where could I find some info on the "Actions" section of the Command-Items? Its something I could definitely find useful.

Thanks.

commented

Comment by me4502

With actions, I plan on greatly improving it before writing the documentation, I've just been very busy recently.

With entity arrow, it still triggers, but it needs to be under very specific circumstances.

Basically you need to set the command item as the bow, or snowball, and it can't use up the snowball stack when you shoot it, as the snowball is used prior to the event being called, therefore I can't check the last snowball in a stack. And you need to keep that item selected until the projectile hits an entity

commented

Comment by jjkrause

Ok, I've done some testing. I have a stack of 10 Command-Items snowballs and when I throw and hit another player, the commands aren't run and I get the "Could not pass event EntityDamageByEntityEvent to CraftBook..." in the console.

Error message: http://pastebin.com/QNcyiHqQ

I'm making a basketball game where a snowball Command-item is the ball. I want to throw the snowball and hit another player to pass it to them. So when they're hit with the snowball, my inventory is cleared and they receive the snowball. The logic is easy, but I can't get it to trigger.

commented

Comment by jjkrause

Oh, and this is my Command-Item: http://pastebin.com/8aXT34QW

commented

Comment by me4502

That's a bukkit issue, update bukkit

commented

Comment by jjkrause

Ok, updated Spigot to the latest and the error messages disappeared and the commands are running now.. Thanks once again! I will send you a donation shortly for all your awesome help.

Quick question: I'm trying to figure out a way to do this: If I throw my "Basketball" and miss the player and the snowball hits the ground/wall, I want a snowball Dropped Item to appear when the ball hit, so the players can race to it and pick it up. Seems complicated.

commented

Comment by jjkrause

Essentials TP doesn't support decimals...

commented

Comment by jjkrause

I figured out how to use /setblock and /summon commands with @p, @d, @e, but I'm still trying to figure out how to break a block when a snowball hits it using @b. I can get the blockname and coordinates if I break the block using a command-item and BLOCK_BREAK clicktype with @b, but no luck yet using a snowball to destroy a block. I think its because the ENTITY_ARROW click-type only triggers when an entity is hit, and a block isn't an entity.

How complicated is it to add these two Click_Types?
BLOCK_HIT: Performs the action when a block is hit/left clicked (then use @b to perform an action on the block)
BLOCK_ARROW: Performs the action when a block is hit by a projectile (again, @b.x @b.y @b.z would return the coords of the block that is hit)

commented

Comment by me4502

Block hit is already there, just under another name. As for block arrow, there is no event for it in bukkit. You can get the arrows position and set it based on that

commented

Comment by jjkrause

BLOCK_BREAK -> The block has to be actually broken before the action is performed. I'd like for it to be performed when the block is hit the first time without actually needing to break it. For lack of a better example, a command-item stick used to turn a bedrock block into a pumpkin when I hit it. If I use BLOCK_BREAK, it will never happen. It would only be possible if the action is performed when the block is hit the first time.

As for getting the arrows position using @e.x @e.y @e.z, how do I trigger it when the arrow or snowball hits a block? I can get the arrow's position when it hits an entity using ENTITY_ARROW, but for a block, I'm lost.

commented

Comment by me4502

I've just added CLICK_X_BLOCK and CLICK_X_AIR events, and also @x.by, etc.

commented

Comment by jjkrause

Excellent! Tested the CLICK_LEFT_BLOCK using the @b.x,@b.y,@b.z and was able to perform an action on the block that was clicked. You realize with the last few additions, you've made Command-Items 10x more powerful...Nice work!

commented

Comment by me4502

Oh cool, have you got any other CommandItem requests? I want to make them amazing before writing the rest of the docs.

commented

Comment by jjkrause

I'm still trying to figure out how to destroy a block with an arrow or snowball, but as you stated, there's no collision event in Bukkit. There's a way of coding it though, as I've seen mini-games where snowballs or eggs destroy blocks on contact. Probably they calculate the projectile's next position using the velocity and determine if its a block other than air.

Question: The MATHVAR you added, can it be used to add 1 for example to @d.by, or is it strictly for defined variables?

commented

Comment by jjkrause

Forget that question about MATHVAR, I saw in the code that it is only used in actions.

Another request:

  • Be able to do arithmetic operations on player/block or entity coordinates. For example, @b.y+1 would give the Y coordinate above the block that was hit. Or, @d.by-1 would be the block under the player that was hit. This opens up the possibility of moving blocks/players with relative coordinates.
commented

Comment by jjkrause

I have another request, but I'm not sure how it would be implemented. I'd like to be able to detect when a player is moving and get the block locations of where they are standing. An example will better explain what I mean: A player is on a playfield, when he runs around, the blocks under him disappear like a TNT-Run type game. I think the issue with this is what actually triggers the event. I wonder if it would be possible to get the block coordinates under each player while they are holding a command-item in their hand and moving? Maybe it would need to trigger every x ticks as to not make it too processor intensive? Not too sure about all this, but I'm sure you'll tell me what's possible and what's not.

commented

Comment by me4502

I added MATHVAR as a way to do the arithmetic on the coordinates as math parsers are incredibly complicated and large.
Basically, define a variable and set it to the coordinate in an action, then use MATHVAR to change it, then reference it when needed.

I plan on making a passive event which runs every few ticks, which could be useful for your last one.

And for plugins that get snowball collisions on blocks, just use @e.x, it should give you the block it hit.

commented

Comment by jjkrause

But what click-type do I use to trigger the command for a snowball collision on a block? ENTITY_ARROW doesn't trigger as there are no entities...

commented

Comment by me4502

Hmm, I'll look through bukkit this afternoon and work it out

commented

Comment by me4502

BLOCK_PROJECTILE has just been added.

commented

Comment by jjkrause

Hmmmm, I tested and can't get it to trigger with BLOCK_PROJECTILE.

Test:
    item: SNOW_BALL*16|TestBall
    commands:
    - msg @p @e.x @e.y @e.z
    permission-node: ''
    run-as: SUPERUSER
    click-type: BLOCK_PROJECTILE
    delay: 0
    cooldown: 0
    cancel-action: true
    consumed-items: []
    consume-self: false
    require-sneaking-state: NONE
    keep-on-death: false
    actions: {}

If I change BLOCK_PROJECTILE to ENTITY_PROJECTILE and hit a cow for example, it messages me the coordinates, but BLOCK_PROJECTILE doesn't trigger when the snowball hits a block.

commented

Comment by me4502

I think I forgot to call it.. I'll fix that this afternoon

commented

Comment by me4502

Thanks for the donation, do you want your server to be listed as a server that donated?

As for the other thing,
Uh, that may be possible when I add more actions.

commented

Comment by jjkrause

I don’t have a proper domain name setup yet, but as soon as I do, I’ll get it listed if that’s ok with you. I think my server demonstrates well what can be done with Craftbook… Looking forward to using the "Actions", but I'll be patient for you to work on it. ;)

commented

Comment by me4502

What sort of actions would be helpful?
Actions are basically either conditions that are required in order to perform the commands, or actions that are performed after the commands. Currently there are actions that can detect a variable beforehand to see if it should perform the command, and an action to set a variable after a command is performed.

commented

Comment by jjkrause

For me, the first few thing to come to mind that would be useful are:

  • set a variable to the x,y,z coordinates of each player involved. Example, if player 1 throws a snowball and hits player 2, variables such as @px/@py/@pz and @dx/@dy/@dz could be used to perform any actions I want, such as using the tp/setblock or summon commands with those variables. Commands "/tp @p @Dx @dy @dz" and "/tp @d @px @py @pz" would switch the two player locations when hit by a snowball or arrow (using the ENTITY_ARROW click_type). Another example: "/setblock @Dx @dy+5 @dz stone" would place a stone block 5 blocks above the person who was hit @d.

  • Set a variable to the x,y,z coordinate of the contact point of a projectile such as a snowball or arrow @cx,@cy,@cz (c for contact maybe?). I'd like to be able to perform an action on the block that was hit by a snowball for example. Ex: "/setblock @cx @cy @cz air" would remove the block was hit by the snowball. Or "/tp @p @cx @cy @cz" would Tp the player to the landing spot of an arrow.

I'll write up more stuff as I think of it...

commented

Comment by me4502

Currently I've been trying to find the best way of making actions parse the @ variables, once I've worked that out I'll continue to add more.

commented

Comment by jjkrause

Great, looking forward to it. Once I can perform the actions listed above, I'll donate again. :)

commented

Comment by me4502

I believe I have just made those two possible. It is untested however. I have yet to have time to write the documentation for it.

commented

Comment by jjkrause

Excellent, I just briefly went through your code and I'll test later this morning.

commented

Comment by me4502

Thanks

commented

Comment by jjkrause

Ok, I quickly played around with the various variables you added and it seems quite straightforward to use. The only minor issue I've detected until now are the decimals in x,y and z that cannot be used with a TP and some other commands. Maybe we will need to add a modifier to truncate the decimal point.

EX: /tp @p @e.x @e.y @e.z will not work if @e.x = 8.5.

Just a note, I'm not using these in the Actions section, but in the Commands section of the Command-Items.

commented

Comment by me4502

Hmm, what plugin adds your tp command? I'll add a .bx for the block x coordinate etc.

commented

Comment by jjkrause

I'm just thinking this would be useful to spawn special power-up items at specific locations in an arena. I know I can already do it with [MC1201], but by doing it with a command, we can make the location dynamic.

commented

Comment by me4502

Added.

commented

Comment by jjkrause

Thanks! Adding the world to the command was a good idea as well. I see you started working on Passive, is it ready or still in "test mode"?

commented

Comment by me4502

It's all ready

commented

Comment by jjkrause

How much work would it be to add @p.w, @d.w, @e.w, @b.w that would return the world name? That way, we can use /COMITEMS SPAWN TestItem @e.bx @e.by @e.bz -w @e.w from the console.

commented

Comment by me4502

Yeah, I can add that

commented

Comment by me4502

Done.

commented

Comment by jjkrause

Excellent, tested and confirmed working. When you have a chance, could you quickly explain how to configure a passive command-item?

commented

Comment by me4502

Passive is basically the same as normal. It'll be activated if the item is held or worn.
It is triggered every half second, and you can use cool down to make it trigger less.

commented

Comment by jjkrause

Excellent. Passive works great! Thanks again.

commented

Comment by me4502

Okay, it should be called now.

commented

Comment by jjkrause

Its being called now, thanks! Donation incoming. One thing though, @e.bx @e.by @e.bz doesn't actually return the coordinates of the block being hit, it returns the coordinates of where the snowball was destroyed, usually 1 block in front (or above, depending on the angle) of the block being hit. I've even seen it 2 returning the coordinates 2 blocks in front.

commented

Comment by me4502

Hmm, in that case the entity must be moving through like that odd.

commented

Comment by jjkrause

One final request for now :) Would it be possible to disable any output to the chat window when running commands? For example, when I throw a snowball, I set //pos1, //pos2 to the location of the snowball impact, then expand the selection by 1 in all directions using //outset 1, then set the region to air using //set air. In the chat window, every time I throw a snowball, I get:

First position set to (coords)
Second position set to (coords)
Region outset.
10 blocks(s) have been changed.

I'm thinking these messages are out of your control as craftbook simply runs the commands and WorldEdit is generating the output. Your thoughts?

commented

Comment by me4502

It's not possible to make commands silent sorry, but if you use console commands they won't show for the player.

commented

Comment by jjkrause

Another idea. Would it be possible to add to the /comitems command to spawn a command-item at a specific location?

Syntax: /comitems spawn x y z

ex: /comitems spawn TestItem @e.bx @e.by @e.bz

That way, if I throw an object such as a snowball to the ground, a dropped item of the snowball could be created at that location and picked up again...

commented

Comment by me4502

Hrm, I guess I could