Lynn_Releases

Actor Studio - Created by Lynn

Jul 7th, 2015
2,178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 14.72 KB | None | 0 0
  1. /*           ACTOR STUDIO :: CREATED BY LYNN      *
  2.  **************************************************
  3.  *                   .:PURPOSE:.                  *
  4.  * The purpose of this filterscript is to create  *
  5.  * actors that are both responsive and/or actors  *
  6.  * that are unresponsive. Wll with the simplicity *
  7.  * of this filterscript. Hopefully you will enjoy!*
  8.  **************************************************/
  9.  
  10. #include <a_samp>
  11. #include <zcmd>
  12. #include <sscanf2>
  13. #include <foreach>
  14.  
  15. #define PF:%0(%1)   forward %0(%1); \
  16.                     public %0(%1) // Automatically creates a Public and Forward, using PF: FunctionName() {
  17.  
  18. #define SCM SendClientMessage // Shortens SendClientMessage to SCM
  19. #define ACTOR_     (9001) // Dialog definition
  20. #define MAX_3DTEXT (1000) // Maximum 3D Text Labels allowed. Matches Max_Actors
  21.  
  22. enum ActorInfo {
  23.     a_ID, // Actor physical ID
  24.     a_SkinID, // Actor Skin
  25.     bool:a_Respond, // Responsive to actions: True = Yes False = No
  26.     Float:a_X, // Position X
  27.     Float:a_Y, // Position Y
  28.     Float:a_Z, // Position Z
  29.     Float:a_R, // Rotation
  30. };
  31. static a_Info[MAX_ACTORS][ActorInfo];
  32.  
  33. static LastSkin;// Last skin used by the Actor Studio
  34. static Text3D:ActorText[MAX_ACTORS]; // 3DText Label created upon actor spawn.
  35. static Actor_ID = 0; // Actors created
  36. static bool:a_Studio_Used = false; // Actor Studio being used: false = No, true = Yes.
  37. static CreatedActor[MAX_ACTORS]; // Most recent created actor, once deleted it takes the place of the next highest ID
  38. static PlayerUpdate[MAX_PLAYERS]; // Update Timer variable
  39.  
  40. public OnFilterScriptInit()
  41. {
  42.     // Please leave the following. Although I'm asking, I know it won't happen because how will I ever know?
  43.     print("\n**************************************************");
  44.     print(" *                                               *");
  45.     print(" *       ACTOR STUDIO : CREATED BY LYNN v1.0     *");
  46.     print(" *           Verison v2.0 avalible soon.         *");
  47.     print(" *                                               *");
  48.     print("**************************************************\n");
  49.     foreach(Player, i)
  50.     {
  51.         PlayerUpdate[i] = SetTimerEx("OnPlayerUpdateEx", 1000, true, "i", i); // Iniates now, in the even the filter script is loaded after players are already connected.
  52.     }
  53.     Actor_ID = 0; // Actors created set to 0.
  54.     // ACTOR DEFAULTS SET TO 0.
  55.     a_Info[Actor_ID][a_ID] = 0;
  56.     a_Info[Actor_ID][a_SkinID] = 0;
  57.     a_Info[Actor_ID][a_Respond] = false;
  58.     a_Info[Actor_ID][a_X] = 0;
  59.     a_Info[Actor_ID][a_Y] = 0;
  60.     a_Info[Actor_ID][a_Z] = 0;
  61.     a_Info[Actor_ID][a_Z] = 0;
  62.     a_Studio_Used = false; // Re-set to false to avoid any complications.
  63. //    Load_Actors();
  64.     return 1;
  65. }
  66.  
  67. public OnFilterScriptExit()
  68. {
  69.     for(new i = 0, j = GetActorPoolSize(); i <= j; i++)
  70.     {
  71.         if(IsValidActor(i))
  72.         {
  73.             DestroyActor(i); // Loops through every actor, deleting it.
  74.         }
  75.     }
  76.     for(new u = 0; u < MAX_3DTEXT; u++)
  77.     {
  78.         Delete3DTextLabel(Text3D:u); // Loops through created 3D TextLabels, deleting them.
  79.     }
  80.     foreach(Player, u) {
  81.         if(IsPlayerAdmin(u)) {
  82.             SCM(u, -1, #** All actors have been destroyed.);// RCON Admins are now aware their creations have been destroyed.
  83.         }
  84.     }
  85.     a_Studio_Used = false; // Studio no longer in-use.
  86.     return 1;
  87. }
  88. // Currently not used. V2.0 will use this function for it's saving system.
  89. public OnPlayerConnect(playerid)
  90. {
  91.     return 1;
  92. }
  93. public OnPlayerDisconnect(playerid, reason)
  94. {
  95.     // Is the player using the actor studio? Well let's reset that real quick...
  96.     if(GetPVarInt(playerid, #Using_Actor_Studio) == 1)
  97.     {
  98.         a_Studio_Used = false;
  99.         DeletePVar(playerid, #Using_Actor_Studio);
  100.     }
  101.     return 1;
  102. }
  103. // ACTOR FUNCTIONS
  104. PF: OnPlayerUpdateEx(playerid)// Update function.
  105. {
  106.     new actorid = GetPlayerTargetActor(playerid);
  107.     if (actorid != INVALID_ACTOR_ID)// Is the target a valid actor? If not, do nothing.
  108.     {
  109.         ApplyActorAnimation(actorid, "PED", "handsup", 4.1, 0, 0, 0, 0, 0); // Make him put his hands up when aimed at.
  110.     }
  111.     return 1;
  112. }
  113.  
  114. PF: OnPlayerGiveDamageActor(playerid, damaged_actorid, Float: amount, weaponid, bodypart)
  115. {
  116.     if(IsActorInvulnerable(damaged_actorid))
  117.     {
  118.         SCM(playerid, -1, #That actor is unresponsive.);// Is this actor responsive to actions? No? Do nothing.
  119.     }
  120.     else
  121.     {
  122.         new Float:hp;
  123.         SetActorHealth(damaged_actorid, hp-amount/2);//Removes half of the normal damage.
  124.     }
  125.     return 1;
  126. }
  127. // ACTOR STUDIO - COMMANDS
  128. CMD:ahelp(playerid, params[])
  129. {
  130.     SCM(playerid, -1, " >> Use /actors to view total amount of actors currently created.");
  131.     SCM(playerid, -1, " >> Use /astudio to open the actor studio and begin creating.");
  132.     SCM(playerid, -1, " >> Please report any bugs on the SA-MP forums, under the Actor Studio post.");
  133.     return true;
  134. }
  135. // Check the total actors within the server.
  136. CMD:actors(playerid, params[])
  137. {
  138.     new str[64];
  139.     format(str, sizeof str, " Actor Studio: {F81414}Total Actors (%d) ", Actor_ID);
  140.     SCM(playerid, -1, str);
  141.     return true;
  142. }
  143. // Start creating actors!
  144. CMD:astudio(playerid, params[])
  145. {
  146.     if(IsPlayerConnected(playerid))
  147.     {
  148.         if(GetPlayerState(playerid) != PLAYER_STATE_DRIVER) {
  149.             if(a_Studio_Used == false) {
  150.                 SetPVarInt(playerid, #Using_Actor_Studio, 1);
  151.                 ShowPlayerDialog(playerid, ACTOR_, DIALOG_STYLE_LIST, "{3399FF}Actor Studio {FFFFFF}- Created by {3399FF}Lynn",
  152.                 "{3399FF}Skin ID\n{3399FF}Responsive\n{3399FF}Duplicate\n{00FF22}Create\n{F81414}Delete", "{F81414}Select", "{F81414}Cancel");
  153.                 a_Studio_Used = true;
  154.             }
  155.             else return SCM(playerid, -1, # >> Actor studio currently in-use.);
  156.         }
  157.         else return SCM(playerid, -1, # >> You may not use this command at this moment.);
  158.     }
  159.     return true;
  160. }
  161. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  162. {
  163.     switch(dialogid)
  164.     {
  165.         case ACTOR_:
  166.         {
  167.             switch(listitem)
  168.             {
  169.                 case 0: {
  170.                     if(!response) {
  171.                         SCM(playerid, -1, # >> You have canceled the Actor Studio progress);
  172.                         a_Studio_Used = false;
  173.                     }
  174.                     else if(response) {
  175.                         ShowPlayerDialog(playerid, ACTOR_+1, DIALOG_STYLE_INPUT, "Actor Skin ID", "{FFFFFF}Input the desired skin id of the new actor.", "Select", "");
  176.                     }
  177.                 }
  178.                 case 1: {
  179.                     if(!response) {
  180.                         SCM(playerid, -1, # >> You have canceled the Actor Studio progress);
  181.                         a_Studio_Used = false;
  182.                     }
  183.                     else if(response) {
  184.                         ShowPlayerDialog(playerid, ACTOR_+2, DIALOG_STYLE_MSGBOX, "Actor Responsive", "{FFFFFF}Would you like your actor to respond to actions?", "Yes", "No");
  185.                     }
  186.                 }
  187.                 case 2: {
  188.                     if(!response) {
  189.                         SCM(playerid, -1, # >> You have canceled the Actor Studio progress);
  190.                         a_Studio_Used = false;
  191.                     }
  192.                     else if(response) {
  193.                         if(Actor_ID != 0)
  194.                         {
  195.                             SCM(playerid, -1, "You are now duplicating. Press '{3399FF}Y{FFFFFF}' to duplicate and '{F81414}N{FFFFFF}' to stop.");
  196.                             SetPVarInt(playerid, "A_Editor", 1);
  197.                         }
  198.                         else {
  199.                             SCM(playerid, -1, #You must create an actor before you can duplicate it.);
  200.                             a_Studio_Used = false;
  201.                         }
  202.                     }
  203.                 }
  204.                 case 3: {
  205.                     if(!response) {
  206.                         SCM(playerid, -1, # >> You have canceled the Actor Studio progress);
  207.                         a_Studio_Used = false;
  208.                     }
  209.                     else if(response) {
  210.                         if(a_Info[Actor_ID][a_SkinID] != 0) {
  211.                             new Float:pX, Float:pY, Float:pZ, Float:pR;
  212.                             GetPlayerPos(playerid, pX, pY, pZ);
  213.                             GetPlayerFacingAngle(playerid, pR);
  214.                             a_Info[Actor_ID][a_X] = pX+0.5;
  215.                             a_Info[Actor_ID][a_Y] = pY;
  216.                             a_Info[Actor_ID][a_Z] = pZ;
  217.                             a_Info[Actor_ID][a_R] = pR;
  218.                             CreatedActor[Actor_ID] = CreateActor(a_Info[Actor_ID][a_SkinID], a_Info[Actor_ID][a_X], a_Info[Actor_ID][a_Y], a_Info[Actor_ID][a_Z], a_Info[Actor_ID][a_R]);
  219.                             LastSkin = a_Info[Actor_ID][a_SkinID];
  220.                             if(a_Info[Actor_ID][a_Respond] == true)
  221.                             {
  222.                                 SetActorInvulnerable(CreatedActor[Actor_ID], false);
  223.                                 SetActorHealth(CreatedActor[Actor_ID], 100);
  224.                                 new string[64];
  225.                                 a_Info[Actor_ID][a_ID] = Actor_ID;
  226.                                 format(string, sizeof(string), "Actor ID: ({3399FF}%d{FFFFFF})\nResponsive", Actor_ID+1);
  227.                                 ActorText[Actor_ID] = Create3DTextLabel(string, -1, a_Info[Actor_ID][a_X], a_Info[Actor_ID][a_Y], a_Info[Actor_ID][a_Z]+0.3, 10.0, 0, 1);
  228.                             }
  229.                             else {
  230.                                 SetActorInvulnerable(CreatedActor[Actor_ID], true);
  231.                                 new string[64];
  232.                                 a_Info[Actor_ID][a_ID] = Actor_ID;
  233.                                 format(string, sizeof(string), "Actor ID: ({3399FF}%d{FFFFFF})\nUnresponsive", Actor_ID+1);
  234.                                 ActorText[Actor_ID] = Create3DTextLabel(string, -1, a_Info[Actor_ID][a_X], a_Info[Actor_ID][a_Y], a_Info[Actor_ID][a_Z]+0.3, 10.0, 0, 1);
  235.                             }
  236.                             Actor_ID++;
  237.                             a_Studio_Used = false;
  238.                         }
  239.                         else {
  240.                             SCM(playerid, -1, ">> You did not input enough information for a new creation.");
  241.                             ShowPlayerDialog(playerid, ACTOR_, DIALOG_STYLE_LIST, "{3399FF}Actor Studio {FFFFFF}- Created by {3399FF}Lynn",
  242.                             "{3399FF}Skin ID\n{3399FF}Responsive\n{3399FF}Duplicate\n{3399FF}Create\n{F81414}Delete", "{F81414}Select", "{F81414}Cancel");
  243.                         }
  244.                     }
  245.                 }
  246.                 case 4: {
  247.                     if(!response) {
  248.                         SCM(playerid, -1, # >> You have canceled the Actor Studio progress);
  249.                         a_Studio_Used = false;
  250.                     }
  251.                     else if(response) {
  252.                         ShowPlayerDialog(playerid, ACTOR_+5, DIALOG_STYLE_MSGBOX, "{FFFFFF}Actor Deletion", "{FFFFFF}Are you sure you sure of this?\nIt will {F81414}DELETE{FFFFFF} your {F81414}LAST{FFFFFF} actor.", "Yes", "No");
  253.                     }
  254.                 }
  255.             }
  256.         }
  257.         case ACTOR_+1: {
  258.             if(!response) return ShowPlayerDialog(playerid, ACTOR_, DIALOG_STYLE_LIST, "{3399FF}Actor Studio {FFFFFF}- Created by {3399FF}Lynn",
  259.             "{3399FF}Skin ID\n{3399FF}Responsive\n{3399FF}Duplicate\n{3399FF}Create\n{F81414}Delete", "{F81414}Select", "{F81414}Cancel");
  260.             else if(response) {
  261.                 new a_sid = strval(inputtext);
  262.                 if(a_sid > 0 && a_sid < 312)
  263.                 {
  264.                     a_Info[Actor_ID][a_SkinID] = a_sid;
  265.                     if(GetPVarInt(playerid, #A_Editor) != 1)
  266.                     {
  267.                         ShowPlayerDialog(playerid, ACTOR_+2, DIALOG_STYLE_MSGBOX, "Actor Responsive", "{FFFFFF}Would you like your actor to respond to actions?", "Yes", "No");
  268.                     }
  269.                 }
  270.                 else {
  271.                     ShowPlayerDialog(playerid, ACTOR_+1, DIALOG_STYLE_INPUT, "Actor Skin ID", "{F81414}ERROR: {FFFFFF}Invalid skin ID, select a new one.", "Input", "");
  272.                 }
  273.             }
  274.         }
  275.         case ACTOR_+2: {
  276.             if(!response) {
  277.                 a_Info[Actor_ID][a_Respond] = false;
  278.                 SCM(playerid, -1, # >> Actor Selection: Unresponsive);
  279.                 ShowPlayerDialog(playerid, ACTOR_, DIALOG_STYLE_LIST, "{3399FF}Actor Studio {FFFFFF}- Created by {3399FF}Lynn",
  280.                 "{3399FF}Skin ID\n{3399FF}Responsive\n{3399FF}Duplicate\n{3399FF}Create\n{F81414}Delete", "{F81414}Select", "{F81414}Cancel");
  281.             }
  282.             else if(response) {
  283.                 a_Info[Actor_ID][a_Respond] = true;
  284.                 SCM(playerid, -1, # >> Actor Selection: Responsive);
  285.                 ShowPlayerDialog(playerid, ACTOR_, DIALOG_STYLE_LIST, "{3399FF}Actor Studio {FFFFFF}- Created by {3399FF}Lynn",
  286.                 "{3399FF}Skin ID\n{3399FF}Responsive\n{3399FF}Duplicate\n{3399FF}Create\n{F81414}Delete", "{F81414}Select", "{F81414}Cancel");
  287.             }
  288.         }
  289.         case ACTOR_+5:
  290.         {
  291.             if(!response) {
  292.                 SCM(playerid, -1, # >> You have decided to keep your actor.);
  293.                 a_Studio_Used = false;
  294.             }
  295.             else if(response) {
  296.                 if(Actor_ID > 0) {
  297.                     Actor_ID--;
  298.                     DestroyActor(CreatedActor[Actor_ID]);
  299.                     Delete3DTextLabel(ActorText[Actor_ID]);
  300.                     a_Studio_Used = false;
  301.                     new str[128];
  302.                     format(str, sizeof str, " >> Actor ID ({3399FF}%d{FFFFFF}) has been {F81414}removed {FFFFFF}from the server.");
  303.                     SCM(playerid, -1, str);
  304.                    
  305.                 }
  306.                 else {
  307.                     SCM(playerid, -1, # >> You have not created any actors to delete.);
  308.                     a_Studio_Used = false;
  309.                 }
  310.             }
  311.         }
  312.     }
  313.     return 1;
  314. }
  315. public OnPlayerCommandText(playerid, cmdtext[])
  316. {
  317.     return false;
  318. }
  319. public OnPlayerStateChange(playerid, newstate, oldstate)
  320. {
  321.     if(oldstate == PLAYER_STATE_ONFOOT && newstate == PLAYER_STATE_DRIVER)
  322.     {
  323.         if(GetPVarInt(playerid, #A_Editor) == 1)
  324.         {
  325.             DeletePVar(playerid, #A_Editor);
  326.             SCM(playerid, -1, # >> You are no longer no longer duplicating actors.);
  327.             a_Studio_Used = false;
  328.         }
  329.     }
  330.     return true;
  331. }
  332. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
  333. {
  334.     if (newkeys & KEY_YES)
  335.     {
  336.         if(GetPVarInt(playerid, #A_Editor) == 1)
  337.         {
  338.             new Float:pX, Float:pY, Float:pZ, Float:pR;
  339.             GetPlayerPos(playerid, pX, pY, pZ);
  340.             GetPlayerFacingAngle(playerid, pR);
  341.             a_Info[Actor_ID][a_X] = pX+0.6;
  342.             a_Info[Actor_ID][a_Y] = pY;
  343.             a_Info[Actor_ID][a_Z] = pZ;
  344.             a_Info[Actor_ID][a_R] = pR;
  345.             // Create an actor, using the information above.
  346.             CreatedActor[Actor_ID] = CreateActor(LastSkin, a_Info[Actor_ID][a_X], a_Info[Actor_ID][a_Y], a_Info[Actor_ID][a_Z], a_Info[Actor_ID][a_R]);
  347.             new string[64];
  348.             // Create the 3D TextLabel for an actor.
  349.             if(a_Info[Actor_ID-1][a_Respond] == true)
  350.             {
  351.                 SetActorInvulnerable(CreatedActor[Actor_ID], false);
  352.                 a_Info[Actor_ID][a_Respond] = true;
  353.                 SetActorHealth(CreatedActor[Actor_ID], 100);
  354.                 format(string, sizeof(string), "Actor ID: ({3399FF}%d{FFFFFF})\nResponsive", Actor_ID+1);
  355.                 ActorText[Actor_ID] = Create3DTextLabel(string, -1, a_Info[Actor_ID][a_X], a_Info[Actor_ID][a_Y], a_Info[Actor_ID][a_Z]+0.3, 10.0, 0, 1);
  356.             }
  357.             else {
  358.                 SetActorInvulnerable(CreatedActor[Actor_ID], true);
  359.                 a_Info[Actor_ID][a_Respond] = false;
  360.                 format(string, sizeof(string), "Actor ID: ({3399FF}%d{FFFFFF})\nUnresponsive", Actor_ID+1);
  361.                 ActorText[Actor_ID] = Create3DTextLabel(string, -1, a_Info[Actor_ID][a_X], a_Info[Actor_ID][a_Y], a_Info[Actor_ID][a_Z]+0.3, 10.0, 0, 1);
  362.             }
  363.             a_Info[Actor_ID][a_ID] = Actor_ID;
  364.             Actor_ID++;
  365.         }
  366.     }
  367.     // Quit the duplication progress.
  368.     if (newkeys & KEY_NO)
  369.     {
  370.         if(GetPVarInt(playerid, #A_Editor) == 1)
  371.         {
  372.             DeletePVar(playerid, #A_Editor);
  373.             SCM(playerid, -1, # >> You are no longer no longer duplicating actors.);
  374.             a_Studio_Used = false;
  375.         }
  376.     }
  377.     return 1;
  378. }
Advertisement
Add Comment
Please, Sign In to add comment