Author Topic: RE: Thrown Weapons - Is This Possible?  (Read 604 times)

Legacy_Pstemarie

  • Hero Member
  • *****
  • Posts: 4368
  • Karma: +0/-0
RE: Thrown Weapons - Is This Possible?
« Reply #15 on: February 10, 2013, 01:54:21 am »


               The final product - used in the OnPhysicalAttacked event to create an item near the target in the event of a miss.


// Check if oAttacker "missed" the caller with a dart or handaxe attack

object oAttacker = GetLastAttacker();

if (GetIsObjectValid(oAttacker) && GetDamageDealtByType(DAMAGE_TYPE_PIERCING) <= 0 || 
    GetDamageDealtByType(DAMAGE_TYPE_SLASHING) <= 0)
{
  object oItem = GetItemInSlot(INVENTORY_SLOT_RIGHTHAND, oAttacker);
 
  // Check the stack size - starting at 2 - to make sure you don't get back more 
  // ammo than you started with
  if (GetIsObjectValid(oItem) && GetItemStackSize(oItem) > 2)
  {
    if (GetBaseItemType(oItem) == BASE_ITEM_DART || GetBaseItemType(oItem) == BASE_ITEM_THROWINGAXE)
    {
       location lLoc = GetRandomLocation(GetArea(OBJECT_SELF), OBJECT_SELF, 3.0);
       object oThrown = CreateObject(OBJECT_TYPE_ITEM, GetResRef(oItem), lLoc);
       SetItemStackSize(oThrown, 1);
       SetIdentified(oThrown, 1);
     }
  }
}

               
               

               


                     Modifié par Pstemarie, 10 février 2013 - 02:06 .
                     
                  


            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
RE: Thrown Weapons - Is This Possible?
« Reply #16 on: February 10, 2013, 02:04:44 am »


               be nice if it was that simple,  But you have your events out of order.

OnPhysicalAttacked  Event happens first.  No damage has yet been done.  
If it was the last item in the stack.    unequip fires followed by unaquire.
Hit roll then happens
if damage is done then the OnDamage event fires.  

Doing everything in the on  OnPhysicalAttacked can not catch the damage for the current attack.  
At least that is my current understanding.  

You are going to need to use more then one event and mostlikely a delayed event to chtch the miss for the current attack
               
               

               
            

Legacy_Pstemarie

  • Hero Member
  • *****
  • Posts: 4368
  • Karma: +0/-0
RE: Thrown Weapons - Is This Possible?
« Reply #17 on: February 10, 2013, 02:12:05 am »


               Well its working - I've been testing and tweaking for two hours. I had to set the stack size check to >2 because it kept generating one extra item otherwise.

OnPhysicalAttacked only handles a miss while OnDamaged uses Sharona's function to drop the missile in the target's inventory.

I'm not sure why GetDamageDealtByType is catching anything in the OnPhysicalAttacked but my SendMessage debugs - which I removed show 0 damage on a miss. I have run several tests using full stacks and partial stacks with all attacks hitting and all attacks missing. So far everything works.
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
RE: Thrown Weapons - Is This Possible?
« Reply #18 on: February 10, 2013, 02:17:44 am »


               Hmm,  Perhaps my understanding is off.   If it is you may have come across a great find.    

Testing.
               
               

               
            

Legacy_Pstemarie

  • Hero Member
  • *****
  • Posts: 4368
  • Karma: +0/-0
RE: Thrown Weapons - Is This Possible?
« Reply #19 on: February 10, 2013, 02:21:01 am »


               I have a knack for stumbling onto stuff ':blush:' Usually I get burned by my "finds", so let's just say I'm waiting for this script to break something else...

I do recall GZ saying something on the old forums about certain function calls being able to rearrange the way events fire, something about priorities and what not. I didn't really understand it, but I think it was why bioware tagged some functions with "Use only this Event" or "Only works in this Event".

The only glitch I have noticed is if you fire the last shot the PC will charge the target. Then if you draw another weapon while charging the PC stops then jumps to the target on the next Heartbeat. Looks like lag to me, but I'm not sure.
               
               

               


                     Modifié par Pstemarie, 10 février 2013 - 02:26 .
                     
                  


            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
RE: Thrown Weapons - Is This Possible?
« Reply #20 on: February 10, 2013, 02:35:06 am »


               Well It is flawed.   Take your attacks down to one attack.   Attack the target then break off combat.    It will be simpler to see what I am talking about.      

Your first attack on a target is going to gove you the damage done the attack before.   So if the target has not been attacked before the first attack is always going to regester as a miss.    

reguardless of wether the next attack hits or misses it is going to use the round before as the indecator of the hit or miss.
               
               

               
            

Legacy_Pstemarie

  • Hero Member
  • *****
  • Posts: 4368
  • Karma: +0/-0
RE: Thrown Weapons - Is This Possible?
« Reply #21 on: February 10, 2013, 02:45:17 am »


               Ok that explains why it always creates an extra miss item when you intiate the first attack with a dart or hand axe. I think with the hacked "fix" though I can live with it since it only affects darts and throwing axes.

EDIT - Ran some more tests doing what you said. It is flawed like you say, but I can live with it since you never get back more ammo than you threw. At this point I'm really just trying to avoid a PC that throws say 5 handaxes or darts at a target and collects back more than 5 between the monster's corpse and the missed axes lying about the ground. While I did have one test that came up one axe short, the rest have all come up with no more than what the PC started with. So, I'll take what I get and move onto the next hack.

If you can't beat it, hack it :innocent:
               
               

               


                     Modifié par Pstemarie, 10 février 2013 - 03:20 .
                     
                  


            

Legacy_Failed.Bard

  • Hero Member
  • *****
  • Posts: 1409
  • Karma: +0/-0
RE: Thrown Weapons - Is This Possible?
« Reply #22 on: February 10, 2013, 06:30:07 am »


               Would it work doing it as a subroutine on a 0.01 delay, or would that get messed up worse once multi-attack flurries are taken into account?
               
               

               
            

Legacy_Pstemarie

  • Hero Member
  • *****
  • Posts: 4368
  • Karma: +0/-0
RE: Thrown Weapons - Is This Possible?
« Reply #23 on: February 10, 2013, 08:51:27 am »


               

Failed.Bard wrote...

Would it work doing it as a subroutine on a 0.01 delay, or would that get messed up worse once multi-attack flurries are taken into account?


It seems that any variation from what I have posted in the "final" code above results in too much ammo being created on a miss.
               
               

               
            

Legacy_WhiZard

  • Hero Member
  • *****
  • Posts: 2149
  • Karma: +0/-0
RE: Thrown Weapons - Is This Possible?
« Reply #24 on: February 10, 2013, 06:30:58 pm »


               

Pstemarie wrote...

Failed.Bard wrote...

Would it work doing it as a subroutine on a 0.01 delay, or would that get messed up worse once multi-attack flurries are taken into account?


It seems that any variation from what I have posted in the "final" code above results in too much ammo being created on a miss.


Try this. In the OnAttacked event for creatures replenish the ammunition for this weapon no matter what.  In the OnDamaged event decrement the ammunition for this weapon by one.  While this won't work in the last flurry for the ammunition, it will accurately distinguish between missing and hitting shots within a flurry.

EDIT: Actually, since the creature can be damaged by spells,  it would be better to replace the OnDamaged decrement with an On Hit decrement given as a unique power to the weapon.
               
               

               


                     Modifié par WhiZard, 10 février 2013 - 06:39 .
                     
                  


            

Legacy_ffbj

  • Hero Member
  • *****
  • Posts: 1097
  • Karma: +0/-0
RE: Thrown Weapons - Is This Possible?
« Reply #25 on: February 13, 2013, 06:05:16 pm »


               Why not just the stack size of the thrown/fired/slung/ item, and just return a certain number of them when the combat is over?
               
               

               
            

Legacy_Highv Priest

  • Full Member
  • ***
  • Posts: 170
  • Karma: +0/-0
RE: Thrown Weapons - Is This Possible?
« Reply #26 on: February 18, 2013, 04:32:56 am »


               In this case you could take advantage of the NPC AI to determine actual amounts. In the OnAttacked simply set a local int(one time per object ID) and a local object(one time per object ID) on the /*EDIT=Should probably be set on the area to keep track of the ammuntion being used on multiple NPCs with it reading each NPCs object ID as well*/NPC that tells them how many they started with and gives them the chance to determine if that object has been destroyed. Then in the OnDamaged event increment a local int by 1 each time they're hit. Then when it comes time for this NPC to die have them take the amount of things you started with and subtract by the amount they have now and then subtract by the local int of number of hits to get the number of misses. Create the missed ones in random locations nearby and the hit ones on the NPC and you're good. It involves using 3 events, but because the events have little code involved it isn't too taxing.

EDIT= MATHS!
[(number they started with{per object ID}-number they have{if different object ID then assume previous stack completely used if local object comes up invalid})-number of hits] = Ammunition created in random locations away from the body.

number of hits(per object ID) = Ammuntion created on the body.
               
               

               


                     Modifié par Highv Priest, 18 février 2013 - 04:40 .
                     
                  


            

Legacy_ffbj

  • Hero Member
  • *****
  • Posts: 1097
  • Karma: +0/-0
RE: Thrown Weapons - Is This Possible?
« Reply #27 on: February 18, 2013, 03:21:31 pm »


               Yeah, something like that. I think I would just do a simple on unacquire and have a % chance, for all thrown or ranged weapons, to survive: bullets, arrows, bolts, 50% chance: darts, axes, bolts, 80%and then then re-create them after a time back in the PC's inventory. Less verisimilitude. Howsoever with any system where things are on the ground or nearby after being fired, why would it be limited to only PC items? Thus: is everything fired by anyone recoverable? I think not. For expedience no one would do that, but that would be more realistic. My approach is less realistic but the idea is the PC recovers part of the fired ammunition over time.

Oh and instead of creating each individual bolt, arrow, etc.. you just keep a running total that ticks up everytime a ranged weapon is used and adds the number to an int if the % chance of survival is met.  So say you fire 10 arrows and get 5 back, and after recreation the int resets to 0.  The only difficulty I see would be worlds with many types of arrows, bolts, etc... then you have to make an int for each individual type, which would be tedious,  Of course flaming arrows don't survive, or you could just have all elemental arrows default to +1 arrows, they lost their elemental magic when they hit.  One approach. 
               
               

               


                     Modifié par ffbj, 18 février 2013 - 03:29 .
                     
                  


            

Legacy_Highv Priest

  • Full Member
  • ***
  • Posts: 170
  • Karma: +0/-0
RE: Thrown Weapons - Is This Possible?
« Reply #28 on: February 18, 2013, 06:41:13 pm »


               The OnUnAcquire event does not trigger when a stack is reduced, only when you receive the message "you have lost <insert name of item>". My method is exceptionally realistic and you could incorporate percentages based on the materials of your ranged items to determine how many of them are actually dropped from misses and hits. Players DO appreciate extremely realistic things in games if it actually has a fundamental point behind it and doesn't just add "flavor" or make the game less fun. In this instance it's a realistic method of retrieving SOME of your ammo similarly to the designs of Skyrim. A long while ago I started occasionally giving my "uber bosses" personalities and the players loved it. Even now the name "Jack O' Lantern" strikes fear upon anyone on my server to have witness him.(imagine a boss that -enjoys- watching you fail and laughs when you do and not only that but will kill you in different ways just for the fun of it) His laugh is the cheer for Karlat "Ahahahahahaha!". Players LOVE fighting Jack O' Lantern because they WANT to see him die. They want the satisfaction of knowing they defeated a geniune monster of a being instead of just some guy.
               
               

               


                     Modifié par Highv Priest, 18 février 2013 - 06:43 .
                     
                  


            

Legacy_ffbj

  • Hero Member
  • *****
  • Posts: 1097
  • Karma: +0/-0
RE: Thrown Weapons - Is This Possible?
« Reply #29 on: February 18, 2013, 10:01:04 pm »


               Oh yeah that's correct stack has to be entirely gone.  Just as well I think it would be too messy anyway.  I know it's like Skyrim which is an ok way to do it.
Yeah I am all into realism too, as long as it is not too much at the expense of playability.