Maybe I suggest instead of delete the player´s weapon, to sync the weapons from the player every 5 minutes like arma 3 Altis life or :
However thanks you for your work and the preview looks amazing
Maybe I suggest instead of delete the player´s weapon, to sync the weapons from the player every 5 minutes like arma 3 Altis life or :
However thanks you for your work and the preview looks amazing
I am making a revamp of essential mode + async sql. I will add by default position saving. I don’t like the way that script works. Every 30 second it runs an insert to the database… I have made a variant of it and only store the position every 3 seconds in a variable, and only when the players drops from the server save it in the database.
I also add by default the dirtymoney and bankbalance.
My goal will be to push most of the developers to use in memory classes instead of running query’s every 30-60 seconds.
It will all be on github so people can upgrade the user table if we want some default stuff in it. That way people don’t have to install 30 mods.
Je t aime. Thanks a lot
I’m having an issue where if I add custom locations into the plugin, the blips disappear from the map and the shops are non-existent. Any ideas on why this may be happening? If any coding is needed let me know.
In fact you can store tables in couchdb, ill get to work on converting the script then ill send you the code Plus i whant to do it for my server to because the mysql isnt saving lol.
Ok guys good news, i finished the conversion and here it is in CouchDB
this is the sv_weashop file just copy and paste this into it
now if you already have essentials 3.x.x installed you need to backup the essentialsmode database in couch and delete it before you restart your server after installation of this script.
Once you delete essentials mode and save this file then go ahead and restart your server. Once the server fully loads and you hop on it once, you can leave and restore your essentialsmode database to its original state.
local max_number_weapons = 15 --maximum number of weapons that the player can buy. Weapons given at spawn doesn't count.
local cost_ratio = 100 --Ratio for withdrawing the weapons. This is price/cost_ratio = cost.
TriggerEvent('es:exposeDBFunctions', function(db)
db.createDatabase('es_weashop', function()end)
end)
RegisterServerEvent('CheckMoneyForWea')
AddEventHandler('CheckMoneyForWea', function(weapon,price)
TriggerEvent('es:getPlayerFromId', source, function(user)
TriggerEvent('es:exposeDBFunctions', function(db)
db.getDocumentByRow('es_weashop', 'identifier', user.identifier, function(dbuser)
if (tonumber(user.money) >= tonumber(price)) then
local player = user.identifier
local nb_weapon = 0
for i=1, #dbuser.weapons do
nb_weapon = nb_weapon + 1
end
print(nb_weapon)
if (tonumber(max_number_weapons) > tonumber(nb_weapon)) then
-- Pay the shop (price)
user:removeMoney((price))
dbuser.weapons[#dbuser.weapons+1] = weapon
dbuser.cost[#dbuser.cost+1] = (price)/cost_ratio
db.updateDocument('es_weashop', dbuser._id, {weapons = dbuser.weapons, cost = dbuser.cost})
TriggerClientEvent('FinishMoneyCheckForWea',source)
TriggerClientEvent("es_freeroam:notify", source, "CHAR_MP_ROBERTO", 1, "Roberto", false, "MURDER TIME. FUN TIME!\n")
else
TriggerClientEvent('ToManyWeapons',source)
TriggerClientEvent("es_freeroam:notify", source, "CHAR_MP_ROBERTO", 1, "Roberto", false, "You have reached the weapon limit ! (max: "..max_number_weapons..")\n")
end
else
-- Inform the player that he needs more money
TriggerClientEvent("es_freeroam:notify", source, "CHAR_MP_ROBERTO", 1, "Roberto", false, "You don't have enough cash !\n")
end
end)
end)
end)
end)
RegisterServerEvent("weaponshop:playerSpawned")
AddEventHandler("weaponshop:playerSpawned", function(spawn)
TriggerEvent('es:getPlayerFromId', source, function(user)
TriggerEvent('weaponshop:GiveWeaponsToPlayer', source)
end)
end)
RegisterServerEvent("weaponshop:GiveWeaponsToPlayer")
AddEventHandler("weaponshop:GiveWeaponsToPlayer", function(player)
TriggerEvent('es:getPlayerFromId', player, function(user)
local playerID = user.identifier
local delay = nil
TriggerEvent('es:exposeDBFunctions', function(db)
--local executed_query = MySQL:executeQuery("SELECT * FROM user_weapons WHERE identifier = '@username'",{['@username'] = playerID})
--local result = MySQL:getResults(executed_query, {'weapon_model','withdraw_cost'}, "identifier")
delay = 2000
db.getDocumentByRow('es_weashop', 'identifier', user.identifier, function(dbuser)
for i=1, #dbuser.weapons do
if (tonumber(user.money) >= tonumber(dbuser.cost[i])) then
TriggerClientEvent("giveWeapon", player, dbuser.weapons[i], delay)
user:removeMoney((dbuser.cost[i]))
else
TriggerClientEvent("es_freeroam:notify", source, "CHAR_MP_ROBERTO", 1, "Roberto", false, "You don't have enough cash !\n")
return
end
end
TriggerClientEvent("es_freeroam:notify", source, "CHAR_MP_ROBERTO", 1, "Roberto", false, "Here are your weapons !\n")
end)
end)
end)
end)
AddEventHandler('es:newPlayerLoaded', function(source, user)
TriggerEvent('es:exposeDBFunctions', function(db)
db.createDocument('es_weashop', {identifier = user.identifier, weapons = {}, cost = {}}, function()end)
end)
end)
Will give it a “shot” later, only 17 more scripts to convert Kappa
I am actually in the process of converting police and its dependencies such as vdk_inv, vdk_recolt, and gcidentity.
It is obv gonna take awhile but im tired of seing “please convert to work with essentials 3.x.x”
Just tested this now and seems to be working ok. If you manage to get more scripts working i think you will gain a few fans off here, and cops works with couchDb it’s just the other scripts that don’t.
So we lose the weapons on respawn<< that’s a good thing, but their back in players inventory when you disconnect/reconnect, the withdrawal amount is how much it costs the player when you reconnect and get your weapons back. How would we go about setting it so you die and lose them and don’t get them back on reconnecting?.
It is probably doing that because I didnt put any checks for nil values within the creation and update of the database. It wont harm anything but ill look at fixing that later on. As for the guns being gone on respawn that is because im guessing you either have the revive script or another script but if its the one with the folder name ragdoll then this is the code i use to give a 10% chance of losing all weapons on death forever. (it is the code below the police code lol)
and yes police works native with couchdb, however I meant I was building the means to use couchdb for these scripts like this, you see even after i convert these scripts to couchdb police still wouldnt be able to do anything with them unless I write the code to let it. (im using mysql-sync as the driver still until i get them all updated so it doesnt break of course.)
if(config.useVDKInventory == true) then
if(db.driver == "mysql") then
local strResult = txt[config.lang]["checking_inventory_part_1"] .. GetPlayerName(target) .. txt[config.lang]["checking_inventory_part_2"]
local executed_query = MySQL:executeQuery("SELECT * FROM `user_inventory` JOIN items ON items.id = user_inventory.item_id WHERE user_id = '@username'", { ['@username'] = identifier })
local result = MySQL:getResults(executed_query, { 'quantity', 'libelle', 'item_id', 'isIllegal' }, "item_id")
if (result) then
for _, v in ipairs(result) do
if(v.quantity ~= 0) then
strResult = strResult .. v.quantity .. "*" .. v.libelle .. ", "
end
if(v.isIllegal == "1" or v.isIllegal == "True" or v.isIllegal == 1 or v.isIllegal == true) then
TriggerClientEvent('police:dropIllegalItem', target, v.item_id)
end
end
end
TriggerClientEvent("police:notify", source, "CHAR_ANDREAS", 1, txt[config.lang]["title_notification"], false, strResult)
elseif(db.driver == "mysql-async") then
MySQL.Async.fetchAll("SELECT * FROM `user_inventory` JOIN items ON items.id = user_inventory.item_id WHERE user_id = @username", { ['@username'] = identifier }, function (result)
local strResult = txt[config.lang]["checking_inventory_part_1"] .. GetPlayerName(target) .. txt[config.lang]["checking_inventory_part_2"]
for _, v in ipairs(result) do
if(v.quantity ~= 0) then
strResult = strResult .. v.quantity .. "*" .. v.libelle .. ", "
end
if(v.isIllegal == "1" or v.isIllegal == "True" or v.isIllegal == 1 or v.isIllegal == true) then
TriggerClientEvent('police:dropIllegalItem', target, v.item_id)
end
end
TriggerClientEvent("police:notify", source, "CHAR_ANDREAS", 1, txt[config.lang]["title_notification"], false, strResult)
end)
end
end
if(config.useWeashop == true) then
if(db.driver == "mysql") then
local strResult = txt[config.lang]["checking_weapons_part_1"] .. GetPlayerName(target) .. txt[config.lang]["checking_weapons_part_2"]
local executed_query = MySQL:executeQuery("SELECT * FROM user_weapons WHERE identifier = '@username'", { ['@username'] = identifier })
local result = MySQL:getResults(executed_query, { 'weapon_model' }, 'identifier' )
if (result) then
for _, v in ipairs(result) do
strResult = strResult .. v.weapon_model .. ", "
end
end
TriggerClientEvent("police:notify", source, "CHAR_ANDREAS", 1, txt[config.lang]["title_notification"], false, strResult)
elseif(db.driver == "mysql-async") then
local del = {}
local strResult = txt[config.lang]["checking_weapons_part_1"] .. GetPlayerName(target) .. txt[config.lang]["checking_weapons_part_2"]
TriggerEvent('es:getPlayerFromId', target, function(user)
TriggerEvent('es:exposeDBFunctions', function(db)
db.getDocumentByRow('es_weashop', 'identifier', user.identifier, function(dbuser)
for i=1, #dbuser.weapons do
strResult = strResult .. tostring(dbuser.weapons[i]) .. ", "
end
end)
end)
end)
db.updateDocument('es_weashop', dbuser._id, {weapons = del, cost = del})
TriggerClientEvent("police:notify", source, "CHAR_ANDREAS", 1, txt[config.lang]["title_notification"], false, strResult)
end
end
end)
AddEventHandler('chatMessage', function(source, n, message)
cm = stringsplit(message, " ")
if cm[1] == "/rev" then
CancelEvent()
if tablelength(cm) > 1 then
local tG = tonumber(cm[2])
local chances = math.random(1, 1000)
if chances < 100 then
TriggerClientEvent("chatMessage", tG, "REV", {255, 0, 0}, "You seem to have lost you weapons! ")
TriggerEvent('es:getPlayerFromId', tG, function(user)
TriggerEvent('es:exposeDBFunctions', function(db)
local del = {}
db.getDocumentByRow('es_weashop', 'identifier', user.identifier, function(dbuser)
db.updateDocument('es_weashop', dbuser._id, {weapons = del, cost = del})
end)
end)
end)
end
TriggerClientEvent("deathr", tG)
end
end
end)
sorry I kinda rambled there, to answer your question this is how
just put this code in whatever script you have that makes players respawn after death and change tG to either source or whatever variable you have set to get the player. (this is a server script not client)
TriggerEvent('es:getPlayerFromId', tG, function(user)
TriggerEvent('es:exposeDBFunctions', function(db)
local del = {}
db.getDocumentByRow('es_weashop', 'identifier', user.identifier, function(dbuser)
db.updateDocument('es_weashop', dbuser._id, {weapons = del, cost = del})
end)
end)
end)
Police is already converted to Essentialmode 3.x.
I’m just waiting for support scripts (like this one) to add full essentialmode compatibility
Would anyone know how to fix foreign key error?
https://gyazo.com/0b1dd13c4bfcf76565153181abcd93a9
Thanks in advance
Try this if you have trouble.
I managed to sort it by deleting some of the sql and it looks like what you posted there. I seen someone have the same problem in another script so managed to fix it that way. Thanks
For some reason, weapons aren’t being given on connecting. They are saving to the database and i’m being charged the fee when connecting but the weapons aren’t being given out.
I’ve used your code above and also
CREATE TABLE IF NOT EXISTS user_weapons
(
id
int AUTO_INCREMENT,
identifier
varchar(255) NOT NULL,
weapon_model
varchar(255) NOT NULL,
withdraw_cost
int NOT NULL,
PRIMARY KEY (id
)) ENGINE=InnoDB DEFAULT CHARSET=utf8 ;
but both had the same result.
So it isn’t this causing the error but i’m still not getting the weapons when i connect.
Edit - If i go to the police station and start shift then end my shift i get my guns back, it’s just when i spawn in to the server i don’t get them.
Edit - So if i spawn on the server as default character (Michael even though it’s set to mp_m_freemode_01) i get my weapons, if i activate model-menu OR clothing shop and spawn as my saved character i don’t get them.
Why do people say “■■■■■■■■■■■■■■” and not just “EssentialMode”??