Skip to content

Instantly share code, notes, and snippets.

@JuniorDjjr
Last active January 5, 2024 17:48
Show Gist options
  • Save JuniorDjjr/b8c2123032a21b99f8dccf583030d9d1 to your computer and use it in GitHub Desktop.
Save JuniorDjjr/b8c2123032a21b99f8dccf583030d9d1 to your computer and use it in GitHub Desktop.
// by Junior_Djjr
// You need: https://forum.mixmods.com.br/f141-gta3script-cleo/t5206-como-criar-scripts-com-cleoplus
SCRIPT_START
{
LVAR_INT scplayer hChar hDamagerChar i j pEntity iCharsProgress iWeaponType iDamagePiece pWeaponInfo iFireType isFireGun hCharCop bCopSeenInFront
LVAR_FLOAT fDamageIntensity fMinCopDistance
GET_PLAYER_CHAR 0 scplayer
SET_SCRIPT_EVENT_CHAR_DAMAGE ON OnCharDamage hChar
// infinite loop
WHILE TRUE
WAIT 0x7FFFFFFF // max signed int
// Test
/*WAIT 0
IF IS_KEY_JUST_PRESSED VK_KEY_Y
STORE_CLOSEST_ENTITIES scplayer i hChar
IF hChar > 0
TASK_KILL_CHAR_ON_FOOT hChar scplayer
ENDIF
ENDIF*/
ENDWHILE
OnCharDamage:
GET_PED_TYPE hChar i
IF i <= 1 // is player
IF IS_WANTED_LEVEL_GREATER i 0
RETURN_SCRIPT_EVENT
ENDIF
ENDIF
IF IS_ON_CUTSCENE
OR IS_ON_SCRIPTED_CUTSCENE
RETURN_SCRIPT_EVENT
ENDIF
GET_CHAR_STAT_ID hChar j
IF NOT i = PEDTYPE_COP
AND NOT j = PEDSTAT_COP
IF NOT IS_CHAR_DEAD hChar
GET_CHAR_DAMAGE_LAST_FRAME hChar pEntity iWeaponType iDamagePiece fDamageIntensity
IF pEntity > 0
GET_ENTITY_TYPE pEntity i
IF i = ENTITY_TYPE_PED
GET_PED_REF pEntity hDamagerChar
IF hDamagerChar > 0
GET_PED_TYPE hDamagerChar i
GET_CHAR_STAT_ID hDamagerChar j
IF NOT i = PEDTYPE_COP
AND NOT j = PEDSTAT_COP
AND i >= 4
IF NOT IS_CHAR_DEAD hDamagerChar
isFireGun = FALSE
IF iWeaponType > 0
IF GET_WEAPONINFO iWeaponType 1 (pWeaponInfo)
GET_WEAPONINFO_FIRE_TYPE pWeaponInfo (iFireType)
IF iFireType = WEAPONFIRE_INSTANT_HIT
OR iFireType = WEAPONFIRE_PROJECTILE
OR iWeaponType = WEAPONTYPE_FLAMETHROWER // this is AREA_EFFECT, but spraycan too, so we need to check by weapontype
// You may want to include knife, chainsaw, katana, but you can't check knife by animgroup because dildo uses the same animgroup
isFireGun = TRUE
ENDIF
ENDIF
ENDIF
IF isFireGun = TRUE
fMinCopDistance = 200.0
bCopSeenInFront = FALSE
ELSE
fMinCopDistance = 70.0
bCopSeenInFront = TRUE
ENDIF
IF GET_CLOSEST_COP_NEAR_CHAR hDamagerChar fMinCopDistance TRUE TRUE TRUE bCopSeenInFront hCharCop
IF GOSUB SetCopKillDamagerChar
RETURN_SCRIPT_EVENT
ENDIF
ENDIF
// If can't find near damager, find near damaged
IF GET_CLOSEST_COP_NEAR_CHAR hChar fMinCopDistance TRUE TRUE TRUE bCopSeenInFront hCharCop
IF GOSUB SetCopKillDamagerChar
RETURN_SCRIPT_EVENT
ENDIF
ENDIF
ENDIF
ENDIF
ENDIF
ENDIF
ENDIF
ENDIF
ENDIF
RETURN_SCRIPT_EVENT
SetCopKillDamagerChar:
IF NOT IS_CHAR_SCRIPT_CONTROLLED hCharCop
OR NOT IS_ON_MISSION
IF NOT GET_CHAR_KILL_TARGET_CHAR hCharCop i
IF isFireGun = TRUE
REQUEST_PRIORITY_MODEL COLT45
LOAD_ALL_PRIORITY_MODELS_NOW
GIVE_WEAPON_TO_CHAR hCharCop WEAPONTYPE_PISTOL 100
MARK_MODEL_AS_NO_LONGER_NEEDED COLT45
ELSE
REQUEST_PRIORITY_MODEL NITESTICK
LOAD_ALL_PRIORITY_MODELS_NOW
GIVE_WEAPON_TO_CHAR hCharCop WEAPONTYPE_NIGHTSTICK 1
MARK_MODEL_AS_NO_LONGER_NEEDED NITESTICK
ENDIF
TASK_KILL_CHAR_ON_FOOT hCharCop hDamagerChar
STREAM_CUSTOM_SCRIPT_FROM_LABEL ProcessCopKilling hCharCop hDamagerChar
//PRINT_STRING_NOW "IH SERJAO, SUJOU" 200
RETURN_TRUE
RETURN
ENDIF
ENDIF
RETURN_FALSE
RETURN
}
SCRIPT_END
{
LVAR_INT hCharCop hCharTarget // In
LVAR_INT i
ProcessCopKilling:
WHILE TRUE
WAIT 0
IF NOT DOES_CHAR_EXIST hCharCop
BREAK
ENDIF
GET_CHAR_HEALTH hCharCop i
IF NOT i > 0
BREAK
ENDIF
IF NOT GET_CHAR_KILL_TARGET_CHAR hCharCop i
CLEAR_CHAR_TASKS_IMMEDIATELY hCharCop
BREAK
ELSE
IF NOT hCharTarget = i // he already changed the target, so, nothing to do here
BREAK
ENDIF
ENDIF
ENDWHILE
TERMINATE_THIS_CUSTOM_SCRIPT
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment