mirror of
https://github.com/BeamMP/Wiki.git
synced 2025-07-01 15:26:05 +00:00
15 lines
2.7 KiB
HTML
15 lines
2.7 KiB
HTML
<!--
|
|
title: Client Scripting in BeamMP
|
|
description: This will briefly introduce you to the concept of scripting for BeamMP on client side.
|
|
published: true
|
|
date: 2022-12-22T09:22:55.124Z
|
|
tags: scripting, client, server, lua, coding, communication
|
|
editor: ckeditor
|
|
dateCreated: 2020-08-28T19:06:03.744Z
|
|
-->
|
|
|
|
<p>BeamMP allows you to create your own client side plugins as well. We have provided a few functions that you can use to communicate with other multiplayer mods, and other players through the server.</p>
|
|
<p>You can create an event your custom functions can hook onto. For example to parse the chat use the <span style="font-family:'Courier New', Courier, monospace;">ChatMessageReceived </span>event as such:</p>
|
|
<p><span style="font-family:'Courier New', Courier, monospace;">local function chatReceived(msg) -- Receive event with parameters</span><br><span style="font-family:'Courier New', Courier, monospace;"> print("chat received: "..msg)</span><br><span style="font-family:'Courier New', Courier, monospace;"> local i = string.find(s, ":") -- Find where our first ':' is, used to separate the sender and message</span><br><span style="font-family:'Courier New', Courier, monospace;"> if i == nil then</span><br><span style="font-family:'Courier New', Courier, monospace;"> print("error parsing message: separator could not be found!")</span><br><span style="font-family:'Courier New', Courier, monospace;"> return -- Could not find separator, cancel function</span><br><span style="font-family:'Courier New', Courier, monospace;"> end</span><br><br><span style="font-family:'Courier New', Courier, monospace;"> print("index of separator: "..tostring(i))</span><br><br><span style="font-family:'Courier New', Courier, monospace;"> local sender = string.sub(msg, 1, i-1) -- Substring our input to separate its 2 parts</span><br><span style="font-family:'Courier New', Courier, monospace;"> local message = string.sub(msg, i+1, -1)</span><br><span style="font-family:'Courier New', Courier, monospace;"> -- Do whatever you want to with the message</span><br><span style="font-family:'Courier New', Courier, monospace;"> print("sender: " .. sender)</span><br><span style="font-family:'Courier New', Courier, monospace;"> print("message: ".. message)</span><br><span style="font-family:'Courier New', Courier, monospace;">end</span></p>
|
|
<p><span style="font-family:'Courier New', Courier, monospace;">AddEventHandler("ChatMessageReceived", chatReceived)</span><br><span style="font-family:'Courier New', Courier, monospace;">TriggerServerEvent("ServerEventName", "Data")</span><br><span style="font-family:'Courier New', Courier, monospace;">AddEventHandler("EventNameToBeCalled", Function())</span></p>
|