Matevsz Posted May 27, 2016 Share Posted May 27, 2016 Hello, how to remove skin player after the entry marker and leave the skin that was at the beginning? I ask for an example? Link to comment
ViRuZGamiing Posted May 27, 2016 Share Posted May 27, 2016 local skin addEventHandler("onMarkerHit", entryMarker, function(hitElement) if (getElementType(hitElement) == "player") then skin = getElementModel(hitElement) --remove skin here (what I don't really understand what you mean by that) end end) addEventHandler("onMarkerHit", exitMarker, function(hitElement) if (getElementType(hitElement) == "player") then setElementModel(hitElement, skin) end end) Link to comment
Matevsz Posted May 27, 2016 Author Share Posted May 27, 2016 I mean that we have the skin of id, eg. 7, enter the marker and begin to work get skin id eg. 54 when once again we enter the marker to get back your skin 7 and finish the job clothes = createPickup(-1886.7001953125, 2142.7001953125, 1.7999999523163, 3, 1275, 2000) function Job(hitElement) local skin = getElementModel(getLocalPlayer()) if skin == 97 then setElementModel(getLocalPlayer(), skin) outputChatBox("Finished job.", localPlayer) else setElementModel(getLocalPlayer(), 97) outputChatBox("Started job.", localPlayer") end end addEventHandler("onClientPickupHit", clothes, Job) everything works but not skin the player who had at the beginning Link to comment
ViRuZGamiing Posted May 27, 2016 Share Posted May 27, 2016 You have a " after localPlayer on line 12 Link to comment
Moderators Citizen Posted May 28, 2016 Moderators Share Posted May 28, 2016 First, as ViRuZGamiing pointed out, you added an extra " at line 12 which is breaking your entire script. You can see that the syntax highlighting after is not okay. So do yourself a favor and use a proper IDE/script editor for Lua. I'm using Notepad++ with the MTA plugin . To do what you want, you need to save the player's current skin when he is starting the job (so in the else part) and then use the value of that skin you saved when he stops working (so in the if part). To do that you could just use a global variable as it is a client sided script, but I'm gonna introduce you with the element datas. To stay simple, element datas are like sticky notes with a name and a value you can paste/attach onto elements like vehicles, players etc. You can add an element data to a player with: setElementData(player, "theDataName", "theDataValue") and then, when you need it, you can get the value back by doing: local value = getElementData(player, "theDataName") -- value = "theDataValue" So here is your code using element datas to remember the skin before he started the job: clothes = createPickup(-1886.7001953125, 2142.7001953125, 1.7999999523163, 3, 1275, 2000) function Job(hitElement) local skin = getElementModel(localPlayer) if skin == 97 then local oldSkin = getElementData(localPlayer, "oldSkin") setElementModel(localPlayer, oldSkin) outputChatBox("Finished job.", localPlayer) else setElementData(localPlayer, "oldSkin", skin, false) setElementModel(localPlayer, 97) outputChatBox("Started job.", localPlayer) end end addEventHandler("onClientPickupHit", clothes, Job) If you are looking closely, you should notice at line 10 I added a 4th argument (false). Here false means that I don't want that element data to be synchronized with the other script side (here your code is running on the client-side so I don't want it to be available using a getElementData on the server-side). Using false here is optional and is just saving some bandwidth because I don't need to know that value on the server-side. Hope it helps you. Regards, Citizen 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