NextGenRP Posted April 24, 2012 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?
Castillo Posted April 24, 2012 Posted April 24, 2012 There's a function that returns a table with all valid skins: https://wiki.multitheftauto.com/wiki/GetValidPedModels
NextGenRP Posted April 24, 2012 Author 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?
Castillo Posted April 24, 2012 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.
NextGenRP Posted April 24, 2012 Author Posted April 24, 2012 Nah i don't understand what you mean there mate
Castillo Posted April 24, 2012 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
Kenix Posted April 24, 2012 Posted April 24, 2012 Nah i don't understand what you mean there mate index = value
Kenix Posted April 24, 2012 Posted April 24, 2012 This this sync only for localPlayer .. You should trigger to server and use setElementModel.
NextGenRP Posted April 24, 2012 Author 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)
Kenix Posted April 25, 2012 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
NextGenRP Posted April 25, 2012 Author 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.
Castillo Posted April 25, 2012 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 )
NextGenRP Posted April 25, 2012 Author Posted April 25, 2012 Ahh thanks Solidsnake14 fast reply and it works thanks.
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