- Documentation
- Shared functions
- createPed
Function
createPed
Creates a new NPC ped on the server (a pedestrian driven by the game, not by a player) and shows it right away to every player nearby. The ped gets 100 health, a random appearance variant (clothes and skin tone, see setPedVariant) and belongs to the resource that created it, so it disappears together with that resource on stop. Optionally it can be made aggressive straight away or told to attack a chosen target.
Syntax
ped createPed(int model, float x, float y, float z [, float rot = 0, bool synced = true, bool aggressive = false, element target = nil])Arguments
modelint- GTA San Andreas ped model (skin) ID, e.g. 0 = CJ, 7 = man in a shirt, 280 = police officer. It must be a valid ped model (
isValidPedModel). Skin -1 (the outfit from the launcher) is for players only; for an NPC the function returnsfalse. xfloat- X coordinate of the spot where the ped will stand (in metres, game world space).
yfloat- Y coordinate of the spot.
zfloat- Z height. Use ground level or slightly above it; too low and the ped falls under the map.
rotfloat, optional = 0- Rotation of the ped around the vertical axis in degrees (the direction it faces). 0 = north.
syncedbool, optional = true- Accepted for compatibility with existing scripts and ignored: peds in Trilogy Hub are always synchronised between players.
aggressivebool, optional = falsetrue= the ped is aggressive: whoever hurts it gets attacked (same assetPedAggressive(ped, true)).Not in MTA:SAtargetelement, optional = nil- A player or another ped the NPC should attack right away (same as
setPedAttackTarget).Not in MTA:SA
Differences from MTA:SA
- Arguments in a different colour differ from MTA:SA.
In MTA:SA
createPed(int modelid, float x, float y, float z, float rot = 0.0, bool synced = true)Returns
The created ped, or false when the model is invalid.
Example
local guard = createPed(280, 1544.5, -1675.2, 13.56, 90)
setPedAggressive(guard, true)
setElementData(guard, "nazwa", "Ochroniarz")
See also
destroyElementDestroys an element together with its children. On the client it also destroys GUI elements.setPedVariantSets a pedestrian's appearance variant: the set of clothes and the skin tone. Every ped model in the Definitive Edition has 4 clothing variants (0-3) and 4 skin variants (0-3); the change is visible to every player. An omitted argument is randomised, which is whycreatePedgives each NPC a random look. Works for NPCs and for players using a ped skin.setPedAggressiveTurns an NPC's aggression on or off. When an aggressive NPC gets hurt by someone (a player or another ped), it starts attacking the attacker on its own, as if a script calledsetPedAttackTarget. A non-aggressive NPC (the default) takes damage and does not react. Works only for NPCs (ped), not for players.setPedAttackTargetMakes an NPC attack a player or another ped: the NPC walks up and punches or shoots with the weapon in its hand until the target dies, disappears or a script stops the fight. The fight is simulated by one player's game (the target player or the nearest player in the same dimension), so the NPC behaves the same for everyone. Passingnilorfalseends the fight. The fight also ends by itself when the target dies, leaves the server or is destroyed.isValidPedModelChecks whether a model number is a real ped model that can be used increatePed,setElementModelorspawnPlayer. It accepts the game's models (0-311 except empty numbers) and new peds added withengineRequestModel. Call it before applying a skin a player typed into a command.