Jump to content

Zone events


justn

Recommended Posts

Hi,

I have some events which i think should be added, first I'll start with.

Zone events

onZoneEnter

The event is triggered when a player enters a zone

Parameters

zone theZone 

theZone: The zone that the player has entered

Source

The source of this event is the zone that the player has entered

Example

This would be the example which outputs chatbox when the player has entered the zone of "Los Santos"

addEventHandler("onZoneEnter",getRootElement(), 
function ( theZone ) 
if theZone == "Los Santos" then 
outputChatBox("A player has entered the zone of "..theZone) 
end 
end) 

&

onZoneExit

This event is triggered when a player exits a zone

Parameters

zone theZone 

theZone: The zone that the player has exited

Source

The source of this event is the zone that the player has exit

Example

This would be the example which outputs chatbox when the player has exits the zone of "Los Santos"

addEventHandler("onZoneExit",getRootElement(), 
function ( theZone ) 
if theZone == "Los Santos" then 
outputChatBox("A player has exited the zone of "..theZone) 
end 
end) 

Thanks, hoping that events would come soon.

  • Like 1
Link to comment

You can just add it to your server using Lua.

local playerData = { } 
  
setTimer ( function ( ) 
    local checkedPlayers = { } 
    for _, v in pairs ( getElementsByType ( "player" ) ) do 
        local x, y, z = getElementPosition ( v ) 
        local zone = getZoneName ( x, y, z ) 
        checkedPlayers[v] = true 
        if ( not playerData [ v ]  ) then 
            if x and y and z then 
                playerData [ v ] = zone 
            end 
        else 
         
            if ( zone ~= playerData [ v ] ) then 
                triggerEvent ( "onZoneChange", v, zone, playerData [ v ] ) 
                playerData [ v ] = zone 
            end 
             
        end 
    end 
     
    -- this is to remove the event from triggering if the player reconnects or something  
    for i, v in pairs ( playerData ) do 
        if ( not checkedPlayers [ i ] ) then 
            playerData [ i ] = nil 
        end 
    end 
end, 200, 0  ) 
  
  
  
-- exmaple 
addEvent ( "onZoneChange", true ) 
addEventHandler ( "onZoneChange", root, function ( new, old ) 
    outputChatBox ( getPlayerName ( source ).." went from "..old.." to "..new ) 
end ) 

Link to comment
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...