Chaosforge Forum

DoomRL => Modding => Topic started by: Autoquark on March 28, 2013, 03:51

Title: Changing the ammo system?
Post by: Autoquark on March 28, 2013, 03:51
This is my first real attempt at modding doomRL, so please bear with me if these questions are rather basic.

I'm trying to alter the doomRL ammo system to be like the system in Doom, where the player has a fixed capacity for each kind of ammo. I thought the easiest way to do this might be to change the size that ammo stacks to in the inventory to the amount I want the player to be able to hold, and then only allow the player's inventory to hold one ammo stack of each kind. Would it be possible to do this using the OnPickup hook? If so, should I define my own ammo types and add the hook to them, or just use the general OnPickup hook and the existing ammo types?

Thanks for any help.
Title: Re: Changing the ammo system?
Post by: tehtmi on March 28, 2013, 04:58
Ammo is maybe the weirdest item type in DoomRL because it is the only thing that stacks.  Ammo stack items are created automatically by the engine to do ammo management, sometimes in unintuitive ways.  Because of this, it won't be easy to implement this kind of system robustly, but here are some approaches you could try.

Hooks on ammo items don't work well in the current version.  OnPickupCheck doesn't seem to be called at all, and OnPickup is called after the ammo is added.  This could probably still be used, but you would have to fix up the ammo in the player's inventory after the fact.  Another thing you can do is use powerups to add ammo to the player's inventory like Game Hunter does in HereticRL.  OnPickupCheck and OnPickup work for powerups and could be used to implement any logic you like.  Either way, you have to worry about other ways that ammo can be created like dropping ammo from the inventory and unloading weapons.  These will probably be hard to handle well.

Yet another approach would be not to use items for ammo at all.  You could add custom properties to the player (or wherever) to track ammo, and again use powerups to add ammo to these counters.  If you go this approach, all your weapons would need to have custom OnFire and OnReload hooks to make use of the custom ammo system, but it is probably doable.  The difficulty I would anticipate here is displaying the ammo to the player.  Probably I would try to add it in to the name of currently equipped weapons using some combination of OnEquip, OnRemove, and OnEquipTick.
Title: Re: Changing the ammo system?
Post by: Autoquark on March 28, 2013, 08:27
Thanks for the detailed answer. I might leave that idea for a bit, at least until I'm more familiar with the system and lua. I guess I'll add some other random questions:

1. If I'm creating an episode, and I want to define custom items, where should I put the definitions? And which hook is best for adding stuff to the player's starting inventory?

EDIT: Nevermind, after looking at the skulltag arena files, I see that you have to use register_item. I thought that they had to be put inside a function.

2. I was also wondering about creating my own mod items. I guess you use ui.msg_choice to let the player choose an item slot to mod, but I can't find out from the wiki how to reference the player's equipped items. Is there any example code for this?

3. Is there any easy way to prevent the level generator from generating the built-in items, or will I have to wait for total conversion mod support?

Thanks again for helping.

EDIT2: After adding various missing values to my new item which weren't included in the tutorial template, I now get the following error message:

core\\core.lua:221: attempt to index field '?' (a nil value)

Here's my item declaration:

Code: [Select]
register_item "new_pulsecannon" {
name = "pulse cannon",
id = "extra_pulsecannon",
desc = "The Microsol Pulse Cannon provides cost-effective firepower thanks to the self-recharging battery.",
ascii = "}" ,
sprite = SPRITE_CHAINGUN,
level = 1,
weight = 1000, --bit of a guess, see item generation page on wiki
flags = {IF_RECHARGE},
firstmsg = "",
color_id = "generic",
--type specific
    type         = ITEMTYPE_RANGED, --required field
damage        = "2d4",           --required field
    damagetype    = DAMAGE_BULLET,   --required field
    group         = "weapon-pistol", --defaults to "weapon-other"
    fire          = 10,              --defaults to 10
    acc           = 0,               --defaults to 0
    radius        = 0,               --defaults to 0 (_RANGED and _NRANGED only)
    shots         = 1,               --defaults to 0
    ammo_id       = "ammo",        --required field (_RANGED only)
    ammomax       = 12,              --required field (_RANGED only)
    reload        = 12,              --defaults to 10 (_RANGED only)
    shotcost      = 1,               --defaults to 0 (_RANGED only). I think 1 makes it a rapid-fire weapon and 0 a single-shot
    altfire       = ALT_AIMED,       --defaults to ALT_NONE (_MELEE and _RANGED only)
    altfirename   = "aimed shot",    --default depends on altfire (_MELEE and _RANGED only)
    altreload     = RELOAD_FULL,     --defaults to RELOAD_NONE (_RANGED only)
    altreloadname = "full",          --default depends on altreload (_RANGED only)
    --soundID       = "pistol",        --defaults to "id" (_RANGED and _NRANGED only)
    missile       = "gun",
psprite   = SPRITE_PLAYER_CHAINGUN --the sprite used to represent the player when equipped
}
Title: Re: Changing the ammo system?
Post by: tehtmi on March 29, 2013, 02:22
2. I was also wondering about creating my own mod items. I guess you use ui.msg_choice to let the player choose an item slot to mod, but I can't find out from the wiki how to reference the player's equipped items. Is there any example code for this?

ui.msg_choice is actually what the real game uses, but there are more abstraction layers built up that you can use.  Mods are somewhat complicated, so here are the hooks from mod_power for you to base your stuff off of:
Code: [Select]
OnUseCheck = function(self,being)
local item, result = being:pick_mod_item('P',being.techbonus)
if not result then return false end
if item ~= nil then self:add_property("chosen_item", item) end
return true
end,

OnUse = function(self,being)
if not self:has_property("chosen_item") then return true end
local item = self.chosen_item
if item.itype == ITEMTYPE_MELEE then
item.damage_sides = item.damage_sides + 1
elseif item.itype == ITEMTYPE_RANGED then
if item.damage_sides >= item.damage_dice then
item.damage_sides = item.damage_sides + 1
else
item.damage_dice = item.damage_dice + 1
end
elseif item.itype == ITEMTYPE_ARMOR then
item.armor = item.armor + 2
elseif item.itype == ITEMTYPE_BOOTS then
item.armor = item.armor * 2
end
item:add_mod('P')
return true
end,
The whole dance with having to use OnUseCheck and the custom property is inelegant, but it allows the mod to not take any time when the player cancels it.  If you don't like that, here's the simpler version from before the change.
Code: [Select]
OnUse = function(self,being)
local item, result = being:pick_mod_item('P',being.techbonus)
if not item then return result end
if item.itype == ITEMTYPE_MELEE then
item.damage_sides = item.damage_sides + 1
elseif item.itype == ITEMTYPE_RANGED then
if item.damage_sides >= item.damage_dice then
item.damage_sides = item.damage_sides + 1
else
item.damage_dice = item.damage_dice + 1
end
elseif item.itype == ITEMTYPE_ARMOR then
item.armor = item.armor + 2
elseif item.itype == ITEMTYPE_BOOTS then
item.armor = item.armor * 2
end
item:add_mod('P')
return true
end,
Using :pick_mod_item will prompt the player, check for assemblies, and make sure you are allowed to mod the item with the given mod.

Quote
3. Is there any easy way to prevent the level generator from generating the built-in items, or will I have to wait for total conversion mod support?

For a particular item, you can just do e.g.
Code: [Select]
items.pistol.weight = 0
If you want to get rid of all of them, you can just loop through before registering any of your own items
Code: [Select]
for _, it in ipairs(items) do
  it.weight = 0
end
Modifying prototypes after they are declared is a bit messy, but it's the only option for built-in things.

Quote
Here's my item declaration:
Wow, what a useless error message.  It is failing because "gun" is not defined as a missile.  It has been renamed to "mgun".  (I think all the missiles gut "m" added at the beginning and all the shotgun-type missiles got "s" added to the beginning.)

Also, the id field should no longer be included in the table; the initial argument to register_item (e.g. "new_pulsecannon") will be used as the id.
Title: Re: Changing the ammo system?
Post by: SPTX on March 29, 2013, 11:45
It is failing because "gun" is not defined as a missile.  It has been renamed to "mgun".  (I think all the missiles gut "m" added at the beginning and all the shotgun-type missiles got "s" added to the beginning.)

Also, the id field should no longer be included in the table; the initial argument to register_item (e.g. "new_pulsecannon") will be used as the id.
I have the same error as this dude (and did the same mistake) however even after changing "gun" to "mgun" I still have the error.
Here is the incriminated code.
Code: [Select]
register_item "SPTXsniperrifle"{
name = "Long range rifle",
    type = ITEMTYPE_RANGED,
sprite = SPRITE_CHAINGUN,
level = 2,
weight = 160,
psprite = SPRITE_PLAYER_SHOTGUN,
    ammo_id = "ammo",
    group = "weapon-shotgun",
    damage = "10d2",
damagetype = DAMAGE_BULLET,
    missile = "mgun",
    fire = 15,
    reload = 10,
    acc = 2,
    ammomax = 5,
flags = {IF_PUMPACTION,IF_SHOTGUN},
    desc = "A rifle designed to shoot targets at very long distances.",
    altfire = ALT_AIMED,
}
Title: Re: Changing the ammo system?
Post by: tehtmi on March 29, 2013, 11:51
I have the same error as this dude (and did the same mistake) however even after changing "gun" to "mgun" I still have the error.

Since you have IF_SHOTGUN, the game is looking in the shotgun list instead of the normal list.  If you want it to be a shotgun, change the missile to a proper shotgun type (like "snormal"), otherwise remove the IF_SHOTGUN flag.
Title: Re: Changing the ammo system?
Post by: SPTX on March 29, 2013, 12:09
Since you have IF_SHOTGUN, the game is looking in the shotgun list instead of the normal list.  If you want it to be a shotgun, change the missile to a proper shotgun type (like "snormal"), otherwise remove the IF_SHOTGUN flag.
Well that fixed it. Thanks. A lot.
Title: Re: Changing the ammo system?
Post by: Autoquark on March 29, 2013, 14:37
Thanks. I've now got the mod running with my own weapons being generated and working correctly. Just a couple of questions: what's the property name of "fire" on a weapon? The wiki says "usetime", but I've tried both "usetime" and just "fire" and I get a lua error saying I'm reading an undeclared variable.
Also, how are OnAltFire hooks for scripted alt fire modes meant to be used. Should I temporarily alter the stats of the weapon and then change them back in the OnFired hook, or is that completely wrong?

I know the lua files for the main game aren't being released yet, but have you considered including an example file with each release containing the definitions for one or two items of each type, and perhaps the ai for one or two enemies? Having examples to look at would be a great help, and if they were copied from the game lua files, they would always be up to date, which would be helpful when there are changes to the system that the wiki hasn't caught up with.

EDIT: Another question - how do I access the player's inventory? I want to go through it to check if a particular kind of ammo is present - I'm trying to make a weapon that draws ammo directly from the inventory.
Title: Re: Changing the ammo system?
Post by: tehtmi on March 29, 2013, 21:14
...what's the property name of "fire" on a weapon? The wiki says "usetime", but I've tried both "usetime" and just "fire" and I get a lua error saying I'm reading an undeclared variable.
"fire" is the name of the prototype property and "usetime" is the object property.  If the Lua error is for an undeclared variable, the problem could be the context you are using it in, as that doesn't sound like an error you'd get when declaring an item.  I'd have to see what you're doing.

Quote
Also, how are OnAltFire hooks for scripted alt fire modes meant to be used. Should I temporarily alter the stats of the weapon and then change them back in the OnFired hook, or is that completely wrong?

OnAltFire is called when you use altfire = ALT_SCRIPT.  I don't consider this to be very mature yet, as most of DoomRL alternate fire modes are not implemented in Lua.  However, what you suggest sounds like the best way to do it to me.  DoomRL's rocket launcher actually uses OnFire to switch the stats back, but I think OnFired would generally work better.

Quote
I know the lua files for the main game aren't being released yet, but have you considered including an example file with each release containing the definitions for one or two items of each type, and perhaps the ai for one or two enemies? ...
This would probably be good, but I'd have to go through Kornel to get permission about what we can post.

Quote
how do I access the player's inventory? I want to go through it to check if a particular kind of ammo is present - I'm trying to make a weapon that draws ammo directly from the inventory.

Currently the only real access seems to be through the inventory iterator
Code: [Select]
for it in player.inv:items() do
  print(it.name)
end
The order they are stored in is undefined (i.e. should not be relied upon).  The rest of the inventory API would be .inv:empty() (this is a predicate), .inv:clear(), .inv:add(it, [params])
Title: Re: Changing the ammo system?
Post by: Autoquark on March 30, 2013, 10:02
I tried looking through the inventory like this:
Code: [Select]
OnFire = function(self) --to draw ammo from inventory
for it in player.inv:items() do
if it.id == "hl_nuclear_ammo" then
it.ammo = it.ammo - 1
return true
end
return false
end
end,
But the hook never seems to return true, although I'm sure I have an ammo item with that id in my inventory. If I make the function always return true, the weapon fires, so I think the problem must be here.

I've worked out what the problem with the "usetime" property was - it wasn't the property at all, I was using the floor() function to round the result of a calculation and I didn't realise I had to put "math.floor()". It works now. Thanks for all your help.
Title: Re: Changing the ammo system?
Post by: tehtmi on March 30, 2013, 10:10
I tried looking through the inventory like this:
The "return false" needs to be outside the loop for this to work as you intended.  You may also need to manually :destroy() the item when its ammo reaches 0, but I'm not 100% sure.
Title: Re: Changing the ammo system?
Post by: Autoquark on March 30, 2013, 16:56
Oops! Silly mistake. You were right about having to destroy the ammo item when it ran out, too. That works now, but I have some more questions:

1. I have a missile defined with the MF_RAY flag set, but the game seems to ignore that and still draws a bullet travelling across the screen. It works in console mode however - has the flag become deprecated since graphics were introduced?

2. Is there a list of sprites somewhere? I don't know the names of any of the missile sprites, so I've had to put in random sprites that I do know for now. Although I suppose there is something to be said for a shotgun that shoots shotguns...

3. I've been trying to change the missile property of a weapons using the OnFire hook, but I always get an error when I try to assign it - what should the assignment look like?

4. This is just out of interest, for now: I notice that calling Player:power_backpack() reshuffles the player's ammo stacks. Is there any way to do this without also turning the backpack on? It would be quite a handy feature.
Title: Re: Changing the ammo system?
Post by: tehtmi on March 30, 2013, 17:18
1. I have a missile defined with the MF_RAY flag set, but the game seems to ignore that and still draws a bullet travelling across the screen. It works in console mode however - has the flag become deprecated since graphics were introduced?
I wouldn't say it is deprecated, just not supported in graphics mode yet.

Quote
2. Is there a list of sprites somewhere? I don't know the names of any of the missile sprites, so I've had to put in random sprites that I do know for now. Although I suppose there is something to be said for a shotgun that shoots shotguns...

Here's all the sprite constants that are declared; use them.  (Spoilered for length)
Spoiler (click to show/hide)
Alternatively, you could also just copy the values from things you know like beings.imp.sprite.

Quote
3. I've been trying to change the missile property of a weapons using the OnFire hook, but I always get an error when I try to assign it - what should the assignment look like?
The value needs to be the number id of the missile.  Number ids are subject to change between versions, so you should translate from the string id e.g.
Code: [Select]
  it.missile = missiles.mgun.nid
  -- or
  it.missile = missiles[string_id].nid

Quote
4. This is just out of interest, for now: I notice that calling Player:power_backpack() reshuffles the player's ammo stacks. Is there any way to do this without also turning the backpack on? It would be quite a handy feature.
Honestly, I suspect there are still bugs in power_backpack ;)  But no, I'm not aware of any other code that resorts the inventory like this; it is tied together with the backpack flag.
Title: Re: Changing the ammo system?
Post by: SPTX on March 30, 2013, 17:29
Speaking of sprite. Can I have the source code of the cyberdemon/spidermastermind?
I need to see how a sprite of a size bigger than one tile is handled. When I try to use them, they are cropped from their upper left corner to one tile.
Title: Re: Changing the ammo system?
Post by: tehtmi on March 30, 2013, 17:31
I need to see how a sprite of a size bigger than one tile is handled. When I try to use them, they are cropped from their upper left corner to one tile.

Give a being (or item) the flag F_LARGE to allow for an oversized sprite.
Title: Re: Changing the ammo system?
Post by: SPTX on March 30, 2013, 18:52
Doesn't seem to work by simply doing that.

I have "psprite = SPRITE_CYBERDEMON," on my item that gives the player the cyberdemon's sprite.
I tried with both "flags = {F_LARGE}" and "OnEquip = function (self,player) player.flags[F_LARGE] = true".
Title: Re: Changing the ammo system?
Post by: tehtmi on March 30, 2013, 21:11
Doesn't seem to work by simply doing that.

It looks like changing it on the fly won't work because the current implementation only checks the flag when the thing is loaded.  It might be hard to do for the player at all because of how early the player is loaded.
Title: Re: Changing the ammo system?
Post by: Autoquark on March 31, 2013, 07:57
OnAltFire is called when you use altfire = ALT_SCRIPT.  I don't consider this to be very mature yet, as most of DoomRL alternate fire modes are not implemented in Lua.  However, what you suggest sounds like the best way to do it to me.  DoomRL's rocket launcher actually uses OnFire to switch the stats back, but I think OnFired would generally work better.

I've got this working by recording the stats at the start of OnAltFire and OnFire and restoring them in OnFired. The problem is that if the user cancels the firing by pressing escape, the stats aren't set back because OnFired doesn't trigger. I don't want to hard code the stats for each mode because this will break weapon modding. Is there any way of fixing this? If not, could you explain how the rocket launcher does it only using OnFire?

Here's my current code:
Code: [Select]
register_item "hl_handgun" {
name = "Glock-17",
desc = "A guard's pistol. Has a large clip and a semi-automatic mode for when you need more firepower.",
ascii = "}" ,
sprite = SPRITE_PISTOL,
level = 0,
weight = 1000, --bit of a guess, see item generation page on wiki
flags = {IF_PISTOL},
firstmsg = "",
color_id = "generic",
--type specific
    type         = ITEMTYPE_RANGED, --required field
damage        = "2d4",           --required field
    damagetype    = DAMAGE_BULLET,   --required field
    group         = "weapon-pistol", --defaults to "weapon-other"
    fire          = 10,              --defaults to 10
    acc           = 2,               --defaults to 0
    radius        = 0,               --defaults to 0 (_RANGED and _NRANGED only)
    shots         = 0,               --defaults to 0. I think 1 makes it a rapid-fire weapon and 0 a single-shot
    ammo_id       = "ammo",        --bullets are "ammo" shells are "" rockets are "" cells are
    ammomax       = 17,              --required field (_RANGED only)
    reload        = 12,              --defaults to 10 (_RANGED only)
    shotcost      = 1,               --defaults to 0 (_RANGED only)
    altfire       = ALT_SCRIPT,       --defaults to ALT_NONE (_MELEE and _RANGED only)
    altfirename   = "semi-auto",    --default depends on altfire (_MELEE and _RANGED only)
    altreload     = RELOAD_DUAL ,     --defaults to RELOAD_NONE (_RANGED only)
    altreloadname = "dualreload",     --default depends on altreload (_RANGED only)
    --soundID       = "pistol",       --defaults to "id" (_RANGED and _NRANGED only)
    missile       = "mgun",
psprite   = SPRITE_PLAYER_PISTOL, --the sprite used to represent the player when equipped

OnCreate = function(self)
self:add_property("normal_shots", self.shots) --these are set again in OnFire to respect changes made by mod packs
self:add_property("normal_acc", self.acc)
end,

OnFire = function(self, being)
self:set_property("normal_shots", self.shots)
self:set_property("normal_acc", self.acc)
return true
end,

OnAltFire = function(self, being)
self:set_property("normal_shots", self.shots)
self:set_property("normal_acc", self.acc)
self.shots = self.shots + 3
self.acc = self.acc - 3
return true
end,

OnFired = function(self, being)
self.shots = self:get_property("normal_shots") --these are set again in OnFire to respect changes made by mod packs
self.acc = self:get_property("normal_acc")
end,
}
Title: Re: Changing the ammo system?
Post by: tehtmi on March 31, 2013, 11:53
The rocket launcher is able to get away with this because it only changes the missile which nothing else really modifies.

If you are worried about modding, I think you could fix this by using a custom item property to keep track of which mode the weapon is in.  In OnFire and OnFired, you can subtract 3 shots and add 3 accuracy, but only if the weapon is in "alt-fire-mode", and in OnAltFire you can add 3 shots and subtract 3 accuracy, but only if the weapon is in "normal-mode".  It still isn't perfect because the effect of a mod sometimes depends on the item's current stats which may be in either mode, so you could also try resetting the stats to normal mode in OnEquipTick.
Title: Re: Changing the ammo system?
Post by: yaflhdztioxo on March 31, 2013, 12:20
We have custom item properties?  I thought that was beings only...
Title: Re: Changing the ammo system?
Post by: Autoquark on March 31, 2013, 13:46
We have custom item properties?  I thought that was beings only...

You definitely do, I've been using them.

If you are worried about modding, I think you could fix this by using a custom item property to keep track of which mode the weapon is in.  In OnFire and OnFired, you can subtract 3 shots and add 3 accuracy, but only if the weapon is in "alt-fire-mode", and in OnAltFire you can add 3 shots and subtract 3 accuracy, but only if the weapon is in "normal-mode".  It still isn't perfect because the effect of a mod sometimes depends on the item's current stats which may be in either mode, so you could also try resetting the stats to normal mode in OnEquipTick.

The problem with this is that OnEquipTick seems to be called before OnAltFire - at any rate, if I press alt fire then cancel the targeting, the alt fire stats remain until another tick has passed, so if I apply a mod pack immediately, it acts on the alt fire stats. The alt fire stats also remain if I immediately unequip the item, but this can be fixed with the OnRemove hook. So it almost works, but without any hook being called immediately after cancelling targeting, I don't see how I can make it perfect. Is there any chance we could get an OnCancelFire hook in the next version?

EDIT: I've decided to fix this by putting an extra check in all of my mod packs which will prevent a mod being applied in the one turn when the stats are wrong. It's not ideal, but as I'm not planning on using any of the original mod packs, it should work. I also have another question: From experimentation it seems that a being's scount can become negative without causing errors. What's the lowest value that it can be safely set to? Or are negative values not intended to be used at all?

EDIT2: Could I have an up to date list of the names of the ally prototype fields? When I use the values from the wiki, it doesn't recognise some of them.
Title: Re: Changing the ammo system?
Post by: tehtmi on April 03, 2013, 04:45
I also have another question: From experimentation it seems that a being's scount can become negative without causing errors. What's the lowest value that it can be safely set to? Or are negative values not intended to be used at all?
Scount is a 32-bit signed integer, so it can be as small as -2147483648.  I found one bug relating to the player having a negative scount however.  It may not occur very much in practice because it only happens on the player's turn (when the player's scount will usually be positive).

Quote
EDIT2: Could I have an up to date list of the names of the ally prototype fields? When I use the values from the wiki, it doesn't recognise some of them.

Ally?  I'm not sure what you're referring to.
Title: Re: Changing the ammo system?
Post by: Autoquark on April 03, 2013, 13:20
Scount is a 32-bit signed integer, so it can be as small as -2147483648.  I found one bug relating to the player having a negative scount however.  It may not occur very much in practice because it only happens on the player's turn (when the player's scount will usually be positive).

So far I'm only changing monster's scount values, so I guess I'll try allowing them to go negative. I'll post if anything odd happens.

Ally?  I'm not sure what you're referring to.

Oops. I meant to say "Being". I think I typed ally because one of the error fields was "group" and I'd tried "ally" and "allegiance" as random guesses at what the new name was.
Title: Re: Changing the ammo system?
Post by: tehtmi on April 03, 2013, 21:35
Being prototype:
Code: [Select]
core.register_blueprint "being"
{
--     fieldname = { required, type, [default] }
name        = { true,  core.TSTRING },
name_plural = { false, core.TSTRING },
id          = { false, core.TSTRING }, -- doesn't need to be in the prototype table; id is passed to the declaration function
sound_id    = { false, core.TIDIN("beings") },
ascii       = { true,  core.TSTRING },
color       = { true,  core.TNUMBER },
sprite      = { true,  core.TNUMBER  },
coscolor    = { false, core.TTABLE },
glow        = { false, core.TTABLE },
overlay     = { false, core.TTABLE },
hp          = { false, core.TNUMBER , 10 },
armor       = { false, core.TNUMBER , 0 },
attackchance= { false, core.TNUMBER , 75 },
todam       = { false, core.TNUMBER , 0 },
tohit       = { false, core.TNUMBER , 0 },
tohitmelee  = { false, core.TNUMBER , 0 },
speed       = { false, core.TNUMBER , 100 },
vision      = { false, core.TNUMBER , 0 },
min_lev     = { true,  core.TNUMBER },
max_lev     = { false, core.TNUMBER , 10000 },
corpse      = { false, core.TANY, 0 },
danger      = { true,  core.TNUMBER },
weight      = { true,  core.TNUMBER },
xp          = { false, core.TNUMBER },
bulk        = { false, core.TNUMBER , 100 },
flags       = { false, core.TFLAGS, {} },
ai_type     = { true,  core.TSTRING },
is_group    = false, -- hard-coded prototype value; can't be specified

res_bullet  = { false, core.TNUMBER, 0 },
res_melee   = { false, core.TNUMBER, 0 },
res_shrapnel= { false, core.TNUMBER, 0 },
res_acid    = { false, core.TNUMBER, 0 },
res_fire    = { false, core.TNUMBER, 0 },
res_plasma  = { false, core.TNUMBER, 0 },

desc            = { true,  core.TSTRING },
kill_desc       = { false, core.TSTRING },
kill_desc_melee = { false, core.TSTRING },

weapon = { false, core.TANY },

OnCreate     = { false, core.TFUNC },
OnAction     = { false, core.TFUNC },
OnAttacked   = { false, core.TFUNC },
OnDie        = { false, core.TFUNC },
OnDieCheck   = { false, core.TFUNC },
OnPickupItem = { false, core.TFUNC },
}
Title: Re: Changing the ammo system?
Post by: Autoquark on April 04, 2013, 08:02
Thanks. Could you tell me what the names of the built in ai types are?

EDIT: Although I've set the weight of all the normal doomRL enemies to zero, the game is still generating special rooms full of lost souls, and it also seems to be generating imps on some levels. Is there any easy way to stop this?
Title: Re: Changing the ammo system?
Post by: SPTX on April 04, 2013, 09:15
I think it may be related to scripted levels as they do not use the generator to place enemies. Try to make a replacement of each being you need replaced using the OnEnter hook.
Title: Re: Changing the ammo system?
Post by: Autoquark on April 04, 2013, 10:48
I think it may be related to scripted levels as they do not use the generator to place enemies. Try to make a replacement of each being you need replaced using the OnEnter hook.

If you mean special levels like Hell's Arena, it's an episode mod, so they're not generated. If you mean stuff like vaults full of lost souls then you're probably right that the monsters are fixed. I was hoping I could specifically change the monsters in each special room, but just replacing each monster type might be the best I can do.

EDIT: Also, how do you add items to a monster's inventory. I've been trying
Code: [Select]
local i = 0
self:set_inv_item(i,being.new("hl_handgun")) i = i+1
self:set_inv_item(i,being.new("ammo")) i = i+1

But it errors. I don't actually need it to use the items, I just want them to be dropped when it dies, so I could spawn them on death instead.
Title: Re: Changing the ammo system?
Post by: SPTX on April 04, 2013, 12:43
There is http://doom.chaosforge.org/wiki/Modding:Being#being_set_inv_item but having to define a slot may cause trouble for beings starting with an inventory.
I'd try
Code: [Select]
being.inv:add("item")Not sure if it's an actual procedure, but seeing how it isn't documented and that both player and being have inventory procedures while player inherits from being, it might just work.
However, don't quote me on that please.
Title: Re: Changing the ammo system?
Post by: shark20061 on April 04, 2013, 20:26
Thanks. Could you tell me what the names of the built in ai types are?

There's:
 former_ai (Used on all former-type enemies, including elite versions),
 baron_ai (Hell Knights and Barons),
 lostsoul_ai,
 demon_ai,
 melee_seek_ai (The previous ai for lost souls),
 cyberdemon_ai,
 jc_ai,
 melee_ranged_ai (Used for most enemies, like Imps and Cacodemons),
 ranged_ai,
 flee_ranged_ai (Unused and broken),
 archvile_ai,
 sequential_ai,
 teleboss_ai (e.g. Lava Elemental and Shambler),
 spawnonly_ai (e.g. Pain and Agony Elementals),
 mastermind_ai
Title: Re: Changing the ammo system?
Post by: tehtmi on April 04, 2013, 20:56
Although I've set the weight of all the normal doomRL enemies to zero, the game is still generating special rooms full of lost souls, and it also seems to be generating imps on some levels. Is there any easy way to stop this?

There are a variety of reasons that enemies will spawn even with 0 weight.  I can think of:
1) being_groups (this is probably giving you those imps); these have weights that can be zeroed
2) vault rooms (this is the room with lost souls probably); I think you can set the weight of this room type to 0 with the new generator stuff
3) some level types (like caves) will pick a being and use it regardless of weights; you can disable these level types, or replace there monster generation functions
Title: Re: Changing the ammo system?
Post by: Autoquark on April 06, 2013, 11:23
Thanks. Is there any way of accessing the target being (or at least its location) from inside the OnFire hook?
Title: Re: Changing the ammo system?
Post by: yaflhdztioxo on April 06, 2013, 11:59
No, and that is something many of us have lamented for as long as modding has existed :(
Title: Re: Changing the ammo system?
Post by: Autoquark on April 08, 2013, 10:17
I'm not sure I understand how the player hooks work. How do I set them, and do I only have the standard being OnCreate, OnAction and OnDie hooks, or is there something like a generic OnFire hook for the player?
Title: Re: Changing the ammo system?
Post by: SPTX on April 08, 2013, 10:45
Wouldn't it work using
Code: [Select]
OnAction()
{
if Being:attack(player) then "your_action"
}
?
Title: Re: Changing the ammo system?
Post by: yaflhdztioxo on April 08, 2013, 17:43
The player is defined before you (the modder) ever get near the engine.  Because of this you must manually modify or extend the player's being hooks.  This is easy to do, and there is a genericized example or two in the Skulltag Arena in the runes and powerups section (okay, granted, it's not easy to find)
Code: [Select]
beings["soldier"].HookYouWantToChange = function

As a practical example, let's day I want to change the OnPickupItem hook AND I want the current hook to still trigger.  I can chain an inline function as follows:
Code: [Select]
    beings["soldier"].OnPickupItem = core.create_seq_function(beings["soldier"].OnPickupItem,
    function(self,i)
      do_stuff
    end)

There are six being hooks.  They're probably documented on the wiki, but just in case they aren't:
Code: [Select]
OnCreate(self)
OnAction(self)
OnAttacked(self)
OnDie(self, overkill)
OnDieCheck(self, overkill)
OnPickupItem(self,i)

Lastly, remember that this logic can be applied to pretty much ANY being, not just the player.  That said, there are very few scenarios where this is useful.  For levels and challenges it is almost always better to use the corresponding (chained) level or challenge hooks.  The only times I have ever needed to use these tricks are when I was making drastic changes to the engine--such as with runes and powerups, both of which in SkulltagRL pretty much required I make my OWN damn affects engine and hook into everything else as a result.
Title: Re: Changing the ammo system?
Post by: Autoquark on April 11, 2013, 06:25
Thanks, yaflhdztioxo. Only three of those being hooks are documented on the wiki.

Does being:wear(item) work on weapons, and does it work for items that aren't in the inventory? I'm trying to implement a grenade weapon that is stored in stacks in the inventory but is equipped one at a time. I've got this:

Code: [Select]
register_item "hl_grenade" { --delayed explosion requires more hooks
name = "Hand Grenade",
desc = "Good thing you can throw accurately.",
ascii = "*" ,
color = BROWN,
sprite = SPRITE_ROCKET,
glow = {1,0,0,0.5},
level = 6,
weight = 200,
flags = {IF_NONMODABLE, IF_NOAMMO},
firstmsg = "These could come in handy.",
color_id = "generic",
--type specific
        type     = ITEMTYPE_RANGED,
damage        = "5d5",
    damagetype    = DAMAGE_FIRE,
    group         = "weapon-rocket",
    fire          = 10,
    acc           = 0,
    radius        = 4,
    shots         = 0, --setting to 1 leads to x1 being appended to name, which is seriously confusing here
    ammo_id       = "shell", --not actually used
    ammomax       = 0,
    reload        = 10,
    shotcost      = 0,
    altfire       = ALT_NONE,
    --altfirename   = "double shot",
    altreload     = RELOAD_FULL,
    --altreloadname = "dualreload",
    --sound_id       = "shotgun",
    missile       = "hl_grenade_missile",
psprite   = SPRITE_PLAYER, --the sprite used to represent the player when equipped

OnCreate = function(self)
self:add_property("quantity", 2)
self:add_property("base_name", self.name) --used by test.SetNameFromQuantity
test.SetNameFromQuantity(self)
end,

OnEquipCheck = function(self, equipper)
if self:get_property("quantity") == 1 then return true end

self:set_property("quantity", self:get_property("quantity") - 1)
test.SetNameFromQuantity(self)
local spawned = item.new(items[self.id].nid) --spawn a new grenade item with 1 quantity
spawned:set_property("quantity", 1) --set quantity
test.SetNameFromQuantity(spawned)
if player:wear(spawned) == true then ui.msg("success") else ui.msg("fail") end --equip the new item
return false --don't equip this item
end,
}

When I attempt to equip a stack of more than 1 grenade, I get the message "success", the size of the stack decreases by 1 but the grenade isn't equipped. Equipping a single grenade works.

Also, it turns out that being.inv:add() does work on monsters. Thanks SPTX for suggesting that - I thought I'd tried it before but evidently not.

EDIT: What sound IDs exist that are appropriate for explosions?
Title: Re: Changing the ammo system?
Post by: SPTX on April 11, 2013, 16:18
EDIT: What sound IDs exist that are appropriate for explosions?
I'll bounce on that asking for a full list of sound IDs.
Title: Re: Changing the ammo system?
Post by: yaflhdztioxo on April 11, 2013, 16:39
If I inadvertently end up providing info that's both useful and not on the wiki please put it up.  I would myself but the time... it is not there.
Title: Re: Changing the ammo system?
Post by: Autoquark on April 13, 2013, 03:21
If I inadvertently end up providing info that's both useful and not on the wiki please put it up.  I would myself but the time... it is not there.

I'll try to do that.

What is it that determines if shottyman applies to a weapon? I assume it's the IF_SHOTGUN flag for shotguns, but is there a new flag for rocket launchers?
Title: Re: Changing the ammo system?
Post by: SPTX on April 13, 2013, 03:59
It's the IF_SHOTGUN flag indeed, the rocket launcher has it for that matter.
Title: Re: Changing the ammo system?
Post by: Autoquark on April 13, 2013, 04:21
It's the IF_SHOTGUN flag indeed, the rocket launcher has it for that matter.

According to the wiki, that flag makes it expect a shotgun missile, and if I try setting IF_SHOTGUN on one of the explosive weapons in my mod, it crashes when it tries to register it.

EDIT: What are the property names of glow and sprite?
Title: Re: Changing the ammo system?
Post by: SPTX on April 13, 2013, 04:47
Wow sorry, I misread and talked out of my ass to boot.
Try making your weapon group either weapon-shotgun or weapon-explosive.
Title: Re: Changing the ammo system?
Post by: Autoquark on April 13, 2013, 05:42
I've been trying to alter item.desc in a hook, but if I do

Code: [Select]
ui.msg(item.desc)
it prints the item name with the damage and ammo appended instead of the description.
Title: Re: Changing the ammo system?
Post by: Equality on April 13, 2013, 06:10
Quote
What are the property names of glow and sprite?
sprite - on ground
psprite - on soldier, equipped
color - in inventory and ascii
coscolor - color for sprites
glow - glow
Title: Re: Changing the ammo system?
Post by: Autoquark on April 13, 2013, 06:36
sprite - on ground
psprite - on soldier, equipped
color - in inventory and ascii
coscolor - color for sprites
glow - glow

I meant how do I refer to them in hooks, rather than what they mean - the wiki claims that the property name of the sprite is the same as the prototype key, but I've been getting errors when I try to reference it, and it doesn't mention the property name for glow at all.
Title: Re: Changing the ammo system?
Post by: yaflhdztioxo on April 13, 2013, 07:54
It sounds like you're talking about prototype properties vs published object properties.  They sometimes line up but they are not always shared.

Name for instance.  You can specify a name when declaring an item prototype and you can change an individual object's name by modifying the object's published 'name' property.  There's a 'name' property in both sets.  Color (ascii color) can also be edited this way.

sprite, psprite, glow, and coscolor are prototype-only properties.  You CANNOT modify these on a single object.  This is because sprites are not generated on the fly--they are assembled based on your prototypes.  There is a published 'picture' property which I assume refers to the actual sprite being used but I have never tampered with it so I cannot offer any advice.
Title: Re: Changing the ammo system?
Post by: Autoquark on April 14, 2013, 08:26
Thanks. According to the wiki, "picture" is just the object property of "ascii", and if I print it using ui.msg, I get a number that depends on the ascii property, so this seems correct. Is there another object property that holds the assembled sprite? I was thinking I might be able to register items with all the sprite and glow combinations I might need (I'm only planning on using pure red, green and blue glows) and then copy the assembled sprite property from an object of that item to the item whose sprite I want to change.

EDIT: So is there no way to change an item's description after it has been created? You didn't mention it, but the wiki says that the object property "desc" is the name of the object rather than the description, and doesn't list an object property for the description.
Title: Re: Changing the ammo system?
Post by: Autoquark on May 19, 2013, 09:40
According to the wiki, one sniper weapon pack causes a weapon to have no range penalties to accuracy, and a second one causes it not to suffer any penalty against hitting a target you can't see. Are there some new item flags that set this behaviour? The wiki states that IF_AUTOHIT is used by sniper packs, but I assume that's for older versions where a sniper pack just caused a weapon to always hit.
Title: Re: Changing the ammo system?
Post by: Uranium on May 19, 2013, 09:59
According to the wiki, one sniper weapon pack causes a weapon to have no range penalties to accuracy, and a second one causes it not to suffer any penalty against hitting a target you can't see. Are there some new item flags that set this behaviour? The wiki states that IF_AUTOHIT is used by sniper packs, but I assume that's for older versions where a sniper pack just caused a weapon to always hit.

Yep, it was split into IF_FARHIT and IF_UNSEENHIT for the first and second mods respectively.