Skip to content

Instantly share code, notes, and snippets.

@JuniorDjjr
Created September 22, 2022 02:10
Show Gist options
  • Save JuniorDjjr/9a0ba94f191ee7b69f3b09cb9ead563f to your computer and use it in GitHub Desktop.
Save JuniorDjjr/9a0ba94f191ee7b69f3b09cb9ead563f to your computer and use it in GitHub Desktop.
// by Junior_Djjr - MixMods.com.br
// You need: https://forum.mixmods.com.br/f141-gta3script-cleo/t5206-como-criar-scripts-com-cleoplus
SCRIPT_START
{
LVAR_INT scplayer lLodBases lBases lLodFans lFans hObj pObj pAngles i iSize bLight iArea
LVAR_INT iModel_windturb_base iModel_windturb_fan iModel_lodwindturb_base iModel_lodwindturb_fan
LVAR_FLOAT x y z f fProgress rx fWind fSpawnDist fCurSpawnDist
WAIT 600
IF NOT GET_MODEL_BY_NAME "windturb_base" (iModel_windturb_base)
OR NOT GET_MODEL_BY_NAME "windturb_fan" (iModel_windturb_fan)
OR NOT GET_MODEL_BY_NAME "lodwindturb_base" (iModel_lodwindturb_base)
OR NOT GET_MODEL_BY_NAME "lodwindturb_fan" (iModel_lodwindturb_fan)
PRINT_STRING_NOW "~r~Error Wind Farm: Models not installed." 10000
TERMINATE_THIS_CUSTOM_SCRIPT
ENDIF
GET_MODEL_INFO iModel_lodwindturb_base i
READ_STRUCT_OFFSET i 0x18 4 (fSpawnDist)
fSpawnDist += 200.0
CREATE_LIST DATATYPE_INT lLodBases
CREATE_LIST DATATYPE_INT lBases
CREATE_LIST DATATYPE_INT lLodFans
CREATE_LIST DATATYPE_INT lFans
//GET_PLAYER_CHAR 0 (scplayer)
//SET_CHAR_COORDINATES scplayer 20.8414 598.5594 9.1859
//SET_TIME_OF_DAY 0 0
WHILE TRUE
WAIT 0
GOSUB GetCurSpawnDist
IF LOCATE_CAMERA_DISTANCE_TO_COORDINATES 0.0 750.0 50.0 fCurSpawnDist
OR LOCATE_CAMERA_DISTANCE_TO_COORDINATES -300.0 666.666 50.0 fCurSpawnDist
GET_AREA_VISIBLE iArea
IF iArea = 0
fSpawnDist += 50.0 //margin
GOSUB Create
//PRINT_STRING_NOW "Created" 1000
WHILE LOCATE_CAMERA_DISTANCE_TO_COORDINATES 0.0 750.0 50.0 fCurSpawnDist
OR LOCATE_CAMERA_DISTANCE_TO_COORDINATES -300.0 666.666 50.0 fCurSpawnDist
WAIT 0
GOSUB ProcessFan
GOSUB ProcessLight
GOSUB GetCurSpawnDist
GET_AREA_VISIBLE iArea
IF NOT iArea = 0
BREAK
ENDIF
ENDWHILE
fSpawnDist -= 50.0 //margin
GOSUB Remove
//PRINT_STRING_NOW "Removed" 1000
ENDIF
ENDIF
ENDWHILE
ProcessLight:
GET_CURRENT_HOUR (i)
IF i >= 20
OR i <= 6
IF timera > 1500
timera = 0
IF bLight = FALSE
bLight = TRUE
ELSE
bLight = FALSE
ENDIF
ENDIF
IF bLight = TRUE
i = 0
GET_LIST_SIZE lBases (iSize)
WHILE i < iSize
GET_LIST_VALUE_BY_INDEX lBases i (hObj)
GET_OFFSET_FROM_OBJECT_IN_WORLD_COORDS hObj -6.0 0.0 0.0 (x y z)
DRAW_CORONA x y z 2.0 CORONATYPE_SHINYSTAR FLARETYPE_NONE 255 40 0
++i
ENDWHILE
ENDIF
ENDIF
RETURN
GetCurSpawnDist:
READ_MEMORY 0xB6F118 4 FALSE (fCurSpawnDist)
fCurSpawnDist *= fSpawnDist
RETURN
ProcessFan:
i = 0
GET_LIST_SIZE lFans (iSize)
WHILE i < iSize
GET_LIST_VALUE_BY_INDEX lFans i (hObj)
GET_OBJECT_COORDINATES hObj (x y z)
f = y - fProgress
PERLIN_NOISE_FRACTAL_2D f y 1 0.3 10.0 2.0 0.1 (f)
ABS_LVAR_FLOAT f
f += 0.75
f *= 3.0
READ_MEMORY 0xC812F0 4 FALSE (fWind) //CWeather::Wind
fWind += 0.4
f *= fWind
//PRINT_FORMATTED_NOW "%f" 1000 fWind
READ_STRUCT_PARAM pAngles i (rx)
rx += f
WHILE rx > 360.0
rx -= 360.0
ENDWHILE
SET_OBJECT_ROTATION hObj rx 0.0 -60.0
GET_LIST_VALUE_BY_INDEX lLodFans i (hObj)
SET_OBJECT_ROTATION hObj rx 0.0 -60.0
WRITE_STRUCT_PARAM pAngles i (rx)
++i
ENDWHILE
fProgress -=@ 0.01
IF fProgress < -10000000.0 // just to avoid bugs after some hours
fProgress = 10000000.0
ENDIF
RETURN
Create:
// first load and create lods, then non-lod, to avoid delays
REQUEST_MODEL iModel_lodwindturb_base
REQUEST_MODEL iModel_lodwindturb_fan
WHILE NOT HAS_MODEL_LOADED iModel_lodwindturb_base
OR NOT HAS_MODEL_LOADED iModel_lodwindturb_fan
WAIT 0
ENDWHILE
CLEO_CALL CreateObjLod 0 lLodBases iModel_lodwindturb_base 135.715729 776.424988 65.456573
CLEO_CALL CreateObjLod 0 lLodFans iModel_lodwindturb_fan 135.715729 776.424988 65.456573
CLEO_CALL CreateObjLod 0 lLodBases iModel_lodwindturb_base 82.882095 814.415955 73.648407
CLEO_CALL CreateObjLod 0 lLodFans iModel_lodwindturb_fan 82.882095 814.415955 73.648407
CLEO_CALL CreateObjLod 0 lLodBases iModel_lodwindturb_base 83.495010 758.280457 66.824715
CLEO_CALL CreateObjLod 0 lLodFans iModel_lodwindturb_fan 83.495010 758.280457 66.824715
CLEO_CALL CreateObjLod 0 lLodBases iModel_lodwindturb_base 39.611641 708.519653 61.441948
CLEO_CALL CreateObjLod 0 lLodFans iModel_lodwindturb_fan 39.611641 708.519653 61.441948
CLEO_CALL CreateObjLod 0 lLodBases iModel_lodwindturb_base 3.200066 745.761230 63.762932
CLEO_CALL CreateObjLod 0 lLodFans iModel_lodwindturb_fan 3.200066 745.761230 63.762932
CLEO_CALL CreateObjLod 0 lLodBases iModel_lodwindturb_base -18.446114 695.305359 59.318298
CLEO_CALL CreateObjLod 0 lLodFans iModel_lodwindturb_fan -18.446114 695.305359 59.318298
CLEO_CALL CreateObjLod 0 lLodBases iModel_lodwindturb_base -37.656158 789.708618 67.826591
CLEO_CALL CreateObjLod 0 lLodFans iModel_lodwindturb_fan -37.656158 789.708618 67.826591
CLEO_CALL CreateObjLod 0 lLodBases iModel_lodwindturb_base -74.496498 727.737366 63.260227
CLEO_CALL CreateObjLod 0 lLodFans iModel_lodwindturb_fan -74.496498 727.737366 63.260227
CLEO_CALL CreateObjLod 0 lLodBases iModel_lodwindturb_base -110.754776 674.543213 59.027172
CLEO_CALL CreateObjLod 0 lLodFans iModel_lodwindturb_fan -110.754776 674.543213 59.027172
CLEO_CALL CreateObjLod 0 lLodBases iModel_lodwindturb_base -172.757111 699.797607 62.938866
CLEO_CALL CreateObjLod 0 lLodFans iModel_lodwindturb_fan -172.757111 699.797607 62.938866
CLEO_CALL CreateObjLod 0 lLodBases iModel_lodwindturb_base -244.989624 737.654419 64.888504
CLEO_CALL CreateObjLod 0 lLodFans iModel_lodwindturb_fan -244.989624 737.654419 64.888504
CLEO_CALL CreateObjLod 0 lLodBases iModel_lodwindturb_base -313.316864 744.839600 67.853119
CLEO_CALL CreateObjLod 0 lLodFans iModel_lodwindturb_fan -313.316864 744.839600 67.853119
CLEO_CALL CreateObjLod 0 lLodBases iModel_lodwindturb_base -332.084412 690.318359 64.730370
CLEO_CALL CreateObjLod 0 lLodFans iModel_lodwindturb_fan -332.084412 690.318359 64.730370
CLEO_CALL CreateObjLod 0 lLodBases iModel_lodwindturb_base -347.864258 626.020935 58.078465
CLEO_CALL CreateObjLod 0 lLodFans iModel_lodwindturb_fan -347.864258 626.020935 58.078465
CLEO_CALL CreateObjLod 0 lLodBases iModel_lodwindturb_base -404.741119 632.010925 56.309280
CLEO_CALL CreateObjLod 0 lLodFans iModel_lodwindturb_fan -404.741119 632.010925 56.309280
CLEO_CALL CreateObjLod 0 lLodBases iModel_lodwindturb_base -380.556030 687.529114 66.636093
CLEO_CALL CreateObjLod 0 lLodFans iModel_lodwindturb_fan -380.556030 687.529114 66.636093
CLEO_CALL CreateObjLod 0 lLodBases iModel_lodwindturb_base -438.870575 709.025146 60.676544
CLEO_CALL CreateObjLod 0 lLodFans iModel_lodwindturb_fan -438.870575 709.025146 60.676544
REQUEST_MODEL iModel_windturb_base
REQUEST_MODEL iModel_windturb_fan
WHILE NOT HAS_MODEL_LOADED iModel_windturb_base
OR NOT HAS_MODEL_LOADED iModel_windturb_fan
WAIT 0
ENDWHILE
CLEO_CALL CreateObj 0 (lBases lLodBases iModel_windturb_base 135.715729 776.424988 65.456573
CLEO_CALL CreateObj 0 (lFans lLodFans iModel_windturb_fan 135.715729 776.424988 65.456573
CLEO_CALL CreateObj 0 (lBases lLodBases iModel_windturb_base 82.882095 814.415955 73.648407
CLEO_CALL CreateObj 0 (lFans lLodFans iModel_windturb_fan 82.882095 814.415955 73.648407
CLEO_CALL CreateObj 0 (lBases lLodBases iModel_windturb_base 83.495010 758.280457 66.824715
CLEO_CALL CreateObj 0 (lFans lLodFans iModel_windturb_fan 83.495010 758.280457 66.824715
CLEO_CALL CreateObj 0 (lBases lLodBases iModel_windturb_base 39.611641 708.519653 61.441948
CLEO_CALL CreateObj 0 (lFans lLodFans iModel_windturb_fan 39.611641 708.519653 61.441948
CLEO_CALL CreateObj 0 (lBases lLodBases iModel_windturb_base 3.200066 745.761230 63.762932
CLEO_CALL CreateObj 0 (lFans lLodFans iModel_windturb_fan 3.200066 745.761230 63.762932
CLEO_CALL CreateObj 0 (lBases lLodBases iModel_windturb_base -18.446114 695.305359 59.318298
CLEO_CALL CreateObj 0 (lFans lLodFans iModel_windturb_fan -18.446114 695.305359 59.318298
CLEO_CALL CreateObj 0 (lBases lLodBases iModel_windturb_base -37.656158 789.708618 67.826591
CLEO_CALL CreateObj 0 (lFans lLodFans iModel_windturb_fan -37.656158 789.708618 67.826591
CLEO_CALL CreateObj 0 (lBases lLodBases iModel_windturb_base -74.496498 727.737366 63.260227
CLEO_CALL CreateObj 0 (lFans lLodFans iModel_windturb_fan -74.496498 727.737366 63.260227
CLEO_CALL CreateObj 0 (lBases lLodBases iModel_windturb_base -110.754776 674.543213 59.027172
CLEO_CALL CreateObj 0 (lFans lLodFans iModel_windturb_fan -110.754776 674.543213 59.027172
CLEO_CALL CreateObj 0 (lBases lLodBases iModel_windturb_base -172.757111 699.797607 62.938866
CLEO_CALL CreateObj 0 (lFans lLodFans iModel_windturb_fan -172.757111 699.797607 62.938866
CLEO_CALL CreateObj 0 (lBases lLodBases iModel_windturb_base -244.989624 737.654419 64.888504
CLEO_CALL CreateObj 0 (lFans lLodFans iModel_windturb_fan -244.989624 737.654419 64.888504
CLEO_CALL CreateObj 0 (lBases lLodBases iModel_windturb_base -313.316864 744.839600 67.853119
CLEO_CALL CreateObj 0 (lFans lLodFans iModel_windturb_fan -313.316864 744.839600 67.853119
CLEO_CALL CreateObj 0 (lBases lLodBases iModel_windturb_base -332.084412 690.318359 64.730370
CLEO_CALL CreateObj 0 (lFans lLodFans iModel_windturb_fan -332.084412 690.318359 64.730370
CLEO_CALL CreateObj 0 (lBases lLodBases iModel_windturb_base -347.864258 626.020935 58.078465
CLEO_CALL CreateObj 0 (lFans lLodFans iModel_windturb_fan -347.864258 626.020935 58.078465
CLEO_CALL CreateObj 0 (lBases lLodBases iModel_windturb_base -404.741119 632.010925 56.309280
CLEO_CALL CreateObj 0 (lFans lLodFans iModel_windturb_fan -404.741119 632.010925 56.309280
CLEO_CALL CreateObj 0 (lBases lLodBases iModel_windturb_base -380.556030 687.529114 66.636093
CLEO_CALL CreateObj 0 (lFans lLodFans iModel_windturb_fan -380.556030 687.529114 66.636093
CLEO_CALL CreateObj 0 (lBases lLodBases iModel_windturb_base -438.870575 709.025146 60.676544
CLEO_CALL CreateObj 0 (lFans lLodFans iModel_windturb_fan -438.870575 709.025146 60.676544
// init angles array
GET_LIST_SIZE lFans (iSize)
i = iSize * 4
ALLOCATE_MEMORY i (pAngles)
IF pAngles = 0 //something is wrong
GOSUB Remove
TERMINATE_THIS_CUSTOM_SCRIPT
ENDIF
i = 0
WHILE i < iSize
GENERATE_RANDOM_FLOAT_IN_RANGE 0.0 360.0 (f)
WRITE_STRUCT_PARAM pAngles i f
++i
ENDWHILE
fProgress = 10000000.0
RETURN
Remove:
CLEO_CALL DeleteObjsFromList 0 (lLodBases)()
CLEO_CALL DeleteObjsFromList 0 (lBases)()
CLEO_CALL DeleteObjsFromList 0 (lLodFans)()
CLEO_CALL DeleteObjsFromList 0 (lFans)()
FREE_MEMORY pAngles
RETURN
}
SCRIPT_END
{
LVAR_INT lList //In
LVAR_INT i iSize hObj
DeleteObjsFromList:
i = 0
GET_LIST_SIZE lList (iSize)
WHILE i < iSize
GET_LIST_VALUE_BY_INDEX lList i (hObj)
DELETE_OBJECT hObj
++i
ENDWHILE
RESET_LIST lList
CLEO_RETURN 0 ()
}
{
LVAR_INT lList iModel //In
LVAR_FLOAT x y z //In
LVAR_INT hNewObj
CreateObjLod:
CREATE_OBJECT_NO_SAVE iModel x y z FALSE FALSE (hNewObj)
SET_OBJECT_HEADING hNewObj -60.0
//SET_OBJECT_MODEL_ALPHA hNewObj 0
LIST_ADD lList hNewObj
CLEO_RETURN 0 ()
}
{
LVAR_INT lList lListLod iModel //In
LVAR_FLOAT x y z //In
LVAR_INT hNewObj i hLodObj
CreateObj:
CREATE_OBJECT_NO_SAVE iModel x y z FALSE FALSE (hNewObj)
SET_OBJECT_HEADING hNewObj -60.0
//SET_OBJECT_MODEL_ALPHA hNewObj 0
LIST_ADD lList hNewObj
//link lod
GET_LIST_SIZE lList (i)
i -= 1
GET_LIST_VALUE_BY_INDEX lListLod i (hLodObj)
CONNECT_LODS hNewObj hLodObj
CLEO_RETURN 0 ()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment