Skip to content

Commit 41c7298

Browse files
committed
update function pages and examples
1 parent 7ee922c commit 41c7298

22 files changed

+140
-118
lines changed

functions/Cursor/examples/getCursorAlpha.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
-- Simple command to test the getCursorAlpha function
2-
addCommandHandler( "cursorAlpha",
1+
addCommandHandler( "cursoralpha",
32
function ()
3+
-- check if cursor is showing
44
if ( isCursorShowing ( ) ) then
55
outputChatBox( "The cursor alpha: "..getCursorAlpha( ) )
66
else

functions/Cursor/examples/getCursorPosition-1.lua

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
function cursorInfo()
2-
if isCursorShowing() then -- if the cursor is showing
2+
-- is the cursor showing?
3+
if isCursorShowing() then
4+
-- get the cursor postion
35
local screenx, screeny, worldx, worldy, worldz = getCursorPosition()
46

5-
outputChatBox( string.format( "Cursor screen position (relative): X=%.4f Y=%.4f", screenx, screeny ) ) -- make the accuracy of floats 4 decimals
6-
outputChatBox( string.format( "Cursor world position: X=%.4f Y=%.4f Z=%.4f", worldx, worldy, worldz ) ) -- make the accuracy of floats 4 decimals accurate
7+
-- make the accuracy of floats 4 decimals and print to chatbox
8+
outputChatBox( string.format( "Cursor screen position (relative): X=%.4f Y=%.4f", screenx, screeny ) )
9+
outputChatBox( string.format( "Cursor world position: X=%.4f Y=%.4f Z=%.4f", worldx, worldy, worldz ) )
710
else
811
outputChatBox( "Your cursor is not showing." )
912
end

functions/Cursor/examples/getCursorPosition-2.lua

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,22 @@
11
addEventHandler( "onClientRender", root,
22
function()
3+
-- is cursor showing?
34
if isCursorShowing() then
5+
-- get cursor position
46
local screenx, screeny, worldx, worldy, worldz = getCursorPosition()
7+
8+
-- get our camera matrix/position
59
local px, py, pz = getCameraMatrix()
10+
11+
-- calculate the exact distance between cursor and camera
612
local hit, x, y, z, elementHit = processLineOfSight ( px, py, pz, worldx, worldy, worldz )
713

8-
if hit then
9-
dxDrawText( "Cursor at " .. x .. " " .. y .. " " .. z, 200, 200 )
10-
if elementHit then
11-
dxDrawText( "Hit element " .. getElementType(elementHit), 200, 220 )
12-
end
14+
-- draw the distance on screen
15+
dxDrawText( "Cursor at X:" .. x .. " Y:" .. y .. " Z:" .. z, 200, 200 )
16+
17+
-- if we got a collision detected and a valid element, draw it as well
18+
if hit and elementHit then
19+
dxDrawText( "Hit element " .. getElementType(elementHit), 200, 220 )
1320
end
1421
end
1522
end

functions/Cursor/examples/setCursorAlpha.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
-- Simple command to test the setCursorAlpha function
2-
addCommandHandler( "cursorAlpha",
1+
addCommandHandler( "cursoralpha",
32
function ()
43
-- Show the cursor if it is not showing or hide the cursor if it is
54
showCursor( not isCursorShowing ( ) )
5+
66
-- Set the alpha to 100
77
setCursorAlpha(100)
88
end

functions/Cursor/examples/setCursorPosition.lua

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
function centerCursorFunction()
2-
local showing = isCursorShowing ()
3-
if showing then -- if the cursor is showing
4-
local screenX, screenY = guiGetScreenSize () --get the screen size in pixels
5-
setCursorPosition (screenX/2, screenY/2) --set the cursor position to the center of the screen
2+
-- is cursor showing?
3+
if showisCursorShowing ()ing then
4+
--get the screen size in pixels
5+
local screenX, screenY = guiGetScreenSize ()
6+
7+
--set the cursor position to the center of the screen
8+
setCursorPosition (screenX/2, screenY/2)
69
else
710
outputChatBox( "Your cursor is not showing." )
811
end
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
showCursor ( true ) -- Shows cursor
2-
showCursor ( false ) -- Doesnt Show Cursor
1+
showCursor ( true ) -- shows cursor
2+
showCursor ( false ) -- hides cursor

functions/Cursor/getCursorAlpha.yaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,18 @@ client:
55
This function is used to get the client's cursor alpha (transparency).
66
preview_images:
77
- path: '/assets/cursor-alpha.jpg'
8-
description: 'Visual representation of the cursor alpha'
8+
description: 'Visual representation of the cursor alpha:'
99
returns:
1010
description: |
11-
Returns a int between 0 and 255, where 255 is fully opaque and 0 is fully transparent.
11+
Returns a number between 0 and 255, where 255 is fully opaque and 0 is fully transparent.
1212
values:
1313
- type: 'int'
1414
name: 'alpha'
1515
version:
1616
added: '1.3.2'
1717
examples:
1818
- path: 'examples/getCursorAlpha.lua'
19+
description: |
20+
This example prints the cursor alpha to chatbox using */cursoralpha* command:
1921
see_also:
2022
- 'category:Client element functions'

functions/Cursor/getCursorPosition.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ client:
44
description: |
55
This function gets the current position of the mouse cursor.
66
Note that for performance reasons, the world position returned is always 300 units away.
7-
If you want the exact world point (similar to [[onClientClick]]), use [[processLineOfSight]] between the camera position and the worldX/Y/Z result of this function.
7+
If you want the exact world point (similar to [onClientClick](/onClientClick)), use [processLineOfSight](/processLineOfSight) between the camera position and the world x/y/z result of this function.
88
(See example below)
99
returns:
1010
description: |
1111
Returns 5 values: *cursorX*, *cursorY*, *worldX*, *worldY*, *worldZ*.
1212
The first two values are the 2D **relative** screen coordinates of the cursor.
13-
The 3 values that follow are the 3D world map coordinates that the cursor points at.
13+
The last 3 values are the 3D world map coordinates that the cursor points at.
1414
If the cursor isn't showing, returns *false* as the first value.
1515
values:
1616
- type: 'float'
@@ -29,7 +29,7 @@ client:
2929
examples:
3030
- path: 'examples/getCursorPosition-1.lua'
3131
description: |
32-
This example prints your cursors current world coordinates and relative screen coordinates to chatbox after typing cursorpos.
32+
This example prints your cursors current world coordinates and relative screen coordinates to chatbox after using */cursorpos* command.
3333
- path: 'examples/getCursorPosition-2.lua'
3434
description: |
35-
This (untested) example uses processLineOfSight to calculate the exact world location: Warning, using the script down there will cause high CPU usage.
35+
This (untested) example uses [processLineOfSight](/processLineOfSight) to calculate the exact world location: Warning, this script causes high CPU usage!

functions/Cursor/isCursorShowing.yaml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
shared: &shared
22
name: 'isCursorShowing'
33
description: |
4-
This function determines the state of a player's cursor.
4+
This function determines the state of a [player](/player)'s cursor.
55
notes:
6-
- This function only handles the cursor state set by the [[showCursor]] function, ignoring it if the console, chatbox, or menu is open.
7-
- If you use this function on the server-side, keep in mind that it only detects the [[showCursor]] function executed on the server-side and does not detect the function executed on the client-side.
6+
- This function only handles the cursor state set by the [showCursor](/showCursor) function, ignoring it if the console, chatbox, or menu is opened.
7+
- If you use this function on the server-side, keep in mind that it only detects the [showCursor](/showCursor) function executed on the server-side and not changes done by client-side.
88
returns:
99
description: |
10-
Returns *true* if the player's cursor is visible, and *false* if it is not.
10+
Returns *true* if the [player](/player)'s cursor is visible, and *false* if it is not.
1111
values:
1212
- type: 'bool'
1313
name: 'result'
@@ -17,28 +17,28 @@ server:
1717
parameters:
1818
- name: 'playerElement'
1919
type: 'player'
20-
description: 'The [[player]] from whom we want to retrieve the cursor state.'
20+
description: 'The [player](/player) from whom we want to retrieve the cursor state.'
2121
examples:
2222
- path: 'examples/isCursorShowing-1.lua'
2323
description: |
24-
This example creates a function to set the state of the player's cursor using the [[showCursor]] function.
24+
This example creates a function to set the state of the [player](/player)'s cursor using the [showCursor](/showCursor) function.
2525
- path: 'examples/isCursorShowing-2.lua'
2626
description: |
27-
This example creates a function that gets the state of the player's cursor and outputs it to the chatbox using the [[outputChatBox]] function.
27+
This example creates a function that gets the state of the [player](/player)'s cursor and outputs it to the chatbox using the [outputChatBox](/outputChatBox) function.
2828
2929
client:
3030
<<: *shared
3131
examples:
3232
- path: 'examples/isCursorShowing-3.lua'
3333
description: |
34-
This example creates a function to set the state of the player's cursor using the [[showCursor]] function.
34+
This example creates a function to set the state of the [player](/player)'s cursor using the [showCursor](/showCursor) function.
3535
- path: 'examples/isCursorShowing-4.lua'
3636
description: |
3737
If you are already advanced in scripting, using this code is recommended, as it is much more compact:
3838
append: true
3939
- path: 'examples/isCursorShowing-5.lua'
4040
description: |
41-
This example creates a function that allows the player to change the state of the cursor using the [[showCursor]] and [[bindKey]] functions.
41+
This example creates a function that allows the [player](/player) to change the state of the cursor using the [showCursor](/showCursor) and [bindKey](/bindKey) functions.
4242
- path: 'examples/isCursorShowing-6.lua'
4343
description: |
4444
If you are already advanced in scripting, using this code is recommended, as it is much more compact:

functions/Cursor/setCursorAlpha.yaml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ client:
22
name: 'setCursorAlpha'
33
pair: 'getCursorAlpha'
44
description: |
5-
This function is used to change alpha (transparency) from the client's cursor.
5+
This function is used to change alpha (transparency) of the client's cursor.
66
preview_images:
77
- path: '/assets/cursor-alpha.jpg'
8-
description: 'Visual representation of the cursor alpha'
8+
description: 'Visual representation of the cursor alpha:'
99
parameters:
1010
- name: 'alpha'
1111
type: 'int'
12-
description: 'The alpha value to set. Value can be 0-255, where 255 is fully opaque and 0 is fully transparent.'
12+
description: 'The alpha value to set. Value can be in between 0 and 255, where 255 is fully opaque and 0 is fully transparent.'
1313
returns:
1414
description: |
1515
Returns *true* if the new alpha value was set, or *false* otherwise.
@@ -20,5 +20,7 @@ client:
2020
added: '1.3.2'
2121
examples:
2222
- path: 'examples/setCursorAlpha.lua'
23+
description: |
24+
This example sets the cursor alpha to 100 using */cursoralpha* command:
2325
see_also:
2426
- 'category:Client GUI functions'

0 commit comments

Comments
 (0)