BlueWall

Casper AO

Mar 2nd, 2012
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.76 KB | None | 0 0
  1. // Low Lag AO by Casper Warden // Completely license free
  2.  
  3. // This script was created on K-Grid and is free to use or modify
  4.  
  5. // ABOUT THIS SCRIPT
  6. // -----------------
  7. //
  8. // This is an animation overrider optimised for use on K-Grid. We don't use
  9. // complicated list parsing, and we don't have a timer firing every 0.5 seconds
  10. // like other AO's.
  11. //
  12. // All configuration is done in the notecard "AOConfig".
  13. // Use a format of
  14. //
  15. // [AnimationState (e.g Walking)]
  16. // Animation one
  17. // Animation two
  18. // Animation three
  19. //
  20. // [AnimationState] ... etc etc
  21. //
  22. // The animations will be selected randomly. You can have more than one animation
  23. // per state.
  24.  
  25. // DO NOT MODIFY THIS SCRIPT UNLESS YOU KNOW WHAT YOU'RE DOING
  26. // THE ONLY CONFIG YOU NEED IS IN THE 'AOConfig' NOTECARD
  27.  
  28.  
  29. //Since list functions are unreliable we're going to use a different list for each anim type
  30.  
  31. list Walking;
  32. list Running;
  33. list CrouchWalking;
  34. list Flying;
  35. list Jumping;
  36. list HoveringDown;
  37. list HoveringUp;
  38. list Crouching;
  39. list FlyDown;
  40. list Standing;
  41. list Hovering;
  42. list Sitting;
  43. list SoftLanding;
  44. list PreJumping;
  45. list Falling;
  46. list Landing;
  47. list StandingUp;
  48. list FlyingSlow;
  49. list SittingonGround;
  50. list Floating;
  51. list SwimmingForward;
  52. list SwimmingUp;
  53. list SwimmingDown;
  54.  
  55. integer aoon=TRUE;
  56. integer radaron=TRUE;
  57. integer siton=TRUE;
  58. integer sittinganywhere=FALSE;
  59.  
  60. key gQueryID;
  61. integer gLine=0;
  62. string currentmode;
  63. string lastactive="";
  64. string lastactiveanim="";
  65.  
  66.  
  67. string GetAnimationFromState(string s) {
  68.  
  69. if (sittinganywhere==TRUE)
  70. {
  71. s="Sitting on Ground";
  72. }
  73.  
  74. list animselect;
  75. if (s=="Walking") {
  76. animselect = Walking;
  77. } else if (s=="Running") {
  78. animselect = Running;
  79. } else if (s=="CrouchWalking") {
  80. animselect = CrouchWalking;
  81. } else if (s=="Flying") {
  82. animselect = Flying;
  83. } else if (s=="Jumping") {
  84. animselect = Jumping;
  85. } else if (s=="Hovering Up") {
  86. animselect = HoveringUp;
  87. } else if (s=="Crouching") {
  88. animselect = Crouching;
  89. } else if (s=="FlyDown") {
  90. animselect = FlyDown;
  91. } else if (s=="Standing") {
  92. animselect = Standing;
  93. } else if (s=="Hovering Down") {
  94. animselect = HoveringDown;
  95. } else if (s=="Hovering") {
  96. animselect = Hovering;
  97. } else if (s=="Sitting") {
  98. if (siton==TRUE)
  99. {
  100. animselect = Sitting;
  101. }
  102. else
  103. {
  104. animselect = [TRUE,FALSE,TRUE];
  105. }
  106. } else if (s=="PreJumping") {
  107. animselect = PreJumping;
  108. } else if (s=="Falling") {
  109. animselect = Falling;
  110. } else if (s=="Soft Landing") {
  111. animselect = SoftLanding;
  112. } else if (s=="Landing") {
  113. animselect = Landing;
  114. } else if (s=="Standing Up") {
  115. animselect = StandingUp;
  116. } else if (s=="Flying Slow") {
  117. animselect = FlyingSlow;
  118. } else if (s=="Sitting on Ground") {
  119. if (sittinganywhere==TRUE)
  120. {
  121. if (SittingonGround==[])
  122. {
  123. animselect=["sit_ground"];
  124. }
  125. else
  126. {
  127. animselect = SittingonGround;
  128. }
  129. }
  130. else
  131. {
  132. animselect = SittingonGround;
  133. }
  134. } else if (s=="Floating") {
  135. animselect = Floating;
  136. } else if (s=="Swimming Forward") {
  137. animselect = SwimmingForward;
  138. } else if (s=="Swimming Up") {
  139. animselect = SwimmingUp;
  140. } else if (s=="Swimming Down") {
  141. animselect = SwimmingDown;
  142. } else {
  143. llOwnerSay("Unknown state: "+s);
  144. return "";
  145. }
  146. if (animselect!=[TRUE,FALSE,TRUE])
  147. {
  148. animselect=llListRandomize(animselect, 1);
  149. return llList2String(animselect,0);
  150. } else {
  151. return lastactiveanim;
  152. }
  153.  
  154. }
  155. StopAllAnims(){
  156.  
  157. integer x;
  158. list h=llGetAnimationList(llGetOwner());
  159. for (x=0; x<llGetListLength(h); x++)
  160. {
  161. llStopAnimation(llList2String(h,x));
  162.  
  163. }
  164.  
  165.  
  166. }
  167. doAOCheck() {
  168. //llOwnerSay("Doing check");
  169. string check=llGetAnimation(llGetOwner());
  170. if (check!=lastactive) {
  171. lastactive=check;
  172. if (check!="") {
  173. string getAnim=GetAnimationFromState(check);
  174. //llOwnerSay(getAnim);
  175. if (lastactiveanim!=getAnim) {
  176. if (lastactiveanim!="") {
  177. llStopAnimation(lastactiveanim);
  178. }
  179. lastactiveanim=getAnim;
  180. llStartAnimation(lastactiveanim);
  181. float vz;
  182. vector pos;
  183. float diff=1.0;
  184. integer count=0;
  185. if (check=="Jumping") {
  186.  
  187.  
  188. @to;
  189. pos=llGetPos();
  190. vz=pos.z;
  191. llSleep(0.2);
  192. pos=llGetPos();
  193. diff=pos.z - vz;
  194.  
  195. if (diff>0.1 || diff < -0.1) {
  196. jump to;
  197. } else {
  198. count++;
  199. if (count<3) {
  200. jump to;
  201. }
  202. }
  203.  
  204.  
  205. doAOCheck();
  206. }
  207. }
  208. }
  209. }
  210. }
  211. default
  212. {
  213.  
  214. state_entry()
  215. {
  216. llSetTimerEvent(30.0);
  217. llSetText("",<1,1,1>,0.0);
  218. llOwnerSay("Reading notecard (will retry in 30 seconds).");
  219. if (llGetInventoryType("AOConfig")==INVENTORY_NONE) {
  220. llOwnerSay("Can't start AO: Notecard 'AOConfig' is missing");
  221. } else {
  222. gQueryID = llGetNotecardLine("AOConfig",0);
  223. }
  224. }
  225. timer()
  226. {
  227. llResetScript();
  228. }
  229. touch_start(integer j)
  230. {
  231. llResetScript();
  232. }
  233. dataserver(key query_id, string data) {
  234. if (query_id == gQueryID) {
  235. if (data != EOF) { // not at the end of the notecard
  236. gLine++;
  237. gQueryID = llGetNotecardLine("AOConfig", gLine); // request next line
  238. data=llStringTrim(data,STRING_TRIM);
  239. if (data!="") {
  240.  
  241. if (llGetSubString(data,0,0)=="[") {
  242. currentmode=llToLower(data);
  243. } else {
  244. if (llGetInventoryType(data)==INVENTORY_NONE) {
  245. llOwnerSay("NOT ADDED: "+data+" - Not found in inventory");
  246. } else {
  247. //Decipher which mode we're in
  248. if (currentmode=="[walking]") {
  249. Walking+=[data];
  250. } else if (currentmode=="[running]") {
  251. Running+=[data];
  252. } else if (currentmode=="[crouchwalking]") {
  253. CrouchWalking+=[data];
  254. } else if (currentmode=="[flying]") {
  255. Flying+=[data];
  256. } else if (currentmode=="[jumping]") {
  257. Jumping+=[data];
  258. } else if (currentmode=="[hovering up]") {
  259. HoveringUp+=[data];
  260. } else if (currentmode=="[crouching]") {
  261. Crouching+=[data];
  262. } else if (currentmode=="[fly down]") {
  263. FlyDown+=[data];
  264. } else if (currentmode=="[standing]") {
  265. Standing+=[data];
  266. } else if (currentmode=="[hovering down]") {
  267. HoveringDown+=[data];
  268. } else if (currentmode=="[hovering]") {
  269. Hovering+=[data];
  270. } else if (currentmode=="[sitting]") {
  271. Sitting+=[data];
  272. } else if (currentmode=="[prejumping]") {
  273. PreJumping+=[data];
  274. } else if (currentmode=="[falling]") {
  275. Falling+=[data];
  276. } else if (currentmode=="[landing]") {
  277. Landing+=[data];
  278. } else if (currentmode=="[soft landing]") {
  279. SoftLanding+=[data];
  280. } else if (currentmode=="[standing up]") {
  281. StandingUp+=[data];
  282. } else if (currentmode=="[flyingslow]") {
  283. FlyingSlow+=[data];
  284. } else if (currentmode=="[sitting on ground]") {
  285. SittingonGround+=[data];
  286. } else if (currentmode=="[floating]") {
  287. Floating+=[data];
  288. } else if (currentmode=="[swimming forward]") {
  289. SwimmingForward+=[data];
  290. } else if (currentmode=="[swimming up]") {
  291. SwimmingUp+=[data];
  292. } else if (currentmode=="[swimming down]") {
  293. SwimmingDown+=[data];
  294. } else {
  295. llOwnerSay("Unknown mode: "+currentmode);
  296. }
  297.  
  298. }
  299. }
  300. }
  301.  
  302. } else {
  303. state Perms;
  304. }
  305. }
  306. }
  307. }
  308. state Perms
  309. {
  310.  
  311. state_entry() {
  312. llRequestPermissions(llGetOwner(),PERMISSION_TRIGGER_ANIMATION);
  313.  
  314. }
  315. run_time_permissions(integer h) {
  316. if (!(h & PERMISSION_TRIGGER_ANIMATION)) {
  317. llOwnerSay("Can't function without permissions. Touch to reset.");
  318. } else {
  319. state On;
  320. }
  321. }
  322. touch_start(integer j) {
  323. llResetScript();
  324. }
  325.  
  326. }
  327. state On
  328. {
  329. state_entry() {
  330. llOwnerSay("AO is now active");
  331. StopAllAnims();
  332. llSetTexture("49d8cc3a-1c3a-4fad-bfd2-75202b894f53",ALL_SIDES);
  333. doAOCheck();
  334. llListen(-9000, "", llGetOwner(), "");
  335. llSetTimerEvent(0);
  336. }
  337. changed(integer j) {
  338. if (j & CHANGED_REGION) {
  339. llResetScript();
  340. } else if (j & CHANGED_ANIMATION) {
  341. if (aoon==TRUE)
  342. {
  343. doAOCheck();
  344. }
  345. }
  346. }
  347. touch_start(integer j)
  348. {
  349. for (j=j-1; j>-1; j--)
  350. {
  351. if (llDetectedLinkNumber(j) == llGetLinkNumber()) {
  352. if (aoon==TRUE)
  353. {
  354. aoon=FALSE;
  355. if (lastactiveanim!="")
  356. {
  357. llStopAnimation(lastactiveanim);
  358. }
  359. llSetTexture("0d19dc46-66e6-4341-beb2-cfe08a5fab96",ALL_SIDES);
  360. }
  361. else
  362. {
  363. aoon=TRUE;
  364. llSetTexture("49d8cc3a-1c3a-4fad-bfd2-75202b894f53",ALL_SIDES);
  365. doAOCheck();
  366. }
  367. } else {
  368.  
  369. //Throw a menu
  370. llDialog(llDetectedKey(j),"What do you want to do?",["Toggle Sit","Sit Anywhere","Reset"],-9000);
  371.  
  372.  
  373. }
  374. }
  375. }
  376. listen(integer channel, string name, key id, string message)
  377. {
  378. if (message=="Reset") {
  379.  
  380. llResetScript();
  381. } else if (message=="Toggle Sit") {
  382.  
  383. if (siton==TRUE)
  384. {
  385. siton=FALSE;
  386. llOwnerSay("Sit off");
  387. if (aoon){
  388. lastactive="";
  389. doAOCheck();
  390. }
  391. } else {
  392.  
  393. siton=TRUE;
  394. llOwnerSay("Sit On");
  395. if (aoon){
  396. lastactive="";
  397. doAOCheck();
  398.  
  399. }
  400.  
  401. }
  402.  
  403. } else if (message=="Sit Anywhere") {
  404.  
  405. if (sittinganywhere==TRUE){
  406.  
  407. sittinganywhere=FALSE;
  408. if (aoon) {
  409. lastactive="";
  410. doAOCheck();
  411. }
  412. else
  413. {
  414. StopAllAnims();
  415. }
  416. }
  417. else
  418. {
  419. sittinganywhere=TRUE;
  420. lastactive="";
  421. doAOCheck();
  422. }
  423. }
  424. }
  425. }
Advertisement
Add Comment
Please, Sign In to add comment