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.
-- 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/3En el cajero terminado, ¿por qué el cliente solo 'pide' y nunca mueve el dinero?
Pista
¿Qué máquina controla el jugador tramposo?
Completa la llamada del cliente al callback que consulta el saldo.
function abrirCajero() ESX.('cajero:saldo', function(cash, bank) print(cash, bank) end)endPista
Desde el cliente se invoca un callback de servidor con ESX.TriggerServerCallback.
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:
RegisterCommand('retirar100', function() xPlayer.addMoney(100) -- mal: en el clienteend)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:
