Scripting/Squirrel/Client Functions: Difference between revisions
No edit summary |
|||
(2 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
== Script Functions == | == Global Functions == | ||
=== Script Functions === | |||
* [[Scripting/Squirrel/Client_Functions/dofile|dofile]](string filename) | * [[Scripting/Squirrel/Client_Functions/dofile|dofile]](string filename) | ||
* [[Scripting/Squirrel/Client_Functions/Script::LoadScript|Script::LoadScript]](string filename) <font color=green>// Same as dofile.</font> | * [[Scripting/Squirrel/Client_Functions/Script::LoadScript|Script::LoadScript]](string filename) <font color=green>// Same as dofile.</font> | ||
Line 6: | Line 7: | ||
* [[Scripting/Squirrel/Client_Functions/Script::GetTicks|Script::GetTicks]]() | * [[Scripting/Squirrel/Client_Functions/Script::GetTicks|Script::GetTicks]]() | ||
== World Functions == | === World Functions === | ||
* [[Scripting/Squirrel/Client_Functions/World::FindPlayer|World::FindPlayer]](int id) | * [[Scripting/Squirrel/Client_Functions/World::FindPlayer|World::FindPlayer]](int id) | ||
* [[Scripting/Squirrel/Client_Functions/World::FindLocalPlayer|World::FindLocalPlayer]]() | * [[Scripting/Squirrel/Client_Functions/World::FindLocalPlayer|World::FindLocalPlayer]]() | ||
* [[Scripting/Squirrel/Client_Functions/World::FindVehicle|World::FindVehicle]](int id) | * [[Scripting/Squirrel/Client_Functions/World::FindVehicle|World::FindVehicle]](int id) | ||
== | === System Functions === | ||
* [[Scripting/Squirrel/Client_Functions/ | * [[Scripting/Squirrel/Client_Functions/System::GetDate|System::GetDate]]([timestamp, [format]]) | ||
* [[Scripting/Squirrel/Client_Functions/System::GetTimestamp|System::GetTimestamp]]() | |||
== Console Functions == | === Console Functions === | ||
* [[Scripting/Squirrel/Client_Functions/Console::Print|Console::Print]](string text) | * [[Scripting/Squirrel/Client_Functions/Console::Print|Console::Print]](string text) | ||
== GUI Functions == | === GUI Functions === | ||
* [[Scripting/Squirrel/Client_Functions/GUI::GetMouseEnabled|GUI::GetMouseEnabled]]() | * [[Scripting/Squirrel/Client_Functions/GUI::GetMouseEnabled|GUI::GetMouseEnabled]]() | ||
* [[Scripting/Squirrel/Client_Functions/GUI::SetMouseEnabled|GUI::SetMouseEnabled]](bool enabled) | * [[Scripting/Squirrel/Client_Functions/GUI::SetMouseEnabled|GUI::SetMouseEnabled]](bool enabled) |
Latest revision as of 08:18, 10 May 2018
Global Functions
Script Functions
- dofile(string filename)
- Script::LoadScript(string filename) // Same as dofile.
- include(string filename)
- print(string text)
- Script::GetTicks()
World Functions
- World::FindPlayer(int id)
- World::FindLocalPlayer()
- World::FindVehicle(int id)
System Functions
- System::GetDate([timestamp, [format]])
- System::GetTimestamp()
Console Functions
- Console::Print(string text)
GUI Functions
- GUI::GetMouseEnabled()
- GUI::SetMouseEnabled(bool enabled)
- GUI::GetMousePos()
- GUI::GetScreenSize()
- GUI::ScreenPosToWorld(Vector screenPosition)
- GUI::WorldPosToScreen(Vector position)
- GUI::GetFocusedElement()
- GUI::SetFocusedElement(GUIElement element)
Data Types
Types int, float, bool and string are built-in types. entity is not an actual type, but can be any of either Player, Vehicle or Building. The actual type can be detected from the return value of entity.Type which is respectively OBJ_PLAYER, OBJ_VEHICLE or OBJ_BUILDING for them.
The values of properties marked as read-only cannot be changed. If a property is marked as bound, then it means the instance of for example a Vector that you get from it is bound to the object. Therefore if you do var = player.Position;, var.X will always contain the player's X position, not the X position when var was assigned. To get an unbound vector, use var = Vector(player.Position);.
Vector
- Constructor Vector(x, y, z)
- Parameter types: float, float, float
- Constructor Vector(vector)
- Parameter types: Vector
- Creates a copy of the specified vector.
- Property X
- Type: float
- Property Y
- Type: float
- Property Z
- Type: float
- Operator +
- Return type: Vector
- Adds the values of two vectors together and returns a new instance.
VectorScreen
- Constructor VectorScreen(x, y)
- Parameter types: int, int
- Constructor VectorScreen(screenVector)
- Parameter types: VectorScreen
- Creates a copy of the specified screen vector.
- Property X
- Type: int
- Property Y
- Type: int
Colour
- Constructor Colour(r, g, b, a)
- Parameter types: int, int, int, int
- Constructor Colour(r, g, b)
- Parameter types: int, int, int
- Alpha is set to 255.
- Constructor Colour(colour)
- Parameter types: Colour
- Creates a copy of the specified colour.
- Property R
- Type: int
- Property G
- Type: int
- Property B
- Type: int
- Property A
- Type: int
- Property Hex
- Type: int
KeyBind
Key values are virtual key codes. When a keybind is created, events about it will start coming, no need to register the keybind anywhere. To make a keybind not send events anymore, all references to it must be removed.
You can use /recordkey in game to get a key code.
- Constructor KeyBind(keyOne)
- Parameter types: int
- Constructor KeyBind(keyOne, keyTwo)
- Parameter types: int, int
- Constructor KeyBind(keyOne, keyTwo, keyThree)
- Parameter types: int, int, int
RayTrace
When ray trace is created, the properties from it will contain the results.
- Constructor RayTrace(start, end, flags)
- Parameter types: Vector, Vector, flags
- Flag values can be or-ed together with the | operator to select which types of entities it should check: RAY_BUILDING, RAY_PED, RAY_VEHICLE, RAY_OBJECT.
- Property Collided (read-only)
- Type: bool
- True when the ray hit something.
- Property Entity (read-only)
- Type: entity
- The entity that was hit, or null if nothing was hit. May also be null if the entity has been destroyed.
- Property Position
- Type: Vector
- The position of the collision, or zero vector if nothing was hit.
Stream
Used to construct the packet to send to the server or to read the data sent by the server. Read functions cannot be used on streams that were created by the script. The format of the stream is little-endian, with the exception that strings are written as a big-endian 2-byte length followed by the characters. Check Server::SendData for sending the stream or event Server::ServerData for receiving it.
- Constructor Stream()
- Creates a new stream for writing, which can be sent to the server.
- Function ReadByte()
- Return type: int
- Reads a single byte from the stream.
- Function ReadInt()
- Return type: int
- Reads an integer (4 bytes) from the stream.
- Function ReadFloat()
- Return type: float
- Reads a float (4 bytes) from the stream.
- Function ReadString()
- Return type: float
- Reads a string from the stream.
- Function WriteByte(value)
- Parameter types: int. Return type: void
- Writes a single byte to the stream.
- Function WriteInt(value)
- Parameter types: int. Return type: void
- Writes an integer (4 bytes) to the stream.
- Function WriteFloat(value)
- Parameter types: float. Return type: void
- Writes a float (4 bytes) to the stream.
- Function WriteString(value)
- Parameter types: string. Return type: void
- Writes a string to the stream.
- Property Error (read-only)
- Type: bool
- Whether writing exceeded the maximum stream size, or a read call tried to read past the end of the stream.
Player
- Property Type (read-only)
- Type: int
- The type of this entity, always OBJ_PLAYER.
- Property ID (read-only)
- Type: int
- Property Local (read-only)
- Type: bool
- Whether this is the local player.
- Property Name (read-only)
- Type: string
- Property Health (read-only)
- Type: float
- Property Armour (read-only)
- Type: float
- Property Position (bound)
- Type: Vector
Vehicle
Vehicle position and speed can only be changed if the vehicle is currently controlled by the current player (either a driver, passenger or the closest player).
- Property Type (read-only)
- Type: int
- The type of this entity, always OBJ_VEHICLE.
- Property ID (read-only)
- Type: int
- Property ModelIndex (read-only)
- Type: int
- Property Health (read-only)
- Type: float
- Property Position (bound)
- Type: Vector
- Property Speed (bound)
- Type: Vector
- Function GetOccupant(slot)
- Parameter types: int. Return type: Player
- The value passed to it is the slot number. 0 for driver, 1-8 for passengers.
Building
- Property Type (read-only)
- Type: int
- The type of this entity, always OBJ_BUILDING.
- Property ModelIndex (read-only)
- Type: int
- Property Position (read-only)
- Type: Vector
GUI Types
GUIElement
There aren't actually any instances of GUIElement, but it is the base class for all other GUI element classes. This means that all properties and functions it has also work on other GUI elements. GUI element flags are used in several places, the available flag constants are:
- GUI_FLAG_NONE
- GUI_FLAG_VISIBLE
- GUI_FLAG_DISABLED
- GUI_FLAG_BACKGROUND
- GUI_FLAG_BORDER
- GUI_FLAG_SHADOW
- GUI_FLAG_DRAGGABLE
- GUI_FLAG_CLIP
- GUI_FLAG_WRAP
- GUI_FLAG_AUTO_RESIZE
- GUI_FLAG_INHERIT_ALPHA
- GUI_FLAG_ANIMATION
- GUI_FLAG_TABSTOP
- GUI_FLAG_MOUSECTRL
- GUI_FLAG_KBCTRL
- GUI_FLAG_SCROLLABLE
- GUI_FLAG_TEXT_SHADOW
- GUI_FLAG_TEXT_TAGS
- GUI_FLAG_DEPTH_TEST
- GUI_FLAG_3D_ENTITY
- GUI_FLAG_CACHE_TEXTURE
- GUI_FLAG_CHECKBOX_CHECKED
- GUI_FLAG_EDITBOX_MASKINPUT
- GUI_FLAG_LISTBOX_MULTISELECT
- GUI_FLAG_LISTBOX_SORTING
- GUI_FLAG_MEMOBOX_TOPBOTTOM
- GUI_FLAG_SCROLLBAR_HORIZ
- GUI_FLAG_WINDOW_TITLEBAR
- GUI_FLAG_WINDOW_CLOSEBTN
- GUI_FLAG_WINDOW_RESIZABLE
Function AddChild(element)
Parameter types: GUIElement. Return type: void.
Makes the specified element a child of this element.
Function IsChildOf(element)
Parameter types: GUIElement. Return type: bool.
Returns true if this element is the child of the specified element.
Function Detach()
Return type: void.
Detaches this element from its parent.
Function MoveForward()
Return type: void.
Moves the siblign element right in front of this one behind it.
Function MoveBackward()
Return type: void.
Moves the sibling element right behind this element to the front of it.
Function SendToTop()
Return type: void.
Moves this element on top of all other sibling elements.
Function SendToBottom()
Return type: void.
Moves this element to the bottom of all other sibling elements.
Property Position (bound)
Type: VectorScreen
Property Size (bound)
Type: VectorScreen
Property Position3D / Pos3D (bound)
Type: Vector
Property Rotation3D (bound)
Type: Vector
Property Size3D (bound)
Type: Vector
Function Set3DTransform(position, rotation, size)
Parameter types: Vector, Vector, Vector. Return type: void.
Sets the 3D transformation of this element.
Property Colour / Color (bound)
Type: Colour
Property TextColour / TextColor (bound)
Type: Colour
Property Alpha
Type: int
Property Text
Type: string
Property TextSize (read-only)
Type: VectorScreen
Size on the screen of the text in this element.
Property TextAlignment
Type: int
Sets the alignment of text. Available constants are:
- GUI_ALIGN_LEFT
- GUI_ALIGN_RIGHT
- GUI_ALIGN_TOP
- GUI_ALIGN_BOTTOM
- GUI_ALIGN_CENTERV
- GUI_ALIGN_CENTERH
- GUI_ALIGN_CENTER
Property FontName
Type: string
Property FontSize
Type: int
Property FontFlags
Type: int
Available flag constants are:
- GUI_FFLAG_NONE
- GUI_FFLAG_BOLD
- GUI_FFLAG_ITALIC
- GUI_FFLAG_ULINE
- GUI_FFLAG_STRIKE
- GUI_FFLAG_NOAA
- GUI_FFLAG_OUTLINE
Property TextPaddingTop
Type: int
Property TextPaddingBottom
Type: int
Property TextPaddingLeft
Type: int
Property TextPaddingRight
Type: int
Property Flags
Type: int
Function AddFlags(flags)
Parameter types: int. Return type: void.
Function RemoveFlags(flags)
Parameter types: int. Return type: void.
GUIButton
Constructor GUIButton()
Constructor GUIButton(position, size, colour)
Parameter types: VectorScreen, VectorScreen, Colour
Constructor GUIButton(position, size, colour, text)
Parameter types: VectorScreen, VectorScreen, Colour, string
Constructor GUIButton(position, size, colour, text, flags)
Parameter types: VectorScreen, VectorScreen, Colour, string, int
GUICanvas
Constructor GUICanvas()
GUICheckbox
Constructor GUICheckbox()
Constructor GUICheckbox(position, colour)
Parameter types: VectorScreen, Colour
Constructor GUICheckbox(position, colour, flags)
Parameter types: VectorScreen, Colour, int
GUIEditbox
Constructor GUIEditbox(position, size, colour)
Parameter types: VectorScreen, VectorScreen, Colour
Constructor GUIEditbox(position, size, colour, text)
Parameter types: VectorScreen, VectorScreen, Colour, string
Constructor GUIEditbox(position, size, colour, text, flags)
Parameter types: VectorScreen, VectorScreen, Colour, string, int
Property HasTextSelected (read-only)
Type: bool
Property TextSelection (read-only)
Type: string
Function SelectText(startIndex, endIndex)
Parameter types: int, int. Return type: void.
Property CursorPos
Type: int
GUILabel
Constructor GUILabel()
Constructor GUILabel(position, colour)
Parameter types: VectorScreen, Colour
Constructor GUILabel(position, colour, text)
Parameter types: VectorScreen, Colour, string
Constructor GUILabel(position, colour, text, flags)
Parameter types: VectorScreen, Colour, string, int
GUIListbox
Constructor GUIListbox()
Constructor GUIListbox(position, size)
Parameter types: VectorScreen, VectorScreen
Constructor GUIListbox(position, size, colour, selectedColour)
Parameter types: VectorScreen, VectorScreen, Colour, Colour
Constructor GUIListbox(position, size, colour, selectedColour, flags)
Parameter types: VectorScreen, VectorScreen, Colour, Colour, int
Property Items (read-only)
Type: array
Function AddItem(item)
Parameter types: string. Return type: void.
Function RemoveItem(item)
Parameter types: string. Return type: void.
Function Clean()
Return type: void.
Removes all items.
Property ItemCount (read-only)
Type: int
Property SelectedCount (read-only)
Type: int
Property SelectedColour (bound)
Type: Colour
Background colour of selected items.
GUIMemobox
Constructor GUIMemobox()
Constructor GUIMemobox(position, size, colour)
Parameter types: VectorScreen, VectorScreen, Colour
Constructor GUIMemobox(position, size, colour, flags)
Parameter types: VectorScreen, VectorScreen, Colour, int
Function AddLine(line)
Parameter types: string. Return type: void.
Function AddLine(line, colour)
Parameter types: string, Colour. Return type: void.
Function Clear()
Return type: void.
Property DisplayPos
Type: float
Property LineHeight
Type: int
Property LineCount (read-only)
Type: int
Property HistorySize
Type: int
GUIProgressBar
Constructor GUIProgressBar()
Constructor GUIProgressBar(position, size, colour)
Parameter types: VectorScreen, VectorScreen, Colour
Constructor GUIProgressBar(position, size, colour, selectedColour)
Parameter types: VectorScreen, VectorScreen, Colour, Colour
Constructor GUIProgressBar(position, size, colour, selectedColour, flags)
Parameter types: VectorScreen, VectorScreen, Colour, Colour, int
Constructor GUIProgressBar(position, size, colour, selectedColour, flags, endValue)
Parameter types: VectorScreen, VectorScreen, Colour, Colour, int, float
Property Value
Type: float
Property MaxValue
Type: float
Property BackgroundShade
Type: float
Property Thickness
Type: int
Property StartColour (bound)
Type: Colour
Property EndColour (bound)
Type: Colour
GUIScrollbar
Constructor GUIScrollbar()
Constructor GUIScrollbar(position, size)
Parameter types: VectorScreen, VectorScreen
Constructor GUIScrollbar(position, size, colour)
Parameter types: VectorScreen, VectorScreen, Colour
Constructor GUIScrollbar(position, size, colour, flags)
Parameter types: VectorScreen, VectorScreen, Colour, int
Function SetParams(contentSize, stepSize, barPosition, barSize)
Parameter types: float, float, float, float. Return type: void.
Property ContentSize
Type: float
Property StepSize
Type: float
Property BarSize
Type: float
Property BarPosition
Type: float
Property BackgroundShade / BGShade
Type: float
GUISprite
Constructor GUISprite()
Constructor GUISprite(fileName, position)
Parameter types: string, VectorScreen
Constructor GUISprite(fileName, position, colour)
Parameter types: string, VectorScreen, Colour
Constructor GUISprite(fileName, position, colour, flags)
Parameter types: string, VectorScreen, Colour, int
Property TextureSize
Type: VectorScreen
Property TopLeftUV
Type: Vector
Property BottomRightUV
Type: Vector
Function SetTexture(fileName)
Parameter types: string. Return type: void.
Function Resize()
Return type: void.
GUIWindow
Constructor GUIWindow()
Constructor GUIWindow(position, size, colour)
Parameter types: VectorScreen, VectorScreen, Colour
Constructor GUIWindow(position, size, colour, text)
Parameter types: VectorScreen, VectorScreen, Colour, string
Constructor GUIWindow(position, size, colour, text, flags)
Parameter types: VectorScreen, VectorScreen, Colour, string, int
Property DragOffset (read-only)
Type: VectorScreen
Property TitleColour (bound)
Type: Colour