{$CLEO}

//Cactus damage
0000: NOP

//Velocity
0004: 19@ = 40
0007: 20@ = 2.0
0087: 21@ = 20@
0013: 21@ *= -1.0
0007: 22@ = 1.0
//
0004: 23@ = 1136
0004: 24@ = 5
0004: 25@ = 1
0004: 26@ = 0
//Currently colliding
0004: 30@ = 0

if
    0AAB: file_exists "cleo\cactusdamage.ini"
then
    0AF0: 19@ = get_int_from_ini_file "cleo\cactusdamage.ini" section "Main" key "Delay"
    0AF2: 20@ = get_float_from_ini_file "cleo\cactusdamage.ini" section "Main" key "MinSpeed"
    0AF2: 22@ = get_float_from_ini_file "cleo\cactusdamage.ini" section "Main" key "BushSize"
    0AF0: 23@ = get_int_from_ini_file "cleo\cactusdamage.ini" section "Main" key "SoundID"
    0AF0: 24@ = get_int_from_ini_file "cleo\cactusdamage.ini" section "Main" key "Health"
    0AF0: 25@ = get_int_from_ini_file "cleo\cactusdamage.ini" section "Main" key "Armour"
    0AF0: 26@ = get_int_from_ini_file "cleo\cactusdamage.ini" section "Main" key "Effect"
end

:main

wait 19@

if and
    0256: player $PLAYER_CHAR defined
    044B: actor $PLAYER_ACTOR on_foot
else_jump @main

//These only work with dynamic or procedural objects
00A0: store_actor $PLAYER_ACTOR position_to 0@ 1@ 2@
0AE3: 10@ = random_object_near_point 0@ 1@ 2@ in_radius 5.0 find_next 1 //IF and SET

if
    03CA: object 10@ exists
else_jump @main

//Has collision - IPL file ones need to be added to object.dat
if or
    09CC: object 10@ model_is 650
    09CC: object 10@ model_is 651
    09CC: object 10@ model_is 653
then
    if
        0179: actor $PLAYER_ACTOR colliding_with_object 10@
    then
        if
            0039: 30@ == 0
        then
            30@ = 1
            0851: set_actor $PLAYER_ACTOR decrease_health_by 24@ affect_armour 25@
            if
                8039: not 23@ == 0
            then
                018C: play_sound 23@ at 0.0 0.0 0.0
            end
            if
                8039: not 26@ == 0
            then
                09B8: create_blood_gush_at 0@ 1@ 2@ with_offset 0 0 0 density 20 on_actor $PLAYER_ACTOR
            end
        end
    else
        30@ = 0
    end
end

//No collision, bushes - need to be added to object.dat
if or
    09CC: object 10@ model_is 753
    09CC: object 10@ model_is 754
    09CC: object 10@ model_is 755
    09CC: object 10@ model_is 756
    09CC: object 10@ model_is 757
then
    //Couldn't find a better way to detect movement
    083D: get_actor $PLAYER_ACTOR velocity_in_direction_XYZ 3@ 4@ 5@
    if or
        0025: 3@ > 20@
        0025: 21@ > 3@
        0025: 4@ > 20@
        0025: 21@ > 4@
        0025: 5@ > 20@
        0025: 21@ > 5@ 
    else_jump @main

    if
        04E6: object 10@ near_point 0@ 1@ 2@ radius 22@ 22@ 22@ flag 0
    then
        0851: set_actor $PLAYER_ACTOR decrease_health_by 24@ affect_armour 25@
        if
            8039: not 23@ == 0
        then
            018C: play_sound 23@ at 0.0 0.0 0.0
        end
        if
            8039: not 26@ == 0
        then
            09B8: create_blood_gush_at 0@ 1@ 2@ with_offset 0 0 0 density 20 on_actor $PLAYER_ACTOR
        end
    end
end

jump @main

0A93: terminate_this_custom_script