Galton Posted March 7, 2015 Share Posted March 7, 2015 hello, my first question is how can I define local player for a server side script? it's something I cannot understand, is there a way to do it? my second question is I'm trying to make a script that will save your skin on death and give your skin back on spawn. but I cannot make it work. this is my code; function getSkin () local playerSkin = getElementModel(getPlayerFromName(source)) end function setSkin () setElementModel(getPlayerFromName(source),playerSkin) end addEventHandler ("onPlayerWasted",root,getSkin) addEventHandler ("onPlayerSpawn",root,setSkin) if I use "myActualNick" instead of source, it works perfectly fine. I don't know what's the problem, but I'd love to get some help. thanks in advance. Link to comment
toxicsmoke11 Posted March 7, 2015 Share Posted March 7, 2015 1) for server-side you usually got events which define source, and custom-events(if you add ones) which source is client and if you really want, you can get a random player with getRandomPlayer() 2) source in that case is an element, not a name. for a name use getPlayerName(source) function onDeath() local skin = getPedSkin(source) -- get dead player's skin model id setElementData(source,"skin-id",skin) -- save id to element(player) 's data end addEventHandler("onPlayerWasted",root,onDeath) -- on spawn function onSpawn() local skin = getElementData(source,"skin-id") or 0 -- or 0 is used in case a player didn't die yet, so he doesn't have a saved skin yet because he didn't die setPedSkin(source,skin) -- set his skin to original one end addEventHandler("onPlayerSpawn",root,onSpawn) Link to comment
Enargy, Posted March 7, 2015 Share Posted March 7, 2015 EDIT: you can also insert skin in a table; skin = {} addEventHandler("onPlayerWasted", root, function() local playerSkin = tonumber(getElementModel(source)) table.insert(skin, {playerSkin}) outputChatBox("inserted skin!", source) end) addEventHandler("onPlayerSpawn", root, function() for index, playerModel in pairs(skin) do setElementModel(source, unpack(playerModel)) table.remove( skin, index ) outputChatBox("loaded skin!", source) end end) Link to comment
Galton Posted March 7, 2015 Author Share Posted March 7, 2015 that was really helpful, thank you both. 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