Skip to content

Commit 8d21327

Browse files
Automatic scraping of event examples! None is missing an example now.
1 parent e72cbd2 commit 8d21327

File tree

480 files changed

+3649
-31
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

480 files changed

+3649
-31
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
addEventHandler('onAccountCreate', root, function(acc)
2+
local accName = getAccountName(acc)
3+
local accType = getAccountType(acc) or ''
4+
iprint('Registered a new '..accType..' account: '..accName)
5+
end)
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
function preventLevelChange(account, key, value)
2+
if (key == "level") then
3+
cancelEvent()
4+
end
5+
end
6+
addEventHandler("onAccountDataChange", root, preventLevelChange)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
function preventLevelChange(account, key, value)
2+
if (wasEventCancelled()) then return end -- If the data change was aborted don't log it.
3+
outputServerLog(getAccountName(account) .. " key: " .. key .. " changed to: " .. tostring(value))
4+
end
5+
addEventHandler("onAccountDataChange", root, preventLevelChange)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
addEventHandler('onAccountRemove', root, function(acc)
2+
local accName = getAccountName(acc)
3+
local accType = getAccountType(acc) or 'Unknown'
4+
iprint('An account has been removed! Type: '..accType..', name: '..accName)
5+
end)

events/Account/onAccountCreate.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,8 @@ parameters:
1010
- name: theAccount
1111
type: account
1212
description: An account element that was created
13+
examples:
14+
- path: examples/onAccountCreate-1.lua
15+
description: This example prints a message every time new account is created.
16+
side: server
1317
canceling: This event cannot be canceled.

events/Account/onAccountDataChange.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,11 @@ parameters:
1616
- name: theValue
1717
type: string
1818
description: the value it is changing to.
19+
examples:
20+
- path: examples/onAccountDataChange-1.lua
21+
description: This examples prevents the key of "level" being added or changed on
22+
every account.
23+
side: server
24+
- path: examples/onAccountDataChange-2.lua
25+
description: This examples logs every single account data change to server log.
26+
side: server

events/Account/onAccountRemove.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,8 @@ parameters:
1010
- name: theAccount
1111
type: account
1212
description: An account element that was removed
13+
examples:
14+
- path: examples/onAccountRemove-1.lua
15+
description: This example prints a message every time new account is created.
16+
side: server
1317
canceling: This event cannot be canceled.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
addEventHandler("onClientBrowserCreated", resourceRoot,
2+
function ()
3+
-- when the browser is loaded
4+
loadBrowserURL(source, "http://mtasa.com") -- load MTA:SA site
5+
end)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
TODO
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
addEventHandler ( "onClientBrowserDocumentReady" , root ,
2+
function ( url )
3+
outputChatBox ( "The page '" .. url .. "' has been successfully loaded.")
4+
end
5+
)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
addEventHandler("onClientBrowserLoadingFailed", root,
2+
function(url, errorCode, errorDescription)
3+
outputChatBox("This webpage is not available" .. url .. "Unknown" .. errorCode .. "Unknown" .. errorDescription)
4+
end
5+
)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
local browser = guiCreateBrowser(0, 0, 800, 600, false, false, false)
2+
local theBrowser = guiGetBrowser(browser)
3+
showCursor(true)
4+
5+
6+
addEventHandler("onClientBrowserLoadingStart", theBrowser, function(url, isMainFrame)
7+
if (isMainFrame) then
8+
outputChatBox("Loading "..url.." in the main frame...")
9+
else
10+
outputChatBox("Loading "..url.." in a iframe...")
11+
end
12+
end)
13+
14+
addEventHandler("onClientBrowserCreated", theBrowser, function()
15+
loadBrowserURL(source, "https://www.w3schools.com/html/html_iframe.asp")
16+
end)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
-- TODO
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
TODO
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
local browser = guiCreateBrowser(0, 0, 800, 600, false, false, false)
2+
local theBrowser = guiGetBrowser(browser)
3+
showCursor(true)
4+
5+
addEventHandler("onClientBrowserCreated", theBrowser, function()
6+
loadBrowserURL(source, "https://www.multitheftauto.com/")
7+
end)
8+
9+
local lastBrowser = nil
10+
addEventHandler("onClientBrowserResourceBlocked", theBrowser, function(url, domain, reason)
11+
if (reason == 0) then
12+
13+
lastBrowser = source
14+
requestBrowserDomains({domain}, false, function(accepted, newDomains)
15+
if (accepted == true) then
16+
reloadBrowserPage(lastBrowser)
17+
end
18+
lastBrowser = nil
19+
end)
20+
21+
end
22+
end)
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
function resourceBlocked(url,domain,reason)
2+
if reason == 0 then
3+
requestBrowserDomains({domain})
4+
end
5+
end
6+
addEventHandler("onClientBrowserResourceBlocked",browserElement,resourceBlocked)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
local browser = guiCreateBrowser(0, 0, 800, 600, false, false, false)
2+
local theBrowser = guiGetBrowser(browser)
3+
showCursor(true)
4+
5+
6+
addEventHandler( "onClientBrowserCreated", theBrowser, function()
7+
loadBrowserURL(source, "https://www.google.com/?ncr&hl=en")
8+
end)
9+
10+
addEventHandler("onClientBrowserTooltip", root, function(text)
11+
if (text ~= "") then
12+
outputChatBox("Tooltip-Text: "..text)
13+
else
14+
outputChatBox("You are not longer hovering a tooltip")
15+
end
16+
end)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
requestBrowserDomains({ "mtasa.com" }) -- request browser domain
2+
showCursor(true) -- show cursor
3+
addEventHandler("onClientBrowserWhitelistChange", root,
4+
function(newDomains)
5+
if newDomains[1] == "mtasa.com" then
6+
local browser = createBrowser(1280, 720, false, false) -- create browser
7+
loadBrowserURL(browser, "http://mtasa.com/") -- load browser url
8+
end
9+
end
10+
)

events/Browser/onClientBrowserCreated.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,7 @@ description: This event is triggered when the CEF browser instance has been crea
99
"CreateBrowser") or [guiCreateBrowser](/wiki/GuiCreateBrowser "GuiCreateBrowser")),
1010
this event will be the convenient place.
1111
parameters: []
12+
examples:
13+
- path: examples/onClientBrowserCreated-1.lua
14+
description: ''
15+
side: client

events/Browser/onClientBrowserCursorChange.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,7 @@ parameters:
1010
- name: cursorId
1111
type: int
1212
description: The new cursor ID. See Cursor IDs.
13+
examples:
14+
- path: examples/onClientBrowserCursorChange-1.lua
15+
description: ''
16+
side: client

events/Browser/onClientBrowserDocumentReady.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,7 @@ parameters:
99
- name: url
1010
type: string
1111
description: the url of the web page loaded.
12+
examples:
13+
- path: examples/onClientBrowserDocumentReady-1.lua
14+
description: ''
15+
side: client

events/Browser/onClientBrowserInputFocusChanged.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ parameters:
99
- name: gainedFocus
1010
type: bool
1111
description: true if an input field has been focused, false if it has lost focus.
12+
examples: []

events/Browser/onClientBrowserLoadingFailed.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,7 @@ parameters:
1515
- name: errorDescription
1616
type: string
1717
description: a short description.
18+
examples:
19+
- path: examples/onClientBrowserLoadingFailed-1.lua
20+
description: ''
21+
side: client

events/Browser/onClientBrowserLoadingStart.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,7 @@ parameters:
1515
description: 'a boolean representing whether the entire page (main frame) was loaded
1616
or an <iframe> inside the page was loaded. true: If the URL is loaded in the main
1717
frame. false: If the URL is loaded in a <iframe>.'
18+
examples:
19+
- path: examples/onClientBrowserLoadingStart-1.lua
20+
description: ''
21+
side: client

events/Browser/onClientBrowserNavigate.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,7 @@ parameters:
1818
type: bool
1919
description: a boolean representing whether the entire page (main frame) was loaded
2020
or an <iframe> inside the page was loaded.
21+
examples:
22+
- path: examples/onClientBrowserNavigate-1.lua
23+
description: ''
24+
side: client

events/Browser/onClientBrowserPopup.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,7 @@ parameters:
1515
- name: isPopup
1616
type: bool
1717
description: ''
18+
examples:
19+
- path: examples/onClientBrowserPopup-1.lua
20+
description: ''
21+
side: client

events/Browser/onClientBrowserResourceBlocked.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,16 @@ parameters:
2222
1: blacklisted
2323
2424
2: blocked protocol scheme'
25+
examples:
26+
- path: examples/onClientBrowserResourceBlocked-1.lua
27+
description: This example asks the user to accept a blocked resource and reloads
28+
the browser if accepted.
29+
side: client
30+
- path: examples/onClientBrowserResourceBlocked-2.lua
31+
description: 'This example sends whitelist requests on demand, which means whenever
32+
a blocked domain is detected/queried by the user.
33+
34+
It''s also a good alternative to requesting CEF domains on server join, because
35+
this is less intrusive and requests will only be sent as soon the player starts
36+
interacting with a browser script.'
37+
side: client

events/Browser/onClientBrowserTooltip.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,8 @@ parameters:
1010
type: string
1111
description: string containing the tooltip text. Empty string if user is not longer
1212
hovering.
13+
examples:
14+
- path: examples/onClientBrowserTooltip-1.lua
15+
description: 'If the user hovers the Google search input field ''Tooltip-Text: Search''
16+
will be printed in the chatbox.'
17+
side: client

events/Browser/onClientBrowserWhitelistChange.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,7 @@ parameters:
1010
- name: changedDomains
1111
type: table
1212
description: a table of changed domains.
13+
examples:
14+
- path: examples/onClientBrowserWhitelistChange-1.lua
15+
description: ''
16+
side: client
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
function input_Console ( text ) --when a player types in the console
2+
-- if it's an ingame player,
3+
if ( getElementType ( source ) == "player" ) then
4+
--split the command by spaces (ASCII 32) and get the first piece of text
5+
local command = gettok ( text, 1, 32 )
6+
--if the first piece of text was "yo",
7+
if ( command == "yo" ) then
8+
--get the player's name
9+
local playerName = getPlayerName ( source )
10+
-- get the action text by substracting the first three characters ("yo ")
11+
local actionText = string.sub ( text, 3 )
12+
-- announce the yo command into the chatbox
13+
outputChatBox ( "* " .. playerName .. " " .. actionText, getRootElement(), 255, 255, 0 )
14+
end
15+
end
16+
end
17+
addEventHandler ( "onConsole", getRootElement(), input_Console ) -- add an event handler for onConsole

events/Client/onConsole.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,7 @@ parameters:
1111
- name: theMessage
1212
type: string
1313
description: a string representing the message entered into the console.
14+
examples:
15+
- path: examples/onConsole-1.lua
16+
description: ''
17+
side: server
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
function onClientColShapeHit( theElement, matchingDimension )
2+
if ( theElement == localPlayer ) then -- Checks whether the entering element is the local player
3+
outputChatBox( "In." ) --Outputs.
4+
end
5+
end
6+
addEventHandler("onClientColShapeHit", root, onClientColShapeHit)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
myZone = createColSphere (2490, -1668, 12.5, 25) -- Creates a collision sphere.
2+
3+
function dimensionChecker (theElement, matchingDimension)
4+
if matchingDimension then -- Checks whether the entering element is in the same dimension as the collision shape.
5+
outputChatBox ("The element is in the same dimension.")
6+
else
7+
outputChatBox ("The element is not in the same dimension.")
8+
end
9+
end
10+
addEventHandler ("onClientColShapeHit", myZone, dimensionChecker)
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
function onClientColShapeLeave( theElement, matchingDimension )
2+
if ( theElement == localPlayer ) then -- Checks whether the leaving element is the local player
3+
outputChatBox( "Out." ) --Outputs.
4+
end
5+
end
6+
addEventHandler("onClientColShapeLeave", root, onClientColShapeLeave)
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
-- create our hill area for our gamemode
2+
local hillArea = createColRectangle ( -2171.0678710938, 678.17950439453, 15, 15 )
3+
4+
-- add hill_Enter as a handler for when a player enters the hill area
5+
function hill_Enter ( thePlayer, matchingDimension )
6+
if getElementType ( thePlayer ) == "player" then --if the element that entered was player
7+
--let's get the name of the player
8+
local nameOfThePlayer = getPlayerName ( thePlayer )
9+
--announce to everyone that the player entered the hill
10+
outputChatBox ( nameOfThePlayer.." entered the zone!", root, 255, 255, 109 )
11+
end
12+
end
13+
addEventHandler ( "onColShapeHit", hillArea, hill_Enter )
14+
15+
-- add hill_Enter as a handler for when a player leaves the hill area
16+
function hill_Exit ( thePlayer, matchingDimension )
17+
if getElementType ( thePlayer ) == "player" then --if the element that left was player
18+
--check if the player is not dead
19+
if isPlayerDead ( thePlayer ) ~= true then
20+
--let's get the name of the player
21+
local nameOfThePlayer = getPlayerName ( thePlayer )
22+
--if he was alive, announce to everyone that the player has left the hill
23+
outputChatBox ( nameOfThePlayer.." left the zone!", root, 255, 255, 109 )
24+
end
25+
end
26+
end
27+
addEventHandler ( "onColShapeLeave", hillArea, hill_Exit )
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
local jailZone = createColCircle ( 1024, 1024, 15 ) -- create a collision shape
2+
3+
-- call 'jailZoneLeave' whenever a player leaves the collision shape:
4+
function jailZoneLeave ( thePlayer )
5+
if getElementType ( thePlayer ) == "player" then -- if the element that left was player
6+
killPlayer ( thePlayer ) -- kill the player
7+
outputChatBox ( "You are not allowed to leave the jail!", thePlayer )
8+
end
9+
end
10+
addEventHandler ( "onColShapeLeave", jailZone, jailZoneLeave )

events/Colshape/onClientColShapeHit.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,12 @@ parameters:
1414
type: bool
1515
description: a boolean referring to whether the hit collision shape was in the same
1616
dimension as the element.
17+
examples:
18+
- path: examples/onClientColShapeHit-1.lua
19+
description: This example outputs "In." to the chatbox whenever the local user enters
20+
a collision shape.
21+
side: client
22+
- path: examples/onClientColShapeHit-2.lua
23+
description: This example outputs to the chatbox if the local user is in the same
24+
dimension as the collision shape or not.
25+
side: client

events/Colshape/onClientColShapeLeave.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,8 @@ parameters:
1414
type: bool
1515
description: a boolean referring to whether the collision shape was in the same
1616
dimension as the element.
17+
examples:
18+
- path: examples/onClientColShapeLeave-1.lua
19+
description: This example outputs "Out." to the chatbox whenever the local user
20+
leaves a collision shape.
21+
side: client

events/Colshape/onColShapeHit.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,8 @@ parameters:
1515
type: bool
1616
description: a boolean referring to whether the hit collision shape was in the same
1717
dimension as the element.
18+
examples:
19+
- path: examples/onColShapeHit-1.lua
20+
description: This example creates a hill area for aKing of the hillgamemode. When
21+
a player enters or leaves the area, it's announced in the chatbox.
22+
side: server

events/Colshape/onColShapeLeave.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,8 @@ parameters:
1616
type: bool
1717
description: a boolean referring to whether the collision shape was in the same
1818
dimension as the element.
19+
examples:
20+
- path: examples/onColShapeLeave-1.lua
21+
description: 'This example kills the player whenever they leave a certain collision
22+
shape:'
23+
side: server

0 commit comments

Comments
 (0)