Advanced QBCore Towing Script
Prompt
Create an advanced towing script for FiveM that integrates seamlessly with the QBCore framework. The script should enable players to dynamically tow vehicles within the game world, providing realistic interactions, physics, and animations. It must support the following capabilities: - Securely attach and detach vehicles to tow trucks or other designated towing vehicles. - Implement realistic physics behavior and towing animations. - Provide intuitive, user-friendly controls and commands to start and stop towing. - Ensure compatibility with QBCore's standard events, player data structures, and conventions. - Include robust error handling to address cases such as invalid vehicle targets, unreachable vehicles, or improper tow states. The code must be modular and thoroughly commented to clarify functionality, enabling easy customization and extension by other developers. # Steps 1. Identify relevant QBCore event hooks, player data accesses, and vehicle data accesses that relate to towing mechanics. 2. Develop functions for attaching and detaching vehicles with realistic physics and animation effects. 3. Map player commands and controls to these towing actions with clear feedback. 4. Test all towing scenarios comprehensively, including different vehicle models, failure states, and release locations. 5. Optimize for performance and responsiveness within a live FiveM server instance. # Output Format Deliver the complete source code as a single, standalone `.lua` file. This file should be ready for direct inclusion as a QBCore FiveM server resource. The script must start with detailed instructions covering installation, usage, and dependencies, followed by well-commented, modular code implementing all specified features. # Notes - The script must target the latest stable versions of QBCore and FiveM as of 2024. - Follow best practices to maintain multiplayer script stability, avoid race conditions, and minimize server load. - Ensure the tow mechanics feel realistic and intuitive to users. - Include safeguards against towing inappropriate vehicles or executing invalid actions.
Related Coding Prompts
Write Code
As a seasoned programmer, your task is to write code in [programming language] to [perform action]. The code should be efficient, well-structured, and optimized for performance. Make sure to follow best practices and industry standards while implementing the necessary algorithms and logic to achieve the desired functionality. Test the code thoroughly to ensure it functions as intended and meets all requirements. Additionally, document the code properly for future reference and maintenance.
Debug Code
Act as a seasoned programmer with over 20 years of commercial experience. Analyze the provided [piece of code] that is causing a specific [error]. Your task involves diagnosing the root cause of the error, understanding the context and functionality intended by the code, and proposing a solution to fix the issue. Your analysis should include a step-by-step walkthrough of the code, identification of any bugs or logical mistakes, and a detailed explanation of how to resolve them. Additionally, suggest any improvements or optimizations to enhance the performance, readability, or maintainability of the code based on your extensive experience. Ensure that your solution adheres to best practices in software development and is compatible with the current development environment where the code is being executed.
Do Code Review
As a seasoned programmer with over 20 years of commercial experience, your task is to perform a comprehensive code review on the provided [piece of code]. Your review should meticulously evaluate the code's efficiency, readability, and maintainability. You are expected to identify any potential bugs, security vulnerabilities, or performance issues and suggest specific improvements or optimizations. Additionally, assess the code's adherence to industry standards and best practices. Your feedback should be constructive and detailed, offering clear explanations and recommendations for changes. Where applicable, provide examples or references to support your suggestions. Your goal is to ensure that the code not only functions as intended but also meets high standards of quality and can be easily managed and scaled in the future. This review is an opportunity to mentor and guide less experienced developers, so your insights should be both educational and actionable.