DoomRL > Modding

Changing the ammo system?

<< < (2/10) > >>

tehtmi:

--- Quote from: SPTX on March 29, 2013, 11:45 ---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.

--- End quote ---

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.

SPTX:

--- Quote from: tehtmi on March 29, 2013, 11:51 ---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.

--- End quote ---
Well that fixed it. Thanks. A lot.

Autoquark:
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.

tehtmi:

--- Quote from: Autoquark on March 29, 2013, 14:37 ---...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.
--- End quote ---
"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?

--- End quote ---

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? ...
--- End quote ---
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.

--- End quote ---

Currently the only real access seems to be through the inventory iterator

--- Code: ---for it in player.inv:items() do
  print(it.name)
end

--- End code ---
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])

Autoquark:
I tried looking through the inventory like this:

--- Code: ---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,
--- End code ---
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.

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version