LUADOC - Farming Simulator 19

Script v1.7.1.0

Engine v1.7.1.0

Foundation Reference

PlayerStateJump

Parent
PlayerStateBase
Functions

activate

Description
Activate method. Set vertical velocity.
Definition
activate()
Code
58function PlayerStateJump:activate()
59 PlayerStateJump:superClass().activate(self)
60
61 local velY = math.sqrt(-2.0 * self.player.motionInformation.gravity * self.player.motionInformation.jumpHeight)
62 local jumpFactor = 2.0
63 self.player.motionInformation.currentSpeedY = velY * jumpFactor
64
65 if self:inDebugMode() then
66 self.playerPos = {}
67 self.jumpDuration = 0.0
68 end
69end

consoleCommandDebugStateJump

Description
Console command to debug draw the jump state
Definition
consoleCommandDebugStateJump()
Code
114function PlayerStateJump:consoleCommandDebugStateJump()
115 self:toggleDebugMode()
116 if self:inDebugMode() then
117 self.playerPos = {}
118 end
119end

deactivate

Description
Deactivate method.
Definition
deactivate()
Code
73function PlayerStateJump:deactivate()
74 PlayerStateJump:superClass().deactivate(self)
75
76 self.jumpWeight = 0
77end

debugDraw

Description
Debug draw method.
Definition
debugDraw(float dt)
Arguments
floatdtdelta time in ms
Code
106function PlayerStateJump:debugDraw(dt)
107 for i=1, #self.playerPos do
108 DebugUtil.drawDebugCircle( self.playerPos[i][1], self.playerPos[i][2], self.playerPos[i][3], 0.1, 10)
109 end
110end

delete

Description
Definition
delete()
Code
31function PlayerStateJump:delete()
32 if self.player.isOwner then
33 removeConsoleCommand("gsToggleDebugStateJump")
34 end
35end

isAvailable

Description
Check if state is available. Check that player is on the ground.
Definition
isAvailable()
Return Values
booltrueif player can jump
Code
48function PlayerStateJump:isAvailable()
49 if self.player:hasHandtoolEquipped() and self.player.baseInformation.currentHandtool:isBeingUsed() then
50 return false
51 end
52 local isOnGround = self.player.baseInformation.isOnGround
53 return isOnGround and not g_currentMission:isInGameMessageActive()
54end

load

Description
Load method
Definition
load()
Code
39function PlayerStateJump:load()
40 if self.player.isOwner then
41 addConsoleCommand("gsToggleDebugStateJump", "Toggle debug mode for Jump", "consoleCommandDebugStateJump", self)
42 end
43end

new

Description
Creating instance of state.
Definition
new(table player, table stateMachine)
Arguments
tableplayerinstance of player
tablestateMachineinstance of the state machine manager
Return Values
tableinstanceinstance of object
Code
19function PlayerStateJump:new(player, stateMachine)
20 local self = PlayerStateBase:new(player, stateMachine, PlayerStateJump_mt)
21
22 -- debug code
23 self.playerPos = {}
24 self.jumpDuration = 0.0
25
26 return self
27end

update

Description
Update method. If the fall player state is available, we deactive this state.
Definition
update(float dt)
Arguments
floatdtdelta time in ms
Code
82function PlayerStateJump:update(dt)
83 if self.stateMachine:isAvailable("fall") or (self.player.baseInformation.isOnGround and self.player.motionInformation.currentSpeedY <= 0.0) then
84 if self:inDebugMode() then
85 local startPos = self.playerPos[1]
86 local endPos = self.playerPos[#self.playerPos]
87 local delta = endPos[2] - startPos[2]
88 print(string.format("[PlayerStateJump:update] End jump / duration(%.4f s) / height(%.4f).", self.jumpDuration * 0.001, delta))
89 end
90 self:deactivate()
91 end
92
93 -- debug code
94 if self:inDebugMode() then
95 local posX, posY, posZ = getWorldTranslation(g_currentMission.player.rootNode)
96 local newEntry = {posX, posY, posZ}
97
98 table.insert(self.playerPos, newEntry)
99 self.jumpDuration = self.jumpDuration + dt
100 end
101end