View difference between Paste ID: iARxSi0f and 2Kg5Xzuj
SHOW: | | - or go back to the newest paste.
1-
function fixed clampFixed (fixed number, fixed min, fixed max) {
1+
function int clamp (int x, int min, int max) {
2-
    fixed realMin = min;
2+
    int realMin = min;
3-
    fixed realMax = max;
3+
    int realMax = max;
4
    
5
    if (min > max) {
6
        realMax = min;
7
        realMin = max;
8
    }
9
    
10-
    if (number > realMax)
10+
    if (x > realMax)
11
        return realMax;
12-
    else if (number < realMin)
12+
    else if (x < realMin)
13
        return realMin;
14
    else
15-
        return number;
15+
        return x;
16
}
17
18-
script "S7_RecoilPitch" (fixed pitch) { // Called like this in code: AMGG BC 1 acs_namedExecuteAlways ("S7_RecoilPitch", 0, 0.5 * 65535)
18+
function int scaleValue (int x, int fromMin, int fromMax, int toMin, int toMax) {
19
    return (x - fromMin) * (toMax - toMin) / (fromMax - fromMin) + toMin;
20-
    fixed newPitch = clampFixed (oldPitch - pitch, -25.0, 25.0);
20+
21
22
function fixed scaleValueFixed (fixed x, fixed fromMin, fixed fromMax, fixed toMin, fixed toMax) {
23
    return fixedDiv (fixedMul (x - fromMin, toMax - toMin), fromMax - fromMin) + toMin;
24
}
25
26
script "S7_RecoilPitch" (fixed offset) { // Called like this in code: TNT1 A 0 acs_namedExecuteAlways ("S7_RecoilPitch", 0, 0.5 * 65535)
27
    fixed oldPitch = getActorPitch (0);
28
    fixed scaledoffset = scaleValueFixed (offset, -90.0, 90.0, -0.25, 0.25);
29
    fixed newPitch = clamp (oldPitch - scaledoffset, -0.25, 0.25);
30
    
31
    setActorPitch (0, newPitch);
32
}