Guest User

Actor System V0.2

a guest
Mar 31st, 2016
1,034
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.34 KB | None | 0 0
  1. /*==============================================================================
  2. =================================[Actor System]=================================
  3. =================================[by Yogurt]====================================
  4. ==============================================================================*/
  5.  
  6. /*===================================[Legal]====================================
  7.  
  8. The contents of this file are subject to the Mozilla Public License
  9. Version 2.o (the "License"); you may not use this file except in
  10. compliance with the License. You may obtain a copy of the License at
  11. http://www.mozilla.org/MPL/
  12.  
  13. Software distributed under the License is distributed on an "AS IS"
  14. basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
  15. License for the specific language governing rights and limitations
  16. under the License.
  17.  
  18. The Original Code is Actor System.
  19.  
  20. The Initial Developer of the Original Code is Yogurt.
  21. Portions created by Initial Developer are Copyright (C) 2016
  22. Initial Developer. All Rights Reserved.
  23.  
  24. Contributor(s): Y_Less, Incognito, Zeex.
  25.  
  26. And dont forget to add my facebook account Muhamad Ramadhan. Thank you
  27.  
  28. ==============================================================================*/
  29.  
  30. /*==================================[Credits]===================================
  31.  
  32. Special Thanks to :
  33. • SA:MP Team past & present
  34.  
  35. Thanks to :
  36. • Y_Less for sscanf, foreach, and YSI
  37. • Incognito for streamer
  38. • Zeex for zcmd
  39. ==============================================================================*/
  40.  
  41. /*=================================[Changelog]==================================
  42.  
  43. Version 0.1:
  44. - Initial release
  45.  
  46. Version 0.2:
  47. - Added Actor Text with 3DTextLabel
  48. - Added Actor Animation
  49. ==============================================================================*/
  50.  
  51. //=============================[Include & Defines]==============================
  52.  
  53. #pragma tabsize 0
  54. #include <a_samp>
  55.  
  56. #include <a_actor>
  57. #include <sscanf2> // sscanf plugin by Y_Less
  58. #include <streamer> // streamer plugin by Incognito
  59.  
  60. #include <YSI\y_iterate> // YSI by Y_Less
  61. #if defined USE_YCMD
  62. #include <YSI\y_commands> // YSI by Y_Less
  63. #else
  64. #include <zcmd> // zcmd include by Zeex
  65. #endif
  66.  
  67.  
  68. #define SEM(%0,%1) SendClientMessage(%0,0xBFC0C200,%1) // SEM = Send Error Message by Myself
  69. #define Loop(%0,%1) for(new %0 = 0; %0 < %1; %0++) // Loop by Myself
  70. #define IsNull(%1) ((!(%1[0])) || (((%1[0]) == '\1') && (!(%1[1])))) // IsNull macro by Y_Less
  71. #define strToLower(%0) \
  72. for(new i; %0[i] != EOS; ++i) \
  73. %0[i] = ('A' <= %0[i] <= 'Z') ? (%0[i] += 'a' - 'A') : (%0[i]) // strToLower by RyDeR`
  74. #define RGBAToInt(%0,%1,%2,%3) \
  75. ((16777216 * (%0)) + (65536 * (%1)) + (256 * (%2)) + (%3)) // RGBAToInt by RyDeR`
  76.  
  77. #define COLOR_GREY 0xAFAFAFAA
  78. #define COLOR_GREEN 0x33AA33AA
  79. #define COLOR_RED 0xAA3333AA
  80. #define COLOR_YELLOW 0xFFFF00AA
  81. #define COLOR_WHITE 0xFFFFFFFF
  82.  
  83. #define MAX_EDITING_ACTOR (100)
  84.  
  85. new Iterator:DynamicActors<MAX_EDITING_ACTOR>;
  86. new DynamicActor[MAX_EDITING_ACTOR];
  87. new Text3D:DynamicActorLabel[MAX_EDITING_ACTOR];
  88.  
  89. //------------------------------------------------------------------------------------------------------
  90.  
  91. //------------------------------------------------------------------------------------------------------
  92.  
  93. public OnFilterScriptInit()
  94. {
  95. print("=========================================");
  96. print("|==========[Actor System V0.1]==========|");
  97. print("|==========[----By Yogurt----]==========|");
  98. print("|==========[Has been loaded!!]==========|");
  99. print("=========================================");
  100. return 1;
  101. }
  102.  
  103. SSCANF:actormenu(string[])
  104. {
  105. if(!strcmp(string,"create",true)) return 1;
  106. else if(!strcmp(string,"add",true)) return 1;
  107. else if(!strcmp(string,"destroy",true)) return 2;
  108. else if(!strcmp(string,"delete",true)) return 2;
  109. else if(!strcmp(string,"remove",true)) return 2;
  110. else if(!strcmp(string,"clear",true)) return 3;
  111. else if(!strcmp(string,"reset",true)) return 3;
  112. else if(!strcmp(string,"goto",true)) return 4;
  113. else if(!strcmp(string,"gethere",true)) return 5;
  114. else if(!strcmp(string,"text",true)) return 6;
  115. else if(!strcmp(string,"anim",true)) return 7;
  116. else if(!strcmp(string,"stopanim",true)) return 8;
  117. return 0;
  118. }
  119.  
  120. //------------------------------------------------------------------------------
  121.  
  122. CMD:actor(playerid,params[])
  123. {
  124. new action,subparam[128],string[256];
  125. unformat(params,"k<actormenu>S()[128]",action,subparam);
  126. switch(action)
  127. {
  128. case 1:
  129. {
  130. if(IsNull(subparam)) return SEM(playerid,"<SYNTAX> : /actor create [skin]");
  131. new model = strval(subparam);
  132. new slot = Iter_Free(DynamicActors);
  133. if(slot != -1)
  134. {
  135. new Float:cPos[4];
  136. GetPlayerPos(playerid,cPos[0],cPos[1],cPos[2]);
  137. GetPlayerFacingAngle(playerid,cPos[3]);
  138. DynamicActor[slot] = CreateActor(model,cPos[0],cPos[1],cPos[2],cPos[3]);
  139. format(string,32,"[Actor ID %d]",slot);
  140. DynamicActorLabel[slot] = CreateDynamic3DTextLabel(string,0xAFAFAFFF,cPos[0],cPos[1],(cPos[2]+0.9),10.0);
  141. Streamer_Update(playerid);
  142. SetPlayerPos(playerid,cPos[0],cPos[1],(cPos[2]+2.0));
  143. Iter_Add(DynamicActors,slot);
  144. format(string,128,"<ACTOR> : Actor model '%d' with slot id '%d' created, total actors: %d",model,slot,Iter_Count(DynamicActors));
  145. SendClientMessage(playerid,-1,string);
  146. }
  147. else SEM(playerid,"<ERROR> : No actor free slot!");
  148. }
  149. case 2:
  150. {
  151. if(IsNull(subparam)) return SEM(playerid,"<SYNTAX> : /actor destroy [slot]");
  152. new slot = strval(subparam);
  153. if(Iter_Contains(DynamicActors,slot))
  154. {
  155. DestroyActor(DynamicActor[slot]);
  156. DestroyDynamic3DTextLabel(DynamicActorLabel[slot]);
  157. Iter_Remove(DynamicActors,slot);
  158. format(string,128,"<ACTOR> : Actor with slot id '%d' has been deleted, total actors: %d",slot,Iter_Count(DynamicActors));
  159. SendClientMessage(playerid,-1,string);
  160. }
  161. else SEM(playerid,"<ERROR> : Invalid actor slot id!");
  162. }
  163. case 3:
  164. {
  165. if(IsNull(subparam)) return SEM(playerid,"<SYNTAX> : /actor clear [confirm]");
  166. if(!strcmp(subparam,"confirm",true))
  167. {
  168. new count = Iter_Count(DynamicActors);
  169. if(count > 0)
  170. {
  171. foreach(new i : DynamicActors)
  172. {
  173. DestroyActor(DynamicActor[i]);
  174. DestroyDynamic3DTextLabel(DynamicActorLabel[i]);
  175. }
  176. Iter_Clear(DynamicActors);
  177. format(string,128,"<ACTOR> : %d actors have been cleared",count);
  178. SendClientMessage(playerid,-1,string);
  179. }
  180. else SEM(playerid,"<ERROR> : There are no actors!");
  181. }
  182. else SEM(playerid,"<SYNTAX> : /actor clear [confirm]");
  183. }
  184. case 4:
  185. {
  186. if(IsNull(subparam)) return SEM(playerid,"<SYNTAX> : /actor goto [slot]");
  187. new slot = strval(subparam);
  188. if(Iter_Contains(DynamicActors,slot))
  189. {
  190. new Float:cPos[3];
  191. GetActorPos(DynamicActor[slot],cPos[0],cPos[1],cPos[2]);
  192. Streamer_UpdateEx(playerid,cPos[0],cPos[1],cPos[2]);
  193. SetPlayerPos(playerid,cPos[0],cPos[1],(cPos[2]+1.5));
  194. format(string,128,"<ACTOR> : Teleported to actor id %d!",slot);
  195. SendClientMessage(playerid,-1,string);
  196. }
  197. else SEM(playerid,"<ERROR> : Invalid actor slot id!");
  198. }
  199. case 5:
  200. {
  201. if(IsNull(subparam)) return SEM(playerid,"<SYNTAX> : /actor gethere [slot]");
  202. new slot = strval(subparam);
  203. if(Iter_Contains(DynamicActors,slot))
  204. {
  205. new Float:cPos[3];
  206. GetPlayerPos(playerid,cPos[0],cPos[1],cPos[2]);
  207. SetActorPos(DynamicActor[slot],cPos[0],cPos[1],cPos[2]);
  208. Streamer_SetFloatData(STREAMER_TYPE_3D_TEXT_LABEL,DynamicActorLabel[slot],E_STREAMER_X,cPos[0]);
  209. Streamer_SetFloatData(STREAMER_TYPE_3D_TEXT_LABEL,DynamicActorLabel[slot],E_STREAMER_Y,cPos[1]);
  210. Streamer_SetFloatData(STREAMER_TYPE_3D_TEXT_LABEL,DynamicActorLabel[slot],E_STREAMER_Z,(cPos[2]+0.8));
  211. Streamer_Update(playerid);
  212. SetPlayerPos(playerid,cPos[0],cPos[1],(cPos[2]+1.5));
  213. format(string,128,"<ACTOR> : Teleported actor id %d to your location!",slot);
  214. SendClientMessage(playerid,-1,string);
  215. }
  216. else SEM(playerid,"<ERROR> : Invalid actor slot id!");
  217. }
  218. case 6:
  219. {
  220. new slot,text[128];
  221. if(sscanf(subparam,"ds[128]",slot,text)) return SEM(playerid,"<SYNTAX> : /actor text [slot] [text]");
  222. if(Iter_Contains(DynamicActors,slot))
  223. {
  224. format(string,128,"[Actor ID %d]\n%s",slot,text);
  225. UpdateDynamic3DTextLabelText(DynamicActorLabel[slot],0xAFAFAFFF,string);
  226. format(string,128,"<ACTOR> : Actor id '%d' has been changed text!",slot);
  227. SendClientMessage(playerid,-1,string);
  228. Streamer_Update(playerid);
  229. }
  230. else SEM(playerid,"<ERROR> : Invalid actor slot id!");
  231. }
  232. case 7:
  233. {
  234. new slot,anim[32],animlib[32];
  235. if(sscanf(subparam,"ds[32]s[32]",slot,animlib,anim)) return SEM(playerid,"<SYNTAX> : /actor anim [slot] [animlib] [anim] || Note: Check animations list from Google!");
  236. if(Iter_Contains(DynamicActors,slot))
  237. {
  238. ApplyActorAnimation(DynamicActor[slot], animlib, anim, 4.1, 0, 0, 0, 0, 9999999);
  239. Streamer_Update(playerid);
  240. format(string,128,"<ACTOR> : Actor id '%d' has been added anim!",slot);
  241. SendClientMessage(playerid,-1,string);
  242. }
  243. else SEM(playerid,"<ERROR> : Invalid actor slot id!");
  244. }
  245. case 8:
  246. {
  247. if(IsNull(subparam)) return SEM(playerid,"<SYNTAX> : /actor stopanim [slot]");
  248. new slot = strval(subparam);
  249. if(Iter_Contains(DynamicActors,slot))
  250. {
  251. ClearActorAnimations(DynamicActor[slot]);
  252. format(string,128,"<ACTOR> : Actor id '%d' has been stoped from animation!",slot);
  253. }
  254. else SEM(playerid,"<ERROR> : Invalid actor slot id!");
  255. }
  256. default:
  257. {
  258. SEM(playerid,"<SYNTAX> : /actor [action]");
  259. SEM(playerid,"<ACTIONS> : create,destroy,clear,goto,gethere,text,anim,stopanim");
  260. }
  261. }
  262. return 1;
  263. }
  264. //------------------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment