Final project: your first ATM · Lesson 4/4 · 7 min

Polish, secure and publish

Connect the client to the callbacks, review security and upload it to the community.

To wrap up, the client calls the callbacks. Here keep it simple (input via chat or your NUI from module 5). The key is that the client only asks; the server already validates.

lua
-- client.lua: open the ATM (simple version)
function abrirCajero()
  ESX.TriggerServerCallback('cajero:saldo', function(cash, bank)
    print(('Cash: %s€  Bank: %s€'):format(cash, bank))
    -- here you'd open your NUI with these values (NUI module)
  end)
end

-- example of withdrawing 100
RegisterCommand('retirar100', function()
  ESX.TriggerServerCallback('cajero:retirar', function(ok)
    print(ok and 'Withdrawn' or 'Could not do it')
  end, 100)
end)

client.lua

Security review (module 7)

  • Money moved only on the server, with balance checked. ✓
  • Amounts validated (number, positive, limit). ✓
  • Per-player anti-spam. ✓
  • No hardcoded secrets, config in config.lua. ✓

Publish it to the community

Package the mi_cajero folder into a .zip and upload it to the Crxative-M Community. It will pass the automatic security audit and, if it's clean, other owners will be able to use it. You've just forged and shared your first complete resource.

You've closed the loop: fundamentals, framework, client-server, database, performance and security, all in a real resource. From here, whatever you can imagine.

Practice what you learned

0/3
Test

En el cajero terminado, ¿por qué el cliente solo 'pide' y nunca mueve el dinero?

Pista

¿Qué máquina controla el jugador tramposo?

Rellena los huecos

Completa la llamada del cliente al callback que consulta el saldo.

1function abrirCajero()
2 ESX.('cajero:saldo', function(cash, bank)
3 print(cash, bank)
4 end)
5end
Pista

Desde el cliente se invoca un callback de servidor con ESX.TriggerServerCallback.

Corrige el error

Un principiante intentó dar dinero desde el CLIENTE. Eso es inseguro. Cámbialo para que pida al servidor el retiro.

Este código tiene un fallo:

1RegisterCommand('retirar100', function()
2 xPlayer.addMoney(100) -- mal: en el cliente
3end)

Reescríbelo corregido:

Pista

Llama a ESX.TriggerServerCallback('cajero:retirar', function(ok) ... end, 100); el servidor decide.

Challenge: code it yourself

Package your ATM into a .zip and upload it to the community so it passes the audit.

Write it yourself in your editor (VS Code) and test it on your server. You learn here by doing it, not by copying.

See hint

Compress the resource folder and upload it at /comunidad/nuevo; review the audit report.

Escribe aquí tu solución:

How was this lesson?