Hi everyone,
I’m working on a script, it’s a ped who sell some weapons, but i’m a beginner in LUA so i need some help…
The ped is nice and when i talk to him, it open the menu BUT, when i choose my weapon, nothing happen… It could be from the Server.lua side, cause i dont really know how to use it.
Client:
function ThrowMenu() -- here's my menu
ClearMenu()
options.menu_title = "Arme de lancé"
Menu.addButton("Fumigène","AchatArme(hash, prix)",nil)
Menu.addButton("Coctail molotov","AchatArme('WEAPON_Molotov', 1000)",nil) -- I try to buy this weapon
Menu.addButton("Bidon d'essence","AchatArme(hash, prix)",nil)
Menu.addButton("Fermer","WeaMenu",nil)
end
local function AchatArme(hash, prix) -- here's the function who call GiveWeaponToPed and who call the serveur function CheckMoneyForWea
local ped = GetPlayerPed(-1)
wait(0)
GiveWeaponToPed(ped, GetHashKey(hash), 1000, false)
TriggerServerEvent('CheckMoneyForWea',hash,prix)
end
Server (copied from the essential weashop script):
RegisterServerEvent('CheckMoneyForWea')
AddEventHandler('CheckMoneyForWea', function(weapon,price)
TriggerEvent('es:getPlayerFromId', source, function(user)
if (tonumber(user.getDirtyMoney) >= tonumber(price)) then
local player = user.identifier
local nb_weapon = 0
local executed_query = MySQL:executeQuery("SELECT * FROM user_weapons WHERE identifier = '@username'",{['@username'] = player})
local result = MySQL:getResults(executed_query, {'weapon_model'}, "identifier")
if result then
for k,v in ipairs(result) do
nb_weapon = nb_weapon + 1
end
end
print(nb_weapon)
if (tonumber(max_number_weapons) > tonumber(nb_weapon)) then
-- Pay the shop (price)
user.removeDirtyMoney((price))
MySQL:executeQuery("INSERT INTO user_weapons (identifier,weapon_model,withdraw_cost) VALUES ('@username','@weapon','@cost')",
{['@username'] = player, ['@weapon'] = weapon, ['@cost'] = (price)/cost_ratio})
-- Trigger some client stuff
TriggerClientEvent('FinishMoneyCheckForWea',source)
TriggerClientEvent("es_freeroam:notify", source, "CHAR_STRETCH", 1, "Pablo", false, "Bon choix! Et en faite, tu ne m'as jamais vu.\n")
else
TriggerClientEvent('ToManyWeapons',source)
TriggerClientEvent("es_freeroam:notify", source, "CHAR_STRETCH", 1, "Pablo", false, "Tu as atteinds la limite d'armes! (max: "..max_number_weapons..")\n")
end
else
-- Inform the player that he needs more money
TriggerClientEvent("es_freeroam:notify", source, "CHAR_STRETCH", 1, "Pablo", false, "T'as pas assez de thune!\n")
end
end)
end)
If someone could tell me what’s wrong with this please!
Have a nide day.