[NEW] The Basics Getting Started Scripting Examples - JayMontana36/LuaPlugin-GTAV GitHub Wiki
Example #1 (Very Basic And Barebones):
--[ Create a new co-routine or "thread" and define the function that will execute on tick/frame ](/JayMontana36/LuaPlugin-GTAV/wiki/-Create-a-new-co-routine-or-"thread"-and-define-the-function-that-will-execute-on-tick/frame-)
JM36.CreateThread(function()
--[ (Optionally) Localize the print function for faster access ](/JayMontana36/LuaPlugin-GTAV/wiki/-(Optionally)-Localize-the-print-function-for-faster-access-)
local print = print
--[ (Optionally) print something ](/JayMontana36/LuaPlugin-GTAV/wiki/-(Optionally)-print-something-)
print("Hello World! This will only run once.")
--[ (Optionally) Make sure that our script/module will continue to loop/run forever (instead of just once) with a `while true do` loop ](/JayMontana36/LuaPlugin-GTAV/wiki/-(Optionally)-Make-sure-that-our-script/module-will-continue-to-loop/run-forever-(instead-of-just-once)-with-a-`while-true-do`-loop-)
while true do
--[ (Optionally) print something ](/JayMontana36/LuaPlugin-GTAV/wiki/-(Optionally)-print-something-)
print("Hello World! This will run forever.")
--[[ (MANDATORY) Don't forget to wait/yield for the next tick/frame or x amount of ms
JM36.yield(nil or TimeToWaitInMS)
JM36.yield(5000) -- 5000ms or 5 seconds
JM36.yield() -- next tick/frame
]]
JM36.yield()
end
--[ (Optionally) print something, except this'll never run unless you `break` out of the `while true do` loop ](/JayMontana36/LuaPlugin-GTAV/wiki/-(Optionally)-print-something,-except-this'll-never-run-unless-you-`break`-out-of-the-`while-true-do`-loop-)
print("Hello World! This will run never.")
end)
The "Info" variable (1st argument sent to loop functions) and game native function call examples:
Structure/Layout:
{
Time --[ integer number ](/JayMontana36/LuaPlugin-GTAV/wiki/-integer-number-)
Player {
Id --[ Id/Handle ](/JayMontana36/LuaPlugin-GTAV/wiki/-Id/Handle-)
Ped --[ Ped/Entity Id/Handle ](/JayMontana36/LuaPlugin-GTAV/wiki/-Ped/Entity-Id/Handle-)
Coords --[ Vector3 ](/JayMontana36/LuaPlugin-GTAV/wiki/-Vector3-)
Vehicle {
IsIn --[ boolean - Is Player In The Vehicle ](/JayMontana36/LuaPlugin-GTAV/wiki/-boolean---Is-Player-In-The-Vehicle-)
IsOp --[ boolean - Is Player Operating The Vehicle ](/JayMontana36/LuaPlugin-GTAV/wiki/-boolean---Is-Player-Operating-The-Vehicle-)
Id --[ Vehicle/Entity Id/Handle ](/JayMontana36/LuaPlugin-GTAV/wiki/-Vehicle/Entity-Id/Handle-)
NetId --[ integer Network Id/Handle ](/JayMontana36/LuaPlugin-GTAV/wiki/-integer-Network-Id/Handle-)
Model --[ hash ](/JayMontana36/LuaPlugin-GTAV/wiki/-hash-)
Name --[ string ](/JayMontana36/LuaPlugin-GTAV/wiki/-string-)
Type {
Bicycle --[ boolean ](/JayMontana36/LuaPlugin-GTAV/wiki/-boolean-)
Bike --[ boolean ](/JayMontana36/LuaPlugin-GTAV/wiki/-boolean-)
Boat --[ boolean ](/JayMontana36/LuaPlugin-GTAV/wiki/-boolean-)
Car --[ boolean ](/JayMontana36/LuaPlugin-GTAV/wiki/-boolean-)
Heli --[ boolean ](/JayMontana36/LuaPlugin-GTAV/wiki/-boolean-)
Jetski --[ void - nothing ](/JayMontana36/LuaPlugin-GTAV/wiki/-void---nothing-)
Plane --[ boolean ](/JayMontana36/LuaPlugin-GTAV/wiki/-boolean-)
Quadbike --[ boolean ](/JayMontana36/LuaPlugin-GTAV/wiki/-boolean-)
Train --[ boolean ](/JayMontana36/LuaPlugin-GTAV/wiki/-boolean-)
AmphibiousCar --[ void - nothing ](/JayMontana36/LuaPlugin-GTAV/wiki/-void---nothing-)
AmphibiousQuadbike --[ void - nothing ](/JayMontana36/LuaPlugin-GTAV/wiki/-void---nothing-)
}
}
}
}
Usage Examples:
JM36.CreateThread(function()
--[ (Optionally) Localize the Info variable (and/or sub keys) for faster access ](/JayMontana36/LuaPlugin-GTAV/wiki/-(Optionally)-Localize-the-Info-variable-(and/or-sub-keys)-for-faster-access-)
local Info = Info
while true do
--[ Get the player's ped entity ID ](/JayMontana36/LuaPlugin-GTAV/wiki/-Get-the-player's-ped-entity-ID-)
local PlayerPed = Info.Player.Ped
--[ Remove invincibility from player's ped ](/JayMontana36/LuaPlugin-GTAV/wiki/-Remove-invincibility-from-player's-ped-)
SetEntityInvincible(PlayerPed, false)
--[ Check if the player is in a vehicle and if the player is the operator of a vehicle ](/JayMontana36/LuaPlugin-GTAV/wiki/-Check-if-the-player-is-in-a-vehicle-and-if-the-player-is-the-operator-of-a-vehicle-)
if Info.Player.Vehicle.IsIn and Info.Player.Vehicle.IsOp then
--[ Get the player's vehicle entity ID ](/JayMontana36/LuaPlugin-GTAV/wiki/-Get-the-player's-vehicle-entity-ID-)
local PlayerVeh = Info.Player.Vehicle.Id
--[ Change license plate text on the vehicle the player's ped is operating ](/JayMontana36/LuaPlugin-GTAV/wiki/-Change-license-plate-text-on-the-vehicle-the-player's-ped-is-operating-)
SetVehicleNumberPlateText(PlayerVeh, "0 HI 0")
end
--[ wait/yield for the next tick/frame ](/JayMontana36/LuaPlugin-GTAV/wiki/-wait/yield-for-the-next-tick/frame-)
JM36.yield()
end
end)