Jump to content

I need help please


Hero192

Recommended Posts

Hey guys,

i want make CJ Clothes Shop and i stuck,

i want these clothes on table shows in gridlist and i can buy them.

Here's my code:

--client side:

cjwindow = guiCreateWindow(519,174,313,332,"CJ",false) 
guiSetVisible (cjwindow, false) 
buybtn = guiCreateButton(13,297,131,27,"Buy",false,cjwindow) 
rejectbtn = guiCreateButton(170,297,131,27,"Cancel",false,cjwindow) 
  
cjGrid = guiCreateGridList(9,20,295,274,false,cjwindow) 
guiGridListSetSelectionMode(cjGrid,0) 
guiGridListAddColumn(cjGrid,"CJ Clothes:",0.85) 
  
addEvent("cjshop:show",true) 
addEventHandler("cjshop:show",root, 
function (cjTable) 
   guiSetVisible(cjwindow,true) 
   showCursor(true) 
   guiGridListClear(cjGrid) 
  for i,v in ipairs (cjTable.allClothes) do 
  local row = guiGridListAddRow (cjGrid) 
  guiGridListSetItemText (cjGrid, row, 1, v[1], false, false) 
    end 
end) 
  
addEventHandler ("onClientGUIClick", root, 
function () 
        if (source == rejectbtn) then 
        guiSetVisible(cjwindow,false) 
        showCursor(false) 
   elseif (source == buybtn) then 
   local row,col = guiGridListGetSelectedItem(cjGrid) 
        if row and col and row ~= -1 and col ~= -1 then 
  
      guiSetVisible(cjwindow,false) 
      showCursor(false) 
      local clothes = guiGridListGetItemText (cjGrid, guiGridListGetSelectedItem (cjGrid), 1) 
      triggerServerEvent("cjshop:buy",localPlayer, clothes,guiGridListGetSelectedItem(cjGrid)+1) 
      else  
      outputChatBox("CJ Clothes Shop: You didn't selecte your clothes.",121,180,23)       
        end 
    end 
end) 

--server side:

local cjclothesmarker = { 
[1]={x=1648.5601806641,y=1732.7150878906,z=10.671875,dim=0,int=0} 
} 
  
local cjTable = { 
    ["Torso"] = 100, 
    ["Hair"] = 130, 
    ["Legs"] = 150, 
    ["Shoes"] = 170, 
    ["Left Upper Arm"] = 110, 
    ["Left Lower Arm"] = 110, 
    ["Right Upper Arm"] = 110, 
    ["Right Lower Arm"] = 110, 
    ["Black Top"] = 120, 
    ["Left Chest"] = 120, 
    ["Right Chest"] = 120, 
    ["Stomach"] = 140, 
    ["Lower Back"] = 140, 
    ["Extra1"] = 200, 
    ["Extra2"] = 230, 
    ["Extra3"] = 260, 
    ["Extra4"] = 250, 
    ["Suit"] , 
} 
  
addEventHandler("onResourceStart",resourceRoot, 
function () 
    for index, pos in pairs(cjclothesmarker) do 
        local cjmarker = createMarker(pos.x, pos.y, pos.z-1, "cylinder", 1.6,  247,187, 7, 120) 
        setElementInterior(cjmarker, pos.int) 
        setElementDimension(cjmarker, pos.dim) 
        addEventHandler("onMarkerHit",cjmarker,onCJMarkerHit) 
    end 
end) 
  
function onCJMarkerHit(player, dim) 
    if not dim then return end 
    if getElementType(player) == "player" then 
    if getElementModel(player) > 0 then  
    outputChatBox("Clothing Shop: You need the CJ skin to be able to buy clothes.",player,255,0,0) return end 
            local result = {} 
        local texture, model 
        -- get all clothes 
        result.allClothes = {} 
        result.playerClothes = {} 
        for type=0,17 do 
            table.insert(result.allClothes, {type = type, name = getClothesTypeName(type)}) 
            texture, model = getPedClothes(player, type) 
            if texture then 
                result.playerClothes[type] = {texture = texture, model = model} 
            end          
        end 
        triggerClientEvent(player,"cjshop:show",player,result) 
    end 
end 
  

Link to comment

--server side; i just didn't copied the full code

local cjclothesmarker = { 
[1]={x=1648.5601806641,y=1732.7150878906,z=10.671875,dim=0,int=0} 
} 
  
local cjTable = { 
    ["Torso"] = 100, 
    ["Hair"] = 130, 
    ["Legs"] = 150, 
    ["Shoes"] = 170, 
    ["Left Upper Arm"] = 110, 
    ["Left Lower Arm"] = 110, 
    ["Right Upper Arm"] = 110, 
    ["Right Lower Arm"] = 110, 
    ["Black Top"] = 120, 
    ["Left Chest"] = 120, 
    ["Right Chest"] = 120, 
    ["Stomach"] = 140, 
    ["Lower Back"] = 140, 
    ["Extra1"] = 200, 
    ["Extra2"] = 230, 
    ["Extra3"] = 260, 
    ["Extra4"] = 250, 
    ["Suit"] , 
} 
  
addEventHandler("onResourceStart",resourceRoot, 
function () 
    for index, pos in pairs(cjclothesmarker) do 
        local cjmarker = createMarker(pos.x, pos.y, pos.z-1, "cylinder", 1.6,  247,187, 7, 120) 
        setElementInterior(cjmarker, pos.int) 
        setElementDimension(cjmarker, pos.dim) 
        addEventHandler("onMarkerHit",cjmarker,onCJMarkerHit) 
    end 
end) 
  
function onCJMarkerHit(player, dim) 
    if not dim then return end 
    if getElementType(player) == "player" then 
    if getElementModel(player) > 0 then 
    outputChatBox("Clothing Shop: You need the CJ skin to be able to buy clothes.",player,255,0,0) return end 
            local result = {} 
        local texture, model 
        -- get all clothes 
        result.allClothes = {} 
        result.playerClothes = {} 
        for type=0,17 do 
            table.insert(result.allClothes, {type = type, name = getClothesTypeName(type)}) 
            texture, model = getPedClothes(player, type) 
            if texture then 
                result.playerClothes[type] = {texture = texture, model = model} 
            end         
        end 
        triggerClientEvent(player,"cjshop:show",player,result) 
    end 
end 
  
addEvent("cjshop:buy",true) 
addEventHandler("cjshop:buy",root, 
function (client, tempTable) 
local cashToPay = 0 
    if (#tempTable > 0) then 
        for index, cloth in pairs(tempTable) do 
            if clothingPrices[getClothesTypeName(getTypeIndexFromClothes(cloth[1], cloth[2]))] then 
                cashToPay = cashToPay + tonumber(clothingPrices[getClothesTypeName(getTypeIndexFromClothes(cloth[1], cloth[2]))]) 
            end 
        end 
    end 
    if getPlayerMoney(client) >= cashToPay then 
    outputChatBox(client,"CJ Shop: you don't have money to buy clothes.",255,0,0) 
    for index, cloth in pairs(tempTable) do 
        addPedClothes(client, cloth[1], cloth[2], getTypeIndexFromClothes(cloth[1], cloth[2])) 
    end 
    saveNewClothing(client) 
    takePlayerMoney(client, tonumber(cashToPay)) 
    outputChatBox(client, "Clothing shop: Come back soon!",0,255,0) 
    else 
        outputChatBox(client, "Clothing shop: You need "..tonumber(cashToPay) .." to buy this clothing.",255,0,0) 
    end 
end) 
  
function saveNewClothing(player) 
    for type=0,17 do 
        local texture, model = getPedClothes(player, type) 
        setAccountData(getPlayerAccount(player),"clothes_".. type,tostring(texture) ..",".. tostring(model)) 
    end 
end 
  

Edited by Guest
Link to comment
local cjclothesmarker = { 
[1]={x=1648.5601806641,y=1732.7150878906,z=10.671875,dim=0,int=0} 
} 
  
local cjTable = { 
    ["Torso"] = 100, 
    ["Hair"] = 130, 
    ["Legs"] = 150, 
    ["Shoes"] = 170, 
    ["Left Upper Arm"] = 110, 
    ["Left Lower Arm"] = 110, 
    ["Right Upper Arm"] = 110, 
    ["Right Lower Arm"] = 110, 
    ["Black Top"] = 120, 
    ["Left Chest"] = 120, 
    ["Right Chest"] = 120, 
    ["Stomach"] = 140, 
    ["Lower Back"] = 140, 
    ["Extra1"] = 200, 
    ["Extra2"] = 230, 
    ["Extra3"] = 260, 
    ["Extra4"] = 250 
} 
  
addEventHandler("onResourceStart",resourceRoot, 
function () 
    for index, pos in pairs(cjclothesmarker) do 
        local cjmarker = createMarker(pos.x, pos.y, pos.z-1, "cylinder", 1.6,  247,187, 7, 120) 
        setElementInterior(cjmarker, pos.int) 
        setElementDimension(cjmarker, pos.dim) 
        addEventHandler("onMarkerHit",cjmarker,onCJMarkerHit) 
    end 
end) 
  
function onCJMarkerHit(player, dim) 
    if not dim then return end 
    if getElementType(player) == "player" then 
    if getElementModel(player) > 0 then 
    outputChatBox("Clothing Shop: You need the CJ skin to be able to buy clothes.",player,255,0,0) return end 
            local result = {} 
        local texture, model 
        -- get all clothes 
        result.allClothes = {} 
        result.playerClothes = {} 
        for type=0,17 do 
            table.insert(result.allClothes, {type = type, name = getClothesTypeName(type)}) 
            texture, model = getPedClothes(player, type) 
            if texture then 
                result.playerClothes[type] = {texture = texture, model = model} 
            end         
        end 
        triggerClientEvent(player,"cjshop:show",player,result) 
    end 
end 
  
addEvent("cjshop:buy",true) 
addEventHandler("cjshop:buy",root, 
function (client, tempTable) 
local cashToPay = 0 
    if (#tempTable > 0) then 
        for index, cloth in pairs(tempTable) do 
            if clothingPrices[getClothesTypeName(getTypeIndexFromClothes(cloth[1], cloth[2]))] then 
                cashToPay = cashToPay + tonumber(clothingPrices[getClothesTypeName(getTypeIndexFromClothes(cloth[1], cloth[2]))]) 
            end 
        end 
    end 
    if getPlayerMoney(client) >= cashToPay then 
    outputChatBox(client,"CJ Shop: you don't have money to buy clothes.",255,0,0) 
    for index, cloth in pairs(tempTable) do 
        addPedClothes(client, cloth[1], cloth[2], getTypeIndexFromClothes(cloth[1], cloth[2])) 
    end 
    saveNewClothing(client) 
    takePlayerMoney(client, tonumber(cashToPay)) 
    outputChatBox(client, "Clothing shop: Come back soon!",0,255,0) 
    else 
        outputChatBox(client, "Clothing shop: You need "..tonumber(cashToPay) .." to buy this clothing.",255,0,0) 
    end 
end) 
  
function saveNewClothing(player) 
    for type=0,17 do 
        local texture, model = getPedClothes(player, type) 
        setAccountData(getPlayerAccount(player),"clothes_".. type,tostring(texture) ..",".. tostring(model)) 
    end 
end 
  

Link to comment
There are. I tested it.

Yeah man you're right,

but there's a problem when i selecte to buy the clothes plus it shows as numbers not names idk why i tried

tostring 

but not working

ERROR:60: attempt to get length of local 'tempTable' (a number value)

Link to comment
local cjclothesmarker = { 
[1]={x=1648.5601806641,y=1732.7150878906,z=10.671875,dim=0,int=0} 
} 
  
local cjTable = { 
    ["Torso"] = 100, 
    ["Hair"] = 130, 
    ["Legs"] = 150, 
    ["Shoes"] = 170, 
    ["Left Upper Arm"] = 110, 
    ["Left Lower Arm"] = 110, 
    ["Right Upper Arm"] = 110, 
    ["Right Lower Arm"] = 110, 
    ["Black Top"] = 120, 
    ["Left Chest"] = 120, 
    ["Right Chest"] = 120, 
    ["Stomach"] = 140, 
    ["Lower Back"] = 140, 
    ["Extra1"] = 200, 
    ["Extra2"] = 230, 
    ["Extra3"] = 260, 
    ["Extra4"] = 250 
} 
  
addEventHandler("onResourceStart",resourceRoot, 
function () 
    for index, pos in pairs(cjclothesmarker) do 
        local cjmarker = createMarker(pos.x, pos.y, pos.z-1, "cylinder", 1.6,  247,187, 7, 120) 
        setElementInterior(cjmarker, pos.int) 
        setElementDimension(cjmarker, pos.dim) 
        addEventHandler("onMarkerHit",cjmarker,onCJMarkerHit) 
    end 
end) 
  
function onCJMarkerHit(player, dim) 
    if not dim then return end 
    if getElementType(player) == "player" then 
    if getElementModel(player) > 0 then 
    outputChatBox("Clothing Shop: You need the CJ skin to be able to buy clothes.",player,255,0,0) return end 
            local result = {} 
        local texture, model 
        -- get all clothes 
        result.allClothes = {} 
        result.playerClothes = {} 
        for type=0,17 do 
            table.insert(result.allClothes, {type = type, name = getClothesTypeName(type)}) 
            texture, model = getPedClothes(player, type) 
            if texture then 
                result.playerClothes[type] = {texture = texture, model = model} 
            end         
        end 
        triggerClientEvent(player,"cjshop:show",player,result) 
    end 
end 
  
addEvent("cjshop:buy",true) 
addEventHandler("cjshop:buy",root, 
function (n) 
    local cashToPay = 0 
    if cjTable[n] then 
        cashToPay = cashToPay + tonumber(cjTable[n]) 
    end 
    if getPlayerMoney(client) >= cashToPay then 
    outputChatBox("CJ Shop: you don't have money to buy clothes.",client,255,0,0) 
    for index, cloth in pairs(tempTable) do 
        addPedClothes(client, cloth[1], cloth[2], getTypeIndexFromClothes(cloth[1], cloth[2])) 
    end 
    saveNewClothing(client) 
    takePlayerMoney(client, tonumber(cashToPay)) 
    outputChatBox("Clothing shop: Come back soon!",client,0,255,0) 
    else 
        outputChatBox("Clothing shop: You need "..tonumber(cashToPay) .." to buy this clothing.",client,255,0,0) 
    end 
end) 
  
function saveNewClothing(player) 
    for type=0,17 do 
        local texture, model = getPedClothes(player, type) 
        setAccountData(getPlayerAccount(player),"clothes_".. type,tostring(texture) ..",".. tostring(model)) 
    end 
end 

cjwindow = guiCreateWindow(519,174,313,332,"CJ",false) 
guiSetVisible (cjwindow, false) 
buybtn = guiCreateButton(13,297,131,27,"Buy",false,cjwindow) 
rejectbtn = guiCreateButton(170,297,131,27,"Cancel",false,cjwindow) 
  
cjGrid = guiCreateGridList(9,20,295,274,false,cjwindow) 
guiGridListSetSelectionMode(cjGrid,0) 
guiGridListAddColumn(cjGrid,"CJ Clothes:",0.85) 
  
addEvent("cjshop:show",true) 
addEventHandler("cjshop:show",root, 
function (cjTable) 
   guiSetVisible(cjwindow,true) 
   showCursor(true) 
   guiGridListClear(cjGrid) 
  for i,v in ipairs (cjTable.allClothes) do 
  local row = guiGridListAddRow (cjGrid) 
  guiGridListSetItemText (cjGrid, row, 1, v.name, false, false) 
    end 
end) 
  
addEventHandler ("onClientGUIClick", root, 
function () 
        if (source == rejectbtn) then 
        guiSetVisible(cjwindow,false) 
        showCursor(false) 
   elseif (source == buybtn) then 
   local row,col = guiGridListGetSelectedItem(cjGrid) 
        if row and col and row ~= -1 and col ~= -1 then 
  
      guiSetVisible(cjwindow,false) 
      showCursor(false) 
      local clothes = guiGridListGetItemText (cjGrid, guiGridListGetSelectedItem (cjGrid), 1) 
      triggerServerEvent("cjshop:buy",localPlayer, clothes) 
      else 
      outputChatBox("CJ Clothes Shop: You didn't selecte your clothes.",121,180,23)       
        end 
    end 
end) 

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...