ServersYour serverFor creatorsForumFAQDocumentationSecurity
Download the launcher
  1. Documentation
  2. Shared functions
  3. createPed

Function

createPed

Server and clientPedsModified from MTA:SA

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 returns false.
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 = false
true = the ped is aggressive: whoever hurts it gets attacked (same as setPedAggressive(ped, true)).Not in MTA:SA
targetelement, 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