Racial powers

Racial powers by CosmicGerbil

This help is very similar to the file lua_pow, written by Fearoffours, which can be found in the lib/help folders of ToME. I used that file to learn to write many of my racial powers. Many thanks to Fearoffours.

If you create a new race for your module, you may want to give them a special racial power. This can be anything from an elemental ball (fire ball, ice ball) to a power that lets you destroy doors and walls.

First you have to write a program in lua to create a power. This script shows a racial power for my fire elemental race. Of course the script could be used for any race, as I will explain later.

FIRE_POWER = add_power
{
        ["name"] =      "Fire ball",
        ["desc"] =      "Your can make fire balls",
        ["desc_get"] =  "You can make fire balls",
        ["desc_lose"] = "You lose ther ability to make fire balls",
        ["level"] =     1,
        ["cost"] =      2,
        ["stat"] =      A_CON,
        ["fail"] =      11,

["power"] =     function()
                local ret, dir, damage
                ret, dir = get_aim_dir();
                if (ret == FALSE) then 
                        return 
                end
                damage = player.lev*3
                msg_print("You send a ball of fire into your enemy.")
                fire_ball(GF_FIRE, dir, damage, 3)
end

}

FIRE_POWER is the name of the racial power. Lua does not like spaces, so you put in the symbol "_" to seperate words and make the script easy to read.

This adds the power (of course)

["name"] =      "Fire ball", The name of the power that will appear when you access it in the game (you access racial powres by typing "U").

["desc"] =      "You can make fire balls", 
        ["desc_get"] =  "You can make fire balls",
        ["desc_lose"] = "You lose the ability to make fire balls",

These three lines describe the power and also losing the power. You may lose a racial power if you get corrupted.

        ["level"] =     1, The experience level you need to be before you can use your power. ["level"] =     10, would mean you could not access a power until you had gained experience level 10.

How much mana it takes to use the power

Which of your stats is dependant on the power. This particular power uses the constitution stat. ["stat"] =      A_INT, would use the intelligence stat.

This means that if your CON stat is less then 11 you cannot use fire ball successfully. The 11 can be any chosen number up to 40, but the higher it gets the more difficult it is to use a power.

["power"] =     function() 
                local ret, dir, damage
                ret, dir = get_aim_dir();
                if (ret == FALSE) then 
                        return 
                end

This part of the script is to do with the direction that you want to aim the fire ball in. Dir means direction. I do not fully understand this part, but a clearer explantaion can be found in lib/help in the file lua_pow

This example shows that the damage your fire ball causes is equal to the fire elementals experince level multiplied by three. A line in the script reading damage = player.lev*7 would be a much more powerful attack :)

msg_print means that a message (msg) is printed on the screen when you use the power.

fire_ball means a ball of *something* is fired, not a ball of fire! You could be firing a water ball or a poison ball.

GF_FIRE is the actual ball of fire. A list of all the GF flags can be found in lib/help and the file lua_gf. These flags are the many different types of attacks that can be used.

Dir and Damage run the parts of the script concerned with the direction of the fire ball and how much damage it causes.

3 is the radius of the fire ball. Quoted from the lua_spel file in lib/help "A "ball" travels from source to the target, exploding at the target, and affecting everything within the given radius of the target location".

end

End, of course, ends the script

} This bracket closes the script. Don't forget it :)

To test the racial power use a clean copy of ToME (or your own module, if you have one). Copy the script into notepad, save the script in the folders lib/script and give it a name (I called mine fire.lua)

To make ToME or your module "read" the new script, go into lib/script and open the file init. Type in anywhere (at the bottom will do):

-- Add racial power
tome_dofile("fire.lua")

The top line does nothing, it is simply a comment explaining what you have added. Any line that starts with -- in a lua script is a comment and is not read by lua.

Now you need to give the script to your race. Open up the p info file in the edit folder, and choose a race. For this example I have used hobbits. You can, of course use any race you wish to give fire ball to.

R:N:3:Hobbit R:D:An old but quiet race related to humans. R:D:They are small and quite weak but good at many things. R:S:-2:2:1:3:2:1:5 R:K:15:18:18:5:12:15:-10:20 R:P:7:110:4:10 R:M:21:12:36:3:60:3:33:3:50:3 R:E:1:1:1:2:1:1 R:Z:create food S:Z:fire ball R:G:RESIST_BLACK_BREATH | XTRA_MIGHT_SLING | R:R:1:0 R:F:SUST_DEX | R:C:Warrior | Archer | Wizard | Rogue | Loremaster

The line S:Z:fire ball is the one that gives hobbits the racial power. The Z is always used for the racial power line, although I have no idea what Z stands for :)

Now, hopefully if I have explained it right, when you play ToME the hobbit race should have fire ball as a racial power.

Beams and Bolts

As well as balls, a power can be written to allow your race to fire beams and bolts. Quoted from the lua_spel file in lib/help again:

"A "bolt" travels from source to target and affects only the target grid. A "beam" travels from source to target, affecting all grids passed through. "

A bolt is useful for a close range attack or when you want a power that can only attack one monster at a time. For example in Gerband, my grue race has the racial power "poison bite". So because a grue can only bite one monster at a time a bolt is suitable. So apart from changing the relevent names: FIRE_POWER to GRUE_POWER, "Fire ball", to "Poison bite", and so on, the important lines in the script now read:

msg_print("You bite your enemy.")

There is no 3 on the end of the last line (or any number at all), because the poison bite does not have a radius, it attacks the target monster directly.

I have not coded any beam powers yet, but such a power could be something like a beam of light, so a race with a beam attack could stand at one end of a corridor, fire the beam, and zap all the monsters down the corridor :)

If anybody wants to use the fire script in their modules, that's great. Just mention me in the credits file :D

Module Developers Discussion/Adding racial powers (last edited 2006-09-14 15:59:53 by host86-142-44-16)