Skip to main content

Understanding Events

Events are the primary way to communicate between client and server scripts in RedM. They allow you to send messages, trigger actions, and share data across different parts of your resource.
Events enable asynchronous communication - you can trigger an event without waiting for a response!

Event Types

1. Client β†’ Server Events

Send data from client to server:
Real Example from RSG:

2. Server β†’ Client Events

Send data from server to specific client(s):
Real Example from RSG:

3. Local Events (Same Side)

Events that stay on the same side (client-to-client or server-to-server):
Local events on client do NOT sync between players. Each client’s local events are independent!

Event Security

Always Validate Server Events

NEVER trust data from client events! Always validate on server-side.

Common Validation Patterns


Callbacks

Callbacks allow you to get a response from an event - like a function call across client/server!

RSGCore Callbacks

Server Callback (Most Common)

Ask the server for data from client:
Real Example from RSG:

Client Callback

Ask the client for data from server:

Advanced Event Patterns

Pattern 1: Event with Confirmation

Send event and wait for confirmation:

Pattern 2: Broadcast to Nearby Players

Send event only to players within range:

Pattern 3: Chain Events

One event triggers another:

Event Handler Management

Removing Event Handlers

Sometimes you need to stop listening to events:

One-Time Events

Event that only triggers once:

Performance Considerations

Don’t Spam Events

Batch Event Data


Common Event Naming Conventions

RSG Framework uses consistent naming:
Examples:
  • rsg-inventory:server:AddItem
  • rsg-banking:client:updateBalance
  • police:server:cuffPlayer
  • hospital:client:revive
Follow this convention in your own resources for consistency!

Debugging Events

Event Listener Helper


Complete Example: Trading System

Putting it all together:

Summary


Next Steps


Need more help? Join the RSG Framework Discord!