Hero192 Posted August 6, 2015 Share Posted August 6, 2015 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
GTX Posted August 6, 2015 Share Posted August 6, 2015 More details please... You are missing cjshop:buy event. Link to comment
Hero192 Posted August 6, 2015 Author Share Posted August 6, 2015 (edited) --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 August 6, 2015 by Guest Link to comment
Hero192 Posted August 6, 2015 Author Share Posted August 6, 2015 When i hit the marker i get the gui visible but with out rows (cj clothes..) only colums here's the warning WARNING:client.lua:20: atempt to index global 'cat' (a nil value) Link to comment
GTX Posted August 6, 2015 Share Posted August 6, 2015 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
Hero192 Posted August 7, 2015 Author Share Posted August 7, 2015 Doesn't works it give warning bad argument line 18 --client side guiGridListSetItemText (cjGrid, row, 1, v[1], false, false) Link to comment
Hero192 Posted August 7, 2015 Author Share Posted August 7, 2015 Anyone can give hand please? Link to comment
GTX Posted August 7, 2015 Share Posted August 7, 2015 guiGridListSetItemText (cjGrid, row, 1, v.type, false, false) Link to comment
Hero192 Posted August 7, 2015 Author Share Posted August 7, 2015 Now no errors about that but i still have the problem about rows, when i hit the marker i have no rows of clothes in gridlist Link to comment
Hero192 Posted August 7, 2015 Author Share Posted August 7, 2015 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
GTX Posted August 7, 2015 Share Posted August 7, 2015 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
Hero192 Posted August 7, 2015 Author Share Posted August 7, 2015 If i selected Torso for example CJ can't use it as clothes, i mean i need to get list of torso..etc like in this screenshot http://imgur.com/uQQwaBJ thanks for your help @GTX Link to comment
Hero192 Posted August 7, 2015 Author Share Posted August 7, 2015 I think so but i have no idea about how to use it thats why im asking for help Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now