Author Topic: Changing Basic Traits  (Read 472 times)

0 Members and 1 Guest are viewing this topic.

Nintaku

  • Newbie
  • *
  • Posts: 6
    • View Profile
Changing Basic Traits
« on: March 31, 2021, 01:50:50 AM »
Hello! I'm excited to be beginning my Solarus journey, and already have rather ambitious goals in mind. I will of course be putting together a small quest to get used to the way the Solarus bits are put together, but after getting my bearings I plan on converting a Zelda-based tabletop RPG system into Solarus as 1:1 as possible. The first step in my plan is setting up the ability for the hero to collect and use different weapons, which is pretty accepted already, but I want to have those weapons be interchangeable. Maybe the hero ditches his Sword for a Spear instead, and now has different damage and the spin attack is replaced.

I've already gotten ahead of myself and started putting together things I'd need. So far I have a script that lists out the base values of weapon and armor ranks, and another listing the exact stats of weapons. I'll probably merge them into a single script at some point, but right now they exist for me to pull data from them so that, for instance, if rank 1 is 6 and sword_att is +0, then rank1 + sword_att = 6 damage. With spear_att being -1, then rank1 + spear_att = 5 damage. Then the target's Defense trait would reduce that damage to a minimum of 1, rather than tunic rank dividing damage.

Any pointers or tips on how to accomplish that would be much appreciated.

I've also started the same project in RPG Maker MV, but I prefer the Solarus engine so far. It's easier to manipulate to do just what I need, once I can figure out what I need to do.

llamazing

  • Full Member
  • ***
  • Posts: 220
    • View Profile
Re: Changing Basic Traits
« Reply #1 on: April 01, 2021, 04:12:46 AM »
I would use the following for the data file:
Code: (lua) [Select]
weapon_class{
  id = "sword",
  attack_sprite = "sword_attack",
  charged_attack_sprite = "sword_charged_attack", --i.e. spin attack
  damage_modifier = -1,
}

weapon_class{
  id = "spear",
  attack_sprite = "spear_attack",
  charged_attack_sprite = "spear_charged_attack",
  damage_modifier = 0,
}

weapon{
  id = "simple_sword",
  class = "sword",
  damage = {6, 7, 8, 10, 12, 15}, --rank 1 is 6 damage, rank 6 is 15 damage
}

weapon{
  id = "legendary_spear",
  class = "spear",
  damage = {8, 10, 13, 16}, --rank 1 is 8 damage, rank 4 is 16 damage
}

Nintaku

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: Changing Basic Traits
« Reply #2 on: April 01, 2021, 10:23:13 AM »
That's fantastic, thank you! :D Before I'd just made a series of values. Plugging my data into this should help handle things quite nicely.

llamazing

  • Full Member
  • ***
  • Posts: 220
    • View Profile
Re: Changing Basic Traits
« Reply #3 on: April 01, 2021, 02:15:35 PM »
Here's a script you can use to read the data file:
Code: (lua) [Select]
--usage:
--local data_loader = require("scripts/data_loader")
--data_loader.load_data("scripts/data.lua")

local data_loader = {}

function data_loader.load_data(path)
  local weapon_classes = {}
  local weapons = {}
 
  assert(sol.file.exists(path), "Error: data file not found: "..path)
 
  --create environment for loading data
  local env = setmetatable({}, {__index = function(self, data_type_name) --default function to handle unknown data entries
    print("WARNING: Unknown data entry: "..tostring(data_type_name))
    return function(properties) end --return dummy function to prevent error because return value will be called
  end})
 
  function env.weapon_class(properties)
    local id = properties.id
    assert(type(id)=="string", "Bad weapon_class property 'id' (string expected)")
    assert(not weapon_classes[id], "Bad weapon_class property 'id', must be unique value: "..id)
   
    local weapon_class_entry = {} --create new weapon entry
    for k,v in pairs(properties) do weapon_class_entry[k] = v end --copy properties to new weapon entry
    weapon_classes[id] = weapon_class_entry
  end
 
  function env.weapon(properties)
    local id = properties.id
    assert(type(id)=="string", "Bad weapon property 'id' (string expected)")
    assert(not weapons[id], "Bad weapon property 'id', must be unique value: "..id)
   
    local weapon_entry = {} --create new weapon entry
    for k,v in pairs(properties) do weapon_entry[k] = v end --copy properties to new weapon entry
    weapons[id] = weapon_entry
  end
 
  --load the data file
  local chunk = sol.main.load_file(path)
  assert(chunk, "Error: unable to read file: "..path)
  setfenv(chunk, env)
  chunk()
 
  --put loaded data into a new table and return it
  return {
    weapon_classes = weapon_classes,
    weapons = weapons,
  }
end

return data_loader
« Last Edit: April 01, 2021, 02:44:53 PM by llamazing »

Nintaku

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: Changing Basic Traits
« Reply #4 on: April 06, 2021, 06:06:30 PM »
Alright, so I'm working on two separate concepts at the same time here. First is the aforementioned ranks and equipment, and second is the less mentioned setup for character stats.

Here's my repository for these scripts: https://github.com/AgentNintaku/reclaim-the-wild/tree/main/data/scripts/rtw

ranked_equipment.lua - I've expanded on the suggested data script, including tables for Ranks 0-5 to apply to my 17 Weapon classes and 4 Armor classes. Still figuring out the language, though, so not sure I've got this right. When I create individual weapons, I really do want to simply call a rank and a weapon class and add them together, with the ability to add in other special modifiers to represent enchantments that will modify things like character traits (we'll get to that) and the weapon's inherent values. It should only require a couple of fields: id, rank, class, and then anything unique to it.

data_loader.lua - I haven't really touched this yet, but been studying it in hopes of getting some insight into how I can phrase my ranked_equipment tables for ease of use.

traits.lua - Here's another important portion of this project. I want the hero and monsters to have Traits, basically RPG stats that can be raised with experience points and have game effects. Most of them don't seem particularly useful to a videogame at first glance, but I have plans. And I can just take out what turns out to not be useful as I move deeper into the project. Point is, I'm not sure how to implement them on the hero. I'm pretty sure I can make good use of the Level and Experience scripts elsewhere to work with these, however. But then I'll need to make my own subscreen for spending points on these traits.

So that's where I'm at so far. At this point I feel I should probably move my updates over to Your Projects, so that'll be where my next post goes.