Guest User

Skin System (MySQL) | By iRaiDeN

a guest
Apr 13th, 2014
1,958
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.18 KB | None | 0 0
  1. #include < a_samp >
  2. #include < a_mysql >
  3. #include < mSelection >
  4. #include < cpstream >
  5.  
  6. #define DB_SERVER "127.0.0.1"
  7. #define DB_USER "root"
  8. #define DB_PASS ""
  9. #define DB_DB "samp"
  10.  
  11. new
  12. dbHandle ,
  13. pName [ MAX_PLAYERS ] [ 24 ] ,
  14. pSkinID [ MAX_PLAYERS ] ,
  15. gQuery [ 256 ] ,
  16. CP ,
  17. skinlist = mS_INVALID_LISTID ;
  18.  
  19. public OnGameModeInit ( )
  20. {
  21. dbHandle = mysql_connect ( DB_SERVER , DB_USER , DB_DB , DB_PASS ) ;
  22. CP = CPS_AddCheckpoint ( 1433.6328,2622.6990,11.3926 , 2.5 , 100 ) ;
  23. skinlist = LoadModelSelectionMenu("skins.txt");
  24. }
  25.  
  26. public OnPlayerConnect ( playerid )
  27. {
  28. GetPlayerName ( playerid , pName [ playerid ] , 24 ) ;
  29. format ( gQuery , 256 , "SELECT skinid FROM skin WHERE username='%s'" , pName [ playerid ] ) ;
  30. mysql_function_query ( dbHandle , gQuery , 128 , "getPlayerData" , "i" , playerid ) ;
  31. return 1 ;
  32. }
  33.  
  34. public OnPlayerEnterCheckpoint ( playerid )
  35. {
  36. if ( CPS_IsPlayerInCheckpoint ( playerid , CP ) )
  37. return ShowModelSelectionMenu ( playerid , skinlist , "Select Skin" ) ;
  38. return 1 ;
  39. }
  40.  
  41. public OnPlayerModelSelection(playerid, response, listid, modelid)
  42. {
  43. if ( listid == skinlist )
  44. {
  45. if ( response )
  46. {
  47. SendClientMessage ( playerid , 0xFF0000FF , "Skin Changed" ) ;
  48. pSkinID [ playerid ] = modelid ;
  49. format ( gQuery , 256 , "INSERT INTO skin (username,skinid) VALUES (%i,%s) " , pSkinID [ playerid ] , pName [ playerid ] ) ;
  50.  
  51. SetPlayerSkin ( playerid , modelid ) ;
  52. }
  53. else SendClientMessage ( playerid , 0xFF0000FF , "Canceled skin selection" ) ;
  54. return 1;
  55. }
  56. return 1;
  57. }
  58.  
  59. public OnPlayerDisconnect ( playerid , reason )
  60. return savePlayerData ( playerid ) ;
  61.  
  62. public OnPlayerSpawn ( playerid )
  63. return SetPlayerSkin ( playerid , pSkinID [ playerid ] ) ;
  64.  
  65. forward getPlayerData ( playerid ) ;
  66. public getPlayerData ( playerid )
  67. {
  68. pSkinID [ playerid ] = cache_get_field_content_int ( 0 , "skinid" , dbHandle ) ;
  69. return 1 ;
  70. }
  71.  
  72. forward savePlayerData ( playerid ) ;
  73. public savePlayerData ( playerid )
  74. {
  75. format ( gQuery , 256 , "UPDATE skin SET skinid='%i'" , pSkinID [ playerid ] ) ;
  76. mysql_function_query ( dbHandle , gQuery , 256 , "" , "" ) ;
  77. return 1 ;
  78. }
Advertisement
Add Comment
Please, Sign In to add comment