🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Skills

posted in trill41 for project ABx
Published November 25, 2018
Advertisement

This is an RPG and RPGs usually have skills. In this game a character can have up to eight skills. NPCs and Players usually can equip skills from the same pool. But I'm not yet sure if this game will have a PvE part, where you fight against NPCs, or if it's just a PvP game. Anyway, NPCs can have and use skills.

Skills

There should be different types of skills, skills that make damage to a target or make AOE damage. Other skills can heal a target or all Actors in an area, etc. All this should be controlled by the Lua script, the server itself has no knowledge what a skill does, and the Client, well, the Client knows nothing.

The basic effect of a skill can be:

  • Resurrect
  • Heal
  • Protect (avoid, reduce damage)
  • Damage

And a skill can have an effect to:

  • Self
  • Selected Target
  • AOE

So a single skill can have one or more of the above effects and one or more of the above listed targets.

At the moment the skill pool is very limited, there are just three skills:

  • Sudden Death (instant suicide): Targets self and makes damage.
  • Instant Kill: Targets the selected target and makes damage.
  • Instant Rezz: Targets the selected target and resurrects.

All these skills are only for testing and don't make sense in a real game.

Skills scripts

Skills are implemented as simple Lua scripts, like bellow the "Instant Kill" skill:


-- Use own include function, because the Lua search path is a mess
-- and it makes it possible to precompile and cache the script
include("/scripts/includes/consts.lua")
include("/scripts/includes/skill_consts.lua")

costEnergy = 0
activation = 0
recharge = 0
range = RANGE_MAP
-- If there will be some AI then the AI must have some basic knowledge of what a skill does
effect = SkillEffectDamage | SkillTargetTarget

function onStartUse(source, target)
  if (target == nil) then
    -- This skill needs a target
    return false
  end
  if (source:GetId() == target:GetId()) then
    -- Can not use this skill on self
    return false
  end;
  if (self:IsInRange(target) == false) then
    -- The target must be in range
    return false
  end  
  if (target:IsDead()) then
    -- Can not kill what's already dead :(
    return false
  end
  return true
end

function onEndUse(source, target)
  -- print("Using Instant Kill on " .. target:GetName())
  return target:Die()
end

function onCancelUse()
end

Of course, this skill is a bit overpowered, but it's just for testing.

Player using skills

A player has a skillbar, usually at the bottom, with all equipped skills:

fw2018-11-25-12-51-53.png.c57cd12b38c59cd97d72e12128569338.png

As almost any action in this game, a hotkey can be assigned to each skill, but is also triggered when the button is clicked.

hotkeys.png.6daaaaeb4e25047cbd99949ced56e4ec.png

NPC using skills

In the same way a player uses skills, NPCs can use skills. They also have a skillbar with max. eight skills. To make this work the NPC Lua scripts have to be extended, like the Pedestrian, to make her Rezz machine:


include("/scripts/includes/chat.lua")
include("/scripts/includes/consts.lua")
include("/scripts/includes/skill_consts.lua")

name = "Pedestrian"
level = 20
modelIndex = 10    -- Female Pedestrian 1 body model
sex = SEX_FEMALE
creatureState = CREATURESTATE_IDLE
prof1Index = 3     -- Monk
prof2Index = 0     -- None
--behavior = "wander"

local rezzTarget = nil

function onInit()
  self:SetSpeed(0.5)
  -- Let's make it a rezz machine :D
  local skillBar = self:GetSkillBar()
  -- Instant rezz skill
  skillBar:AddSkill(9996)
  return true
end

function onUpdate(timeElapsed)
  if (self:IsDead() == false and rezzTarget == nil) then
    local actors = self:GetActorsInRange(RANGE_CASTING)
    for i, v in ipairs(actors) do
      if (v:IsDead()) then
        rezzTarget = v
        break
      end
    end
    if (rezzTarget ~= nil) then
      self:FollowObject(rezzTarget)
      self:Say(CHAT_CHANNEL_GENERAL, rezzTarget:GetName() .. ", you noob!")
    end
  end

end

function onClicked(creature)
end

-- self was selected by creature
function onSelected(creature)
  self:Say(CHAT_CHANNEL_GENERAL, "Not now!")
end

-- creature collides with self
function onCollide(creature)
end

function onArrived()
  -- self:FollowObject(rezzTarget) was called to go to the target. Now she is there.
  if (rezzTarget ~= nil) then
    local skillBar = self:GetSkillBar()
    local skills = skillBar:GetSkillsWithEffect(SkillEffectResurrect)
    if (skills[1] ~= nil) then
      self:SetSelectedObject(rezzTarget)
      self:UseSkill(skills[1])
    end
    rezzTarget = nil
  end
end

function onEndUseSkill()
  rezzTarget = nil
  self:SetState(CREATURESTATE_IDLE)
end

function onStartUseSkill(skill)
  local targetName = "Everything!"
  local target = skill:GetTarget()
  if (target ~= nil) then
    targetName = target:GetName()
  end
  print("Using skill " .. skill:GetName() .. " on " .. targetName)
end

function onDied()
  self:Say(CHAT_CHANNEL_GENERAL, "Aaaaarrrrrrggghhh")
end

function onResurrected()
  self:Say(CHAT_CHANNEL_GENERAL, "Oh, ty")
end

This NPC will go to dead people if they are in a certain range, and will resurrect them.

Video

Next Entry Collisions
0 likes 0 comments

Comments

Nobody has left a comment. You can be the first!
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Profile
Author
Advertisement

Latest Entries

Advertisement