NPC functions - WoutProvost/FCNPC-AI GitHub Wiki
Home ▸ Functions ▸ NPC functions
(name[])
FAI_Create
- Description: Creates an NPC.
- Parameters:
name[]
: The playername the NPC should have. See SetPlayerName for any restrictions.- Return values:
Valid npcid
: The function executed successfully.INVALID_PLAYER_ID
: The function failed to execute. FCNPC_Create failed.- Notes: The other settings have the following default values:
fullName[]
:""
, which is an empty string. See FAI_SetFullName.iconid
: INVALID_ICON_ID. See FAI_SetMapiconInfo.iconMarker
: 23 which is the Skull/Loco markerid. See FAI_SetMapiconInfo.iconColor
: 0xff0000ff. See FAI_SetMapiconInfo.iconStyle
: MAPICON_LOCAL. See FAI_SetMapiconInfo.Float:maxHealth
: 100.0. See FAI_SetMaxHealth.Float:rangeDisplay
: 0.0. See FAI_SetDisplayRange.Float:rangeAggro
: 20.0. See FAI_SetAggroRange.bool:displayIfDead
: true. See FAI_SetDisplayIfDead.Float:currentHealth
: -1.0. See FAI_SetCurrentHealth false.targetid
: INVALID_PLAYER_ID. See FAI_SetTarget false.moveType
: FCNPC_MOVE_TYPE_AUTO. See FAI_SetMoveInfo.Float:moveSpeed
: FCNPC_MOVE_SPEED_AUTO. See FAI_SetMoveInfo.bool:moveUseMapAndreas
: false. See FAI_SetMoveInfo.Float:moveRadius
: 0.0. See FAI_SetMoveInfo.bool:moveSetAngle
: true. See FAI_SetMoveInfo.Float:rangedAttackRange
: 20.0. See FAI_SetRangedAttackInfo.rangedAttackDelay
: -1. See FAI_SetRangedAttackInfo.bool:rangedAttackSetAngle
: true. See FAI_SetRangedAttackInfo.Float:meleeAttackRange
: 1.0. See FAI_SetMeleeAttackInfo.meleeAttackDelay
: -1. See FAI_SetMeleeAttackInfo.bool:meleeAttackUseFightStyle
: false. See FAI_SetMeleeAttackInfo.bool:allowNPCTargets
: true. See FAI_SetAllowNPCTargets false.behaviour
: FAI_BEHAVIOUR_NEUTRAL. See FAI_SetBehaviour false.
(npcid, name[], len)
FAI_GetFullName
- Description: Get an NPC's fullName.
- Parameters:
npcid
: The ID of the NPC to get the fullName of.name[]
: An array into which to store the fullName, passed by reference.len
: The length of the string that should be stored. Recommended to be FAI_MAX_FULL_NAME.- Return values:
FullName length
: The function executed successfully.-1
: The function failed to execute. An invalid npcid was given.
(npcid, name[])
FAI_SetFullName
- Description: Set an NPC's fullName which is displayed in TextDraw 3.
- Parameters:
npcid
: The ID of the NPC to set the fullName of.name[]
: The name to set. Max length is FAI_MAX_FULL_NAME. If""
(an empty string) is given, this will be set to be the same as the playername.- Return values:
1
: The function executed successfully.0
: The function failed to execute. An invalid npcid was given.
(npcid, &iconid, &iconMarker, &iconColor, &iconStyle)
FAI_GetMapiconInfo
- Description: Get an NPC's iconid, iconMarker, iconColor and iconStyle.
- Parameters:
npcid
: The ID of the NPC to get the mapiconInfo of.&iconid
: The variable into which to store the iconid, passed by reference.&iconMarker
: The variable into which to store the iconMarker, passed by reference.&iconColor
: The variable into which to store the iconColor, passed by reference.&iconStyle
: The variable into which to store the iconStyle, passed by reference.- Return values:
1
: The function executed successfully.0
: The function failed to execute. An invalid npcid was given.
(npcid, iconid, iconMarker, iconColor, iconStyle)
FAI_SetMapiconInfo
- Description: Set an NPC's iconid, iconMarker, iconColor and iconStyle which will display on the map at the NPCs position. See SetPlayerMapIcon. If INVALID_ICON_ID is used, no mapicon will display and the other values will be ignored.
- Parameters:
npcid
: The ID of the NPC to set the mapiconInfo of.iconid
: The iconid to set. Defaults to INVALID_ICON_ID.iconMarker
: The iconMarker to set. Defaults to 23 which is the Skull/Loco markerid.iconColor
: The iconColor to set. Defaults to 0xff0000ff.iconStyle
: The iconStyle to set. Defaults to MAPICON_LOCAL.- Return values:
1
: The function executed successfully.0
: The function failed to execute. An invalid npcid was given.
(npcid, &Float:health)
FAI_GetMaxHealth
- Description: Get an NPC's maxHealth.
- Parameters:
npcid
: The ID of the NPC to get the maxHealth of.&Float:health
: The variable into which to store the maxHealth, passed by reference.- Return values:
1
: The function executed successfully.0
: The function failed to execute. An invalid npcid was given.
(npcid, Float:health)
FAI_SetMaxHealth
- Description: Set an NPC's maxHealth.
- Parameters:
npcid
: The ID of the NPC to set the maxHealth of.Float:health
: The maxHealth to set. If a value < 0.0 was given, it will be reset to 0.0. If the value is 0.0, the NPC will die immediately.- Return values:
1
: The function executed successfully.0
: The function failed to execute. An invalid npcid was given.- Notes: When using very large values like >= 2 billion, bugs can occur due to overflow.
(npcid, &Float:range)
FAI_GetDisplayRange
- Description: Get an NPC's displayRange.
- Parameters:
npcid
: The ID of the NPC to get the displayRange of.&Float:range
: The variable into which to store the displayRange, passed by reference.- Return values:
1
: The function executed successfully.0
: The function failed to execute. An invalid npcid was given.
(npcid, Float:range)
FAI_SetDisplayRange
- Description: Set the range at which the NPC's TextDraws should appear for a player.
- Parameters:
npcid
: The ID of the NPC to set the displayRange of.Float:range
: The displayRange to set. If a value < 0.0 was given, it will be reset to 0.0. If the value is 0.0, the NPC's TextDraws will never show.- Return values:
1
: The function executed successfully.0
: The function failed to execute. An invalid npcid was given.- Notes:
- The NPC's textdraws will show for a player if the NPC is valid for that player.
- If the player is in the displayRange of more than 1 NPC, only the closest NPC will show for that player.
- All NPC/spell textdraws are hidden for a player if that player dies.
- If you don't want to show an NPC's textdraws at all, set that NPC's displayRange to 0.0.
(npcid, &Float:range)
FAI_GetAggroRange
- Description: Get an NPC's aggroRange.
- Parameters:
npcid
: The ID of the NPC to get the aggroRange of.&Float:range
: The variable into which to store the aggroRange, passed by reference.- Return values:
1
: The function executed successfully.0
: The function failed to execute. An invalid npcid was given.
(npcid, Float:range)
FAI_SetAggroRange
- Description: Set the range at which a player aggros the NPC.
- Parameters:
npcid
: The ID of the NPC to set the aggroRange of.Float:range
: The aggroRange to set. If a value < 0.0 was given, it will be reset to 0.0. If the value is 0.0, no player will take aggro from the NPC by approaching him.- Return values:
1
: The function executed successfully.0
: The function failed to execute. An invalid npcid was given.- Notes:
(npcid)
FAI_GetDisplayIfDead
- Description: Get an NPC's displayIfDead.
- Parameters:
npcid
: The ID of the NPC to get the displayIfDead of.- Return values:
1
: The function executed successfully. DisplayIfDead is true.0
: The function executed successfully. DisplayIfDead is false.-1
: The function failed to execute. An invalid npcid was given.
(npcid, bool:displayIfDead)
FAI_SetDisplayIfDead
- Description: Set wether the NPC's TextDraws and mapicon should keep being shown to players when the NPC is dead.
- Parameters:
npcid
: The ID of the NPC to set the displayIfDead of.bool:displayIfDead
: True to keep displaying the TextDraws, false to do not.- Return values:
1
: The function executed successfully.0
: The function failed to execute. An invalid npcid was given.- Notes: Setting this option to true has no effect if the NPC's displayRange is 0.
(npcid, &Float:health)
FAI_GetCurrentHealth
- Description: Get an NPC's currentHealth.
- Parameters:
npcid
: The ID of the NPC to get the currentHealth of.&Float:health
: The variable into which to store the currentHealth, passed by reference.- Return values:
1
: The function executed successfully.0
: The function failed to execute. An invalid npcid was given.
(npcid, Float:health)
FAI_SetCurrentHealth
- Description: Set an NPC's currentHealth which is displayed in TextDraw 2 and represented by the TextDraw 0 health bar.
- Parameters:
npcid
: The ID of the NPC to set the currentHealth of.Float:health
: The currentHealth to set. If a value < 0.0 was given, it will be reset to the NPC's maxHealth. If the value is 0.0, the NPC will die immediately.- Return values:
1
: The function executed successfully.0
: The function failed to execute. An invalid npcid was given.- Notes: When using very large values like >= 2 billion, bugs can occur due to overflow.
(npcid)
FAI_GetTarget
- Description: Get an NPC's target.
- Parameters:
npcid
: The ID of the NPC to get the target of.- Return values:
Valid playerid
: The function executed successfully. The NPC has a target.INVALID_PLAYER_ID
: The function executed successfully. The NPC has no target.-1
: The function failed to execute. An invalid npcid was given.
(npcid, playerid)
FAI_SetTarget
- Description: Set NPC's target which he will move to and attack.
- Parameters:
npcid
: The ID of the NPC to set the target of.playerid
: The target to set. Can be INVALID_PLAYER_ID.- Return values:
1
: The function executed successfully.0
: The function failed to execute. An invalid npcid was given, or old target was equal to the new target, or the player was invalid for the NPC, or the player was not streamed in for the NPC.
(npcid, &type, &Float:speed, &bool:useMapAndreas, &Float:radius, &bool:setAngle)
FAI_GetMoveInfo
- Description: Get an NPC's moveType, moveSpeed, moveUseMapAndreas, moveRadius and moveSetAngle.
- Parameters:
npcid
: The ID of the NPC to get the moveInfo of.&type
: The variable into which to store the moveType, passed by reference.&Float:speed
: The variable into which to store the moveSpeed, passed by reference.&bool:useMapAndreas
: The variable into which to store the moveUseMapAndreas, passed by reference.&Float:radius
: The variable into which to store the moveRadius, passed by reference.&bool:setAngle
: The variable into which to store the moveSetAngle, passed by reference.- Return values:
1
: The function executed successfully.0
: The function failed to execute. An invalid npcid was given.
(npcid, type, Float:speed, bool:useMapAndreas, Float:radius, bool:setAngle)
FAI_SetMoveInfo
- Description: Set an NPC's moveType, moveSpeed, moveUseMapAndreas, moveRadius and moveSetAngle which will determine his movement settings. See FCNPC_GoToPlayer.
- Parameters:
npcid
: The ID of the NPC to set the moveInfo of.type
: The moveType to set. Defaults to FCNPC_MOVE_TYPE_AUTO.Float:speed
: The moveSpeed to set. Defaults to FCNPC_MOVE_SPEED_AUTO.bool:useMapAndreas
: The moveUseMapAndreas to set. Defaults to false.Float:radius
: The moveRadius to set. Defaults to 0.0.bool:setAngle
: The moveSetAngle to set. Defaults to true.- Return values:
1
: The function executed successfully.0
: The function failed to execute. An invalid npcid was given.- Notes: If
useMapAndreas
is true, MapAndreas must be initialized with MapAndreas_Init and the plugin address must be passed to FCNPC with FCNPC_InitMapAndreas to take effect.
(npcid, &Float:range, &delay, &bool:setAngle)
FAI_GetRangedAttackInfo
- Description: Get an NPC's rangedAttackRange, rangedAttackDelay and rangedAttackSetAngle.
- Parameters:
npcid
: The ID of the NPC to get the rangedAttackInfo of.&Float:range
: The variable into which to store the rangedAttackRange, passed by reference.&delay
: The variable into which to store the rangedAttackDelay, passed by reference.&bool:setAngle
: The variable into which to store the rangedAttackSetAngle, passed by reference.- Return values:
1
: The function executed successfully.0
: The function failed to execute. An invalid npcid was given.
(npcid, Float:range, delay, bool:setAngle)
FAI_SetRangedAttackInfo
- Description: Set an NPC's rangedAttackRange, rangedAttackDelay and rangedAttackSetAngle which will determine his ranged attack settings. See FCNPC_AimAtPlayer.
- Parameters:
npcid
: The ID of the NPC to set the rangedAttackInfo of.Float:range
: The rangedAttackRange to set. Defaults to 20.0. If the value is -1, the NPC will never move while ranged attacking and will thus ranged attack from any distance.delay
: The rangedAttackDelay to set. Defaults to -1.bool:setAngle
: The rangedAttackSetAngle to set. Defaults to true.- Return values:
1
: The function executed successfully.0
: The function failed to execute. An invalid npcid was given.- Notes: The rangedAttackRange is different from the aggro range.
(npcid, &Float:range, &delay, &bool:useFightStyle)
FAI_GetMeleeAttackInfo
- Description: Get an NPC's meleeAttackRange, meleeAttackDelay and useFightStyle.
- Parameters:
npcid
: The ID of the NPC to get the meleeAttackInfo of.&Float:range
: The variable into which to store the meleeAttackRange, passed by reference.&delay
: The variable into which to store the meleeAttackDelay, passed by reference.&bool:useFightStyle
: The variable into which to store the useFightStyle, passed by reference.- Return values:
1
: The function executed successfully.0
: The function failed to execute. An invalid npcid was given.
(npcid, Float:range, delay, bool:useFightStyle)
FAI_SetMeleeAttackInfo
- Description: Set an NPC's meleeAttackRange, meleeAttackDelay and useFightStyle which will determine his melee attack settings. See FCNPC_MeleeAttack.
- Parameters:
npcid
: The ID of the NPC to set the meleeAttackInfo of.Float:range
: The meleeAttackRange to set. Defaults to 1.0. If the value is -1, the NPC will never move while melee attacking and will thus melee attack from any distance.delay
: The meleeAttackDelay to set. Defaults to -1.bool:useFightStyle
: The useFightStyle to set. Defaults to false.- Return values:
1
: The function executed successfully.0
: The function failed to execute. An invalid npcid was given.- Notes:
- If the NPC should attack with the equipped melee weapon instead of with his fists, set
useFightStyle
to false. If the NPC should attack with his fists, regardless if he has a melee weapon equipped, setuseFightStyle
to true.- The meleeAttackRange is different from the aggro range.
(npcid)
FAI_GetAllowNPCTargets
- Description: Get an NPC's allowNPCTargets.
- Parameters:
npcid
: The ID of the NPC to get the allowNPCTargets of.- Return values:
1
: The function executed successfully. AllowNPCTargets is true.0
: The function executed successfully. AllowNPCTargets is false.-1
: The function failed to execute. An invalid npcid was given.
(npcid, bool:allowNPCTargets)
FAI_SetAllowNPCTargets
- Description: Set wether the NPC can target NPC's.
- Parameters:
npcid
: The ID of the NPC to set the allowNPCTargets of.bool:allowNPCTargets
: True to allow NPC targets, false to do not.- Return values:
1
: The function executed successfully.0
: The function failed to execute. An invalid npcid was given.
(npcid)
FAI_GetBehaviour
- Description: Get an NPC's behaviour.
- Parameters:
npcid
: The ID of the NPC to get the behaviour of.- Return values:
Valid behaviour
: The function executed successfully.-1
: The function failed to execute. An invalid npcid was given.
(npcid, behaviour)
FAI_SetBehaviour
- Description: Set wether the NPC will attack on sight, on damage or not at all.
- Parameters:
npcid
: The ID of the NPC to set the behaviour of.behaviour
: The behaviour to set.- Return values:
1
: The function executed successfully.0
: The function failed to execute. An invalid npcid was given, or an invalid behaviour was given.
(npcid)
FAI_DestroyNPC
- Description: Destroys an NPC that was created using one of the FAI_Create functions.
- Parameters:
npcid
: The ID of the NPC to destroy.- Return values:
1
: The function executed successfully.0
: The function failed to execute. An invalid npcid was given.
()
FAI_DestroyAll
- Description: Destroys all NPCs that were created using one of the FAI_Create functions. This function gets executed automatically when OnFilterScriptExit is called, if the include is included in a filterscript, or when OnGameModeExit is called, if the include is included in a gamemode.
- Parameters: This function has no parameters.
- Return values: This function always returns 1.
(playerid, npcid)
FAI_IsValidForPlayer
- Description: Checks if a player is valid for an NPC.
- Parameters:
playerid
: The ID of the player to check if he is valid for the NPC.npcid
: The ID of the NPC to check the player for.- Return values: (bool)
true
: The player is connected, the NPC is valid, the player is not equal to the NPC's npcid, (the NPC is not dead or the NPC's displayIfDead is true), (the player is no npc and his interior equals the NPC's interior and his world equals the NPC's world and his state is not equal to PLAYER_STATE_NONE and his state is not equal to PLAYER_STATE_WASTED and his state is not equal to PLAYER_STATE_SPAWNED and his state is not equal to PLAYER_STATE_SPECTATING and he hasn't got his game paused) or (the player is an npc created with FCNPC and he is valid and he is spawned and he is not dead and his interior equals the NPC's interior and his world equals the NPC's world).false
: The player is not valid for the NPC.
(playerid, npcid)
FAI_IsPlayerInDisplayRange
- Description: Checks if a player is in the displayRange of an NPC.
- Parameters:
playerid
: The ID of the player to check.npcid
: The ID of the NPC to check.- Return values: (bool)
true
: The player is in the displayRange.false
: The player is not in the displayRange, or the player is not connected or the NPC is not valid or the player is not valid for the NPC.
(playerid, npcid)
FAI_IsPlayerInAggroRange
- Description: Checks if a player is in the aggroRange of an NPC.
- Parameters:
playerid
: The ID of the player to check.npcid
: The ID of the NPC to check.- Return values: (bool)
true
: The player is in the aggroRange .false
: The player is not in the aggroRange , or the player is not connected or the NPC is not valid or the player is not valid for the NPC.
(npcid)
FAI_HasMeleeWeapons
- Description: Checks if an NPC currently has a melee weapon equipped.
- Parameters:
npcid
: The ID of the NPC to check.- Return values: (bool)
true
: The NPC has a melee weapon equipped.false
: The NPC has no melee weapon equipped. Or an invalid npcid was given.
(npcid, textdraw)
FAI_GetTextDraw
- Description: Get one of an NPC's TextDraw IDs.
- Parameters:
npcid
: The ID of the NPC to get the TextDraw of.textdraw
: The TextDraw of the NPC.- Return values: (Text)
Text:Valid TextDraw
: The function executed successfully.Text:INVALID_TEXT_DRAW
: The function failed to execute. An invalid npcid was given, or a textdraw < 0 was given, or a textdraw > = FAI_MAX_TEXTDRAWS was given.
(npcid)
FAI_GetCurrentHealthPercent
- Description: Get an NPC's currentHealthPercent which is displayed in TextDraw 1. This will be different from just using
currentHealth / maxHealth * 100
, becausefloatround_ceil
is used for various reasons.- Parameters:
npcid
: The ID of the NPC to get the currentHealthPercent of.- Return values:
Valid percent
: The function executed successfully.-1
: The function failed to execute. An invalid npcid was given.
(npcid, damagerid, Float:amount)
FAI_Damage
- Description: Damage an NPC.
- Parameters:
npcid
: The ID of the NPC to damage.damagerid
: The ID of the player that gets credit for the damage. Can be INVALID_PLAYER_ID.Float:amount
: The amount of damage to be afflicted.- Return values:
1
: The NPC died because of the damage.0
: The NPC didn't die, or the NPC is not valid, or the damagerid is not connected, or the NPC is already dead, or the players's interior doesn't equal the NPC's interior.- Notes: Internally, there will be checked if the NPC's interior is equal to the players's interior, because the NPC is visible and thus damagable in other interiors.
(npcid, healerid, Float:amount)
FAI_Heal
- Description: Heal an NPC.
- Parameters:
npcid
: The ID of the NPC to heal.healerid
: The ID of the player that gets credit for the healing. Can be INVALID_PLAYER_ID.Float:amount
: The amount of healing to be afflicted.- Return values:
1
: The NPC healed fully because of the healing.0
: The NPC didn't heal fully, or the NPC is not valid, or the healerid is not connected, or the NPC is dead.
(npcid)
FAI_IsEncounterStarted
- Description: Checks if an NPC encounter is started.
- Parameters:
npcid
: The ID of the NPC to check the encounter state of.- Return values: (bool)
true
: The NPC's encounter has started.false
: The NPC's encounter has not been started. Or an invalid npcid was given.
(npcid)
FAI_StopEncounter
- Description: Stop an encounter of an NPC.
- Parameters:
npcid
: The ID of the NPC to stop the encounter of.- Return values:
1
: The function executed successfully, regardless if the NPC's encounter was started or not.0
: An invalid npcid was given.