Skip to content

Commit

Permalink
Added events example
Browse files Browse the repository at this point in the history
Updated wrappers & call layouts
  • Loading branch information
Freeeaky committed May 17, 2015
1 parent aa0decb commit 67113a6
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 5 deletions.
48 changes: 48 additions & 0 deletions build/GTALua/addons/_example_05_events/main.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
--
-- Check out our the Wiki!
-- http://wiki.gtalua.com/index.php/Main_Page
-- http://wiki.gtalua.com/index.php/Getting_Started
-- http://wiki.gtalua.com/index.php/API
--
-- I recommend matching addon name & script thread name
example_events = ScriptThread("example_05_events")

-- OnPedCreated Handler
function example_events:EventHandler_PedCreated(ped_id)
-- Only touch the entity shortly later!
-- It might be instantly deleted again from a game script
timer.Simple(200, function()
-- Note: an ID is passed! not a Ped class
local ped = Ped(ped_id)

-- Always make sure that it exists
if not ped:Exists() then return end

-- Add Blip for them
ped:AttachBlip()
end)
end

-- OnVehicleCreated Handler
function example_events:EventHandler_VehicleCreated(vehicle_id)
timer.Simple(2000, function()
local vehicle = Vehicle(vehicle_id)
if not vehicle:Exists() then return end

-- Blip
vehicle:AttachBlip()

-- Neon Lights
vehicle:SetNeonLights(true, math.random(0,255), math.random(0,255), math.random(0,255))
end)
end

-- Run
function example_events:Run()
-- Add Handler
example_events:AddEventHandler("OnPedCreated", "EventHandler_PedCreated")
example_events:AddEventHandler("OnVehicleCreated", "EventHandler_VehicleCreated")
end

-- Register
example_events:Register()
9 changes: 9 additions & 0 deletions build/GTALua/internal/game/Ped.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@ function Ped:__init(id)
self._type = "Ped"
end

-- Delete
function Ped:Delete()
self:_CheckExists()
local c_handle = CMemoryBlock(4)
c_handle:WriteDWORD32(0, self.ID)
natives.PED.DELETE_PED(c_handle)
c_handle:Release()
end

-- Weapon Switching
function Ped:AllowWeaponSwitching(b)
self:_CheckExists()
Expand Down
31 changes: 29 additions & 2 deletions build/GTALua/internal/game/Vehicle.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ end
-- Delete
function Vehicle:Delete()
self:_CheckExists()
natives.VEHICLE.DELETE_VEHICLE(self.ID)
local c_handle = CMemoryBlock(4)
c_handle:WriteDWORD32(0, self.ID)
natives.VEHICLE.DELETE_VEHICLE(c_handle)
c_handle:Release()
end

-- Is vehicle stuck on roof (returns true/false)
Expand Down Expand Up @@ -75,7 +78,7 @@ function Vehicle:SetEngineState(b)
end

-- Checks whether the vehicle is on all wheels
function Vehicle:IsVehicleOnAllWheels()
function Vehicle:IsOnAllWheels()
self:_CheckExists()
return natives.VEHICLE.IS_VEHICLE_ON_ALL_WHEELS(self.ID)
end
Expand All @@ -84,4 +87,28 @@ end
function Vehicle:Fix()
self:_CheckExists()
natives.VEHICLE.SET_VEHICLE_FIXED(self.ID)
end

-- Neon Lights
function Vehicle:SetNeonLights(enabled, r, g, b, location)
self:_CheckExists()

-- on/off
if location == nil then
natives.VEHICLE.SET_VEHICLE_NEON_LIGHTS_ON(self.ID, 0, enabled)
natives.VEHICLE.SET_VEHICLE_NEON_LIGHTS_ON(self.ID, 1, enabled)
natives.VEHICLE.SET_VEHICLE_NEON_LIGHTS_ON(self.ID, 2, enabled)
natives.VEHICLE.SET_VEHICLE_NEON_LIGHTS_ON(self.ID, 3, enabled)
else
natives.VEHICLE.SET_VEHICLE_NEON_LIGHTS_ON(self.ID, location, enabled)
end

-- color
if r == nil then return end
if type(r) == "table" then
b = r.b
g = r.g
r = r.r
end
natives.VEHICLE.SET_VEHICLE_NEON_LIGHTS_COLOUR(self.ID, r, g, b)
end
6 changes: 3 additions & 3 deletions build/GTALua/native_call_layout.ini
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ _0x1A092BB0C3808B96=ab)v

[PED]
CREATE_PED=aaffffbb)a
DELETE_PED=a)v
DELETE_PED=m)v
CLONE_PED=abbb)a
_0xE952D6431689AD9A=aa)v
IS_PED_IN_VEHICLE=aab)b
Expand Down Expand Up @@ -597,7 +597,7 @@ SET_CAN_ATTACK_FRIENDLY=abb)v
GET_PED_ALERTNESS=a)a
SET_PED_ALERTNESS=aa)v
SET_PED_GET_OUT_UPSIDE_DOWN_VEHICLE=ab)v
SET_PED_MOVEMENT_CLIPSET=aaf)v
SET_PED_MOVEMENT_CLIPSET=asf)v
RESET_PED_MOVEMENT_CLIPSET=af)v
SET_PED_STRAFE_CLIPSET=aa)v
RESET_PED_STRAFE_CLIPSET=a)v
Expand Down Expand Up @@ -910,7 +910,7 @@ _0x288DF530C92DAD6F=af)v

[VEHICLE]
CREATE_VEHICLE=affffbb)a
DELETE_VEHICLE=a)v
DELETE_VEHICLE=m)v
_0x7D6F9A3EF26136A0=ab)v
_0x5D14D4154BFE7B2C=ab)v
_0xE6B0E8CFC3633BF0=a)a
Expand Down

0 comments on commit 67113a6

Please sign in to comment.