ulfricmalcom

Dragon Shouts

Feb 8th, 2013
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 14.02 KB | None | 0 0
  1. /* Particle Effects
  2.  
  3. 18692 fire
  4. 18697 helidust
  5. 18731 tear gas
  6. 18732 large tear gas
  7. 18675 coke puff
  8.  
  9. */
  10.  
  11. #define FILTERSCRIPT
  12.  
  13. #include <a_samp>
  14. #include <zcmd>
  15. #include <sscanf2>
  16.  
  17. new Float: speed = 0.5; // by default
  18. new dragonBorns[512];
  19. new dragonBorn[MAX_PLAYERS];
  20. new myShout[MAX_PLAYERS];
  21. new myCoolDown[MAX_PLAYERS];
  22. new shoutEffect[MAX_PLAYERS][3];// 0 = disarm, 1 = fire damage, 2 = frost damage
  23. new fireEffect[MAX_PLAYERS];
  24. new frostEffect[MAX_PLAYERS];
  25. new playerWeapon[MAX_PLAYERS];
  26. new useCoolDown = 0; //default 0 - off
  27. new timerID;
  28. new shoutNames[5][30] = {"Unrelenting Force", "Whirlwind Sprint", "Disarm", "Fire Breath", "Frost Breath"};
  29. new shoutCool[5] = {18, 14, 16, 25, 25};
  30.  
  31. public OnFilterScriptInit()
  32. {
  33.     print("\n--------------------------------------");
  34.     print(" ulfricmalcom");
  35.     print("--------------------------------------\n");
  36.     timerID = SetTimer("OneSecUpdate", 1000, true);
  37.     for(new i = 0; i < MAX_PLAYERS; i++)
  38.     {
  39.         if(IsPlayerConnected(i)) playerWeapon[i] = GetPlayerWeapon(i);
  40.         /*fireEffect[i] = -1;
  41.         frostEffect[i] = -1;*/
  42.     }
  43.     return 1;
  44. }
  45.  
  46. public OnFilterScriptExit()
  47. {
  48.     print("Shout unloaded.");
  49.     KillTimer(timerID);
  50.     return 1;
  51. }
  52.  
  53. public OnPlayerUpdate(playerid)
  54. {
  55.     //weapon swap checker
  56.     new iCurWeap = GetPlayerWeapon(playerid);
  57.     if(iCurWeap != playerWeapon[playerid])
  58.     {
  59.         if(shoutEffect[playerid][0] > 0)
  60.         {
  61.             if(iCurWeap > 15 || iCurWeap < 43)SetPlayerArmedWeapon(playerid, 0);
  62.         }
  63.         playerWeapon[playerid] = iCurWeap;
  64.     }
  65.     return 1;
  66. }
  67.  
  68. public OnPlayerSpawn(playerid)
  69. {
  70.     for(new e = 0; e < 3; e++) shoutEffect[playerid][e] = 0;
  71.     return 1;
  72. }
  73.  
  74. /*CMD:cooldown(playerid, params[])
  75. {
  76.     new string[128], option[5];
  77.     if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, -1, " ");
  78.     if(useCoolDown == 0){
  79.         useCoolDown = 1;
  80.         option = "on";
  81.     }else{
  82.         useCoolDown = 0;
  83.         option = "off";
  84.     }
  85.     format(string, 128, "Cool down is now %s.", option);
  86.     SendClientMessageToAll(-1, string);
  87.     return 1;
  88. }*/
  89. CMD:dshout(playerid, params[])
  90. {
  91.     new Float:x, Float:y, Float:z, string[128];
  92.     new shouttype = myShout[playerid];
  93.     GetPlayerHealth(playerid, z);
  94.     if(!dragonBorn[playerid]) return SendClientMessage(playerid, -1, " * You cannot shout, you are not the dragon born!");
  95.     if(z < 0.0000001) return SendClientMessage(playerid, -1, "You can't shout if you are dead.");
  96.     if(useCoolDown == 1 && myCoolDown[playerid] != 0)
  97.     {
  98.         format(string, sizeof(string), "Please wait for %d seconds before shouting again.", myCoolDown[playerid]);
  99.         return SendClientMessage(playerid, -1, string);
  100.     }
  101.     if(IsPlayerInAnyVehicle(playerid))
  102.     {
  103.         GetPlayerPos(playerid, x, y, z);
  104.         CreateExplosion(x, y, z, 2, 10.0);
  105.         SetPlayerHealth(playerid, 0.0);
  106.         return SendClientMessage(playerid, -1, "You shouted in a vehicle, thus creating an awesome explosion.");
  107.     }
  108.     GetPlayerPos(playerid, x, y, z);
  109.     SendShoutSoundToAll(x, y, z, myShout[playerid]);
  110.     SetTimerEx("ApplyShout", 1000, false, "ii", shouttype, playerid);
  111.     if(shouttype == 0) SetPlayerChatBubble(playerid, "FUS RO DAH", -1, 35, 5000);
  112.     else if(shouttype == 1) SetPlayerChatBubble(playerid, "WULD NAH KEST", -1, 35, 5000);
  113.     else if(shouttype == 2) SetPlayerChatBubble(playerid, "ZUN HAL VIIK", -1, 35, 5000);
  114.     else if(shouttype == 3) SetPlayerChatBubble(playerid, "YOL TOOR SHUL", -1, 35, 5000);
  115.     else if(shouttype == 4) SetPlayerChatBubble(playerid, "FO KRAH DIIN", -1, 35, 5000);
  116.     return 1;
  117. }
  118.  
  119. CMD:setshout(playerid, params[])
  120. {
  121.     new shouttype, string[128];
  122.     if(!dragonBorn[playerid]) return SendClientMessage(playerid, -1, " * You cannot shout, you are not the dragon born!");
  123.     if(sscanf(params, "d", shouttype))
  124.     {
  125.         SendClientMessage(playerid, -1, "Syntax: /setshout [shoutid]");
  126.         SendClientMessage(playerid, -1, "Unrelenting Force(0) Whirlwind Sprint(1) Disarm(2) Fire Breath(3) Frost Breath(4)");
  127.         return 1;
  128.     }
  129.     if(shouttype > 4 || shouttype < 0) return SendClientMessage(playerid, -1, "Invalid ID");
  130.     format(string, 128, "%s  >>>  %s", shoutNames[myShout[playerid]], shoutNames[shouttype]);
  131.     SendClientMessage(playerid, -1, string);
  132.     myShout[playerid] = shouttype;
  133.     return 1;
  134. }
  135. CMD:ldb(playerid, params[])                             // non robust all the way to ddb
  136. {
  137.     LoadDragonBorn();
  138.     return 1;
  139. }
  140. CMD:ddisplay(playerid, params[])
  141. {
  142.     SendClientMessage(playerid, -1, dragonBorns);      
  143.     return 1;
  144. }
  145. CMD:adb(playerid, params[])
  146. {
  147.     AddPlayerToDragonBorn(strval(params));
  148.     return 1;
  149. }
  150. CMD:ddb(playerid, params[])
  151. {
  152.     DeletePlayerFromDragonBorn(strval(params));
  153.     return 1;
  154. }
  155. forward ApplyShout(shouttype, senderid);
  156. public ApplyShout(shouttype, senderid)
  157. {
  158.     new string[128], name[MAX_PLAYER_NAME + 1];
  159.     GetPlayerName(senderid, name, sizeof(name));
  160.    
  161.     new Float: x, Float:y, Float:z, Float: xEx, Float: yEx;
  162.     GetPlayerPos(senderid, x, y, z);
  163.     GetXYInFrontOfPlayer(senderid, x, y, 5.0);
  164.     GetXYInFrontOfPlayer(senderid, xEx, yEx, 10.0);
  165.    
  166.     //-------------------------------------------------------------------//
  167.    
  168.     if(shouttype == 1)
  169.     {
  170.         new Float:angle, Float:xV, Float:yV;
  171.         GetPlayerPos(senderid, x, y, z);
  172.         GetPlayerFacingAngle(senderid, angle);
  173.         xV = (0.65 * floatsin(-angle, degrees));
  174.         yV = (0.65 * floatcos(-angle, degrees));
  175.         SetPlayerVelocity(senderid, xV, yV, 0.2);
  176.         if(useCoolDown == 1) myCoolDown[senderid] += shoutCool[shouttype];
  177.         return 1;
  178.     }
  179.    
  180.     for(new i = 0; i < MAX_PLAYERS; i++)
  181.     {
  182.         if(IsPlayerConnected(i))
  183.         {
  184.             if(IsPlayerInRangeOfPoint(i, 5.0, x, y, z) || IsPlayerInRangeOfPoint(i, 8.0, xEx, yEx, z))
  185.             {
  186.                 if(i != senderid)
  187.                 {
  188.                     if(shouttype == 0)
  189.                     {
  190.                         new Float: health, bool:inVeh;
  191.                         new Float: opX, Float: opY, Float:opZ, Float: xV, Float: yV, Float: fAngle;
  192.                         new Float: victimX, Float: victimY;
  193.                         GetPlayerPos(senderid, opX, opY, opZ);
  194.                         GetPlayerPos(i, victimX, victimY, opZ);
  195.                         fAngle = GetFacingPos(victimX, victimY, opX, opY);
  196.                         xV = (speed * floatsin(-fAngle, degrees));
  197.                         yV = (speed * floatcos(-fAngle, degrees));
  198.                         xV *= -1;
  199.                         yV *= -1;
  200.                         if (IsPlayerInAnyVehicle(i)) inVeh = true;
  201.                         GetPlayerHealth(i, health);
  202.                         if(inVeh)
  203.                         {
  204.                             xV *= 0.85;
  205.                             yV *= 0.85;
  206.                             SetVehicleVelocity(GetPlayerVehicleID(i), xV, yV, 0.5);
  207.                             inVeh = false;
  208.                         }
  209.                         else
  210.                         {
  211.                             health -= 2.0;
  212.                             SetPlayerVelocity(i, xV, yV, 0.3);
  213.                             SetPlayerHealth(i, health);
  214.                         }
  215.                     }
  216.                     else if(shouttype == 2)
  217.                     {
  218.                         new weap = GetPlayerWeapon(senderid);
  219.                         shoutEffect[i][0] = 10;
  220.                         if(weap > 15 || weap < 43)SetPlayerArmedWeapon(i, 0);
  221.                         if(GetPlayerWeapon(i) != 0) GameTextForPlayer(i, "~n~~n~~n~~n~~n~~n~~n~~r~Disarmed~n~~g~Wait for 10 seconds", 2000, 3);
  222.                         else GameTextForPlayer(i, "~n~~n~~n~~n~~n~~n~~n~~n~~g~Additional 10 seconds added - Disarm", 2000, 3);
  223.                         FallFromPlayer(senderid, i);
  224.                     }
  225.                     else if(shouttype == 3 || shouttype == 4)
  226.                     {
  227.                         new Float:health;
  228.                         if(shouttype == 3)
  229.                         {
  230.                             GameTextForPlayer(i, "~n~~n~~n~~n~~n~~n~~n~~r~Fire Effect Added", 2000, 3);
  231.                             GameTextForPlayer(i, "~n~~n~~n~~n~~n~~n~~n~~n~~g~OH lord jesus there is a FiRe!", 2000, 3);
  232.                             if(IsPlayerInAnyVehicle(i))
  233.                             {
  234.                                 new Float: px, Float: py, Float: pz;
  235.                                 GetPlayerPos(i, px, py, pz);
  236.                                 CreateExplosion(px, py, pz, 7, 20);
  237.                             }
  238.                             shoutEffect[i][1] = 10;
  239.                         }
  240.                         else
  241.                         {
  242.                             GameTextForPlayer(i, "~n~~n~~n~~n~~n~~n~~n~~b~Frost Effect Added", 2000, 3);
  243.                             shoutEffect[i][2] = 10;
  244.                         }
  245.                         new slot = GetNextSlot(i);
  246.                         if(slot == -1) SendClientMessage(i, -1, "No Object will be attached.");
  247.                         else
  248.                         {
  249.                             if(shouttype == 3 && fireEffect[i] == -1)
  250.                             {
  251.                                 SetPlayerAttachedObject(i, slot, 18692, 1, 0.0, 0.0, -1.613);
  252.                                 fireEffect[i] = slot;
  253.                             }
  254.                             else if(shouttype == 4 && frostEffect[i] == -1)
  255.                             {
  256.                                 SetPlayerAttachedObject(i, slot, 18675, 1, -1.04, 0.18, -1.991);
  257.                                 frostEffect[i] = slot;
  258.                             }
  259.                         }
  260.                         GetPlayerHealth(i, health);
  261.                         SetPlayerHealth(i, (health - 10.0));
  262.                         FallFromPlayer(senderid, i);
  263.                     }
  264.                     //---------------------------------------------//
  265.                    
  266.                     if(shouttype != 1)
  267.                     {
  268.                         format(string, sizeof(string), "%s has applied %s on you.", name, shoutNames[shouttype]);
  269.                         SendClientMessage(i, -1, string);
  270.                     }
  271.                     else SendClientMessage(i, -1, "Invalid shout ID passed.");//close if statement
  272.                 }// not the command sender
  273.             }// range check
  274.         }//online check
  275.     }//close loop
  276.     if(useCoolDown == 1)
  277.     {
  278.         if(shouttype == 0 || shouttype == 2 || shouttype == 3 || shouttype == 4) myCoolDown[senderid] += shoutCool[shouttype];
  279.     }
  280.     return 1;
  281. }//close function
  282.  
  283. forward SendShoutSoundToAll(Float:x, Float:y, Float:z, shouttype);
  284. public SendShoutSoundToAll(Float:x, Float:y, Float:z, shouttype)
  285. {
  286.     if(shouttype == 0 || shouttype == 1 || shouttype == 2 || shouttype == 3 || shouttype == 4)
  287.     {
  288.         for(new i = 0; i< MAX_PLAYERS; i++)
  289.         {
  290.             if(IsPlayerConnected(i))
  291.             {
  292.                 if(IsPlayerInRangeOfPoint(i, 70.0, x, y, z))
  293.                 {
  294.                     if(shouttype == 0) PlayAudioStreamForPlayer(i, "http://images.wikia.com/elderscrolls/images/8/81/UnrelentingForce.ogg", x, y, z, 70.0, 1);
  295.                     else if(shouttype == 1) PlayAudioStreamForPlayer(i, "http://images.wikia.com/elderscrolls/images/4/4b/Whirlwindsprint.ogg", x, y, z, 70.0, 1);
  296.                     else if(shouttype == 2) PlayAudioStreamForPlayer(i, "http://images.wikia.com/elderscrolls/images/5/5c/Disarm.ogg", x, y, z, 70.0, 1);
  297.                     else if(shouttype == 3) PlayAudioStreamForPlayer(i, "http://images.wikia.com/elderscrolls/images/f/f5/FireBreath.ogg", x, y, z, 70.0, 1);
  298.                     else if(shouttype == 4) PlayAudioStreamForPlayer(i, "http://images.wikia.com/elderscrolls/images/a/aa/FrostBreath.ogg", x, y, z, 70.0, 1);
  299.                 }//range check
  300.             }//online checker
  301.         }//loop
  302.     }
  303.     else{
  304.         new string[128];
  305.         format(string, 128, "Invalid ID(%d) passed to X:%f, Y:%f, Z:%f", shouttype, x, y, z);
  306.         SendClientMessageToAll(-1, string);
  307.     }
  308. }
  309.  
  310. forward OneSecUpdate();
  311. public OneSecUpdate()
  312. {
  313.     new Float:health;
  314.     for(new i = 0; i < MAX_PLAYERS; i++)
  315.     {
  316.         if(IsPlayerConnected(i))
  317.         {
  318.             if(myCoolDown[i] != 0 && useCoolDown == 1) myCoolDown[i] -= 1; //shout cooldown
  319.             for(new e = 0; e < 3; e++) if(shoutEffect[i][e] != 0) shoutEffect[i][e] -= 1; //effect cooldown
  320.             if(shoutEffect[i][1] == 0 && fireEffect[i] >= 0)
  321.             {
  322.                 RemovePlayerAttachedObject(i, fireEffect[i]);
  323.                 fireEffect[i] = -1;
  324.             }
  325.             else if(shoutEffect[i][2] == 0 && frostEffect[i] >= 0)
  326.             {
  327.                 RemovePlayerAttachedObject(i, frostEffect[i]);
  328.                 frostEffect[i] = -1;
  329.             }
  330.             if(shoutEffect[i][1] != 0 || shoutEffect[i][2] != 0)
  331.             {
  332.                 GetPlayerHealth(i, health);
  333.                 SetPlayerHealth(i, (health - 5.0));
  334.             }
  335.             //printf("Player ID: %d, Fire Object: %d, Frost Object: %d", i, fireEffect[i], frostEffect[i]);
  336.         }//online checker
  337.     }//close loop
  338. }
  339.  
  340. forward Float: GetFacingPos(Float: fromX, Float: fromY, Float: x, Float: y);
  341. Float: GetFacingPos(Float: fromX, Float: fromY, Float:x, Float:y)//http://forum.sa-mp.com/showthread.php?t=38965&page=338
  342. {
  343.     new Float:angle;
  344.     new Float:misc = 5.0;
  345.     angle = 180.0-atan2(fromX-x,fromY-y);
  346.     angle += misc;
  347.     misc *= -1;
  348.     angle += misc;
  349.     return angle;
  350. }
  351.  
  352. GetNextSlot(playerid)
  353. {
  354.     for(new i = 0; i < MAX_PLAYER_ATTACHED_OBJECTS; i++)
  355.     {
  356.         if(!IsPlayerAttachedObjectSlotUsed(playerid, i)) return i;
  357.     }
  358.     return -1;
  359. }
  360.  
  361. FallFromPlayer(playerid, victim)
  362. {
  363.     new Float: pX, Float: pY, Float: z, Float: vicX, Float: vicY, Float: angle;
  364.     GetPlayerPos(playerid, pX, pY, z);
  365.     GetPlayerPos(victim, vicX, vicY, z);
  366.     angle = GetFacingPos(vicX, vicY, pX, pY);
  367.     SetPlayerFacingAngle(victim, angle);
  368.     ApplyAnimation(victim, "PED", "BIKE_fallR", 4.0, 0, 1, 1, 0, 0);
  369. }
  370.  
  371. GetXYInFrontOfPlayer(playerid, &Float:x, &Float:y, Float:distance)
  372. {
  373.     // Credit: Y_Less
  374.  
  375.     new Float:a;
  376.  
  377.     GetPlayerPos(playerid, x, y, a);
  378.     GetPlayerFacingAngle(playerid, a);
  379.  
  380.     if (GetPlayerVehicleID(playerid)) {
  381.         GetVehicleZAngle(GetPlayerVehicleID(playerid), a);
  382.     }
  383.  
  384.     x += (distance * floatsin(-a, degrees));
  385.     y += (distance * floatcos(-a, degrees));
  386. }
  387. LoadDragonBorn()
  388. {
  389.     new name[MAX_PLAYER_NAME + 1];
  390.     new File: file = fopen("DragonBorns.txt", io_read);
  391.     if (!fexist("DragonBorns.txt")) return print(">>>>>.DragonBorn.txt doesn not exits! make one in the folder.<<<<<<");
  392.     else{
  393.         fread(file, dragonBorns);
  394.         for(new i = 0; i < MAX_PLAYERS; i++)
  395.         {
  396.             if(IsPlayerConnected(i))
  397.             {
  398.                 GetPlayerName(i, name, sizeof(name));
  399.                 if(strfind(dragonBorns, name, false) != -1) dragonBorn[i] = 1;
  400.                 else dragonBorn[i] = 0;
  401.             }
  402.         }
  403.     }
  404.     fclose(file);
  405.     return 1;
  406. }
  407. DeletePlayerFromDragonBorn(playerid)
  408. {
  409.     new name[MAX_PLAYER_NAME + 1];
  410.     new File: file = fopen("DragonBorns.txt", io_write);
  411.     if (!fexist("DragonBorns.txt")) return print(">>>>>.DragonBorn.txt doesn not exits! make one in the folder.<<<<<<");
  412.     else{
  413.         GetPlayerName(playerid, name, sizeof(name));
  414.         if(strfind(dragonBorns, name, false) == -1) return 1;
  415.         new spos = strfind(dragonBorns, name, false);
  416.         new epos = spos + strlen(name);
  417.         epos += 1;
  418.         strdel(dragonBorns, spos, epos);
  419.         fwrite(file, dragonBorns);
  420.     }
  421.     fclose(file);
  422.     return 1;
  423. }
  424. AddPlayerToDragonBorn(playerid)
  425. {
  426.     new name[MAX_PLAYER_NAME + 1], string[30];
  427.     new File: file = fopen("DragonBorns.txt", io_append);
  428.     if (!fexist("DragonBorns.txt")) return print(">>>>>.DragonBorn.txt doesn not exits! make one in the folder.<<<<<<");
  429.     if(strfind(dragonBorns, name, false) != -1) return 1;
  430.     GetPlayerName(playerid, name, sizeof(name));
  431.     format(string, sizeof(string), "%s,", name);
  432.     strcat(dragonBorns, string, sizeof(dragonBorns));
  433.     fwrite(file, string);
  434.     fclose(file);
  435.     return 1;
  436. }
Advertisement
Add Comment
Please, Sign In to add comment