Hello All,
I have created a plugin that allows a user to add 5 items to their “inventory” and then recall it… BUT is only works on a local basis… I.E… If a user (1) adds 5 items and then does /search 1 it will recall the items but if another person on the server does /search 1 then it wont work…
I believe the problem is that the main chunk of code which saves the information is client side instead of server side… I have tried switching the code around so the script is server side instead but then everything breaks…
After many hours researching i still cannot find the answer i am looking for… So my questions are;
Can you request information from a client and update a server script?
Does the server script need to be in LUA or can it be in a .dll format?
Client side [C#];
if (Game.Player.Character.Model.IsLoaded == true)
{
Dictionary<string, string[]> inventoryDict = new Dictionary<string, string[]>();
int pID = CitizenFX.Core.Native.API.GetPlayerServerId(Game.Player.Handle);
string ServerID = Convert.ToString(pID);
string PlayerHandle = Convert.ToString(Game.Player.ServerId);
EventHandlers["PlayerSearch:AddItem"] += new Action<string>((string message) =>
{
string[] items = message.Split(',');
if (message != null)
{
inventoryDict.Add(ServerID, new string[5] { items[0], items[1], items[2], items[3], items[4] });
TriggerEvent("chatMessage", "Inventory", new int[] { 255, 255, 0 }, items[0] + ", " + items[1] + ", " + items[2] + ", " + items[3] + " and " + items[4] + " have been added to your inventory" + " {" + ServerID + "} ");
}
});
Server side [LUA]
AddEventHandler('chatMessage', function(source, name, message)
cm = stringsplit(message, " ")
if(cm[1] == "/additem") then
CancelEvent()
table.remove(cm, 1)
TriggerClientEvent("PlayerSearch:AddItem", source, table.concat(cm, " "))
end
if(cm[1] == "/removeitem") then
CancelEvent()
table.remove(cm, 1)
TriggerClientEvent("PlayerSearch:ClearItem", source, table.concat(cm, " "))
end
if(cm[1] == "/search") then
CancelEvent()
table.remove(cm, 1)
TriggerClientEvent("PlayerSearch:Search", source, table.concat(cm, " "))
end
end)