Jump to content

Attack Code Handler


ORMtnMan

Recommended Posts

All, I am trying to make a mod that adjusts how the ranged attacks are handled.

 

For instance, if you have a bat, you swing it and there is multiple zombies in front of you, you hit all of them (if they are within the swing arc).

 

Though, with firearms, you fire at one target. The code selects the target that is the closest within the firing arc. Though this can seem a bit hokey when you have a 30 zombie thick horde and you shoot a gun toward the crown and miss completely because the code only runs the to-hit against that closest zombie.

 

I want to write a code that allows for secondary hits if you miss the first... Now my issue is. I can't find an LUA that handles this. So I am at a loss on where to look.

 

Can someone point me to the correct LUA or Java to help expedite the process?

 

Thanks in advance,

Link to comment
Share on other sites

It's neither lua or java. It's mostly handled in the media/scripts -folder. Guns are mostly in the items.txt and newitems.txt.

 

Well, I understand the guns themselves are in the items.txt, but that is not where the target acquisition script is, which is what I am looking for...

 

It would look something like:

 

Get all zombies within arc, choose first closest zombie to player, random number gen to do to hit chance, compare against base gun to hit and skill.

Link to comment
Share on other sites

It's in java but you can hook into it with OnWeaponSwingHitPoint (see http://pz-mods.net/guide/event-reference/ )

 

I don't know how you would tell that you missed that first zombie though. You might have to get creative, like an OnTick mixed with OnWeaponHitCharacter (I assume that fires when zombies are hit) mixed with OnWeaponSwingHitPoint (which I think fires whenever a zombie is in range.)

OnWeaponSwingHitPoint and the weapon is a gun set global variable timestamp.

OnWeaponHitCharacter unset the timestamp because a zombie was hit.

OnTick if the timestamp compared to time is long enough (but not too long to make the gameplay feel unresponsive) then you know that you missed and then try to implement a hit on a different zombie.

 

When you implement your custom behavior you'd also want to make it work with multiplayer which could be fun...

Link to comment
Share on other sites

Have a feeling it'll be partially in Java, but  run a Find on the Lua directory and go through all references to a specific gun; should let you know if it's possible to modify from Lua.

My money is on the Reloading directory, personally.

 

Well, I scoured through the entire reload folder and the only reference to the script is the removal of ammo onfire script (e.g. function shogtun:fireshot ())

 

It's gotta be here somewhere... I'll keep digging and let everyone know just so I can hopefully make it easier for someone else.

It's in java but you can hook into it with OnWeaponSwingHitPoint (see http://pz-mods.net/guide/event-reference/ )

 

I don't know how you would tell that you missed that first zombie though. You might have to get creative, like an OnTick mixed with OnWeaponHitCharacter (I assume that fires when zombies are hit) mixed with OnWeaponSwingHitPoint (which I think fires whenever a zombie is in range.)

OnWeaponSwingHitPoint and the weapon is a gun set global variable timestamp.

OnWeaponHitCharacter unset the timestamp because a zombie was hit.

OnTick if the timestamp compared to time is long enough (but not too long to make the gameplay feel unresponsive) then you know that you missed and then try to implement a hit on a different zombie.

 

When you implement your custom behavior you'd also want to make it work with multiplayer which could be fun...

 

Well, this is incredibly helpful! Thank you,

 

I'll give that a go and see if it gets me anywhere.

 

I guess the issue is, that if there is another LUA that does the same function it would cause some weird issues... so I need to see if one is already lying around somewhere...

 

The FireShot script leads me to believe there is... because it isn't an event handler.

Link to comment
Share on other sites

I'm pretty sure you can have multiple functions for the same event so there shouldn't be any conflict issues. You don't need to 'fire' the gun again, you just need to do damage to targets which can probably be done programmatically.

 

I think fireshot is triggered by ReloadManager fireShotHook which is triggered by an OnWeaponSwingHitPoint event (grep is very useful)

 

Edit: though I guess if you wanted to you could hook fireshot or fireShotHook instead of adding your own event action.

Link to comment
Share on other sites

I'm pretty sure you can have multiple functions for the same event so there shouldn't be any conflict issues. You don't need to 'fire' the gun again, you just need to do damage to targets which can probably be done programmatically.

 

I think fireshot is triggered by ReloadManager fireShotHook which is triggered by an OnWeaponSwingHitPoint event (grep is very useful)

 

Edit: though I guess if you wanted to you could hook fireshot or fireShotHook instead of adding your own event action.

 

You make a good point, if nothing is happening after the first miss, than there would be no conflict in the action... Let me tinker with that and see what I get

 

So to reason this out I have a OnWeaponSwingHitPoint, which will tell me if the attack was successful. So it would go something like:

 

function blahblah:fireshot ()

 

Float ISMIss

ismiss=0

 

OnWeaponSwingHitPoint

Set isMiss to 1

 

If isMiss =0

Then Run script for checking hit against next zombie and loop back if needed.

 

That sound about right (bad syntax aside)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...