Chaosforge Forum

  • March 28, 2024, 09:07
  • Welcome, Guest
Please login or register.



Login with username, password and session length
Pages: [1] 2  All

Author Topic: Can we have tutorial on how to make a the main.lua file?  (Read 14424 times)

SPTX

  • Sergeant
  • *
  • Offline Offline
  • Posts: 77
  • Lost Soul
    • View Profile

What we have here doesn't explain anything about the needed "run" function, for example.
It would be nice to have such things explained.
Logged

tehtmi

  • Programmer
  • Local Inquisitor
  • Lieutenant Colonel
  • *
  • *
  • Offline Offline
  • Posts: 458
    • View Profile
Re: Can we have tutorial on how to make a the main.lua file?
« Reply #1 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.
Logged

SPTX

  • Sergeant
  • *
  • Offline Offline
  • Posts: 77
  • Lost Soul
    • View Profile
Re: Can we have tutorial on how to make a the main.lua file?
« Reply #2 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?
Logged

tehtmi

  • Programmer
  • Local Inquisitor
  • Lieutenant Colonel
  • *
  • *
  • Offline Offline
  • Posts: 458
    • View Profile
Re: Can we have tutorial on how to make a the main.lua file?
« Reply #3 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).
Logged

SPTX

  • Sergeant
  • *
  • Offline Offline
  • Posts: 77
  • Lost Soul
    • View Profile
Re: Can we have tutorial on how to make a the main.lua file?
« Reply #4 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.
Logged

tehtmi

  • Programmer
  • Local Inquisitor
  • Lieutenant Colonel
  • *
  • *
  • Offline Offline
  • Posts: 458
    • View Profile
Re: Can we have tutorial on how to make a the main.lua file?
« Reply #5 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.
Logged

SPTX

  • Sergeant
  • *
  • Offline Offline
  • Posts: 77
  • Lost Soul
    • View Profile
Re: Can we have tutorial on how to make a the main.lua file?
« Reply #6 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
« Last Edit: March 29, 2013, 13:31 by SPTX »
Logged

Autoquark

  • Backer
  • Lance Corporal
  • *
  • *
  • Offline Offline
  • Posts: 23
  • Lost Soul
    • View Profile
Re: Can we have tutorial on how to make a the main.lua file?
« Reply #7 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. I had trouble finding it too. Are you aware of the Modding Documentation page? For a while I thought modding:tutorial linked to all the modding pages there were.
Logged

SPTX

  • Sergeant
  • *
  • Offline Offline
  • Posts: 77
  • Lost Soul
    • View Profile
Re: Can we have tutorial on how to make a the main.lua file?
« Reply #8 on: March 29, 2013, 14:50 »

Here. I had trouble finding it too.
Ah! Thanks. That will boost my productivity.
« Last Edit: March 29, 2013, 14:53 by SPTX »
Logged

yaflhdztioxo

  • Programmer
  • Local Inquisitor
  • Captain
  • *
  • *
  • Offline Offline
  • Posts: 298
  • Lost Sole
    • View Profile
Re: Can we have tutorial on how to make a the main.lua file?
« Reply #9 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...
Logged

tehtmi

  • Programmer
  • Local Inquisitor
  • Lieutenant Colonel
  • *
  • *
  • Offline Offline
  • Posts: 458
    • View Profile
Re: Can we have tutorial on how to make a the main.lua file?
« Reply #10 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.
Logged

SPTX

  • Sergeant
  • *
  • Offline Offline
  • Posts: 77
  • Lost Soul
    • View Profile
Re: Can we have tutorial on how to make a the main.lua file?
« Reply #11 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.
« Last Edit: March 30, 2013, 04:07 by SPTX »
Logged

yaflhdztioxo

  • Programmer
  • Local Inquisitor
  • Captain
  • *
  • *
  • Offline Offline
  • Posts: 298
  • Lost Sole
    • View Profile
Re: Can we have tutorial on how to make a the main.lua file?
« Reply #12 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.
Logged

SPTX

  • Sergeant
  • *
  • Offline Offline
  • Posts: 77
  • Lost Soul
    • View Profile
Re: Can we have tutorial on how to make a the main.lua file?
« Reply #13 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 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.
« Last Edit: March 30, 2013, 07:23 by SPTX »
Logged

yaflhdztioxo

  • Programmer
  • Local Inquisitor
  • Captain
  • *
  • *
  • Offline Offline
  • Posts: 298
  • Lost Sole
    • View Profile
Re: Can we have tutorial on how to make a the main.lua file?
« Reply #14 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)
Logged
Pages: [1] 2  All