NextGenRP Posted April 24, 2012 Share Posted April 24, 2012 Hey guys, I've created some GUI buttons so a player can select their skin but the problem is i have done it like this: When they press the "Back Skin" button it does it like this: setElementModel(getLocalPlayer(),skin -1) And the same with "Next Skin", But when the skin gets to 2 it stops changing the skins, I think its because there is no skin 3 so how can i "skip" the ones that are not there? Link to comment
Castillo Posted April 24, 2012 Share Posted April 24, 2012 There's a function that returns a table with all valid skins: https://wiki.multitheftauto.com/wiki/GetValidPedModels Link to comment
NextGenRP Posted April 24, 2012 Author Share Posted April 24, 2012 Thanks Solidsnake14 that will work. Link to comment
NextGenRP Posted April 24, 2012 Author Share Posted April 24, 2012 I just can't get my head around this man, function onSkinbackBtun(button) if(button == "left") then if(source == backSkinButton) then local skin = getElementModel(getLocalPlayer()) if(skin ~= 0) then local allskins = getValidPedModels ( ) for key, newskin in ipairs( allSkins ) do if newskin == tonumber( skin -1 ) then setElementModel(getLocalPlayer(),skin -1) guiSetText(skinIDLabel,"ID: "..getElementModel(getLocalPlayer())) else outputChatBox("You can't go back any more!", 255,255,0) end playSoundFrontEnd ( 32 ) end end end end end But how do i make it if the skin is not valid to set it to the next available skin? Link to comment
Castillo Posted April 24, 2012 Share Posted April 24, 2012 getValidPedModels returns a table, so you can do this: getValidPedModels ( ) [ 1 ] -- Returns 0 getValidPedModels ( ) [ 2 ] -- Returns 1 getValidPedModels ( ) [ 3 ] -- Returns 2 If you get what I mean. Link to comment
NextGenRP Posted April 24, 2012 Author Share Posted April 24, 2012 Nah i don't understand what you mean there mate Link to comment
Castillo Posted April 24, 2012 Share Posted April 24, 2012 Try this: local skin = 0 function onSkinbackBtun ( button ) if ( button == "left" ) then if ( source == backSkinButton ) then local allSkins = getValidPedModels ( ) skin = skin - 1 if ( allSkins [ skin ] ) then setElementModel ( localPlayer, allSkins [ skin ] ) guiSetText ( skinIDLabel,"ID: ".. getElementModel ( localPlayer ) ) else outputChatBox("You can't go back any more!", 255,255,0) end playSoundFrontEnd ( 32 ) end end end Link to comment
Kenix Posted April 24, 2012 Share Posted April 24, 2012 Nah i don't understand what you mean there mate index = value Link to comment
NextGenRP Posted April 24, 2012 Author Share Posted April 24, 2012 Works perfect thanks Solidsnake14 Link to comment
Kenix Posted April 24, 2012 Share Posted April 24, 2012 This this sync only for localPlayer .. You should trigger to server and use setElementModel. Link to comment
NextGenRP Posted April 24, 2012 Author Share Posted April 24, 2012 So i still need to set it server side? Also (didn't want to start a new thread) if im doing this: triggerServerEvent("createNewChar", getLocalPlayer(), firstname, lastname, age, descript, weight, muscle) How do i start the server function? function createChar(firstname, lastname, age, descript, weight, muscle) Like that or this: function createChar(source, firstname, lastname, age, descript, weight, muscle) Don't worry about telling me about the events and stuff i got that covered (I think) Link to comment
Castillo Posted April 25, 2012 Share Posted April 25, 2012 Remove "source" from the function name. Link to comment
Kenix Posted April 25, 2012 Share Posted April 25, 2012 source ( element who call event ) = latent predefined variable in event. You don't need add 'source' to arguments function-handler. https://wiki.multitheftauto.com/wiki/AddEventHandler Link to comment
NextGenRP Posted April 25, 2012 Author Share Posted April 25, 2012 Thanks guys can you see where the error is here: closeWindowbut = guiCreateButton(168,368,114,34,"Close",false,jobWindow) addEventHandler("onClientGUIClick", closeWindowbut, closeWindow, false) function closeWindow(button) if button == "left" then if source == closeWindowbut then guiSetVisible(jobWindow, false) showCursor(false) end end end It doesn't seem to do anything when i click the button. Link to comment
Castillo Posted April 25, 2012 Share Posted April 25, 2012 You're adding the event before creating the function. closeWindowbut = guiCreateButton(168,368,114,34,"Close",false,jobWindow) function closeWindow ( button ) if ( button == "left" ) then if ( source == closeWindowbut) then guiSetVisible(jobWindow, false) showCursor(false) end end end addEventHandler ( "onClientGUIClick", closeWindowbut, closeWindow, false ) Link to comment
NextGenRP Posted April 25, 2012 Author Share Posted April 25, 2012 Ahh thanks Solidsnake14 fast reply and it works thanks. 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