Jump to content

SCRIPT HELP: I will step on you with my mech


irswat

Recommended Posts

I am writing a script so this mech devp and I are working on can step on NPC's. It's a challenge. I know the script is wrong, but I dont know how to fix it.

I figured out the dimensions of the mech in units. Relative to the mech I know what areas are "under" each foot.

I can't figure out how to check if an NPC is under the foot. The main difficulty that I'm having is GetPos returns a value relative to the cell, not the player. To transform the NPC pos to be relative to the player is proving to be the major difficulty.

Here is the code. It goes in a ref-walking script that does work.

;Mech will step on you script
set NPCProximity to player.GetDistance rCurrentNPC
if (NPXProximity < 504)
    set CurrentNPCPOSX to rCurrentNPC.GetPos X
    set CurrentNPCPOSY to rCurrentNPC.GetPos Y
    set CurrentNPCPOSZ to rCurrentNPC.GetPos Z
    set CurrentPOSX to player.GetPos X
    set CurrentPOSY to player.GetPos Y
    set CurrentPOSZ to player.GetPos Z
    set CurrentAngleHeading to player.GetHeadingAngle rCurrentNPC
    
    ;Is this how I can get NPC reference position relative to player?
    ;Will this detection method work regardless of what direction I'm facing?
    ;will this work regardless of where the NPC is relative to me?
    ;will this work on negative as well as positive coordinates?
    set OffsetX to CurrentNPCPosX-CurrentPosX
    set OffsetY to CurrentNPCPosY-CurrentPosY
    set OffsetZ to CurrentNPCPosZ-CurrentPosZ
    
    ;coordinates of mechs' left foot relative to player
    ; LFULX  -70
    ; LFURX  -16.75
    ; LFLLX  -70
    ; LFLRX  -16.75
    ; LFULY  26.625
    ; LFURY  26.625
    ; LFLLY  -26.625
    ; LFLRY  -26.625
    
    ;coordinates of mechs' right foot relative to player
    ; RFULX  16.75
    ; RFURX  70
    ; RFLLX  16.75
    ; RFLRX  70
    ; RFULY  26.625
    ; RFURY  26.625
    ; RFLLY  -26.625
    ; RFLRY  -26.625
                
    if (OffsetX>16.75)&&(OffsetX<70)&&(OffsetY<26.625)&&(OffsetY>-26.625)&&(OffsetZ>=0)&&(OffsetZ<=128)
        set DangerZoneRF to 1
    elseif (OffsetX<-16.75)&&(OffsetX>-70)&&(OffsetY<26.625)&&(OffsetY>-26.825)&&(OffsetZ>=0)&&(OffsetZ<=128)
        set DangerZoneLF to 1
    endif
            
    set ForwardKey to GetControl 0
    set BackwardKey to GetControl 1
    if (rCurrentNPC.IsMoving)    ;if the mech is moving
        Playsound mech_footstep
        If (FootstepMetronome==0)
        if footsteptimer > 1;
            set FootstepMetronome to 1
            set footsteptimer to 0
        endif
        else
            set FootstepMetronome to 0
        endif
        if (bIsPressed != IsKeyPressed ForwardKey)
            set bIsPressed to IsKeyPressed ForwardKey
            if bIsPressed
                set footsteptimer to footsteptimer+GetSecondsPassed
                if(FootstepMetronome==1)&&(DangerZoneRF)
                    rCurrentNPC.KillActor 1 5
                    PlaySound squish
                    MessageEx "You stepped on %n" rCurrentNPC
                elseif (FootstepMetronome==0)&&(DangerZoneLF)
                    rCurrentNPC.KillActor 1 5
                    PlaySound squish
                    MessageEx "You stepped on %n" rCurrentNPC
                endif
            else
            endif
        elseif (bIsPressed != IsKeyPressed BackwardKey)
            set bIsPressed to IsKeyPressed ForwardKey
            if bIsPressed
                set footsteptimer to footsteptimer+GetSecondsPassed
            if(FootstepMetronome==1)&&(DangerZoneRF)
                rCurrentNPC.KillActor 1 5
                PlaySound squish
                MessageEx "You stepped on %n" rCurrentNPC
            elseif (FootstepMetronome==0)&&(DangerZoneLF)
                rCurrentNPC.KillActor 1 5
                PlaySound squish
                MessageEx "You stepped on %n" rCurrentNPC
            endif
        else
        endif
    elseif (rCurrentNPC.IsMoving == 0)
            set footsteptimer to 0
    endif
    
    ;how can the NPC get close enough to step on?
    ;perhaps I will add some random variability for this
    ;so sometimes an NPC won't get knocked away
    ;allowing them to get close enough to be stepped on
    if (OffsetX>70)&&(Offsetx<198)||(OffsetY>26.625)&&(OffsetY<155)
        player.PushActorAway rCurrentNPC 10
    endif
endif

Can you help me get this npc crushing script to work? I think the real problem is transforming the GetPos values in such a way that they are relational to the player, and not the cell. I don't think I'm going about this the right way.

Edited by irswat
Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...