KiCHo666 Posted May 24, 2018 Share Posted May 24, 2018 Hello!This is my code. It's a function that gets triggered by OnHit event: scn MadMomentumFUNCTION;PUBLICref rTargetref rAttacker;PRIVATEref rPusherfloat fHealthfloat fBaseHealthfloat fHitDamagefloat fGlobTimeMultfloat fPushfloat fVelAbsfloat fVelXfloat fVelYfloat fVelZfloat fPosXfloat fPosYfloat fPosZfloat fPosNewXfloat fPosNewYfloat fPosNewZbegin _function{rTarget, rAttacker};CHECK IF TARGET IS DEAD if rTarget.IsActor && rTarget.GetDead == 0;GET TARGET'S CURRENT HEALTH AND DAMAGE HIT DID let fHealth := rTarget.Getav Health let fHitDamage := rTarget.GetHitHealthDamage;GET ALL TARGET'S VELOCITIES Let fVelAbs := rTarget.GetActorVelocity Let fVelX := rTarget.GetActorVelocity X Let fVelY := rTarget.GetActorVelocity Y Let fVelZ := rTarget.GetActorVelocity Z;GET CURRENT GLOBAL TIME MULTIPLIER Let fGlobTimeMult := GetGlobalTimeMultiplier;CALCULATE PUSH VALUE Let fPush := ((fVelAbs / 10) / fGlobTimeMult);CHECK IF HIT WAS FATAL if eval fHealth < fHitDamage;SPAWN A PUSHER REFERENCE AT TARGET'S LOCATION Let rPusher := rTarget.PlaceAtMe MadPusher;MOVE PUSHER TO SPECIFIED NODE ON TARGET rPusher.MoveToNode rTarget "Bip01 PushBone";GET THE CURRENT POSITION OF PUSHER Let fPosX := rPusher.GetPos X Let fPosY := rPusher.GetPos Y Let fPosZ := rPusher.GetPos Z Print "X: " + $fPosX + " Y: " + $fPosY + " Z: " + $fPosZ;OFFSET PUSHER POSITION <-------------- DOESN'T WORK rPusher.SetPos X ((fPosX) - (fVelX)) rPusher.SetPos Y ((fPosY) - (fVelY)) rPusher.SetPos Y ((fPosZ) - (fVelZ));GET NEW PUSHER POSITION (JUST FOR THE TEST) Let fPosNewX := rPusher.GetPos X Let fPosNewY := rPusher.GetPos Y Let fPosNewZ := rPusher.GetPos Z Print "X: " + $fPosNewX + " Y: " + $fPosNewY + " Z: " + $fPosNewZ;PUSH TARGET rPusher.PushActorAway rTarget fPush;DELETE PUSHER REFERENCE rPusher.Disable rPusher.MarkForDelete endif endifend The problem I have is that SetPos doesn't actually move rPusher reference to the location I specified. It stays on the location where MoveToNode has moved it and I tested it in the game with Print function. 1st line shows the position of rPusher after it has been moved to a node on rTarget, 2nd line shows the current velocity values of a target, 3rd line should print updated values (velocity values were used as offset), but as you can see, they are exactly the same as the 1st line.Things I tried:- Using MoveTo - Doesn't work- Spawning rPusher earlier and THEN using MoveTo when function is triggered - Doesn't work- Using vanilla compailer (non-NVSE compiler override) and using "Set To" instead of "Let" - Doesn't work- Calling Update3D after setting new position - Doesn't workIn my earlier attempts I got the desired effect (with tricks), but with using Callback function with 5 frame delay so it created an offset between target and pusher, but later on I discovered that had many issues because of a way I did it.It NEEDS to be all done in a single frame in order to avoid side effects.I'm at my wits end, so if anyone knows how to make SetPos/MoveTo work, that'll be great!Thanks in advance! Link to comment Share on other sites More sharing options...
EPDGaffney Posted May 25, 2018 Share Posted May 25, 2018 I'm going to test your code. What is MadPusher and what is PushBone? Also, could you do me a favour and just paste your event handler? I don't have a lot of time, but I want to take a few minutes when I can and see what I can find out for you. Also, I've found that you can't use SetPos or SetAngle on scaled meshes. I don't think that applies to MoveTo, but it may. And you probably would have realised this by now if it mattered here, but PushActorAway doesn't work on corpses. I'm assuming this occurs just before the actor dies and that's why it's not a problem. Link to comment Share on other sites More sharing options...
KiCHo666 Posted May 25, 2018 Author Share Posted May 25, 2018 (edited) I'll pack the mod into a zip and send it to your PM if you don't mind. Edited May 25, 2018 by KiCHo666 Link to comment Share on other sites More sharing options...
EPDGaffney Posted May 25, 2018 Share Posted May 25, 2018 Absolutely. Go for it. May be a day or two before I can really look at it, but I will. Link to comment Share on other sites More sharing options...
KiCHo666 Posted May 25, 2018 Author Share Posted May 25, 2018 Thanks! Link to comment Share on other sites More sharing options...
Mktavish Posted May 25, 2018 Share Posted May 25, 2018 Ya it would seem it is simply not working because of PlaceAtMe MadPusher hasn't been in the world long enough to set it as rPusher. Plus don't you need a count integer with it like this ...rTarget.PlaceAtMe MadPusher 1 And what type of object is MadPusher ? But also ... instead of spawning the object earlier then using MoveTo , How about just place it in a remote cell giving it a specific reference , and use "MadPusherRef.MoveTo rTarget ( x,y,z offsets)" Then move it back to an x marker in that remote cell instead of deleting it. Link to comment Share on other sites More sharing options...
KiCHo666 Posted May 25, 2018 Author Share Posted May 25, 2018 (edited) Hm, but MoveToNode moves the spawned object correctly.Count integer didn't make any difference.I tried different types...static, activator and misc item.But isn't that the same thing I did earlier? For testing purposes, I spawned object on player's position when game was loaded and then I called MoveTo when I shot actor to move already spawned rPusher to rTarget position. That didn't work. Edited May 25, 2018 by KiCHo666 Link to comment Share on other sites More sharing options...
Mktavish Posted May 25, 2018 Share Posted May 25, 2018 Ya I was just stuck on where "PlaceAtMe" in its description says "Trying to run script commands on objects created in the same frame may not work, since it takes some time to place the object in the world. It is advised to wait a few frames or use a timed pause before attempting to manipulate these objects through scripts." And I wasn't familiar with "MoveToNode" But if that is working ???However it seems maybe you are trying to do to much in one frame. So what if instead of placing a ref , setting a ref variable , then moving it.You just got the Float position of the node , then did the offset calculations comming up with the new float variables.Then run ... MadPusherRef.SetPos X fPosXMadPusherRef.SetPos Y fPosYMadPusherRef.SetPos Z fPosZ IDK ... I guess I am a bit confused to what exactly is going on , but then again its not to hard to confuse me. Link to comment Share on other sites More sharing options...
KiCHo666 Posted May 26, 2018 Author Share Posted May 26, 2018 It seems that MoveTo, SetPos simply won't work in 1 frame situations like UDFs. Even after I used PlaceAtMe to spawn an object a minute before having to move that spawned object next to a target, it simply would not work. Link to comment Share on other sites More sharing options...
Mktavish Posted May 26, 2018 Share Posted May 26, 2018 Hmmm ... what if you had a cascade of event handlers ? Errr does that defeat the purpose ?... I don't really know , But it could start another script right ? Link to comment Share on other sites More sharing options...
Recommended Posts