#raycast deal dmg

1 messages · Page 1 of 1 (latest)

cyan breach
#

i have a question, i stole this wonderful raycast from online - but how do i make it damage entities the particles hit?

on right click:
if 1 of player's tool is stick:
if name of player's tool is "&4Apple Wand":
appleraycast(player, 20, 20, red)

function appleraycast(p: player, length: number, dmg: number, color: color):
set {_x} to 0
set {_l} to 0
loop {_length} times: #loops as many times as long as the length from the function input
add 1 to {_x}
add 0.25 to {_l}
set {_rg%{_x}%} to location {_l} meters infront of {_p}
set {_rg%{_x}%} to location 1.25 meters above {_rg%{_x}%} #aligns with where player is looking
set {_x} to 0
loop {_length}*10 times:
add 1 to {_x}
if {_color} is red:
show 4 red dust at {_rg%{_x}%} #change color or particle type

loop entities in radius 1.5 around {_rg%{_x}%}:
    if loop-entity is not a player:
        damage loop-entity by {_dmg}
        stop #if you want your projectile to pierce entities, delete this line
loop blocks in radius 0.5 around {_rg%{_x}%}:
    if loop-block is not air:
        stop #projectile does not go through blocks, but passes through expected blocks
tough geode
#
  1. Format code on discord please
  2. Looks like that code already is supposed to damage
#
  1. I really just hate this code.
  • why is {_rg%{_x}%} not a list?
  • and, Why is {_x} there when there’s no code that uses previous points?
  • the comment “#aligns with where player is looking” is misleading, it should say “raise vector to head height”. Also, why not just use player’s head location?
  • why are players excluded from the loop? If this is to prevent the first point from damaging the event-player, only that one needs to be excluded
glass gazelle
#

Looks like example from mhut forum

tough geode
#

You can make (or find/re-use this) particle line code, but i would personally use an skbee ray trace. Then you simply

  • get the hit entity
  • damage it
  • showParticleLine(event-player’s head location, {_targetEntity})
cyan breach
#

Iits supposed to damage mobs not players

#

i have no idea how raycast works

#

thats one of things i cant understand

tough geode
#

Hang on, why is your length 20? No wonder its not working—thats step size not max length

cyan breach
#

im so confused, what do i need to change?

tough geode
#

Your code is jumping 20 blocks at a time—its going to likely miss most entities you want it to hit

cyan breach
#

i fixed that, but how do i make it damage

tough geode
#

As i said, looks like the code already does

#

You should be able to tell by reading the code and seeing the function has a dmg parameter, and a line damage loop-entity by {_dmg}

tough geode
cyan breach
#

i would think, i would just hav to do appleraycast(player, 20, 1000, red)

cyan breach
#

what should i set it to then?

#

because if i do 1, it wotn go far

worn trellis
cyan breach
#

particles are so confusing to me

tough geode
#

Then use skript-particles built in line

#

Ray trace to get the target