Chaosforge Forum

  • December 18, 2018, 06:53
  • 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 4194 times)

SPTX

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

Logged

SPTX

  • Sergeant
  • *
  • Offline Offline
  • Posts: 76
  • Lost Soul
    • View Profile
Re: Can we have tutorial on how to make a the main.lua file?
« Reply #17 on: March 30, 2013, 09:13 »

Welp, I just tried and it yields the same error.
« Last Edit: March 30, 2013, 09: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 #18 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.
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 #19 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.
Logged

SPTX

  • Sergeant
  • *
  • Offline Offline
  • Posts: 76
  • Lost Soul
    • View Profile
Re: Can we have tutorial on how to make a the main.lua file?
« Reply #20 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.
« Last Edit: March 30, 2013, 09:28 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 #21 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.
« Last Edit: March 30, 2013, 09:35 by yaflhdztioxo »
Logged

SPTX

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

tehtmi

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

SPTX

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

tehtmi

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

SPTX

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

SPTX

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