api.lua 815 B

1234567891011121314151617181920212223242526272829303132333435
  1. -- get current skin
  2. function skins.get_player_skin(player)
  3. local skin = player:get_attribute("skinsdb:skin_key")
  4. return skins.get(skin) or skins.get(skins.default)
  5. end
  6. -- Assign skin to player
  7. function skins.assign_player_skin(player, skin)
  8. local skin_obj
  9. local skin_key
  10. if type(skin) == "string" then
  11. skin_obj = skins.get(skin) or skins.get(skins.default)
  12. else
  13. skin_obj = skin
  14. end
  15. skin_key = skin_obj:get_key()
  16. if skin_key == skins.default then
  17. skin_key = ""
  18. end
  19. player:set_attribute("skinsdb:skin_key", skin_key)
  20. end
  21. -- update visuals
  22. function skins.update_player_skin(player)
  23. local skin = skins.get_player_skin(player)
  24. skin:set_skin(player)
  25. end
  26. -- Assign and update
  27. function skins.set_player_skin(player, skin)
  28. skins.assign_player_skin(player, skin)
  29. skins.update_player_skin(player)
  30. end