Jump to content

[HELP] Skin Save List


Lalalu

Recommended Posts

Hello there! thanks for visiting my post.

Some of you helped me a lot a few months ago with a skin save list using database.

Today, this post is to ask you if its possible to add skins to that list from another script, for example using a command from another external script.

This is the code i'm using;

Server side

function myskins(thePlayer,commandName) if thePlayer then local acc = getPlayerAccount( thePlayer ) local acc_name = getAccountName( acc ) local q = dbQuery(connection,"SELECT username,skin FROM skins WHERE username=?",tostring(acc_name)) local rezult = dbPoll(q,-1) if #rezult > 0 then triggerClientEvent(thePlayer,"skin_inventory",thePlayer,rezult) end end end addCommandHandler("myskins",myskins,false,false) addEvent("ChangeSkin",true) change_skin = function(Player,skin) if source == Player and client == source then setElementModel(Player,skin) end end addEventHandler("ChangeSkin",getRootElement(),change_skin)

Client side

function centerWindow (center_window) local screenW, screenH = guiGetScreenSize() local windowW, windowH = guiGetSize(center_window, false) local x, y = (screenW - windowW) /2,(screenH - windowH) /2 return guiSetPosition(center_window, x, y, false) end addEvent("skin_inventory",true)
function skin_inventory_gui(rezult) skin_list = guiCreateWindow(329, 246, 465, 381, "MY SKINS", false) centerWindow(skin_list) guiWindowSetMovable(skin_list, false) guiWindowSetSizable(skin_list, false) skins = guiCreateGridList(9, 20, 376, 351, false, skin_list) guiGridListAddColumn(skins, "Description", 0.5) guiGridListAddColumn(skins, "Model/Skin Owned", 0.5) close = guiCreateButton(389, 20, 66, 21, "X", false, skin_list) set_skin = guiCreateButton(389, 40, 66, 21, "SET SKIN", false, skin_list) guiSetProperty(close, "NormalTextColour", "FFAAAAAA") showCursor(true) for key, value in ipairs(rezult) do 
local row = guiGridListAddRow(skins) guiGridListSetItemText (skins, row, 1, "Skin Model ->", false, true)
    guiGridListSetItemText (skins, row, 2, value.skin, false, true)
  end 
  addEventHandler ( "onClientGUIClick", close, closeinventory,false) 
 addEventHandler ( "onClientGUIClick", set_skin, closeinventory,false)
end addEventHandler("skin_inventory",root,skin_inventory_gui) closeinventory = function(button,state) 
  if (button == "left") and (state == "up") then if source == set_skin then if (guiGridListGetSelectedItem (skins)) then local skin_to_change = guiGridListGetItemText (skins, guiGridListGetSelectedItem (skins), 2) triggerServerEvent("ChangeSkin",localPlayer,localPlayer,skin_to_change) outputChatBox("[SKIN SYSTEM] You have changed your skin",160,255,160) end end showCursor (false) guiSetVisible(skin_list,false) end end 

 

Edited by Lalalu
  • Like 1
Link to comment
19 hours ago, Lalalu said:

Hello there! thanks for visiting my post.

Some of you helped me a lot a few months ago with a skin save list using database.

Today, this post is to ask you if its possible to add skins to that list from another script, for example using a command from another external script.

This is the code i'm using;

Server side

function myskins(thePlayer,commandName) if thePlayer then local acc = getPlayerAccount( thePlayer ) local acc_name = getAccountName( acc ) local q = dbQuery(connection,"SELECT username,skin FROM skins WHERE username=?",tostring(acc_name)) local rezult = dbPoll(q,-1) if #rezult > 0 then triggerClientEvent(thePlayer,"skin_inventory",thePlayer,rezult) end end end addCommandHandler("myskins",myskins,false,false) addEvent("ChangeSkin",true) change_skin = function(Player,skin) if source == Player and client == source then setElementModel(Player,skin) end end addEventHandler("ChangeSkin",getRootElement(),change_skin)

Client side

function centerWindow (center_window) local screenW, screenH = guiGetScreenSize() local windowW, windowH = guiGetSize(center_window, false) local x, y = (screenW - windowW) /2,(screenH - windowH) /2 return guiSetPosition(center_window, x, y, false) end addEvent("skin_inventory",true)
function skin_inventory_gui(rezult) skin_list = guiCreateWindow(329, 246, 465, 381, "MY SKINS", false) centerWindow(skin_list) guiWindowSetMovable(skin_list, false) guiWindowSetSizable(skin_list, false) skins = guiCreateGridList(9, 20, 376, 351, false, skin_list) guiGridListAddColumn(skins, "Description", 0.5) guiGridListAddColumn(skins, "Model/Skin Owned", 0.5) close = guiCreateButton(389, 20, 66, 21, "X", false, skin_list) set_skin = guiCreateButton(389, 40, 66, 21, "SET SKIN", false, skin_list) guiSetProperty(close, "NormalTextColour", "FFAAAAAA") showCursor(true) for key, value in ipairs(rezult) do 
local row = guiGridListAddRow(skins) guiGridListSetItemText (skins, row, 1, "Skin Model ->", false, true)
    guiGridListSetItemText (skins, row, 2, value.skin, false, true)
  end 
  addEventHandler ( "onClientGUIClick", close, closeinventory,false) 
 addEventHandler ( "onClientGUIClick", set_skin, closeinventory,false)
end addEventHandler("skin_inventory",root,skin_inventory_gui) closeinventory = function(button,state) 
  if (button == "left") and (state == "up") then if source == set_skin then if (guiGridListGetSelectedItem (skins)) then local skin_to_change = guiGridListGetItemText (skins, guiGridListGetSelectedItem (skins), 2) triggerServerEvent("ChangeSkin",localPlayer,localPlayer,skin_to_change) outputChatBox("[SKIN SYSTEM] You have changed your skin",160,255,160) end end showCursor (false) guiSetVisible(skin_list,false) end end 

 

Yes you can add skins from another script with a command but how your command is looking or in which way you want to use that command to add skins?

Link to comment
7 hours ago, FlorinSzasz said:

Yes you can add skins from another script with a command but how your command is looking or in which way you want to use that command to add skins?

Well, i want to achieve that with my inventory system (another script) opening a box gives you a skin and add it to the gridlist. I want to know how can I add a skin to that gridlist  from another script so i can try to use it with my inventory.

Edited by Lalalu
  • Like 1
Link to comment

well first you should add this code to the server side (i have a copy of the code i gave you long time ago for skinInventory)

addSkinFromBox = function(player,model) -- after model add coins / money the player used to buy the box if he used
    if model ~= nil then  
    local acc_name = getAccountName(getPlayerAccount(player))
    local query = dbQuery(connection,"SELECT username,skin FROM skins WHERE username=? AND skin=? LIMIT 1",tostring(acc_name),tonumber(model))
    local rez = dbPoll(query,-1)
        if #rez > 0 then
            outputChatBox("[SKIN_SYSTEM] You have this skin already!",player)
            -- if he pays with something give the player money back or coins or something else if you should give him.
        elseif #rez == 0 then 
            -- if he doesnt have the skin update db and insert it to db!
            dbExec(connection,"INSERT INTO skins (username,skin) VALUES (?,?)",tostring(acc_name),tonumber(model))
            outputChatBox("[SKIN_SYSTEM] You got a new Skin!",player,104,255,104)
        end 
    end 
end 

Also If your inventory system script is in another folder you have to add this in the meta.xml where your skininventory resource is (not the inventory resource)

<export function="addSkinFromBox" type="server"/> 

And in the inventory resource where is your openBox event or function use this call.

exports["test"]:addSkinFromBox(player,model)
-- between -> " " you put your resource name folder where your skinInventory scripts are for example my skin inventory resource is in test folder
-- player -> you put the player variable or thePlayer or client it depends what variable you have in you inventory script.
-- model -> the model variable or how it is named in your resource.

AND  if your inventory script is in the same folder with skinInventory script then you only add this in your openBox event or function! ->

addSkinFromBox(player,model)

 

Link to comment
3 hours ago, FlorinSzasz said:

well first you should add this code to the server side (i have a copy of the code i gave you long time ago for skinInventory)

addSkinFromBox = function(player,model) -- after model add coins / money the player used to buy the box if he used
    if model ~= nil then  
    local acc_name = getAccountName(getPlayerAccount(player))
    local query = dbQuery(connection,"SELECT username,skin FROM skins WHERE username=? AND skin=? LIMIT 1",tostring(acc_name),tonumber(model))
    local rez = dbPoll(query,-1)
        if #rez > 0 then
            outputChatBox("[SKIN_SYSTEM] You have this skin already!",player)
            -- if he pays with something give the player money back or coins or something else if you should give him.
        elseif #rez == 0 then 
            -- if he doesnt have the skin update db and insert it to db!
            dbExec(connection,"INSERT INTO skins (username,skin) VALUES (?,?)",tostring(acc_name),tonumber(model))
            outputChatBox("[SKIN_SYSTEM] You got a new Skin!",player,104,255,104)
        end 
    end 
end 

Also If your inventory system script is in another folder you have to add this in the meta.xml where your skininventory resource is (not the inventory resource)

<export function="addSkinFromBox" type="server"/> 

And in the inventory resource where is your openBox event or function use this call.

exports["test"]:addSkinFromBox(player,model)
-- between -> " " you put your resource name folder where your skinInventory scripts are for example my skin inventory resource is in test folder
-- player -> you put the player variable or thePlayer or client it depends what variable you have in you inventory script.
-- model -> the model variable or how it is named in your resource.

AND  if your inventory script is in the same folder with skinInventory script then you only add this in your openBox event or function! ->

addSkinFromBox(player,model)

 

Thank you. OK ok im gonna try that

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...