-- LUA Script - precede every function and global member with lowercase name of script + '_main' local U = require "scriptbank\\utillib" local P = require "scriptbank\\physlib" local Q = require "scriptbank\\quatlib" local M = require "scriptbank\\ai\\module_combatcore" local rad = math.rad local deg = math.deg local tan = math.tan local atan = math.atan local abs = math.abs local cos = math.cos local sin = math.sin local charX, charY, charZ local angX, angY, angZ = rad( 45 ), rad( 0 ), rad ( 0 ) local mouse_spr = mouse_spr or CreateSprite( LoadImage( "scriptbank\\images\\mouse_cursor.png" )) SetSpriteSize( mouse_spr, 1.5, -1 ) SetSpriteOffset( mouse_spr, 0.75, 1.2 ) SetSpritePosition( mouse_spr, 200, 200 ) local PlayerFOV = 25 local distance = 1000 local anims = { sat = { ff = 3744, lf = 3828 }, sitdown = { ff = 3710, lf = 3744 }, getup = { ff = 3828, lf = 3862 }, ascend1 = { ff = 4110, lf = 4147 }, ascend2 = { ff = 4148, lf = 4225 }, ascend3 = { ff = 4226, lf = 4255 }, descend = { ff = 4225, lf = 4148 } } -- csi_unarmedladderascend1 = 4148,4110 -- csi_unarmedladderascend2 = 4148,4255 -- csi_unarmedladderascend3 = 4225,4255 -- csi_unarmedladderdecend1 = 4255,4225 -- csi_unarmedladderdecend2 = 4225,4148 function iso_view_init( e ) SetPlayerFOV( PlayerFOV ) ActivateMouse() PositionMouse( GetDesktopWidth() / 2, GetDesktopHeight() / 2) CharacterControlManual( e ) CharacterControlUnarmed( e ) AISetEntityControl( g_Entity[ e ].obj, AI_MANUAL ) end local aspect = GetDeviceWidth() / GetDeviceHeight() local mousePress = false local freezeScreen = false local EkeyPressed = false local state = 'walking' local hfov = g_PlayerFOV / 50 * 90 + 20 local hfov = hfov / 100 * 90 + 20 local hfov = rad( hfov / aspect / 2) * 1.405 local vfov = hfov / aspect * 1.1 local ax, ay = nil, nil local function calcaxay() local hfov = g_PlayerFOV / 50 * 90 + 20 local hfov = hfov / 100 * 90 + 20 local hfov = rad( hfov / aspect / 2) * 1.405 local vfov = hfov / aspect * 1.1 ax = 1 / tan( hfov ) ay = 1 / tan( vfov ) end local function getRelativePos( xo, zo, obj ) local x, y, z, _, ya, _ = GetObjectPosAng( obj ) local offx, offy, offz = U.Rotate3D( xo, 0, zo, 0, rad( ya ), 0 ) return x + offx, y, z + offz, ya end local tgt = nil local top = nil local climbSpeed = 0.6 local ladderHght = 190 local mouseWheelLast = 0 function iso_view_main( e ) local Ent = g_Entity[ e ] charX, charY, charZ = Ent.x, Ent.y, Ent.z local mx, my = g_MouseX, g_MouseY SetSpritePosition( mouse_spr, mx, my ) local px, py, pz = U.Rotate3D( 0, 0, -distance, angX, angY, angZ ) px, py, pz = charX + px, charY + py, charZ + pz SetFreezePosition( px, py, pz ) SetFreezeAngle( deg( angX ), deg( angY ), deg( angZ ) ) TransportToFreezePosition() ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ local tweakVal = 47 + ( 7 * 500 / distance ) local omx, omy = ( mx - 50 ) / 50, ( my - tweakVal ) / tweakVal local quat = Q.FromEuler( angX, angY, angZ ) if ax == nil or ay == nil then calcaxay() end local xAng = atan( omx / ax ) local yAng = atan( omy / ay ) if omx ~= 0 then local fact = 1 - ( 0.18 * omx * omx ) yAng = yAng * fact end local qoff = Q.FromEuler( yAng, xAng, 0 ) quat = Q.Mul( quat, qoff ) local paX, paY, paZ = Q.ToEuler( quat ) local rayX, rayY, rayZ = U.Rotate3D ( 0, 0, 4000, paX, paY, paZ ) local rayX, rayY, rayZ = px + rayX, py + rayY, pz + rayZ local obj = IntersectAll( px, py, pz, rayX, rayY, rayZ, 0 ) local hit = 'terrain' if obj ~= 0 then rayX = GetIntersectCollisionX() rayY = GetIntersectCollisionY() rayZ = GetIntersectCollisionZ() if GetObjectExist( obj ) == 1 then local entity = P.ObjectToEntity( obj ) if entity ~= nil and entity ~= e then local str = GetEntityName( entity ) PromptLocal( entity, str ) hit = str else hit = 'object' end end elseif RayTerrain( px, py, pz, rayX, rayY, rayZ ) == 1 then rayX = GetRayCollisionX() rayY = GetRayCollisionY() rayZ = GetRayCollisionZ() end ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ if ( g_MouseClick == 1 or g_MouseClick == 2 ) and not mousePress then mousePress = true end if g_MouseClick == 0 then mousePress = false end if mousePress then if ( hit == 'terrain' or hit == 'object' ) and ( state == 'walking' or state == 'atchair' or state == 'atladder' or state == 'atladdertop' ) then if g_MouseClick == 1 then SetCharacterToWalk( e ) else SetCharacterToRun( e ) end AIEntityGoToPosition( Ent.obj, rayX, rayZ) state = 'walking' elseif hit == 'Chair' and state == 'walking' then state = 'walktochair' SetCharacterToWalk( e ) local x, y, z, ya = getRelativePos( 0, -18, obj ) AIEntityGoToPosition( Ent.obj, x, z ) tgt = { obj = obj, x = x, y = y, z = z, ya = ya } elseif hit == 'Ladder' and state == 'walking' then SetCharacterToWalk( e ) local x, y, z, ya = getRelativePos( 0, 0, obj ) local x2, y2, z2, ya2 = getRelativePos( 0, -40, obj ) tgt = { obj = obj, x = x, y = y, z = z, ya = ya } top = { obj = obj, x = x2, y = y2 + ladderHght, z = z2, ya = ya2 } if charY > y + 10 then -- already up the ladder state = 'walktoladdertop' AIEntityGoToPosition( Ent.obj, top.x, top.z ) else state = 'walktoladder' AIEntityGoToPosition( Ent.obj, tgt.x, tgt.z ) end end end if ShowDecal1 ~= nil and tgt ~= nil then ShowDecal1( tgt.x, tgt.y, tgt.z ) end Prompt( g_MouseWheel ) if g_MouseWheel < 0 then if distance < 1200 then distance = distance + 10 end elseif g_MouseWheel > 0 then if distance > 250 then distance = distance - 10 end end local ya = deg( angY ) --PromptLocal( e, ya ) if g_KeyPressA == 1 then ya = ya - 0.97 if ya < -180 then ya = 179 end angY = rad( ya ) end if g_KeyPressD == 1 then ya = ya + 0.97 if ya > 180 then ya = -179 end angY = rad( ya ) end local frame = GetAnimationFrame( e ) --Prompt( state .. ", " .. frame ) if g_KeyPressE == 1 then if not EkeyPressed then if state == 'atchair' then state = 'sitdown' elseif state == 'sat' then state = 'getup' elseif state == 'atladder' then state = 'ascend1' elseif state == 'atladdertop' then state = 'descend' end EkeyPressed = true end else EkeyPressed = false end if state == 'walktochair' then if U.CloserThan( Ent.x, 0, Ent.z, tgt.x, 0, tgt.z, 50 ) then state = 'atchair' AIEntityStop( Ent.obj ) StopAnimation( e ) else AIEntityGoToPosition( Ent.obj, tgt.x, tgt.z ) end elseif state == 'walktoladder' then if U.CloserThan( charX, 0, charZ, tgt.x, 0, tgt.z, 50 ) then state = 'atladder' AIEntityStop( Ent.obj ) StopAnimation(e) else AIEntityGoToPosition( Ent.obj, tgt.x, tgt.z ) end elseif state == 'walktoladdertop' then if U.CloserThan( charX, 0, charZ, top.x, 0, top.z, 50 ) then state = 'atladdertop' AIEntityStop( Ent.obj ) StopAnimation(e) else AIEntityGoToPosition( Ent.obj, top.x, top.z ) end elseif state == 'atchair' then Prompt( "E key to sit on chair" ) elseif state == 'atladder' then Prompt( "E key to climb ladder" ) elseif state == 'atladdertop' then Prompt( "E key to descend ladder" ) elseif state == 'ascend1' then CharacterControlLimbo( e ) SetRotation( e, 0, tgt.ya - 180, 0 ) SetPosition( e, tgt.x, tgt.y, tgt.z ) local anim = anims[ state ] SetAnimationFrames( anim.ff, anim.lf ) PlayAnimation( e ) state = 'climbing1' elseif state == 'climbing1' then if frame == anims[ 'ascend1' ].lf then state = 'ascend2' end if frame > 4130 then CollisionOff( e ) local y = charY + climbSpeed SetPosition( e, charX, y, charZ ) AISetEntityPosition( Ent.obj, charX, y, charZ ) end elseif state == 'climbing2' then if ( charY - tgt.y ) > ladderHght then state = 'ascend3' end CollisionOff( e ) local y = charY + climbSpeed SetPosition( e, charX, y, charZ ) AISetEntityPosition( Ent.obj, charX, y, charZ ) elseif state == 'ascend2' then local anim = anims[ state ] SetAnimationFrames( anim.ff, anim.lf ) LoopAnimation( e ) state = 'climbing2' elseif state == 'ascend3' then local anim = anims[ state ] SetAnimationFrames( anim.ff, anim.lf ) PlayAnimation( e ) state = 'ontop' elseif state == 'ontop' and frame == anims[ 'ascend3' ].lf then state = 'walking' SetPosition( e, top.x, top.y, top.z ) AISetEntityPosition( Ent.obj, top.x, top.y, top.z ) AIEntityGoToPosition( Ent.obj, top.x, top.z ) CharacterControlManual( e ) CharacterControlUnarmed( e ) AISetEntityControl( Ent.obj, AI_MANUAL ) CollisionOn( e ) elseif state == 'sitdown' then CharacterControlLimbo( e ) SetRotation( e, 0, tgt.ya - 180, 0 ) SetPosition( e, tgt.x, tgt.y, tgt.z ) local anim = anims[ state ] SetAnimationFrames( anim.ff, anim.lf ) PlayAnimation( e ) state = 'sitting' elseif state == 'sitting' and frame == anims[ 'sitdown' ].lf then state = 'sat' local anim = anims[ state ] SetAnimationFrames( anim.ff, anim.lf ) LoopAnimation( e ) elseif state == 'sat' then Prompt( "E key to stand up" ) elseif state == 'getup' then local anim = anims[ state ] SetAnimationFrames( anim.ff, anim.lf ) PlayAnimation( e ) state = 'gettingup' elseif state == 'gettingup' and frame == anims[ 'getup' ].lf then state = 'walking' CharacterControlManual( e ) CharacterControlUnarmed( e ) AISetEntityControl( Ent.obj, AI_MANUAL ) end end