Action RPG Framework

by Forum_account
Action RPG Framework
A framework for developing action RPGs.
ID:1241423
 
Sometimes it's fun to whack a monster and send it flying across the screen. Here's some code to do just that!

First, add this to a new file, or to the bottom of your abilities.dm file.

mob
proc
knockback(mob/attacker, strength)
var/dir = get_dir(attacker, src)
_push(dir, strength)

pull(mob/attacker, strength)
var/dir = get_dir(src, attacker)
world << "Pulling [src] toward [attacker] at [strength] ([dir]) "
_push(dir, strength)

_push(dir, strength)
switch(dir)
if(NORTH)
vel_y += strength
if(SOUTH)
vel_y += -strength
if(EAST)
vel_x += strength
if(WEST)
vel_x += -strength
if(NORTHWEST)
vel_y += strength * 2/3
vel_x += -strength * 2/3
if(NORTHEAST)
vel_y += strength * 2/3
vel_x += strength * 2/3
if(SOUTHWEST)
vel_y += -strength * 2/3
vel_x += -strength * 2/3
if(SOUTHEAST)
vel_y += -strength * 2/3
vel_x += strength * 2/3


Next, go into your abilities.dm file and find the ability you'd like to add knockback to. Check out the effect() proc, it'll look like this:

        effect(mob/user)

// find a target in the attacker's melee range
var/mob/target = user.melee_target()

// trigger a 40 tick cooldown for this ability and
// a 10 tick cooldown for all attacks
user.cooldown("melee-attack", cooldown)
user.cooldown("attack", 10)

// inflict damage and show a graphical effect on the target
PhysicalCombat.attack(user, target, 5 + user.power)
target.effect("dagger-slash")
target.noise('hit-1.wav', frequency = rand(0.7, 1.3))


Simply add the new call to the method:

            target.knockback(user, 10)



Suddenly, knockback!