-
Notifications
You must be signed in to change notification settings - Fork 16
Event functions #51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Event functions #51
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,4 +7,8 @@ function specialEventHandler ( text ) | |
| end | ||
|
|
||
| -- Add it as a handler for our event | ||
| addEventHandler ( "onSpecialEvent", root, specialEventHandler ) | ||
| addEventHandler ( "onSpecialEvent", root, specialEventHandler ) | ||
|
|
||
| -- You can then trigger this event later on using: | ||
| triggerEvent ( "onSpecialEvent", root, "test" ) | ||
| -- This will cause the handler to be triggered, so "test" will be output to the chatbox. | ||
|
Comment on lines
+10
to
+14
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please use code formatting, even if the examples are copied from the wiki. All functions edited so far have nicely formatted code without extra spacing, unnecessary blank lines, etc. In Visual Studio Code, it’s simply Ctrl + Shift + F. |
||
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| function onVehicleStartEnter() | ||
| cancelEvent() | ||
| cancelEvent() | ||
| end | ||
| addEventHandler("onVehicleStartEnter", root, onVehicleStartEnter) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,23 @@ | ||
| function greetingCommand ( playerSource, commandName ) | ||
| triggerClientEvent ( playerSource, "onGreeting", playerSource, "Hello World!" ) | ||
| -- ***************************************************************************** | ||
| -- SERVER CODE | ||
| function greetingCommandOne ( playerSource, commandName, playerName ) | ||
| if playerName then | ||
| local thePlayer = getPlayerFromName ( playerName ) | ||
| if thePlayer then | ||
| triggerClientEvent ( thePlayer, "onGreeting", thePlayer, "Hello World!" ) | ||
| else | ||
| -- invalid player name specified | ||
| end | ||
| else | ||
| -- No player name specified | ||
| end | ||
| end | ||
| addCommandHandler ( "greet", greetingCommand ) | ||
| addCommandHandler ( "greet_one", greetingCommandOne ) | ||
|
|
||
| -- ***************************************************************************** | ||
| -- CLIENT CODE | ||
| function greetingHandler ( message ) | ||
| outputChatBox ( "The server says: " .. message ) | ||
| end | ||
| addEvent( "onGreeting", true ) | ||
| addEventHandler( "onGreeting", localPlayer, greetingHandler ) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,16 @@ | ||
| function greetingHandler ( message ) | ||
| outputChatBox ( "The server says: " .. message ) | ||
| -- ***************************************************************************** | ||
| -- SERVER CODE | ||
| function commandFunction(source) | ||
| triggerClientEvent(source, "toClientSide", resourceRoot, "Hello World!") | ||
| end | ||
| addEvent( "onGreeting", true ) | ||
| addEventHandler( "onGreeting", localPlayer, greetingHandler ) | ||
| addCommandHandler("cool", commandFunction) | ||
|
|
||
| -- ***************************************************************************** | ||
| -- CLIENT CODE | ||
| function nameFunction(message) | ||
| if source == resourceRoot then | ||
| outputChatBox(message) | ||
| end | ||
| end | ||
| addEvent("toClientSide", true ) | ||
| addEventHandler("toClientSide", resourceRoot, nameFunction) |
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,17 @@ | ||
| -- ***************************************************************************** | ||
| -- CLIENT CODE | ||
| if fileExists("text.txt") | ||
| file = fileOpen("test.txt") --Open a file (you can create it yourself). | ||
| local data = fileRead(file,100*1024*1024) --Max 100 MB | ||
| fileClose(file) --Close File | ||
| triggerLatentServerEvent("onReadFile",5000,false,root,data) --trigger | ||
| end | ||
| end | ||
|
|
||
| -- ***************************************************************************** | ||
| -- SERVER CODE | ||
| addEvent("onReadFile",true) | ||
| addEventHandler("onReadFile",root,function(data) | ||
| local file = fileCreate("text.txt") --Save "data" into "text.txt" | ||
| fileWrite(file,data) | ||
| fileClose(file) | ||
| end) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don’t want to be an orthography nitpicker, but please pay attention to errors in the text, typos, or things like this (a space before a period). Unfortunately, the scraping process made a real mess of the texts and descriptions. Sometimes the descriptions are even incorrect. Try to fix all of that. We want the new wiki to be BETTER than the old one - clear and reliable. Always make sure the current description matches the source code, and whenever possible, try to emphasize key words using backticks or bold formatting. Unfortunately, simply copying content from the old wiki into the new one is not a sufficient process.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, always bold what the function returns - whether it’s true, false, or nil