Bilal135 Posted December 5, 2018 Share Posted December 5, 2018 So, i created two buttons in a gui, '>' for 'next skin' and '<' for previous skin. But unfortunately, the code doesn't seem to work very well. Any help regarding this would be really appreciated. skin_btn_next = guiCreateButton(96, 273, 33, 16, ">", false, window) skin_btn_previous = guiCreateButton(58, 273, 33, 16, "<", false, window) function isSkinValid(skinid) local allSkins = getValidPedModels() for _, skin in ipairs(allSkins) do if skin == tonumber(skinid) then return true else return false end end end ped = createPed(0, -2614.0212402344, 1451.1651611328, 7.1875, 180) local skin = getElementModel(ped) local new_skin = skin + 1 local previous_skin = new_skin - 1 if source == skin_btn_next then if isSkinValid(new_skin) then setElementModel(ped, new_skin) else setElementModel(ped, new_skin + 1) end end if source == skin_btn_previous then setElementModel(ped, previous_skin) end (These are just the relevant parts of the script) Entire script; https://pastebin.com/aYydg3TX Link to comment
Moderators IIYAMA Posted December 5, 2018 Moderators Share Posted December 5, 2018 local allSkins = getValidPedModels() -- get all skins, (this only has to be executed one time) do -- DO this when pressing a button local index = 1 local skin = getElementModel(ped) local nextButtonUsed = true -- did I press right(true)? Or left(false) -- find the (new) skin index from the table for i=1, #allSkins do if allSkins[i] == skin then index = i + (nextButtonUsed and 1 or -1) break end end -- Index not matching the table? Adjust! if index < 1 then index = #allSkins elseif index > #allSkins then index = 1 end -- set the model setElementModel(ped, allSkins[index]) end Link to comment
Bilal135 Posted December 5, 2018 Author Share Posted December 5, 2018 It worked like a charm @IIYAMA. Thank you. (Still figuring out how you did it) 1 Link to comment
Moderators IIYAMA Posted December 5, 2018 Moderators Share Posted December 5, 2018 3 hours ago, Bilal135 said: It worked like a charm @IIYAMA. Thank you. (Still figuring out how you did it) Feel free to ask questions about the code! Manually debugging it makes understanding code a lot easier: 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