-
Notifications
You must be signed in to change notification settings - Fork 311
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(new/resource): basic first resource
- Loading branch information
1 parent
5e33bbd
commit a0c603b
Showing
11 changed files
with
242 additions
and
199 deletions.
There are no files selected for viewing
61 changes: 61 additions & 0 deletions
61
content/docs/scripting-manual/introduction/creating-your-first-script-extra.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
--- | ||
title: How to create your first FiveM resource (advanced part) | ||
weight: 490 | ||
--- | ||
|
||
Creating an "extra" or advanced section for your FiveM resource development guide is an excellent way to cater to developers who are ready to take their skills to the next level. This advanced section can delve deeper into topics such as security measures, optimization techniques, and advanced scripting practices. Here's how you can set up this advanced section in a new file: | ||
|
||
--- | ||
|
||
# Advanced Topics in FiveM Resource Development | ||
|
||
Congratulations on making your first FiveM resource! As you continue your journey in FiveM development, you'll encounter more complex scenarios and challenges. This advanced guide aims to equip you with the knowledge and techniques to tackle these situations, ensuring your resources are robust, optimized, and secure. | ||
|
||
## Security Measures | ||
|
||
### Validating Parameters | ||
|
||
In the basic guide, we introduced a simple validation step to ensure that the client script receives a valid parameter from the server. This is crucial for preventing cheating attempts and maintaining the integrity of your game environment. Here's how you can enhance this validation process: | ||
|
||
```lua | ||
RegisterServerEvent('cfx:client:firstEvent', function(information) | ||
-- Ensure the parameter is a string and not nil | ||
assert(type(information) == 'string' and information ~= nil, 'Invalid parameter received') | ||
|
||
-- Proceed with the event logic | ||
TriggerEvent('chat:addMessage', { | ||
template = '<div class="chat-message"><b>SYSTEM</b><br>{0} has been sent to you</div>', | ||
args = {information} | ||
}) | ||
end) | ||
``` | ||
|
||
This code snippet uses `assert` to enforce that the `information` parameter is a non-nil string. If the validation fails, it throws an error, preventing the execution of any potentially harmful code. | ||
|
||
### Advanced Security Practices | ||
|
||
Beyond parameter validation, consider implementing more advanced security measures, such as: | ||
|
||
- **Checksum Validation**: Verify the integrity of your scripts by comparing checksums on both the client and server. | ||
- **Permission Checks**: Ensure that players can only execute commands or events they are allowed to, based on permissions or user roles. | ||
- **Rate Limiting**: Prevent abuse by limiting the frequency at which players can trigger certain events or commands. | ||
|
||
## Optimization Techniques | ||
|
||
As your resources grow in complexity, keeping them optimized is key to maintaining a smooth player experience. Here are some optimization tips: | ||
|
||
- **Minimize Network Traffic**: Only send necessary data between the client and server to reduce bandwidth usage. | ||
- **Use Timers Wisely**: Avoid creating too many timers or using them too frequently, as they can significantly impact performance. | ||
- **Cache References**: Instead of repeatedly calling `GetPlayerName`, `GetPlayerServerId`, etc., cache these values when possible. Natives that will never change value doesn't require to be call every time on the same player session. | ||
|
||
## Advanced Scripting Practices | ||
|
||
To elevate your scripting skills, explore the following advanced practices: | ||
|
||
- **Object-Oriented Programming (OOP)**: Utilize OOP principles in Lua to create more organized and scalable code. | ||
- **Metatables and Metamethods**: Leverage Lua's metatables and metamethods to extend the functionality of tables and create more dynamic data structures. | ||
- **Coroutines**: Use coroutines for cooperative multitasking within your scripts, allowing for non-blocking operations. | ||
|
||
--- | ||
|
||
This advanced guide is just the beginning of what's possible in FiveM resource development. As you explore these topics, you'll find that the possibilities are endless. Keep experimenting, learning, and most importantly, enjoy the process of creating amazing experiences for your players. |
380 changes: 181 additions & 199 deletions
380
content/docs/scripting-manual/introduction/creating-your-first-script.md
Large diffs are not rendered by default.
Oops, something went wrong.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+17.2 KB
content/docs/scripting-manual/introduction/img/example_client_code.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+6.19 KB
content/docs/scripting-manual/introduction/img/example_preview_return.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+33.2 KB
content/docs/scripting-manual/introduction/img/example_server_code.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+5.2 KB
content/docs/scripting-manual/introduction/img/resource_folder_client.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+5.42 KB
content/docs/scripting-manual/introduction/img/resource_folder_server.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.