1. #include <a_samp>
  2. #include <a_mysql>
  3. #include <streamer>
  4. #include <sscanf2>
  5. #include <zcmd>
  6. #define host "localhost"
  7. #define user "root"
  8. #define db "mydb" /* CHANGE THIS TO YOUR DATABASE NAME */
  9. #define pass ""
  10. #define COLOR_GREY 0xAFAFAFAA
  11. static mysql;
  12. enum aDATA {
  13. aID,
  14. ValidActor,
  15. aName[24],
  16. ActorSkin,
  17. Float:aX,
  18. Float:aY,
  19. Float:aZ,
  20. Float:aA,
  21. Text3D:ActorText,
  22. ActorPlayer,
  23. Actor_AnimLib[30],
  24. Actor_AnimName[30]
  25. };
  26. new ActorData[MAX_ACTORS][aDATA];
  27. /* SQL */
  28. forward OnActorLoad();
  29. #define FILTERSCRIPT
  30. #if defined FILTERSCRIPT
  31. public OnFilterScriptInit()
  32. {
  33. print("\n--------------------------------------");
  34. print(" Blank Filterscript by your name here");
  35. print("--------------------------------------\n");
  36. sql_LoadAllActors();
  37. return 1;
  38. }
  39. public OnFilterScriptExit()
  40. {
  41. return 1;
  42. }
  43. #else
  44. main()
  45. {
  46. print("\n----------------------------------");
  47. print(" Blank Gamemode by your name here");
  48. print("----------------------------------\n");
  49. }
  50. #endif
  51. /* Commands */
  52. CMD:reloadactors(playerid,params[]) {
  53. sql_LoadAllActors();
  54. return true;
  55. }
  56. CMD:changeactoranim(playerid,params[]) {
  57. new id;
  58. if(sscanf(params,"i",id)) return SendClientMessage(playerid,COLOR_GREY,"Usage: /changeactoranim [actorid]");
  59. new calc = id-1;
  60. if(ActorData[calc][ValidActor] == 0) return SendClientMessage(playerid,COLOR_GREY,"<ACTOR SYSTEM> Invalid actor ID");
  61. new animlib[32];
  62. new animname[32];
  63. GetAnimationName(GetPlayerAnimationIndex(playerid),animlib,32,animname,32);
  64. sql_UpdateActorAnim(id,animlib,animname);
  65. SendClientMessage(playerid,COLOR_GREY,"<ACTOR SYSTEM> You have changed actors animation to your current animation. Reload actors to apply effects");
  66. return true;
  67. }
  68. CMD:createactor(playerid,params[]) {
  69. new actorName[24],skin;
  70. if(sscanf(params,"is[24]",skin,actorName)) return SendClientMessage(playerid,COLOR_GREY,"Usage: /createactor [skinid] [name] ");
  71. new Float:x,Float:y,Float:z,Float:a;
  72. GetPlayerPos(playerid,x,y,z);
  73. GetPlayerFacingAngle(playerid,a);
  74. new animlib[32];
  75. new animname[32];
  76. GetAnimationName(GetPlayerAnimationIndex(playerid),animlib,32,animname,32);
  77. sql_CreateActor(actorName, skin, x,y,z,a, animlib, animname);
  78. new string[128];
  79. format(string,sizeof(string), "New actor created. Skin ID: %i Name: %s. Type /reloadactors to reload all actors",skin,actorName);
  80. SendClientMessage(playerid,COLOR_GREY,string);
  81. return true;
  82. }
  83. CMD:setactorskin(playerid,params[]) {
  84. new ss[10],id;
  85. if(sscanf(params,"is[10]",id,ss)) return SendClientMessage(playerid,COLOR_GREY,"Usage: /setactorskin [actorid] [skinid]");
  86. new calc = id-1;
  87. if(ActorData[calc][ValidActor] == 0) return SendClientMessage(playerid,COLOR_GREY,"<ACTOR SYSTEM> Invalid actor ID");
  88. sql_UpdateActor(id,"skin",ss);
  89. new string[128];
  90. format(string,sizeof(string),"<ACTOR SYSTEM> Edited actors ID: %i Skin ID to %s. Reload actors to apply effects",id,ss);
  91. SendClientMessage(playerid,COLOR_GREY,string);
  92. return true;
  93. }
  94. CMD:setactorname(playerid,params[]) {
  95. new ss[24],id;
  96. if(sscanf(params,"is[24]",id,ss))
  97. return SendClientMessage(playerid,COLOR_GREY,"Usage: /setactorname [actorid] [new_name]");
  98. new calc = id-1;
  99. if(ActorData[calc][ValidActor] == 0) return SendClientMessage(playerid,COLOR_GREY,"<ACTOR SYSTEM> Invalid actor ID");
  100. new string[128];
  101. format(string,sizeof(string),"<ACTOR SYSTEM> Edited actors ID: %i name to %s. Reload actors to apply effects",id,ss);
  102. SendClientMessage(playerid,COLOR_GREY,string);
  103. sql_UpdateActor(id,"name",ss);
  104. return true;
  105. }
  106. CMD:moveactor(playerid,params[]) {
  107. new id;
  108. if(sscanf(params,"i",id)) return SendClientMessage(playerid,COLOR_GREY,"Usage: /moveactor [actorid]");
  109. new calc = id-1;
  110. if(ActorData[calc][ValidActor] == 0) return SendClientMessage(playerid,COLOR_GREY,"<ACTOR SYSTEM> Invalid actor ID");
  111. new string[128];
  112. format(string,sizeof(string),"<ACTOR SYSTEM> Actor ID: %i moved to your current location. Reload actors to apply effects",id);
  113. SendClientMessage(playerid,COLOR_GREY,string);
  114. new Float:x,Float:y,Float:z,Float:a;
  115. GetPlayerFacingAngle(playerid,a);
  116. GetPlayerPos(playerid,x,y,z);
  117. sql_MoveActor(id,x,y,z,a);
  118. return true;
  119. }
  120. /* Functions */
  121. sql_CreateActor(name[]="N/A", skin, Float:x, Float:y,Float:z,Float:a,lib[],libname[]) {
  122. new query[256];
  123. mysql_format(mysql,query,sizeof(query),"INSERT INTO `actors` (`Name`,`SkinID`,`X`,`Y`,`Z`,`A`,`anim_lib`,`anim_name`) VALUES ('%e',%i,%f,%f,%f,%f,'%e','%e')",name,skin,x,y,z,a,lib,libname);
  124. mysql_tquery(mysql,query,"","");
  125. }
  126. sql_UpdateActorAnim(id, anim[], animname[]) {
  127. new query[128];
  128. mysql_format(mysql,query,sizeof(query),"UPDATE `actors` SET `anim_lib`='%e', `anim_name`='%e' WHERE `ID`=%d",anim,animname,id);
  129. mysql_tquery(mysql, query, "","");
  130. }
  131. stock PreloadAnimLib(playerid, animlib[])
  132. {
  133. ApplyAnimation(playerid,animlib,"null",0.0,0,0,0,0,0);
  134. }
  135. sql_LoadAllActors() {
  136. for(new i = 0; i < MAX_ACTORS; i++) {
  137. if(ActorData[i][ValidActor] == 1) {
  138. ActorData[i][aID] = 0;
  139. DestroyActor(ActorData[i][ActorPlayer]);
  140. DestroyDynamic3DTextLabel(ActorData[i][ActorText]);
  141. }
  142. }
  143. mysql_tquery(mysql, "SELECT * FROM `actors`", "OnActorLoad", "");
  144. return true;
  145. }
  146. sql_MoveActor(id,Float:x,Float:y,Float:z,Float:a) {
  147. new query[128];
  148. mysql_format(mysql,query,sizeof(query),"UPDATE `actors` SET `X`=%f, `Y`=%f, `Z`=%f, `A`=%f WHERE `ID`=%d",x,y,z,a,id);
  149. mysql_tquery(mysql,query,"","");
  150. }
  151. sql_UpdateActor(id,var[],varamount[]) {
  152. new query[128];
  153. if(strcmp(var,"name") == 0) {
  154. mysql_format(mysql,query,sizeof(query),"UPDATE `actors` SET `Name`='%e' WHERE `ID`=%d",varamount,id);
  155. mysql_tquery(mysql,query,"","");
  156. }
  157. if(strcmp(var,"skin") == 0) {
  158. new val = strval(varamount);
  159. mysql_format(mysql,query,sizeof(query),"UPDATE `actors` SET `SkinID`=%i WHERE `ID`=%d",val,id);
  160. mysql_tquery(mysql,query,"","");
  161. }
  162. }
  163. strcpy(dest[], const source[], maxlength=sizeof dest) strcat((dest[0] = EOS, dest), source, maxlength);
  164. /* SQL Callbacks */
  165. public OnActorLoad() {
  166. new rows = cache_num_rows(),
  167. count = 0,
  168. string[30],
  169. Sname[30],
  170. SLib[30],
  171. SAnimName[30];
  172. for(new i=0; i < rows; i++) {
  173. ActorData[i][ValidActor] = 1;
  174. ActorData[i][aID] = cache_get_field_content_int(i,"ID");
  175. ActorData[i][ActorSkin] = cache_get_field_content_int(i,"SkinID");
  176. ActorData[i][aX] = cache_get_field_content_float(i,"X");
  177. ActorData[i][aY] = cache_get_field_content_float(i,"Y");
  178. ActorData[i][aZ] = cache_get_field_content_float(i,"Z");
  179. ActorData[i][aA] = cache_get_field_content_float(i,"A");
  180. cache_get_field_content(i,"anim_lib",SLib);
  181. strcpy(ActorData[i][Actor_AnimLib],SLib,50);
  182. cache_get_field_content(i,"anim_name",SAnimName);
  183. strcpy(ActorData[i][Actor_AnimName],SAnimName,50);
  184. cache_get_field_content(i,"Name",Sname);
  185. strcpy(ActorData[i][aName],Sname,24);
  186. format(string,sizeof(string),"{00FFFF}%s(%i)",ActorData[i][aName],ActorData[i][aID]);
  187. ActorData[i][ActorText] = CreateDynamic3DTextLabel(string, 0x008080FF,ActorData[i][aX],ActorData[i][aY],ActorData[i][aZ]+1.05, 10.0, INVALID_PLAYER_ID, INVALID_VEHICLE_ID, 0);
  188. ActorData[i][ActorPlayer] = CreateActor(ActorData[i][ActorSkin],ActorData[i][aX],ActorData[i][aY],ActorData[i][aZ],ActorData[i][aA]);
  189. count += 1;
  190. ApplyActorAnimation(ActorData[i][ActorPlayer],ActorData[i][Actor_AnimLib],ActorData[i][Actor_AnimName], 4.0, 1, 0, 0, 0, 0);
  191. }
  192. if(count == 0) print("<ACTOR SYSTEM> SQL: No actors found the in the SQL.");
  193. else printf("<ACTOR SYSTEM> Total %i actors loaded.",count);
  194. return true;
  195. }