Jump to content

Skin selection menu edit


koragg

Recommended Posts

Hello, it's been some time since I found this awesome resource (click) but I need help with making it work on my race server. As I know posting code here is prefered here goes:

Client

local screenWidth, screenHeight = guiGetScreenSize()

function createSkinWindow()
	windowWidth, windowHeight = 335, 414
	windowX, windowY = (screenWidth / 1) - (windowWidth / 1), (screenHeight / 2) - (windowHeight / 2)
	skinWindow = guiCreateWindow(windowX, windowY, windowWidth, windowHeight, "CORPG Skin Shop", false)
	guiSetAlpha(skinWindow, 1)
	skinGridlist = guiCreateGridList(9, 25, 317, 325, false, skinWindow)
	skinTitleColumn = guiGridListAddColumn(skinGridlist, "Title", 0.45)
	skinIDColumn = guiGridListAddColumn(skinGridlist, "ID", 0.2)
	skinBuyButton = guiCreateButton(9, 371, 132, 33, "Buy Skin\n$500", false, skinWindow)
	skinExitButton = guiCreateButton(194, 371, 132, 33, "Exit", false, skinWindow)
	guiSetVisible(skinWindow, false)

	--Events
	addEventHandler("onClientGUIClick", skinExitButton, function () guiSetVisible(skinWindow, false) showCursor(false) setPlayerHudComponentVisible("all", true) setElementModel(localPlayer, model) setElementFrozen(localPlayer, false) end, false)
	addEventHandler("onClientGUIClick", skinBuyButton, buySkin, false)
	addEventHandler("onClientGUIClick", skinGridlist, previewSkin, false)
end
addEventHandler("onClientResourceStart", resourceRoot, createSkinWindow)

function showSkin(skinsTable)
	guiGridListClear(skinGridlist)
	setElementFrozen(localPlayer, true)
	for category, skins in pairs(skinsTable) do
		local row = guiGridListAddRow(skinGridlist)
		guiGridListSetItemText(skinGridlist, row, 1, category, true, false)
		for id, name in pairs(skins) do
			local row = guiGridListAddRow(skinGridlist)
			guiGridListSetItemText(skinGridlist, row, 1, name, false, false)
			guiGridListSetItemText(skinGridlist, row, 2, id, false, false)
		end
	end
	guiSetVisible(skinWindow, true)
	showCursor(true)
	model = getElementModel(localPlayer)
end
addEvent("clothes.showSkin", true)
addEventHandler("clothes.showSkin", root, showSkin)

function previewSkin()
	local row = guiGridListGetSelectedItem(skinGridlist)
	if (not row or row == -1) then return end
	local id = guiGridListGetItemText(skinGridlist, row, 2)
	id = tonumber(id)
	if (not id) then return end
	setElementModel(localPlayer, id)
end

function buySkin()
	if (getPlayerMoney() <= 500) then
		outputChatBox("You can not afford to buy this skin", 255, 0, 0)
		return
	end
	local row = guiGridListGetSelectedItem(skinGridlist)
	if (not row or row == -1) then return end
	local id = guiGridListGetItemText(skinGridlist, row, 2)
	id = tonumber(id)
	if (not id) then return end
	setElementModel(localPlayer, model)
	setElementFrozen(localPlayer, false)
	guiSetVisible(skinWindow, false)
	showCursor(false)
	triggerServerEvent("clothes.buySkin", root, id)
	triggerServerEvent("clothes.buySkin", root, id)
end

Server

skinsTable = {}
skinsTable.all = {}
skinsTable.categories = {}
shops = {
	--x, y, z, dimension, interior
	{ x = 207.60717773438, y = -100.33073425293, z = 1004.2578125, dim = 0, int = 15},
	{ x = 161.3233795166, y = -83.255378723145, z = 1000.8046875, dim = 0, int = 18},
	{ x = 207.02481079102, y = -129.17749023438, z = 1002.5078125, dim = 0, int = 3},
	{ x = 204.39889526367, y = -159.35827636719, z = 999.5234375, dim = 0, int = 14},
	{ x = 206.37413024902, y = -8.2102794647217, z = 1000.2109375, dim = 0, int = 5},
	{ x = 207.55685424805, y = -100.3268737793, z = 1004.2578125, dim = 1, int = 15},
	{ x = 161.33987426758, y = -83.251647949219, z = 1000.8046875, dim = 1, int = 18},
	{ x = 206.37982177734, y = -8.0149660110474, z = 1000.2109375, dim = 1, int = 5},
	{ x = 207.58236694336, y = -100.33797454834, z = 1004.2578125, dim = 2, int = 15},
	{ x = 161.47146606445, y = -83.262077331543, z = 1000.8046875, dim = 2, int = 18},
	{ x = 161.37335205078, y = -83.253326416016, z = 1000.8046875, dim = 3, int = 18},
	{ x = 207.55435180664, y = -100.32672119141, z = 1004.2578125, dim = 3, int = 15},
	{ x = 206.95558166504, y = -129.18096923828, z = 1002.5078125, dim = 1, int = 3},
	{ x = 206.37959289551, y = -7.8779788017273, z = 1000.2109375, dim = 2, int = 5},
}

function loadSkins()
	local xml = xmlLoadFile("files/skins.xml")
	for index, category in pairs(xmlNodeGetChildren(xml)) do
		local cName = xmlNodeGetAttribute(category, "name")
		skinsTable.categories[cName] = {}
		for index, skin in pairs(xmlNodeGetChildren(category)) do
			local id, name = xmlNodeGetAttribute(skin, "model"), xmlNodeGetAttribute(skin, "name")
			skinsTable.categories[cName][id] = name
			skinsTable.all[id] = name
		end
	end
	xmlUnloadFile(xml)
end
addEventHandler("onResourceStart", resourceRoot, loadSkins)

function getSkinsTable(category)
	if not category then
		return  skinsTable.categories or false
	elseif category == "all" then
		return skinsTable.all or false
	else
		return skinsTable[category] or false
	end
	return false
end

function createSkinShops()
	for index, shop in pairs(shops) do
		local x, y, z, int, dim = shop.x, shop.y, shop.z, shop.int, shop.dim
		marker = createMarker(x, y, z, "cylinder", 1.5, 255, 255, 0, 170)
		setElementInterior(marker, int)
		setElementDimension(marker, dim)
		addEventHandler("onMarkerHit", marker, enteredShop)
	end
end
addEventHandler("onResourceStart", resourceRoot, createSkinShops)

function enteredShop(player, matchingDim)
	if (player and getElementType(player) == "player" and matchingDim) then
		local skins = getSkinsTable()
		triggerClientEvent(player, "clothes.showSkin", player, skins)
		triggerClientEvent(player, "clothes.showSkin", player, skins)
	end
end

function buySkin(model)
	if (getPlayerMoney(client) >= 500) then
		takePlayerMoney(client, 500)
		outputChatBox("You have succesfully bought the skin!", client, 0, 255, 0)
		setAccountData(getPlayerAccount(client), "clothes.boughtSkin", model)
		setElementModel(client, model)
	end
end
addEvent("clothes.buySkin", true)
addEventHandler("clothes.buySkin", root, buySkin)

function getBoughtSkin(player)
	if (not isElement(player)) then return end
	return tonumber(getAccountData(getPlayerAccount(player), "clothes.boughtSkin")) or 0
end

meta

<meta>
    <info author="Anubhav" type="script" name="[A-Team-Skin Shop" descriptions="Skin Shop" version="1.3.4"/>
    <script src="clothes_c.lua" type="client"/>
	<script src="clothes_s.lua" type="server"/>
	
	<export function="getBoughtSkin" type="server"/>
	<min_mta_version server="1.3.1-9.04939.0" client="1.3.1-9.04939.0"/>
</meta>

files/skins.xml

<skins>
	<group name="Special">
		<skin model="1" name="Truth" />
		<skin model="2" name="Maccer" />
		<skin model="265" name="Tenpenny" />
		<skin model="266" name="Pulaski" />
		<skin model="267" name="Hern" />
		<skin model="268" name="Dwayne" />
		<skin model="269" name="Big Smoke" />
		<skin model="270" name="Sweet" />
		<skin model="271" name="Ryder" />
		<skin model="272" name="Forelli Guy" />
		<skin model="290" name="Rose" />
		<skin model="291" name="Kent Paul" />
		<skin model="292" name="Cesar" />
		<skin model="293" name="OG Loc" />
		<skin model="294" name="Wuzi Mu" />
		<skin model="295" name="Mike Toreno" />
		<skin model="296" name="Jizzy" />
		<skin model="297" name="Madd Dogg" />
		<skin model="298" name="Catalina" />
		<skin model="299" name="Claude from GTA 3" />
		<skin model="300" name="Ryder" />
		<skin model="301" name="Ryder Robber" />
		<skin model="302" name="Emmet" />
		<skin model="303" name="Andre" />
		<skin model="304" name="Kendl" />
		<skin model="305" name="Jethro" />
		<skin model="306" name="Zero" />
		<skin model="307" name="T-bone Mendez" />
		<skin model="308" name="Sindaco Guy" />
		<skin model="309" name="Janitor" />
		<skin model="310" name="Big Bear" />
		<skin model="311" name="Big Smoke with Vest" />
		<skin model="312" name="Physco" />
	</group>
	<group name="Beach">
		<skin model="18" name="Black Beachguy" />
		<skin model="45" name="Beach Mustache" />
		<skin model="92" name="Rollergirl" />
		<skin model="96" name="Soccer Player" />
		<skin model="97" name="Baywatch Dude" />
		<skin model="138" name="Bikini Tattoo" />
		<skin model="139" name="Yellow Bikini" />
		<skin model="140" name="Buxom Bikini" />
		<skin model="154" name="Beach Blonde" />
		<skin model="251" name="Lifeguard" />
		<skin model="252" name="Naked Freak" />
	</group>
	<group name="Casual Generics">
		<skin model="7" name="Casual Jeanjacket" />
		<skin model="10" name="Old Fat Lady" />
		<skin model="14" name="Floral Shirt" />
		<skin model="15" name="Plaid Baldy" />
		<skin model="20" name="Fresh Prince" />
		<skin model="23" name="Skater Kid" />	
		<skin model="32" name="Eyepatch" />
		<skin model="39" name="Old Maid" />
		<skin model="53" name="Golf Lady" />
		<skin model="54" name="Hispanic Woman" />
		<skin model="56" name="Legwarmers 1" />
		<skin model="58" name="Chinese Plaid" />
		<skin model="60" name="Chinese Casual" />
		<skin model="62" name="Pajama Man 1" />
		<skin model="69" name="Denim Girl" />
		<skin model="72" name="Bearded Hippie" />
		<skin model="88" name="Casual Old Lady" />
		<skin model="93" name="Hoop Earrings 1" />
		<skin model="101" name="Jacket Hippie" />
		<skin model="136" name="Old Rasta" />
		<skin model="142" name="African 1" />
		<skin model="143" name="Sam Jackson" />
		<skin model="170" name="PubeStache Tshirt" />
		<skin model="182" name="Pajama Man 2" />
		<skin model="184" name="Neckbeard" />
		<skin model="188" name="Green Shirt" />
		<skin model="215" name="Explorer" />
		<skin model="218" name="Old Woman" />
		<skin model="220" name="African 2" />
		<skin model="221" name="Beardo Casual" />
		<skin model="222" name="Beardo Clubbing" />
		<skin model="224" name="Elderly Asian 1" />
		<skin model="225" name="Elderly Asian 2" />
		<skin model="226" name="Legwarmers 2" />
		<skin model="229" name="Asian Tourist" />
		<skin model="231" name="Grannie" />
		<skin model="232" name="Grouchy lady" />
		<skin model="233" name="Hoop Earrings 2" />
		<skin model="234" name="Buzzcut" />
		<skin model="236" name="Happy Old Man" />
		<skin model="250" name="Green Tshirt" />
		<skin model="262" name="Pajama Man 2 b" />
	</group>	
	<group name="Celebrities">	
		<skin model="20" name="Fresh Prince" />
		<skin model="91" name="Sharon Stone" />
		<skin model="143" name="Sam Jackson" />
		<skin model="147" name="Sigmund Freud" />
		<skin model="240" name="Hugh Grant" />
		<skin model="251" name="Lifeguard" />
		<skin model="258" name="Joe Pesci" />
		<skin model="259" name="Chris Penn" />
	</group>
	<group name="Country">
		<skin model="31" name="Fat Cowgirl" />
		<skin model="33" name="Bounty Hunter" />
		<skin model="34" name="Marlboro Man" />
		<skin model="44" name="Tatooed Plaid" />
		<skin model="128" name="Native Rancher" />
		<skin model="129" name="Native Librarian" />
		<skin model="130" name="Native Ugly" />
		<skin model="131" name="Native Sexy" />
		<skin model="132" name="Native Geezer" />
		<skin model="133" name="Furys Trucker" />
		<skin model="157" name="Farmer Girl" />
		<skin model="158" name="Farmer" />
		<skin model="159" name="Farmer Redneck" />
		<skin model="160" name="Bald Redneck" />
		<skin model="161" name="Smoking Cowboy" />
		<skin model="162" name="Inbred" />
		<skin model="196" name="Aunt May" />
		<skin model="197" name="Smoking Maid" />
		<skin model="198" name="Ranch Cowgirl" />
		<skin model="199" name="Heidi" />
		<skin model="200" name="Hairy Redneck" />
		<skin model="201" name="Trucker Girl" />
		<skin model="202" name="Beer Trucker" />
		<skin model="236" name="Happy Old Man" />
		<skin model="261" name="Southerner" />
	</group>
	<group name="Duplicates">
		<skin model="25" name="Varsity jacket" />
		<skin model="66" name="Varsity Bandits" />
		<skin model="56" name="Legwarmers 1" />
		<skin model="226" name="Legwarmers 2" />
		<skin model="221" name="Beardo Casual" />
		<skin model="222" name="Beardo Clubbing" />
		<skin model="247" name="Biker Vest" />
		<skin model="254" name="Biker Vest b" />
	</group>
	<group name="Authorities">
		<skin model="71" name="Security Guard" />
		<skin model="163" name="Casino Bouncer 1" />
		<skin model="164" name="Casino Bouncer 2" />
		<skin model="165" name="Agent Kay" />
		<skin model="166" name="Agent Jay" />
	</group>
	<group name="Fatties">
		<skin model="10" name="Old Fat Lady" />
		<skin model="31" name="Fat Cowgirl" />
		<skin model="38" name="Old Golf Lady" />
		<skin model="39" name="Old Maid" />
		<skin model="53" name="Golf Lady" />
		<skin model="54" name="Hispanic Woman" />
		<skin model="88" name="Casual Old Lady" />
		<skin model="89" name="Cleaning Lady" />
		<skin model="103" name="Baller Jacket" />
		<skin model="103" name="Baller Jacket" />
		<skin model="105" name="Grove Sweater" />
		<skin model="130" name="Native Ugly" />
		<skin model="151" name="Melanie" />
		<skin model="182" name="Pajama Man 2" />
		<skin model="197" name="Smoking Maid" />
		<skin model="199" name="Heidi" />
		<skin model="207" name="Grove Booty" />
		<skin model="218" name="Old Woman" />
		<skin model="231" name="Grannie" />
		<skin model="232" name="Grouchy lady" />
		<skin model="245" name="Ghetto Ho" />
		<skin model="258" name="Joe Pesci" />
		<skin model="259" name="Chris Penn" />
	</group>
	<group name="Formal Generics">
		<skin model="9" name="Business Lady" />
		<skin model="17" name="Black suit" />
		<skin model="57" name="Chinese Businessman" />
		<skin model="61" name="Pilot" />
		<skin model="76" name="Businesswoman 1" />
		<skin model="141" name="Cute Librarian" />
		<skin model="147" name="Sigmund Freud" />
		<skin model="148" name="Businesswoman 2" />
		<skin model="149" name="Businesswoman 2 b" />
		<skin model="150" name="Businesswoman 3" />
		<skin model="169" name="Asian Escort" />
		<skin model="186" name="Teacher" />
		<skin model="187" name="Japanese Businessman 1" />
		<skin model="219" name="Lady In Red" />
		<skin model="227" name="Japanese Businessman 2" />
		<skin model="228" name="Japanese Businessman 3" />
		<skin model="255" name="Limo Driver" />
		<skin model="263" name="Asian Hostess" />
	</group>
	<group name="Fighters">
		<skin model="49" name="Ninja Sensei" />
		<skin model="80" name="Red Boxer" />
		<skin model="81" name="Blue Boxer" />
		<skin model="180" name="Bball Player" />
		<skin model="203" name="Ninja 1" />
		<skin model="204" name="Ninja 2" />
	</group>
	<group name="Gangs">
		<skin model="114" name="Aztecas Stripes" />
		<skin model="115" name="Aztecas Jacket" />
		<skin model="116" name="Aztecas Shorts" />
		<skin model="13" name="Homegirl" />
		<skin model="102" name="Baller Shirt" />
		<skin model="103" name="Baller Jacket" />
		<skin model="104" name="Baller Sweater" />
		<skin model="100" name="Biker Blackshirt" />
		<skin model="247" name="Biker Vest" />
		<skin model="248" name="Biker Headband" />
		<skin model="254" name="Biker Vest b" />
		<skin model="121" name="Da Nang Army" />
		<skin model="122" name="Da Nang Bandana" />
		<skin model="123" name="Da Nang Shades" />
		<skin model="0" name="CJ" />
		<skin model="105" name="Grove Sweater" />
		<skin model="106" name="Grove Topbutton" />
		<skin model="107" name="Grove Jersey" />
		<skin model="207" name="Grove Booty" />
		<skin model="125" name="Mafia Enforcer" />
		<skin model="126" name="Mafia Wiseguy" />
		<skin model="127" name="Mafia Hitman" />
		<skin model="173" name="Rifa Hat" />
		<skin model="174" name="Rifa Vest" />
		<skin model="175" name="Rifa Suspenders" />
		<skin model="111" name="Russian Muscle" />
		<skin model="112" name="Russian Hitman" />
		<skin model="113" name="Russian Boss" />
		<skin model="120" name="Sindacco Suit" />
		<skin model="124" name="Sindacco Muscle" />
		<skin model="117" name="Triad 1" />
		<skin model="118" name="Triad 2" />
		<skin model="119" name="Triad 3" />
		<skin model="108" name="Vagos Topless" />
		<skin model="109" name="Vagos Pants" />
		<skin model="110" name="Vagos Shorts" />
	</group>
	<group name="Gangstas">
		<skin model="19" name="Beach Gangsta" />
		<skin model="21" name="Striped Gangsta" />
		<skin model="22" name="Orange Sportsman" />
		<skin model="28" name="Black Dealer" />
		<skin model="29" name="White Dealer" />
		<skin model="30" name="Religious Essey" />
		<skin model="47" name="Top Button Essey" />
		<skin model="67" name="Red Bandana" />
		<skin model="143" name="Sam Jackson" />
		<skin model="241" name="Afro Brother" />
		<skin model="242" name="Dreadlock Brother" />
		<skin model="243" name="Ghetto Booty" />
	</group>
	<group name="Girlfriends">
		<skin model="190" name="Barbara Schternvart" />
		<skin model="191" name="Helena Wankstein" />
		<skin model="192" name="Michelle Cannes" />
		<skin model="193" name="Katie Zhan" />
		<skin model="194" name="Millie Perkins" />
		<skin model="195" name="Denise Robinson" />
	</group>
	<group name="Homeless">
		<skin model="77" name="Bag Lady" />
		<skin model="78" name="Homeless Scarf" />
		<skin model="79" name="Fat Homeless" />
		<skin model="95" name="Poor Old Man" />
		<skin model="134" name="Homeless Smoker" />
		<skin model="135" name="Skullcap Hobo" />
		<skin model="137" name="Boxhead" />
		<skin model="200" name="Hairy Redneck" />
		<skin model="212" name="Tin Foil Hat" />
		<skin model="213" name="Hobo Elvis" />
		<skin model="230" name="Hooded Hobo" />
	</group>
	<group name="Nightclubbers">
		<skin model="43" name="Porn Producer" />
		<skin model="46" name="Dark Romeo" />
		<skin model="59" name="Chinese Romeo" />
		<skin model="185" name="Nervous Guy" />
		<skin model="223" name="Greasy Nightclubber" />
		<skin model="240" name="Hugh Grant" />
	</group>
	<group name="Sex Industry">
		<skin model="43" name="Porn Producer" />
		<skin model="63" name="Trashy Hooker" />
		<skin model="64" name="Transvestite" />
		<skin model="75" name="Skanky Hooker" />
		<skin model="85" name="Furcoat Hooker" />
		<skin model="87" name="Firecrotch" />
		<skin model="90" name="Barely Covered" />
		<skin model="152" name="Schoolgirl 1" />
		<skin model="178" name="Masked Stripper" />
		<skin model="237" name="Leopard Hooker" />
		<skin model="238" name="Amazon" />
		<skin model="244" name="Lace Stripper" />
		<skin model="245" name="Ghetto Ho" />
		<skin model="246" name="Cop Stripper" />
		<skin model="249" name="Pimp" />
		<skin model="256" name="Shoolgirl 2" />
		<skin model="257" name="Bondage Girl" />
	</group>
	<group name="Sports">
		<skin model="13" name="Homegirl" />
		<skin model="21" name="Striped Gangsta" />
		<skin model="22" name="Orange Sportsman" />
		<skin model="23" name="Skater Kid" />
		<skin model="24" name="LS Coach" />
		<skin model="25" name="Varsity jacket" />
		<skin model="36" name="Mailman" />
		<skin model="51" name="Black Bicyclist" />
		<skin model="52" name="White Bicyclist" />
		<skin model="53" name="Golf Lady" />
		<skin model="66" name="Varsity Bandits" />
		<skin model="80" name="Red Boxer" />
		<skin model="81" name="Blue Boxer" />
		<skin model="92" name="Rollergirl" />
		<skin model="94" name="Andy Capp" />
		<skin model="96" name="Soccer Player" />
		<skin model="99" name="Rollerguy" />
		<skin model="180" name="Bball Player" />`
		<skin model="195" name="Denise Robinson" />
	</group>
	<group name="Tough Guys">
		<skin model="0" name="CJ" />
		<skin model="18" name="Black Beachguy" />
		<skin model="28" name="Black Dealer" />
		<skin model="30" name="Religious Essey" />
		<skin model="33" name="Bounty Hunter" />
		<skin model="183" name="Klingon" />
	</group>
	<group name="Tourists">
		<skin model="26" name="Hiker" />
		<skin model="35" name="Fisherman" />
		<skin model="37" name="Baseball Dad" />
		<skin model="38" name="Old Golf Lady" />
		<skin model="210" name="Sloppy Tourist" />
		<skin model="235" name="Retired Tourist" />
	</group>
	<group name="Wealthy">
		<skin model="12" name="Classy Gold Hooker" />
		<skin model="40" name="Classy Dark Hooker" />
		<skin model="41" name="Tracksuit Girl" />
		<skin model="55" name="Rich Bitch" />
		<skin model="91" name="Sharon Stone" />
		<skin model="99" name="Rollerguy" />
		<skin model="216" name="Turtleneck" />
		<skin model="240" name="Hugh Grant" />
	</group>
	<group name="Weirdos">
		<skin model="75" name="Skanky Hooker" />
		<skin model="137" name="Boxhead" />
		<skin model="151" name="Melanie" />
		<skin model="167" name="Chicken" />
		<skin model="181" name="Punk" />
		<skin model="212" name="Tin Foil Hat" />
		<skin model="213" name="Hobo Elvis" />
		<skin model="230" name="Hooded Hobo" />
		<skin model="241" name="Afro Brother" />
		<skin model="242" name="Dreadlock Brother" />
		<skin model="252" name="Naked Freak" />
		<skin model="264" name="Whoopee the Clown" />
	</group>
	<group name="Barbers">
		<skin model="156" name="Old Reece" />
		<skin model="176" name="Style Barber" />
		<skin model="177" name="Vanilla Ice Barber" />
	</group>
	<group name="Career Workers">
		<skin model="61" name="Pilot" />
		<skin model="68" name="Preist" />
		<skin model="70" name="Scientist" />
		<skin model="147" name="Sigmund Freud" />
	</group>
	<group name="Casino Workers">
		<skin model="11" name="Card Dealer 1" />
		<skin model="82" name="Fatty Elvis" />
		<skin model="83" name="Whitesuit Elvis" />
		<skin model="84" name="Bluesuit Elvis" />
		<skin model="163" name="Casino Bouncer 1" />
		<skin model="164" name="Casino Bouncer 2" />
		<skin model="169" name="Asian Escort" />
		<skin model="171" name="Card Dealer 2" />
		<skin model="172" name="Card Dealer 3" />
		<skin model="189" name="Valet" />
		<skin model="213" name="Hobo Elvis" />
		<skin model="214" name="Caligula Waitress" />
	</group>
	<group name="Construction Workers">
		<skin model="16" name="Earmuff Worker" />
		<skin model="27" name="Construction 1" />
		<skin model="153" name="Foreman" />
		<skin model="260" name="Construction 2" />
	</group>
	<group name="Drug Workers">
		<skin model="28" name="Black Dealer" />
		<skin model="29" name="White Dealer" />
		<skin model="144" name="Drug Worker 1" />
		<skin model="145" name="Drug Worker 2" />
		<skin model="146" name="Drug Worker 3" />
	</group>
	<group name="Food Workers">
		<skin model="155" name="Pizza Guy" />
		<skin model="167" name="Chicken" />
		<skin model="168" name="Hotdog Vender" />
		<skin model="205" name="Burger Girl" />
		<skin model="209" name="Noodle Vender" />
		<skin model="264" name="Whoopee the Clown" />
	</group>
	<group name="Other Workers">
		<skin model="36" name="Mailman" />
		<skin model="50" name="Mechanic" />
		<skin model="71" name="Security Guard" />
		<skin model="189" name="Valet" />
		<skin model="251" name="Lifeguard" />
		<skin model="253" name="Bus Driver" />
		<skin model="255" name="Limo Driver" />
	</group>
	<group name="Truckers">
		<skin model="128" name="Native Rancher" />
		<skin model="133" name="Furys Trucker" />
		<skin model="201" name="Trucker Girl" />
		<skin model="202" name="Beer Trucker" />
		<skin model="206" name="Money Trucker" />
	</group>
</skins>

I wanna remove the markers part and just make it open/work with a command handler. I tried to delete the shops {} and the shop functions (createskinshops and enteredshop) + added this to client file

addCommandHandler ( "skins", createSkinWindow )

but it didn't open the gui nor gave any errors in debug.

Link to comment

Thanks @pa3ck. Now I have other problem, can't seem to save skin ID to account so when player joins (and has set skin before) it would get his account data and set that skin on him. I tried, no errors but skin doesn't save on reconnect or even on mapchange :\

Client (not really needed I guess but still here it is)

local screenWidth, screenHeight = guiGetScreenSize()

function createSkinWindow()
	windowWidth, windowHeight = 335, 414
	windowX, windowY = (screenWidth / 1) - (windowWidth / 1), (screenHeight / 2) - (windowHeight / 2)
	skinWindow = guiCreateWindow(290, 250, 350, 410, "Skin Selection Menu", false)
	guiSetAlpha(skinWindow, 1)
	skinGridlist = guiCreateGridList(9, 25, 357, 325, false, skinWindow)
	skinTitleColumn = guiGridListAddColumn(skinGridlist, "Title", 0.45)
	skinIDColumn = guiGridListAddColumn(skinGridlist, "ID", 0.45)
	skinBuyButton = guiCreateButton(9, 363, 132, 33, "Set Skin", false, skinWindow)
	skinExitButton = guiCreateButton(194, 363, 132, 33, "Exit", false, skinWindow)
	guiSetVisible(skinWindow, false)

	--Events
	addEventHandler("onClientGUIClick", skinExitButton, function () guiSetVisible(skinWindow, false) showCursor(false) setPlayerHudComponentVisible("all", true) setElementModel(localPlayer, model) setElementFrozen(localPlayer, false) end, false)
	addEventHandler("onClientGUIClick", skinBuyButton, buySkin, false)
	addEventHandler("onClientGUIClick", skinGridlist, previewSkin, false)
end
addEventHandler("onClientResourceStart", resourceRoot, createSkinWindow)

function showSkin(skinsTable)
	guiGridListClear(skinGridlist)
	setElementFrozen(localPlayer, true)
	for category, skins in pairs(skinsTable) do
		local row = guiGridListAddRow(skinGridlist)
		guiGridListSetItemText(skinGridlist, row, 1, category, true, false)
		for id, name in pairs(skins) do
			local row = guiGridListAddRow(skinGridlist)
			guiGridListSetItemText(skinGridlist, row, 1, name, false, false)
			guiGridListSetItemText(skinGridlist, row, 2, id, false, false)
		end
	end
	guiSetVisible(skinWindow, true)
	showCursor(true)
	model = getElementModel(localPlayer)
end
addEvent("clothes.showSkin", true)
addEventHandler("clothes.showSkin", root, showSkin)

function previewSkin()
	local row = guiGridListGetSelectedItem(skinGridlist)
	if (not row or row == -1) then return end
	local id = guiGridListGetItemText(skinGridlist, row, 2)
	id = tonumber(id)
	if (not id) then return end
	setElementModel(localPlayer, id)
end

function buySkin()
	local row = guiGridListGetSelectedItem(skinGridlist)
	if (not row or row == -1) then return end
	local id = guiGridListGetItemText(skinGridlist, row, 2)
	id = tonumber(id)
	if (not id) then return end
	setElementModel(localPlayer, model)
	setElementFrozen(localPlayer, false)
	guiSetVisible(skinWindow, false)
	showCursor(false)
	triggerServerEvent("clothes.buySkin", root, id)
end

Server

skinsTable = {}
skinsTable.all = {}
skinsTable.categories = {}

function loadSkins()
	local xml = xmlLoadFile("files/skins.xml")
	for index, category in pairs(xmlNodeGetChildren(xml)) do
		local cName = xmlNodeGetAttribute(category, "name")
		skinsTable.categories[cName] = {}
		for index, skin in pairs(xmlNodeGetChildren(category)) do
			local id, name = xmlNodeGetAttribute(skin, "model"), xmlNodeGetAttribute(skin, "name")
			skinsTable.categories[cName][id] = name
			skinsTable.all[id] = name
		end
	end
	xmlUnloadFile(xml)
end
addEventHandler("onResourceStart", resourceRoot, loadSkins)

function getSkinsTable(category)
	if not category then
		return  skinsTable.categories or false
	elseif category == "all" then
		return skinsTable.all or false
	else
		return skinsTable[category] or false
	end
	return false
end

function buySkin(model)
        local playeraccount = getPlayerAccount(source)
		if playeraccount and not isGuestAccount(playeraccount) then
		outputChatBox("You have succesfully set "..model.." as your skin!", source, 0, 255, 0, true)
		setAccountData(playeraccount, "skinid", model)
		setElementModel(source, model)
		end
end
addEvent("clothes.buySkin", true)
addEventHandler("clothes.buySkin", root, buySkin)

function getBoughtSkin(player)
	if (not isElement(player)) then return end
	return tonumber(getAccountData(getPlayerAccount(player), "skinid")) or 0
end

function open ( player, cmd )
	local skins = getSkinsTable()
    if getElementData ( player,'LoggedIn' ) ~= true then 
    outputChatBox("You need to register and login in order to set a skin!", player, 255,153,0)
    return
    end	
	triggerClientEvent(player, "clothes.showSkin", player, skins)
end
addCommandHandler("skins", open)

function onPlayerQuit(model)
local playeraccount = getPlayerAccount ( source )
  if ( playeraccount ) and not isGuestAccount ( playeraccount ) then
     local getskin = getElementModel(source, model)
     if ( getskin ) then
       setAccountData ( playeraccount, "skinid", getskin)
     end
  end
end
addEventHandler ( "onPlayerQuit", getRootElement ( ), onPlayerQuit )

addEventHandler( 'onPlayerJoin',root,
	function (	)
		setElementData ( source,'LoggedIn',false )
	end
)

function onPlayerLogin (_, playeraccount )
      if ( playeraccount ) and not isGuestAccount ( playeraccount ) then
          local skinmodel = getAccountData ( playeraccount, "skinid" )
		  if skinmodel then
		  setElementModel(source, skinmodel)
		  end
		  if not isGuestAccount( playeraccount ) then
			setElementData ( source,'LoggedIn',true )
		  end
      end
end
addEventHandler ( "onPlayerLogin", getRootElement ( ), onPlayerLogin )

 

Link to comment
function onPlayerQuit( )
local playeraccount = getPlayerAccount ( source )
  if ( playeraccount ) and not isGuestAccount ( playeraccount ) then
     local getskin = getElementModel(source)
     if ( getskin ) then
       setAccountData ( playeraccount, "skinid", getskin)
     end
  end
end
addEventHandler ( "onPlayerQuit", getRootElement ( ), onPlayerQuit )

 

Link to comment

Still nothing :(

skinsTable = {}
skinsTable.all = {}
skinsTable.categories = {}

function loadSkins()
	local xml = xmlLoadFile("files/skins.xml")
	for index, category in pairs(xmlNodeGetChildren(xml)) do
		local cName = xmlNodeGetAttribute(category, "name")
		skinsTable.categories[cName] = {}
		for index, skin in pairs(xmlNodeGetChildren(category)) do
			local id, name = xmlNodeGetAttribute(skin, "model"), xmlNodeGetAttribute(skin, "name")
			skinsTable.categories[cName][id] = name
			skinsTable.all[id] = name
		end
	end
	xmlUnloadFile(xml)
end
addEventHandler("onResourceStart", resourceRoot, loadSkins)

function getSkinsTable(category)
	if not category then
		return  skinsTable.categories or false
	elseif category == "all" then
		return skinsTable.all or false
	else
		return skinsTable[category] or false
	end
	return false
end

function buySkin(model)
        local playeraccount = getPlayerAccount(client)
		if playeraccount and not isGuestAccount(playeraccount) then
		outputChatBox("You have succesfully set "..model.." as your skin!", client, 0, 255, 0, true)
		setAccountData(playeraccount, "skinid", model)
		setElementModel(client, model)
		end
end
addEvent("clothes.buySkin", true)
addEventHandler("clothes.buySkin", root, buySkin)

function getBoughtSkin(player)
	if (not isElement(player)) then return end
	return tonumber(getAccountData(getPlayerAccount(player), "skinid")) or 0
end

function open ( player, cmd )
	local skins = getSkinsTable()
    if getElementData ( player,'LoggedIn' ) ~= true then 
    outputChatBox("You need to register and login in order to set a skin!", player, 255,153,0)
    return
    end	
	triggerClientEvent(player, "clothes.showSkin", player, skins)
end
addCommandHandler("skins", open)

function onPlayerQuit()
local playeraccount = getPlayerAccount (source)
  if ( playeraccount ) and not isGuestAccount ( playeraccount ) then
     local getskin = getElementModel(source)
     if ( getskin ) then
       setAccountData ( playeraccount, "skinid", getskin)
     end
  end
end
addEventHandler ( "onPlayerQuit", getRootElement ( ), onPlayerQuit )

function onPlayerLogin (_, playeraccount )
      if ( playeraccount ) and not isGuestAccount ( playeraccount ) then
          local skinmodel = getAccountData ( playeraccount, "skinid" )
		  if skinmodel then
		  setElementModel(source, skinmodel)
		  end
		  if not isGuestAccount( playeraccount ) then
			setElementData ( source,'LoggedIn',true )
		  end
      end
end
addEventHandler ( "onPlayerLogin", getRootElement ( ), onPlayerLogin )

 

Link to comment

I fixed it by using this code : https://community.multitheftauto.com/index.php?p=resources&s=details&id=786:)

OK, just this...can the command handler be at client side? I'm going to integrate it as a button click but it has to be client function to work, now's server.

local screenWidth, screenHeight = guiGetScreenSize()

function createSkinWindow()
	windowWidth, windowHeight = 335, 414
	windowX, windowY = (screenWidth / 1) - (windowWidth / 1), (screenHeight / 2) - (windowHeight / 2)
	skinWindow = guiCreateWindow(290, 250, 350, 410, "Skin Selection Menu", false)
	guiSetAlpha(skinWindow, 1)
	skinGridlist = guiCreateGridList(9, 25, 357, 325, false, skinWindow)
	skinTitleColumn = guiGridListAddColumn(skinGridlist, "Title", 0.45)
	skinIDColumn = guiGridListAddColumn(skinGridlist, "ID", 0.45)
	skinBuyButton = guiCreateButton(9, 363, 132, 33, "Set Skin", false, skinWindow)
	skinExitButton = guiCreateButton(194, 363, 132, 33, "Exit", false, skinWindow)
	guiSetVisible(skinWindow, false)

	--Events
	addEventHandler("onClientGUIClick", skinExitButton, function () guiSetVisible(skinWindow, false) showCursor(false) setPlayerHudComponentVisible("all", true) setElementModel(localPlayer, model) setElementFrozen(localPlayer, false) end, false)
	addEventHandler("onClientGUIClick", skinBuyButton, buySkin, false)
	addEventHandler("onClientGUIClick", skinGridlist, previewSkin, false)
end
addEventHandler("onClientResourceStart", resourceRoot, createSkinWindow)

function showSkin(skinsTable)
	guiGridListClear(skinGridlist)
	setElementFrozen(localPlayer, true)
	for category, skins in pairs(skinsTable) do
		local row = guiGridListAddRow(skinGridlist)
		guiGridListSetItemText(skinGridlist, row, 1, category, true, false)
		for id, name in pairs(skins) do
			local row = guiGridListAddRow(skinGridlist)
			guiGridListSetItemText(skinGridlist, row, 1, name, false, false)
			guiGridListSetItemText(skinGridlist, row, 2, id, false, false)
		end
	end
	guiSetVisible(skinWindow, true)
	showCursor(true)
	model = getElementModel(localPlayer)
end
addEvent("clothes.showSkin", true)
addEventHandler("clothes.showSkin", root, showSkin)

function previewSkin()
	local row = guiGridListGetSelectedItem(skinGridlist)
	if (not row or row == -1) then return end
	local id = guiGridListGetItemText(skinGridlist, row, 2)
	id = tonumber(id)
	if (not id) then return end
	setElementModel(localPlayer, id)
end

function buySkin()
	local row = guiGridListGetSelectedItem(skinGridlist)
	if (not row or row == -1) then return end
	local id = guiGridListGetItemText(skinGridlist, row, 2)
	id = tonumber(id)
	if (not id) then return end
	setElementModel(localPlayer, model)
	setElementFrozen(localPlayer, false)
	guiSetVisible(skinWindow, false)
	showCursor(false)
	triggerServerEvent("clothes.buySkin", root, id)
end

 

Edited by koragg
Link to comment
21 hours ago, pa3ck said:

Are you sure you edited this:

 


triggerServerEvent("clothes.buySkin", root, id)

and used localPlayer instead of root?

Yes but I got an error (don't remember what exactly). So I asked @dugasz1 and he did this:

Server:

function open ( )
 local skins = getSkinsTable()
    if getElementData ( client,'LoggedIn' ) ~= true then 
    outputChatBox("You need to register and login in order to set a skin!", client, 255,153,0)
    return
    end 
 triggerClientEvent(client, "clothes.showSkin", client, skins)
end
addEvent("openRequest", true)
addEventHandler("openRequest", resourceRoot, open)

Client:

function sendOpenRequestForServer ()
 triggerServerEvent("openRequest", resourceRoot)
end

And works now. I just gotta learn those trigger stuff somehow :)

Link to comment
  1.  
function onPlayerQuit( )
local playeraccount = getPlayerAccount ( source )
if ( playeraccount ) and not isGuestAccount ( playeraccount ) then
local getskin = getElementModel(source)
if ( getskin ) then
setAccountData ( playeraccount, "skinid", getskin)
end
end
end
addEventHandler ( "onPlayerQuit", getRootElement ( ), onPlayerQuit )


function onPlayerLogin( )
local get = getAccountData(playeraccount, "skinid")

setElementModel(source, get)

end

addEventHandler ( "onPlayerLogin", getRootElement ( ), onPlayerLogin)

 

 

Add this part to server side.

 

Link to comment

Thanks but I already made the save function work like this:

function onPlayerQuit ( )
      local playeraccount = getPlayerAccount ( source )
      if ( playeraccount ) then
            local playerskin = getPedSkin ( source )
            setAccountData ( playeraccount, "skin", playerskin )
      end
end
addEventHandler ( "onPlayerQuit", getRootElement ( ), onPlayerQuit )

function onPlayerSpawn ( )
      local playeraccount = getPlayerAccount ( source )
      if ( playeraccount ) then
            local playerskin = getAccountData ( playeraccount, "skin" )
            if ( playerskin ) then
                  setPedSkin ( source, playerskin )
            end
      end
end
addEventHandler ( "onPlayerSpawn", getRootElement ( ), onPlayerSpawn )

function onPlayerWasted ( )
      local playeraccount = getPlayerAccount ( source )
      if ( playeraccount ) then
            local playerskin = getPedSkin ( source )
            setAccountData ( playeraccount, "skin", playerskin )
      end
end
addEventHandler ( "onPlayerWasted", getRootElement ( ), onPlayerWasted )

addEventHandler( 'onPlayerJoin',root,
	function (	)
		setElementData ( source,'LoggedIn',false )
	end
)

function onPlayerLogin ( )
      local playeraccount = getPlayerAccount ( source )
      if ( playeraccount ) then
            local playerskin = getAccountData ( playeraccount, "skin" )
            if ( playerskin ) then
                  setPedSkin ( source, playerskin )
            end
		  if not isGuestAccount( playeraccount ) then
			setElementData ( source,'LoggedIn',true )
		  end
      end
end
addEventHandler ( "onPlayerLogin", getRootElement ( ), onPlayerLogin )

function onPlayerLogout ( )
local playeraccount = getPlayerAccount ( source )
      if ( playeraccount ) and isGuestAccount(playeraccount) then
	  setPedSkin ( source, 0 )
	  end
end
addEventHandler ( "onPlayerLogout", getRootElement ( ), onPlayerLogout )

Just couldn't make the GUI open function client side but as I said a friend helped me with that. Problem fixed :) Thanks for all your replies guys ^^

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