Solved Help detecting block at projectile hit

  • Welcome to skUnity!

    Welcome to skUnity! This is a forum where members of the Skript community can communicate and interact. Skript Resource Creators can post their Resources for all to see and use.

    If you haven't done so already, feel free to join our official Discord server to expand your level of interaction with the comminuty!

    Now, what are you waiting for? Join the community now!

  • LOOKING FOR A VERSION OF SKRIPT?

    You can always check out skUnity Downloads for downloads and any other information about Skript!

Status
Not open for further replies.

Akaramine

New Member
Apr 12, 2017
9
0
0
41
Using code provided in documentation examples.
code_language.skript:
on projectile hit:
    if {gameset.%shooter%} is true:
        set {_block} to the block at location 0.5 in front of the projectile
        if {_block} is air:
            set {_block} to the block at location 0.1 behind the projectile
        console command "tm amsg %shooter% %{_block}%"

It seems to nearly always return air. The weird part is this worked for a few minutes. Would sometimes return air, but it was mostly correct. But after a few minutes, it got to the point where it always returns "air" as the block.

I have also tried using block at event-location with the same results

Is there a better way to get this?

Thanks for any help!
 
using 1 instead of 0.1 worked better for me

if you want to see where {_block} is when testing then just set it to a different block. ex:
code_language.skript:
on projectile hit:
    set {_block} to the block at location 1 in front of the projectile
    set the block at {_block} to obsidian
 
using 1 instead of 0.1 worked better for me

if you want to see where {_block} is when testing then just set it to a different block. ex:
code_language.skript:
on projectile hit:
    set {_block} to the block at location 1 in front of the projectile
    set the block at {_block} to obsidian

Thanks for the reply.

Still being really inaccurate. Surely there's a better way to gath what block you hit with a projectile?
 
Thanks for the reply.

Still being really inaccurate. Surely there's a better way to gath what block you hit with a projectile?
The ProjectileHitEvent has a getHitBlock method in newer versions, so, you could do the following with Skript-Mirror:

code_language.skript:
on projectile hit:

    if event.getHitBlock() is set:

        set {_block} to event.getHitBlock()

Other thing you can try is this if you don't want Skript-Mirror:

code_language.skript:
on projectile hit:

    while block 0.1 in front projectile is air:
   
        set {_block} to block 0.1 in front projectile
        wait 1 tick
 
thanks i'll give these a try. I'm unfamiliar with skript-mirror, i'll check it out
Skript-Mirror is a kinda new addon which let's you do Reflection in Skript, that means you can use java methods in a Skript, which is useful for this kind of cases where there is no addon with a proper implementation of the requested thing. It's also useful for do hooks in another plugins.

Another thing, the above code that uses a while loop could work without the wait, but better to put it there just to be sure it won't crash your server (while loops without a wait can crash your server if you use Bukkit methods (methods that modify the world in some way, although that one doesn't) in them)
 
the while statement was still not accurate. But I downloaded skript-mirror. Amazing. It's perfect.

even when my statement above was working, if i hit the exact corner of the block it would be air. But with the java call and skript-mirror it's flawless every time.
I'm not really familiar with programming or java. But I could see this coming in super handy. especially with the the calls to other plugins.

Thanks so much!
 
Status
Not open for further replies.