ID:2762530
 
(See the best response by Shadowkaroth.)
var/turf/lower_left
var/turf/upper_right
switch(owner.dir)
if(NORTH)
lower_left = locate(owner.x - 1, owner.y + 1, owner.z)
upper_right = locate(owner.x + 1, owner.y + 3, owner.z)
if(SOUTH)
lower_left = locate(owner.x - 1, owner.y - 3, owner.z)
upper_right = locate(owner.x + 1, owner.y - 1, owner.z)
if(WEST)
lower_left = locate(owner.x - 3, owner.y - 1, owner.z)
upper_right = locate(owner.x - 1, owner.y + 1, owner.z)
if(EAST)
lower_left = locate(owner.x + 1, owner.y - 1, owner.z)
upper_right = locate(owner.x + 3, owner.y + 1, owner.z)

for(var/turf/affected_tile in block(lower_left, upper_right)) //everything in the 2x3 block is found.
affected_tile.Shake(4, 4, 2 SECONDS)
for(var/i in affected_tile)
var/atom/movable/affected = i
if(!ishuman(affected) && !istype(affected, /obj/item) && !isdroid(affected))
affected.Shake(4, 4, 20)
continue
if(ishuman(affected)) //if they're human, they also should get knocked off their feet from the blast.
var/mob/living/carbon/human/H = affected
if(H.stat == DEAD) //unless they are dead, then the blast mysteriously ignores them.
continue
H.apply_effects(1, 1) // Stun
shake_camera(H, 2, 1)
var/throwlocation = affected.loc //first we get the target's location
for(var/x in 1 to 6)
throwlocation = get_step(throwlocation, owner.dir) //then we find where they're being thrown to, checking tile by tile.
affected.throw_at(throwlocation, 6, 1, owner, TRUE):



Hello so i'm trying to contribute to an ss13 project i like, i am trying to make an Aoe knockback ability where Z or owner is in the center and everything around it within 5x5 us knocked away.

I have been looking at code to do with this trying to get hints but they are all written differently and i don't want to copy paste.i'v attatched an imgur link for anyone who wants to see an image of what i need. help would really be appreciated, Thank you!

Edit: also note i am dum :( so please use laymans explaining.

https://imgur.com/a/HnqGaX4
:


Best response
Please edit your post or use the html tag <dm to indicate code in your post. For the most part at first glance this all seems like it would indeed do what you desire.

But it seems to be just all ss13 code and I cannot confirm if it set up to do everything it should be doing correctly.
(I did not use your link)
Here's what you want in simple dm.

atom/proc/AOE_PUSH(RANGE)
for(var/atom/movable/m in oview(RANGE,src))
step_away(m,src)

atom/proc/AOE_PUSH_THROUGH_WALLS(RANGE)
for(var/atom/movable/m in orange(RANGE,src))
step_away(m,src)
In response to Kozuma3
Thank you!!! Do I just attatch it to the current code? Im going to leave a // to credit you in the code aswell if that is ok
In response to Vilereaver41
You already seem to be doing everything in a manner that should achieve the desired result. I could have sworn in your initial statement you did not want to use any copy and paste..

Kozuma's post/snippet is an alternate way to "push" things away from the specified "src" by using its own function to push things from its center.

range() is an alternative to block() that would allow you to skip the first few if()s that you are using. For the most part it seems like you need the other parts of your code for 'ss13' reasons. It also would seem the things that for loop is doing would need to be inside the function that Kozuma suggested.
In response to Shadowkaroth
oh sorry about the confusion yes i didnt want to copy paste ;/ but it seems i wont be able to avoid it and will need to give credit. so the code i posted in the first of this thread is already there.

 atom/proc/AOE_PUSH(5)
for(var/atom/movable/m in oview(5,src))
step_away(m,src)

atom/proc/AOE_PUSH_THROUGH_WALLS(5)
for(var/atom/movable/m in orange(5,src))
step_away(m,src)

for(var/turf/affected_tile in block(lower_left, upper_right)) //everything in the 2x3 block is found.
affected_tile.Shake(4, 4, 2 SECONDS)
for(var/i in affected_tile)
var/atom/movable/affected = i
if(!ishuman(affected) && !istype(affected, /obj/item) && !isdroid(affected))
affected.Shake(4, 4, 20)
continue
if(ishuman(affected)) //if they're human, they also should get knocked off their feet from the blast.
var/mob/living/carbon/human/H = affected
if(H.stat == DEAD) //unless they are dead, then the blast mysteriously ignores them.
continue
H.apply_effects(1, 1) // Stun
shake_camera(H, 2, 1)
var/throwlocation = affected.loc //first we get the target's location
for(var/x in 1 to 6)
throwlocation = get_step(throwlocation, owner.dir) //then we find where they're being thrown to, checking tile by tile.
affected.throw_at(throwlocation, 6, 1, owner, TRUE)


i am still learning as i go along. i was told the first block of code wasn't really needed and i could replace it with what Kozuma gave me, but now i need to specify a 5x5 range originating from the owner's position. again sorry for hte confusion, i don't get things quickly;/ how would i use the code he gave me to turn the ability into a 5x5 knockback AOE.
-----
-----
--O--
-----
-----
In response to Avrinsygin
The orange() and oview() do this by using their first argument to denote "range".
thank you!
 atom/proc/AOE_PUSH(RANGE = 5)
for(var/atom/movable/m in oview(RANGE,src))
step_away(m,src)

atom/proc/AOE_PUSH_THROUGH_WALLS(RANGE = 5)
for(var/atom/movable/m in orange(RANGE,src))
step_away(m,src)
guessing it would be like this?
In response to Avrinsygin
Avrinsygin wrote:
 atom/proc/AOE_PUSH(RANGE = 5)
> for(var/atom/movable/m in oview(RANGE,src))
> step_away(m,src)
>
> atom/proc/AOE_PUSH_THROUGH_WALLS(RANGE = 5)
> for(var/atom/movable/m in orange(RANGE,src))
> step_away(m,src)
>


Thoses are procs, you would call those procs as needed via

thing_you_want_as_the_center.AOE_PUSH(5)


Which would execute the proc.

RANGE is the name of the argument to be used for that function, when that function is executed the argument you specified (In the above code 5 is used) will replace RANGE as needed within the function.
I see hmm. would either of you be available on discord? I am willing to pay a commission for help, seems that I'm not understanding well enough.
In response to Avrinsygin
Avrinsygin wrote:
I see hmm. would either of you be available on discord? I am willing to pay a commission for help, seems that I'm not understanding well enough.

If you've never messed with programming before and have yet to understand basic syntax I'd suggest just opening up a fresh DreamMaker project and create a game of tag :D

You can Message me for free and awful help via Kozuma3#6777