DoomRL > Modding
Changing the ammo system?
SPTX:
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".
tehtmi:
--- Quote from: SPTX on March 30, 2013, 18:52 ---Doesn't seem to work by simply doing that.
--- End quote ---
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.
Autoquark:
--- Quote from: tehtmi on March 29, 2013, 21:14 ---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.
--- End quote ---
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: ---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,
}
--- End code ---
tehtmi:
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.
yaflhdztioxo:
We have custom item properties? I thought that was beings only...
Navigation
[0] Message Index
[#] Next page
[*] Previous page
Go to full version