Skip to content

Commit

Permalink
feat(new/resource): basic first resource
Browse files Browse the repository at this point in the history
  • Loading branch information
PsychoShock committed Jun 4, 2024
1 parent 5e33bbd commit a0c603b
Show file tree
Hide file tree
Showing 11 changed files with 242 additions and 199 deletions.
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 content/docs/scripting-manual/introduction/creating-your-first-script.md

Large diffs are not rendered by default.

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.
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.
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.

0 comments on commit a0c603b

Please sign in to comment.