Back to Home

ESO Lua File v100023

ingame/vibration/vibration.lua

[◄ back to folders ]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
local function Vibrate(eventCode, duration, coarseMotor, fineMotor, leftTriggerMotor, rightTriggerMotor, foundInfo, debugSourceInfo)
    if IsInGamepadPreferredMode() and foundInfo then
        SetGamepadVibration(duration, coarseMotor, fineMotor, leftTriggerMotor, rightTriggerMotor, debugSourceInfo)
    end
end
local function GetVibrationFromEventInfo(actionResult, sourceType, targetType)
    -- WARNING! If you change this function, please update the event filter in c++ also, or remove
    -- the filter (REGISTER_FILTER_VIBRATION_FILTER) below.
    local actionType = nil
    --player doing stuff to people
    if sourceType == COMBAT_UNIT_TYPE_PLAYER then    
        if actionResult == ACTION_RESULT_DIED or         --player killed someone (self included ie falling damage)
         actionResult == ACTION_RESULT_DIED_XP or 
         actionResult == ACTION_RESULT_KILLING_BLOW then        
            actionType = GAMEPAD_VIBRATION_TRIGGER_KILLED
        end
    end
    --people doing stuff to player
    if targetType == COMBAT_UNIT_TYPE_PLAYER and sourceType ~= COMBAT_UNIT_TYPE_PLAYER then 
        if actionResult == ACTION_RESULT_DIED or                --player died
         actionResult == ACTION_RESULT_DIED_XP or 
         actionResult == ACTION_RESULT_KILLING_BLOW then
            actionType = GAMEPAD_VIBRATION_TRIGGER_DIED
        elseif actionResult == ACTION_RESULT_STUNNED then       --player got stunned
            actionType = GAMEPAD_VIBRATION_TRIGGER_STUNNED
        elseif actionResult == ACTION_RESULT_KNOCKBACK then     --player got knockedback
            actionType = GAMEPAD_VIBRATION_TRIGGER_KNOCKED_BACK
        elseif actionResult == ACTION_RESULT_STAGGERED then     --player got staggered
            actionType = GAMEPAD_VIBRATION_TRIGGER_STAGGERED
        end
    end
    return actionType;
end
local function OnCombatEvent(event, 
                        actionResult, 
                        isError, 
                        abilityName, 
                        abilityGraphic, 
                        abilityActionSlotType, 
                        sourceName, 
                        sourceType, 
                        targetName, 
                        targetType, 
                        hitValue, 
                        powerType, 
                        damageType, 
                        shouldLog)
                        
    local actionType = GetVibrationFromEventInfo(actionResult, sourceType, targetType)
    if actionType ~= nil then
        Vibrate(nil, GetVibrationInfoFromTrigger(actionType))
    end
end
local function OnHighFallEvent()
    Vibrate(nil, GetVibrationInfoFromTrigger(GAMEPAD_VIBRATION_TRIGGER_FALL_DAMAGE_HIGH))
end
local function OnLowFallEvent()
    Vibrate(nil, GetVibrationInfoFromTrigger(GAMEPAD_VIBRATION_TRIGGER_FALL_DAMAGE_LOW))
end
EVENT_MANAGER:RegisterForEvent("Vibration", EVENT_VIBRATION, Vibrate)
EVENT_MANAGER:RegisterForEvent("Vibration", EVENT_COMBAT_EVENT, OnCombatEvent)
EVENT_MANAGER:AddFilterForEvent("Vibration", EVENT_COMBAT_EVENT, REGISTER_FILTER_VIBRATION_FILTER, 0)
EVENT_MANAGER:RegisterForEvent("Vibration", EVENT_HIGH_FALL_DAMAGE, OnHighFallEvent)
EVENT_MANAGER:RegisterForEvent("Vibration", EVENT_LOW_FALL_DAMAGE, OnLowFallEvent)