Chaosforge Forum

  • March 29, 2024, 05:42
  • Welcome, Guest
Please login or register.



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

Author Topic: Changing the ammo system?  (Read 28405 times)

Autoquark

  • Backer
  • Lance Corporal
  • *
  • *
  • Offline Offline
  • Posts: 23
  • Lost Soul
    • View Profile
Re: Changing the ammo system?
« Reply #30 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?
Logged

yaflhdztioxo

  • Programmer
  • Local Inquisitor
  • Captain
  • *
  • *
  • Offline Offline
  • Posts: 298
  • Lost Sole
    • View Profile
Re: Changing the ammo system?
« Reply #31 on: April 06, 2013, 11:59 »

No, and that is something many of us have lamented for as long as modding has existed :(
Logged

Autoquark

  • Backer
  • Lance Corporal
  • *
  • *
  • Offline Offline
  • Posts: 23
  • Lost Soul
    • View Profile
Re: Changing the ammo system?
« Reply #32 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?
Logged

SPTX

  • Sergeant
  • *
  • Offline Offline
  • Posts: 77
  • Lost Soul
    • View Profile
Re: Changing the ammo system?
« Reply #33 on: April 08, 2013, 10:45 »

Wouldn't it work using
Code: [Select]
OnAction()
{
if Being:attack(player) then "your_action"
}
?
Logged

yaflhdztioxo

  • Programmer
  • Local Inquisitor
  • Captain
  • *
  • *
  • Offline Offline
  • Posts: 298
  • Lost Sole
    • View Profile
Re: Changing the ammo system?
« Reply #34 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.
Logged

Autoquark

  • Backer
  • Lance Corporal
  • *
  • *
  • Offline Offline
  • Posts: 23
  • Lost Soul
    • View Profile
Re: Changing the ammo system?
« Reply #35 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?
« Last Edit: April 11, 2013, 09:53 by Autoquark »
Logged

SPTX

  • Sergeant
  • *
  • Offline Offline
  • Posts: 77
  • Lost Soul
    • View Profile
Re: Changing the ammo system?
« Reply #36 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.
Logged

yaflhdztioxo

  • Programmer
  • Local Inquisitor
  • Captain
  • *
  • *
  • Offline Offline
  • Posts: 298
  • Lost Sole
    • View Profile
Re: Changing the ammo system?
« Reply #37 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.
Logged

Autoquark

  • Backer
  • Lance Corporal
  • *
  • *
  • Offline Offline
  • Posts: 23
  • Lost Soul
    • View Profile
Re: Changing the ammo system?
« Reply #38 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?
Logged

SPTX

  • Sergeant
  • *
  • Offline Offline
  • Posts: 77
  • Lost Soul
    • View Profile
Re: Changing the ammo system?
« Reply #39 on: April 13, 2013, 03:59 »

It's the IF_SHOTGUN flag indeed, the rocket launcher has it for that matter.
Logged

Autoquark

  • Backer
  • Lance Corporal
  • *
  • *
  • Offline Offline
  • Posts: 23
  • Lost Soul
    • View Profile
Re: Changing the ammo system?
« Reply #40 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?
« Last Edit: April 13, 2013, 04:40 by Autoquark »
Logged

SPTX

  • Sergeant
  • *
  • Offline Offline
  • Posts: 77
  • Lost Soul
    • View Profile
Re: Changing the ammo system?
« Reply #41 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.
« Last Edit: April 13, 2013, 04:51 by SPTX »
Logged

Autoquark

  • Backer
  • Lance Corporal
  • *
  • *
  • Offline Offline
  • Posts: 23
  • Lost Soul
    • View Profile
Re: Changing the ammo system?
« Reply #42 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.
Logged

Equality

  • Second Lieutenant
  • *
  • Offline Offline
  • Posts: 174
  • Lost Soul
    • View Profile
Re: Changing the ammo system?
« Reply #43 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
Logged
Once advanced DoomRL player
Find mysterious sword Dragonslayer
Say "Best thing ever found!" and start jumping around...
But he can't get the sword from the ground

Autoquark

  • Backer
  • Lance Corporal
  • *
  • *
  • Offline Offline
  • Posts: 23
  • Lost Soul
    • View Profile
Re: Changing the ammo system?
« Reply #44 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.
Logged
Pages: 1 2 [3] 4  All