multi-accounts.pwn 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. #include <YSI\y_hooks>
  2. #define MAX_MULTIPLE_CHARACTERS 3
  3. #define PVAR_LOGIN_CHARCAM "P_LCC"
  4. new p_iLoginActors[MAX_MULTIPLE_CHARACTERS];
  5. Login_FetchAccountsData(playerid)
  6. {
  7. format(szMiscArray, sizeof(szMiscArray), "SELECT `id`, `Model` FROM `accounts` WHERE '%d' IN (`LinkedAccount0`, `LinkedAccount1`, `LinkedAccount2`) LIMIT 3", GetPlayerSQLId(playerid));
  8. mysql_tquery(MainPipeline, szMiscArray, true, "Login_OnFetchAccountsData", "i", playerid);
  9. }
  10. forward Login_OnFetchAccountsData(playerid);
  11. public Login_OnFetchAccountsData(playerid)
  12. {
  13. new iRows = cache_get_row_count();
  14. if(!iRows) return SendClientMessage(playerid, COLOR_RED, "Something went terribly wrong.");
  15. new iFields,
  16. iCount;
  17. cache_get_data(iRows, iFields, MainPipeline);
  18. while(iCount < iRows)
  19. {
  20. PlayerInfo[playerid][pAccountIDs][iCount] = cache_get_field_content_int(iCount, "id", MainPipeline);
  21. switch(iCount)
  22. {
  23. case 0: p_iLoginActors[iCount] = CreateActor(cache_get_field_content_int(iCount, "Model", MainPipeline), 5.7748, 14.1756, 1628.3788, 270.0);
  24. case 1: p_iLoginActors[iCount] = CreateActor(cache_get_field_content_int(iCount, "Model", MainPipeline), 6.0349, 15.4743, 1628.4349, 270.0);
  25. case 2: p_iLoginActors[iCount] = CreateActor(cache_get_field_content_int(iCount, "Model", MainPipeline), 5.9984, 16.3238, 1628.3381, 270.0);
  26. }
  27. iCount++;
  28. }
  29. Login_ChooseCharacter(playerid);
  30. return 1;
  31. }
  32. Login_ChooseCharacter(playerid)
  33. {
  34. SetPVarInt(playerid, PVAR_LOGIN_CHARCAM, 1); // middle char
  35. SetPlayerVirtualWorld(playerid, playerid);
  36. SetPlayerInterior(playerid, 0);
  37. SetPlayerTime(playerid, 0, 0);
  38. SetPlayerWeather(playerid, 0);
  39. InterpolateCameraPos(playerid, 14.8219, 16.1507, 1632.1367, 10.0860, 15.5576, 1628.5403, 3000, CAMERA_MOVE);
  40. InterpolateCameraLookAt(playerid, 13.8253, 16.0869, 1631.7872, 9.0879, 15.5258, 1628.4460, 3000, CAMERA_MOVE);
  41. }
  42. Login_SwitchCamera(playerid, source, destination)
  43. {
  44. SetPVarInt(playerid, PVAR_LOGIN_CHARCAM, destination);
  45. switch(source)
  46. {
  47. case 0:
  48. {
  49. InterpolateCameraPos(playerid, 9.1368, 12.0155, 1628.7153, 10.4134, 15.4542, 1628.7153, 3000, CAMERA_MOVE);
  50. InterpolateCameraLookAt(playerid, 8.3955, 12.6845, 1628.5813, 9.4166, 15.3944, 1628.5713, 3000, CAMERA_MOVE);
  51. }
  52. case 1:
  53. {
  54. switch(destination)
  55. {
  56. case 0:
  57. {
  58. InterpolateCameraPos(playerid, 10.4134, 15.4542, 1628.7153, 9.1368, 12.0155, 1628.7153, 3000, CAMERA_MOVE);
  59. InterpolateCameraLookAt(playerid, 9.4166, 15.3944, 1628.5713, 8.3955, 12.6845, 1628.5813, 3000, CAMERA_MOVE);
  60. }
  61. case 2:
  62. {
  63. InterpolateCameraPos(playerid, 10.4134, 15.4542, 1628.7153, 8.7182, 19.5138, 1628.7153, 3000, CAMERA_MOVE);
  64. InterpolateCameraLookAt(playerid, 9.4166, 15.3944, 1628.5713, 8.7182, 19.5138, 1628.7153, 3000, CAMERA_MOVE);
  65. }
  66. }
  67. }
  68. case 2:
  69. {
  70. InterpolateCameraPos(playerid, 8.7182, 19.5138, 1628.7153, 10.4134, 15.4542, 1628.7153, 3000, CAMERA_MOVE);
  71. InterpolateCameraLookAt(playerid, 8.0880, 18.7392, 1628.62133, 9.4166, 15.3944, 1628.5713, 3000, CAMERA_MOVE);
  72. }
  73. }
  74. }
  75. Login_LoadCharacter(playerid, choice)
  76. {
  77. g_mysql_SaveAccount(playerid);
  78. OnPlayerDisconnect(playerid, 1);
  79. format(szMiscArray, sizeof(szMiscArray), "SELECT `Username` FROM `accounts` WHERE `id` = %d LIMIT 1", PlayerInfo[playerid][pAccountIDs][choice]);
  80. mysql_tquery(MainPipeline, szMiscArray, true, "Login_OnLoadCharacter", "i", playerid);
  81. }
  82. forward Login_OnLoadCharacter(playerid);
  83. public Login_OnLoadCharacter(playerid)
  84. {
  85. new iRows,
  86. iFields,
  87. iCount,
  88. szName[MAX_PLAYER_NAME];
  89. cache_get_data(iRows, iFields, MainPipeline);
  90. cache_get_field_content(iCount, "Username", szName, MainPipeline, sizeof(szName));
  91. while(iCount < iRows)
  92. {
  93. SetPlayerName(playerid, szName);
  94. iCount++;
  95. }
  96. DeletePVar(playerid, PVAR_LOGIN_CHARCAM);
  97. for(new i; i < sizeof(p_iLoginActors); ++i) DestroyActor(p_iLoginActors[i]);
  98. g_mysql_LoadAccount(playerid);
  99. return 1;
  100. }
  101. hook OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
  102. {
  103. if(GetPVarInt(playerid, PVAR_LOGIN_CHARCAM))
  104. {
  105. new logincharacter = GetPVarInt(playerid, PVAR_LOGIN_CHARCAM);
  106. if(newkeys & KEY_LEFT)
  107. {
  108. if(logincharacter == 0) return 1;
  109. Login_SwitchCamera(playerid, logincharacter, logincharacter - 1);
  110. return 1;
  111. }
  112. if(newkeys & KEY_RIGHT)
  113. {
  114. if(logincharacter == 2) return 1;
  115. Login_SwitchCamera(playerid, logincharacter, logincharacter + 1);
  116. return 1;
  117. }
  118. if(newkeys & KEY_SPRINT)
  119. {
  120. Login_LoadCharacter(playerid, logincharacter);
  121. return 1;
  122. }
  123. }
  124. return 1;
  125. }
  126. CMD:charselection(playerid, params[])
  127. {
  128. Login_FetchAccountsData(playerid);
  129. return 1;
  130. }