Chaosforge Forum

DoomRL => Modding => Topic started by: SPTX on March 29, 2013, 07:31

Title: Can we have tutorial on how to make a the main.lua file?
Post by: SPTX on March 29, 2013, 07:31
What we have here doesn't explain anything about the needed "run" function, for example.
It would be nice to have such things explained.
Title: Re: Can we have tutorial on how to make a the main.lua file?
Post by: tehtmi on March 29, 2013, 11:27
"run" is a special function required "single" type levels that does what the OnCreate hook normally does for levels that are declared with register_level.  For other level hooks, "single" levels can just use the corresponding module hooks since there is only one level anyway.

Typically, the "run" function will set up the map (maybe with a generator.place_tile call) and place the player (level:player(x,y)).  Any other stuff is typically just as effective if it appears in the top-level scope of main.lua (or a required file).

As far as making a tutorial, we'd love to do it, but it is just a matter of finding the time, but feel free to continue asking questions.
Title: Re: Can we have tutorial on how to make a the main.lua file?
Post by: SPTX on March 29, 2013, 11:42
"run" is a special function required "single" type levels that does what the OnCreate hook normally does for levels that are declared with register_level.  For other level hooks, "single" levels can just use the corresponding module hooks since there is only one level anyway.

Typically, the "run" function will set up the map (maybe with a generator.place_tile call) and place the player (level:player(x,y)).
That's what I figured out. So I used episode instead, but it seems I have to script the whole episode myself. Isn't there a way to just call for the default one?
Title: Re: Can we have tutorial on how to make a the main.lua file?
Post by: tehtmi on March 29, 2013, 11:54
Isn't there a way to just call for the default one?

You can call DoomRL.OnCreateEpisode in the OnCreateEpisode hook to create the default episode (and use DoomRL.OnGenerate to use the default generator).
Title: Re: Can we have tutorial on how to make a the main.lua file?
Post by: SPTX on March 29, 2013, 12:16
You can call DoomRL.OnCreateEpisode in the OnCreateEpisode hook to create the default episode (and use DoomRL.OnGenerate to use the default generator).
I tried this
Code: [Select]
function SPTXContentPack.OnCreateEpisode()
DoomRL.CreateEpisode()
end
But get this error : main/lua6: attempt to call field 'CreateEpisode' (a nil value)
Line 6 is "DoomRL.CreateEpisode()". Do I have to send any argument? I tried DoomRL.CreateEpisode(1) for shit and giggles, but it lend the same error.
Title: Re: Can we have tutorial on how to make a the main.lua file?
Post by: tehtmi on March 29, 2013, 12:35
Ah, sorry.  I'm running in the dev environment, so I guess that's not allowed normally.  The example provided by classic.module should show you how to get a basic episode.  All that really remains is to add the special levels, which I believe are still available even in the normal environment.

classic.module shows how to do "script" levels that replace basic levels.  To add special stairs to a level (this is partly a function of the generator), do e.g.:
Code: [Select]
player.episode[2].special = "hells_arena"

The ids of the special levels are more or less what you would expect, but you can print out the "levels" table to check.
Title: Re: Can we have tutorial on how to make a the main.lua file?
Post by: SPTX on March 29, 2013, 12:50
Ah, sorry.  I'm running in the dev environment, so I guess that's not allowed normally.  The example provided by classic.module should show you how to get a basic episode.  All that really remains is to add the special levels, which I believe are still available even in the normal environment.

classic.module shows how to do "script" levels that replace basic levels.  To add special stairs to a level (this is partly a function of the generator), do e.g.:
Code: [Select]
player.episode[2].special = "hells_arena"

The ids of the special levels are more or less what you would expect, but you can print out the "levels" table to check.
That will do until I can get the content done, however I really intended to use the base levels for my mod, as I just aimed for a content mod.
What are the names of the boss levels? And how do I set the levels to use the generators for the levels after bosses (like hell)

Now, on an unrelated note, I have several questions.

1. How do I use sprites? What folder, format, res, colour of alpha channel...?
2. I intend to make a(some) new klasse(s), with their own traits, but I can't get my hands on any source of either klass or trait to see how they are made.
3. Is there a list somewhere of items ID? I quite struggled to find that 10mm ammo's name was "ammo" for example. I am planning to make some assemblies and have a hard time imagining all the name combinations I'd have to try to find the mods IDs
Title: Re: Can we have tutorial on how to make a the main.lua file?
Post by: Autoquark on March 29, 2013, 14:43
2. I intend to make a(some) new klasse(s), with their own traits, but I can't get my hands on any source of either klass or trait to see how they are made.

I don't think traits are very moddable yet, but I'm not sure of the details. If you look in the skulltag arena source (available from this forum) in skulltag_arena_traits.lua, there are some minor modifications made to trait effects.

3. Is there a list somewhere of items ID? I quite struggled to find that 10mm ammo's name was "ammo" for example. I am planning to make some assemblies and have a hard time imagining all the name combinations I'd have to try to find the mods IDs

Here. (http://doom.chaosforge.org/wiki/Modding:sID) I had trouble finding it too. Are you aware of the Modding Documentation (http://doom.chaosforge.org/wiki/Modding:Documentation) page? For a while I thought modding:tutorial linked to all the modding pages there were.
Title: Re: Can we have tutorial on how to make a the main.lua file?
Post by: SPTX on March 29, 2013, 14:50
Here. (http://doom.chaosforge.org/wiki/Modding:sID) I had trouble finding it too.
Ah! Thanks. That will boost my productivity.
Title: Re: Can we have tutorial on how to make a the main.lua file?
Post by: yaflhdztioxo on March 29, 2013, 15:17
Skulltag USED to modify traits but I no longer need that hack.  The file will be removed next version.

If I recall correctly you couldn't modify traits before the first pick either, which was a problem...
Title: Re: Can we have tutorial on how to make a the main.lua file?
Post by: tehtmi on March 29, 2013, 20:57
2. I intend to make a(some) new klasse(s), with their own traits, but I can't get my hands on any source of either klass or trait to see how they are made.

Sorry, I think klass and trait modification isn't really supported in the current version.
Title: Re: Can we have tutorial on how to make a the main.lua file?
Post by: SPTX on March 30, 2013, 01:19
That is sad. And what about the sprites?

EDIT :
I have an other issue :
Code: [Select]
function OnEquip()
player.res_fire = player.res_fire+25
player.movetime = player.movetime+5
function OnRemove()
player.res_fire = player.res_fire-25 end end
It says "expected ( near OnEquip". It seems to be a syntax error, but I just don't get it. The code is inserted into an weapon type item. My objective was to change the player stats according to the equipped weapon and revert if unequipped.

Can we have the sources for player emitted sounds too? I also need a way to override default player melee attack (when you bump into a monster without an equipped melee weapon or with an equipped ranged weapon).
I also wanted to prevent weapon switching, I think that can be achieved looping the player:quick_weapon function with the weapon I want to keep in hand as the ID.

EDIT 2 : On a side note, the field "damage_add" doesn't seem to be valid anymore on items, so I added +1 to my dice roll (1d3+1). It appears ingame and works.
Title: Re: Can we have tutorial on how to make a the main.lua file?
Post by: yaflhdztioxo on March 30, 2013, 05:54
Okay, that's a register_item you've spliced code out of right?

Proper syntax is:
Code: [Select]

OnEquip = function (self,being)
your_actions
end,

Damage_Add is still a valid item attribute.  I've manipulated it in 0997 with success before.  Other options for boosting damage on equip would be adjusting the player's todamall trait.

Now for critiques.  Why are you adding these adjustments to the OnEquip hook when you can just modify the item directly?  You are also increasing/decreasing attributes by fixed amounts.  For resistances I *think* that's the right way to do it but for movetime it NEEDS to be a multiplier (player.movetime = player.movetime * 1.05).  If you don't do this the math gets wonky fast and can easily be exploited for good or for ill.

Player sounds may or may not be modifiable.  The sound engine is still one of the weak spots in DoomRL modding.  IF they can be changed it would be with this code:
Code: [Select]
beings["soldier"].sound_melee = core.resolve_sound_id("your_sound")You can reuse another being's sound by replacing "your_sound" with their sound name.  For instance, "soldier.melee" would be the player's default punching noise.  If you have a custom sound in your /sound directory then you would replace "your_sound" with its extension-less name.

As for quick_weapon that cannot be abused.  Only cursed weapons block the equip/unequip logic.
Title: Re: Can we have tutorial on how to make a the main.lua file?
Post by: SPTX on March 30, 2013, 06:31
Proper syntax is:
Code: [Select]

OnEquip = function (self,being)
your_actions
end,
Thanks I am trying that right away.

EDIT : alright this works however I can't make more than one function to work on an item, when I try to put a second one, like for :
Code: [Select]
OnEquip = function (self,player)
player.res_acid = player.res_acid+50 end
OnRemove = function (self,player)
player.res_acid = player.res_acid-50 end
The crashlog tells me that the last line of the second one (where I remove the res bonus) is expected to close my whole item declaration even though neither notepad++ nor I see a syntax error.
here (http://img198.imageshack.us/img198/508/sanstitrexey.jpg) I just changed the enabled functions but the issue is still the same (second function in order fucking up)
Embedding the second function in the first allows the game to launch but will ultimately cause an error on use.
--------------------------

Quote
Damage_Add is still a valid item attribute.  I've manipulated it in 0997 with success before. Other options for boosting damage on equip would be adjusting the player's todamall trait.
Don't know why, it just did not accept damage_add, unless it takes upper casing into account, I don't think I made a mistake. Also I don't want to boost the overall player damage, just the weapons, so the "XdY+Z" notation is perfect.

Quote
Now for critiques. Why are you adding these adjustments to the OnEquip hook when you can just modify the item directly?
For damage I don't, that's is unrelated. Sorry if I was not clear about it. I do this for the later (resistances), which aren't handled by weapons.

Quote
You are also increasing/decreasing attributes by fixed amounts. For resistances I *think* that's the right way to do it but for movetime it NEEDS to be a multiplier (player.movetime = player.movetime * 1.05).  If you don't do this the math gets wonky fast and can easily be exploited for good or for ill.
That clears some things up, thanks.

Player sounds may or may not be modifiable. The sound engine is still one of the weak spots in DoomRL modding. IF they can be changed it would be with this code:
Code: [Select]
beings["soldier"].sound_melee = core.resolve_sound_id("your_sound")You can reuse another being's sound by replacing "your_sound" with their sound name.  For instance, "soldier.melee" would be the player's default punching noise.  If you have a custom sound in your /sound directory then you would replace "your_sound" with its extension-less name.[/quote]
I'll try that, however I noticed the sound_ID were different from the actual sound file names eg : the ID for the shotgun fire is "shotgun" but the filename is "dsshotgn". How does the game differentiate ID from filename?
Quote
As for quick_weapon that cannot be abused.  Only cursed weapons block the equip/unequip logic.
My aim isn't to prevent the weapon from just being unequipped but also to prevent the player from changing weapon at all, ie : note being able to switch to the "prepared" slot.
Title: Re: Can we have tutorial on how to make a the main.lua file?
Post by: yaflhdztioxo on March 30, 2013, 07:47
You are missing a comma.  The functions are just like the other attributes--they must be comma delimited.

I don't actually know if it is case sensitive.  I don't think so.  Never thought about it, which is a failing on my part really.

Weapons do in fact have resistance attributes.  I do not know if they have any effect though; must research.  If not, well there are ways to go about hacking it in, and you've found one so that's fine (unless teht knows better)
Title: Re: Can we have tutorial on how to make a the main.lua file?
Post by: SPTX on March 30, 2013, 07:52
You are missing a comma.  The functions are just like the other attributes--they must be comma delimited.
Where is that comma supposed to go?
I tried on both lines of each and none want to work.
Title: Re: Can we have tutorial on how to make a the main.lua file?
Post by: yaflhdztioxo on March 30, 2013, 09:09
After the 'end' statement.

Code: [Select]
{
...,
OnEquip = function (self,player)
player.res_acid = player.res_acid+50
end,
OnRemove = function (self,player)
player.res_acid = player.res_acid-50
end,
}

This is an assignment, just like hp = 50 is an assignment.  In that context there is no difference between the number 50 and the big block of text from function() to end; both are just objects being assigned to a table index.
What you are actually doing is creating a Lua table with a bunch of attributes which is then being passed to the register_item procedure.  Lua tables have a fairly simple set of rules.  One of them is that multiple assignments must be separated by a comma.  The last comma is technically superfluous but it's easy to forget to add it when you expand a definition so I suggest adding it anyway.

Title: Re: Can we have tutorial on how to make a the main.lua file?
Post by: SPTX on March 30, 2013, 09:13
Welp, I just tried and it yields the same error.
Title: Re: Can we have tutorial on how to make a the main.lua file?
Post by: yaflhdztioxo on March 30, 2013, 09:19
Post your current procedure as a non-jpeg so I can copy it in and see what happens.

And fer chrissakes, use indenting :/.  I cannot stress this enough for new coders.  It will make your life and by extension my life easier.
Title: Re: Can we have tutorial on how to make a the main.lua file?
Post by: Autoquark on March 30, 2013, 09:23
I've done some experimentation:

Weapon resistance attributes grant Torso and Foot resistance when wielded. Prepared weapons do not grant resistance. Weapons with resistance attributes have braces appended to their name with the first letter of the resistance(s) - for example, a pistol granting positive melee resistance and negative acid resistance (i.e. vulnerability) in some quantity appears as:

pistol (2d4) [6/6] {m-a}

The resistance value is not shown in the inventory sidebar.

Ammo packs do not grant resistance when prepared, although the resistance attribute is shown in the inventory sidebar.

So you don't need your hooks to make the player resistant - just set a resistance value on the item.
Title: Re: Can we have tutorial on how to make a the main.lua file?
Post by: SPTX on March 30, 2013, 09:24
Post your current procedure as a non-jpeg so I can copy it in and see what happens.

And fer chrissakes, use indenting :/.  I cannot stress this enough for new coders.  It will make your life and by extension my life easier.
Nevermind, my mistake, that works.
Thanks a lot.

I'll try using indenting, I already do it here and there, but I have a hard time getting the conventions right.

So you don't need your hooks to make the player resistant - just set a resistance value on the item.
You are right. I wonder where I fucked up.
Anyway, there are monsters in the game that are invulnerable to fluids. How is this achieved? They don't seem to use resistances since there is no pain sound.
Title: Re: Can we have tutorial on how to make a the main.lua file?
Post by: yaflhdztioxo on March 30, 2013, 09:34
You can be invincible to fluids by either having an acid/lava resistance of 100% (no monsters have this to my knowledge) or by having the BF_ENVIROSAFE flag (which is meant to simulate flying creatures usually).

And thanks to Autoquark for experimenting in new and inventive ways :).  We need more of that.  And also more wiki love.
Title: Re: Can we have tutorial on how to make a the main.lua file?
Post by: SPTX on March 30, 2013, 09:57
How do you ADD a flag?
I use
Code: [Select]
OnEquip = function (self,player)
player.flags = {BF_ENVIROSAFE} end,
(which didn't grant me fluid invulnerability btw) but I believe it replaces the flags instead of adding to it. I also tried some other silly equations that obviously give errors.
Title: Re: Can we have tutorial on how to make a the main.lua file?
Post by: tehtmi on March 30, 2013, 10:07
To add a flag do
Code: [Select]
player.flags[BF_ENVIROSAFE] = true
If you are doing this in OnEquip, OnRemove, it is possible for there to be strange interactions.  For example, the player can equip your item, then equip the phaseshift set which also grants to the flag.  Then if the player unequips the phaseshift set, that will remove the flag even though your item is still equipped.  The only reason the phaseshift wet works is that there is no other way of changing this flag.  The classic way of solving this problem is to do something like
Code: [Select]
OnEquip(self, player)
  if not player:has_property("envirosafe") then
    player:add_property("envirosafe", 0)
  end
  player.envirosafe = player.envirosafe + 1
  player.flags[BF_ENVIROSAFE] = true
end,
...
OnRemove(self, player)
  if not player:has_property("envirosafe") then
    player:add_property("envirosafe", 0)
  end
  player.envirosafe = player.envirosafe - 1
  if player.envirosafe <= 0 then
    player.flags[BF_ENVIROSAFE] = false
  end
end,
However, this requires all things modifying this flag to use this protocol.  Or you can just ignore it since it's usually an edge case.

damage_add is a valid item property that just effects that particular item.  The corresponding prototype property isn't accepted by the blueprint because it is intended to be parsed from the damage string, as you discovered.

Weapon resistances are used in DoomRL by the Acid Spitter, so they are officially supported (if not widely used).
Title: Re: Can we have tutorial on how to make a the main.lua file?
Post by: SPTX on March 30, 2013, 11:47
Thank you, it works wonders.

Now I have yet an other questions.

1. How are the monster's melee attack handled? I am thinking about monsters that have both ranged and melee attacks, such as cacodemons. They obviously don't switch weapons, and they seem to be rolling dice too.
What I want to do is basically override the player melee attack that is used under the same circumstances (ranged weapon equipped, bumping into an enemy) But I don't find anything helping me in either "being" and "thing" nor "player" pages of the wiki.

2. is there any parameter that defines the aggressive behaviour or monsters toward the player? I'd want to invert that behaviour (friendly monsters attacking other monsters)
Title: Re: Can we have tutorial on how to make a the main.lua file?
Post by: tehtmi on March 30, 2013, 12:36
1. How are the monster's melee attack handled?
Monster melee attacks work exactly the same as the player's default fists attack; they do 1d3 damage plus any bonuses.  The only bonus is typically the monster's todam modifier (which only applies to melee attacks as opposed to todamall).

Quote
2. is there any parameter that defines the aggressive behaviour or monsters toward the player? I'd want to invert that behaviour (friendly monsters attacking other monsters)

The built-in AIs don't really have support for this.  You can either write your own AI or try to hack the built-in AI; probably writing a new one is simpler as long as you don't need it to be very complex.
Title: Re: Can we have tutorial on how to make a the main.lua file?
Post by: SPTX on March 30, 2013, 12:46
Monster melee attacks work exactly the same as the player's default fists attack; they do 1d3 damage plus any bonuses.  The only bonus is typically the monster's todam modifier (which only applies to melee attacks as opposed to todamall).
I figured as much, the thing is I have no idea how the default fist attack works and can't find doc on it.

Quote
The built-in AIs don't really have support for this.  You can either write your own AI or try to hack the built-in AI; probably writing a new one is simpler as long as you don't need it to be very complex.
Well, I'd just want them to ignore the player and attack other beings instead. This is for player-spawned lostsouls and resurrected monsters precisely. So this applies only to the last created being, three at most concerning the lostsouls which should not bee an issue if turning the monsters friendly could be done by a function call.
Title: Re: Can we have tutorial on how to make a the main.lua file?
Post by: SPTX on April 02, 2013, 03:40
As for quick_weapon that cannot be abused.  Only cursed weapons block the equip/unequip logic.
I just tried the cursed weapons thinking it would just prevent me to unequip the weapon, but it also prevents switching, which is perfect for what I wanted.