Advertisement
FoxHound

DynInt

Jun 18th, 2011
500
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 16.41 KB | None | 0 0
  1. /*                      DynInt
  2.  *              ( Dynamic Interiors )
  3.  *       (c) Copyright 2011-2012 by FoxHound
  4.  *
  5.  * @author    : FoxHound aka PSPgamer_10
  6.  * @date      : 17 June 2011
  7.  * @version   : v1.0
  8.  *
  9.  * This file is provided as is (no warranties).
  10.  *
  11.  *           ___           ___
  12.  *          /\__\         /|  |
  13.  *         /:/ _/_       |:|  |
  14.  *        /:/ /\__\      |:|  |
  15.  *       /:/ /:/  /    __|:|__|
  16.  *      /:/_/:/  /    /::::\__\_____
  17.  *      \:\/:/  /     ~~~~\::::/___/
  18.  *       \::/__/          |:|~~|
  19.  *        \:\  \          |:|  |
  20.  *         \:\__\         |:|__|
  21.  *          \/__/         |/__/
  22.  *      +--+-+-+-+-+-+-+-+-+-+--+
  23.  *      | p r o d u c t i o n s |
  24.  *      +--+-+-+-+-+-+-+-+-+-+--+
  25.  *
  26.  */
  27.  
  28. //--> INCLUDES
  29.     #include <a_samp>
  30.  
  31. //--> DEFINES
  32.     #define FILE_INTERIORS       "interiors.txt" //Write here where the File is/should be
  33.     #define MAX_INTERIORS        10              //Change this value to the max. amount of your Interiors in File.
  34.     #define InteriorCreateDialog 137
  35.     #define InteriorNameDialog   138
  36.  
  37. //--> FORWARD
  38.     forward OnInteriorUpdate();
  39.  
  40. //--> 'NEW's
  41.     enum e_Interior {
  42.         IntName[32],iEnterPickup,iExitPickup,Float:enterX, Float:enterY, Float:enterZ,
  43.         Float:enterSpawnX, Float:enterSpawnY, Float:enterSpawnZ, Float:enterSpawnA, enterSpawnInt,
  44.         Float:exitX, Float:exitY, Float:exitZ,
  45.         Float:exitSpawnX, Float:exitSpawnY, Float:exitSpawnZ, Float:exitSpawnA, exitSpawnInt };
  46.     new Interior[MAX_INTERIORS][2][e_Interior],InteriorTimer,InteriorCount;
  47.  
  48. //--> OnFilterScriptInit
  49.     public OnFilterScriptInit() {
  50.         for(new i=0;i<MAX_INTERIORS;i++) { Interior[i][0][iEnterPickup]=-1; Interior[i][0][iExitPickup]=-1; } //Be sure that this Line comes BEFORE "LoadInteriors()"
  51.  
  52.         LoadInteriors();
  53.  
  54.         InteriorTimer = SetTimer("OnInteriorUpdate",2000,1);
  55.  
  56.         return print("\n--------------------------------------\n Dynamic Interior System bY FoxHound\n--------------------------------------\n"); }
  57.  
  58. //--> OnFilterScriptExit
  59.     public OnFilterScriptExit() {
  60.         return KillTimer(InteriorTimer); }
  61.  
  62. //--> OnRconCommand
  63.     public OnRconCommand(cmd[]) {
  64.         if(!strcmp(cmd,"reloadinteriors",true)) { UnloadInteriors(); LoadInteriors(); } }
  65.  
  66.     public OnPlayerCommandText(playerid,cmdtext[]) {
  67.         if(!strcmp(cmdtext,"/cinterior",true) && IsPlayerAdmin(playerid)) {
  68.             if(InteriorCount==MAX_INTERIORS) { return SendClientMessage(playerid,0xFAFAFAFA,"ERROR: Before you create another Interior, you must change the amount of max. interiors in the Script."); }
  69.             return ShowPlayerDialog(playerid,InteriorCreateDialog,DIALOG_STYLE_LIST,"Interior Infos","Save Enter-Pickup Position\nSave Exit-Pickup Position\nSave Spawnposition (Inside)\nSave Spawnposition (Outside)\n{FF0000}Create Interior!","Choose","Cancel"); }
  70.         return 0; }
  71.  
  72. //--> OnDialogResponse
  73.     public OnDialogResponse(playerid,dialogid,response,listitem,inputtext[]) {
  74.         if(dialogid==InteriorCreateDialog) {
  75.             if(!response) return 1;
  76.             if(response) {
  77.                 if(listitem==0) {
  78.                     new Float:xyz[3];
  79.                     GetPlayerPos(playerid,xyz[0],xyz[1],xyz[2]);
  80.                     Interior[InteriorCount+1][1][enterX]=xyz[0]; Interior[InteriorCount+1][1][enterY]=xyz[1]; Interior[InteriorCount+1][1][enterZ]=xyz[2];
  81.                     SendClientMessage(playerid,0xFAFAFAFA,"* Enterpickup Position saved.");
  82.                     return ShowPlayerDialog(playerid,InteriorCreateDialog,DIALOG_STYLE_LIST,"Interior Infos","Save Enter-Pickup Position\nSave Exit-Pickup Position\nSave Spawnposition (Inside)\nSave Spawnposition (Outside)\n{FF0000}Create Interior!","Choose","Cancel"); }
  83.                 if(listitem==1) {
  84.                     new Float:xyz[3];
  85.                     GetPlayerPos(playerid,xyz[0],xyz[1],xyz[2]);
  86.                     Interior[InteriorCount+1][1][exitX]=xyz[0]; Interior[InteriorCount+1][1][exitY]=xyz[1]; Interior[InteriorCount+1][1][exitZ]=xyz[2];
  87.                     SendClientMessage(playerid,0xFAFAFAFA,"* Exitpickup position saved.");
  88.                     return ShowPlayerDialog(playerid,InteriorCreateDialog,DIALOG_STYLE_LIST,"Interior Infos","Save Enter-Pickup Position\nSave Exit-Pickup Position\nSave Spawnposition (Inside)\nSave Spawnposition (Outside)\n{FF0000}Create Interior!","Choose","Cancel"); }
  89.                 if(listitem==2) {
  90.                     new Float:xyza[4], pInt=GetPlayerInterior(playerid);
  91.                     GetPlayerPos(playerid,xyza[0],xyza[1],xyza[2]); GetPlayerFacingAngle(playerid,xyza[3]);
  92.                     Interior[InteriorCount+1][1][enterSpawnX]=xyza[0]; Interior[InteriorCount+1][1][enterSpawnY]=xyza[1]; Interior[InteriorCount+1][1][enterSpawnZ]=xyza[2]; Interior[InteriorCount+1][1][enterSpawnA]=xyza[3]; Interior[InteriorCount+1][1][enterSpawnInt]=pInt;
  93.                     SendClientMessage(playerid,0xFAFAFAFA,"* Spawnposition (Inside) saved.");
  94.                     return ShowPlayerDialog(playerid,InteriorCreateDialog,DIALOG_STYLE_LIST,"Interior Infos","Save Enter-Pickup Position\nSave Exit-Pickup Position\nSave Spawnposition (Inside)\nSave Spawnposition (Outside)\n{FF0000}Create Interior!","Choose","Cancel"); }
  95.                 if(listitem==3) {
  96.                     new Float:xyza[4], pInt=GetPlayerInterior(playerid);
  97.                     GetPlayerPos(playerid,xyza[0],xyza[1],xyza[2]); GetPlayerFacingAngle(playerid,xyza[3]);
  98.                     Interior[InteriorCount+1][1][exitSpawnX]=xyza[0]; Interior[InteriorCount+1][1][exitSpawnY]=xyza[1]; Interior[InteriorCount+1][1][exitSpawnZ]=xyza[2]; Interior[InteriorCount+1][1][exitSpawnA]=xyza[3]; Interior[InteriorCount+1][1][exitSpawnInt]=pInt;
  99.                     SendClientMessage(playerid,0xFAFAFAFA,"* Spawnposition (outside) saved.");
  100.                     return ShowPlayerDialog(playerid,InteriorCreateDialog,DIALOG_STYLE_LIST,"Interior Infos","Save Enter-Pickup Position\nSave Exit-Pickup Position\nSave Spawnposition (Inside)\nSave Spawnposition (Outside)\n{FF0000}Create Interior!","Choose","Cancel"); }
  101.                 if(listitem==4) {
  102.                     if(!Interior[InteriorCount+1][1][enterX] && !Interior[InteriorCount+1][1][enterY] && !Interior[InteriorCount+1][1][enterZ]) { return SendClientMessage(playerid,0xFAFAFAFA,"* You didn't save the Enterpickup!"); }
  103.                     if(!Interior[InteriorCount+1][1][enterSpawnX] && !Interior[InteriorCount+1][1][enterSpawnY] && !Interior[InteriorCount+1][1][enterSpawnZ] && !Interior[InteriorCount+1][1][enterSpawnA] && !Interior[InteriorCount+1][1][enterSpawnInt]) { return SendClientMessage(playerid,0xFAFAFAFA,"* You didn't save the Spawnposition (inside)!"); }
  104.                     if(!Interior[InteriorCount+1][1][exitX] && !Interior[InteriorCount+1][1][exitY] && !Interior[InteriorCount+1][1][exitZ]) { return SendClientMessage(playerid,0xFAFAFAFA,"* You didn't save the Exitpickup!"); }
  105.                     if(!Interior[InteriorCount+1][1][exitSpawnX] && !Interior[InteriorCount+1][1][exitSpawnY] && !Interior[InteriorCount+1][1][exitSpawnZ] && !Interior[InteriorCount+1][1][exitSpawnA] && !Interior[InteriorCount+1][1][exitSpawnInt]) { return SendClientMessage(playerid,0xFAFAFAFA,"* You didn't save the Spawnposition (outside)!"); }
  106.                     ShowPlayerDialog(playerid,InteriorNameDialog,DIALOG_STYLE_INPUT,"Interiorname","Please enter a Name for your Interior.\nex.: 'LSPD' 'BSN' '24/7'...","Enter","Cancel");
  107.                 } } }
  108.         else if(dialogid==InteriorNameDialog) {
  109.             if(!response) {
  110.                 Interior[InteriorCount+1][1][enterX]=0; Interior[InteriorCount+1][1][enterY]=0; Interior[InteriorCount+1][1][enterZ]=0;
  111.                 Interior[InteriorCount+1][1][enterSpawnX]=0; Interior[InteriorCount+1][1][enterSpawnY]=0; Interior[InteriorCount+1][1][enterSpawnZ]=0; Interior[InteriorCount+1][1][enterSpawnA]=0; Interior[InteriorCount+1][1][enterSpawnInt]=0;
  112.                 Interior[InteriorCount+1][1][exitX]=0; Interior[InteriorCount+1][1][exitY]=0; Interior[InteriorCount+1][1][exitZ]=0;
  113.                 Interior[InteriorCount+1][1][exitSpawnX]=0; Interior[InteriorCount+1][1][exitSpawnY]=0; Interior[InteriorCount+1][1][exitSpawnZ]=0; Interior[InteriorCount+1][1][exitSpawnA]=0; Interior[InteriorCount+1][1][exitSpawnInt]=0;
  114.                 return SendClientMessage(playerid,0xFAFAFAFA,"You cancelled."),1; }
  115.             if(response) {
  116.                 new string[256];
  117.                 //////////////////////////
  118.                 Interior[InteriorCount+1][0][enterX]=Interior[InteriorCount+1][1][enterX]; Interior[InteriorCount+1][0][enterY]=Interior[InteriorCount+1][1][enterY]; Interior[InteriorCount+1][0][enterZ]=Interior[InteriorCount+1][1][enterZ];
  119.                 Interior[InteriorCount+1][0][enterSpawnX]=Interior[InteriorCount+1][1][enterSpawnX]; Interior[InteriorCount+1][0][enterSpawnY]=Interior[InteriorCount+1][1][enterSpawnY]; Interior[InteriorCount+1][0][enterSpawnZ]=Interior[InteriorCount+1][1][enterSpawnZ]; Interior[InteriorCount+1][0][enterSpawnA]=Interior[InteriorCount+1][1][enterSpawnA]; Interior[InteriorCount+1][0][enterSpawnInt]=Interior[InteriorCount+1][1][enterSpawnInt];
  120.                 Interior[InteriorCount+1][0][exitX]=Interior[InteriorCount+1][1][exitX]; Interior[InteriorCount+1][0][exitY]=Interior[InteriorCount+1][1][exitY]; Interior[InteriorCount+1][0][exitZ]=Interior[InteriorCount+1][1][exitZ];
  121.                 Interior[InteriorCount+1][0][exitSpawnX]=Interior[InteriorCount+1][1][exitSpawnX]; Interior[InteriorCount+1][0][exitSpawnY]=Interior[InteriorCount+1][1][exitSpawnY]; Interior[InteriorCount+1][0][exitSpawnZ]=Interior[InteriorCount+1][1][exitSpawnZ]; Interior[InteriorCount+1][0][exitSpawnA]=Interior[InteriorCount+1][1][exitSpawnA]; Interior[InteriorCount+1][0][exitSpawnInt]=Interior[InteriorCount+1][1][exitSpawnInt];
  122.                 format(Interior[InteriorCount+1][0][IntName],32,"%s",inputtext);
  123.                 format(string,sizeof(string),"%s|%f|%f|%f|%f|%f|%f|%f|%d|%f|%f|%f|%f|%f|%f|%f|%d\n",Interior[InteriorCount][0][IntName],Interior[InteriorCount+1][0][enterX],Interior[InteriorCount+1][0][enterY],Interior[InteriorCount+1][0][enterZ],Interior[InteriorCount+1][0][enterSpawnX],Interior[InteriorCount+1][0][enterSpawnY],Interior[InteriorCount+1][0][enterSpawnZ],Interior[InteriorCount+1][0][enterSpawnA],Interior[InteriorCount+1][0][enterSpawnInt],
  124.                                                                                                     Interior[InteriorCount+1][0][exitX],Interior[InteriorCount+1][0][exitY],Interior[InteriorCount+1][0][exitZ],Interior[InteriorCount+1][0][exitSpawnX],Interior[InteriorCount+1][0][exitSpawnY],Interior[InteriorCount+1][0][exitSpawnZ],Interior[InteriorCount+1][0][exitSpawnA],Interior[InteriorCount+1][0][exitSpawnInt]);
  125.                 new File:intFile = fopen(FILE_INTERIORS,io_readwrite);
  126.                 fwrite(intFile,string); fclose(intFile);
  127.                 SendClientMessage(playerid,0x33CCFFFF,"* Interior created and saved.");
  128.  
  129.                 SendClientMessage(playerid,0x33CCFFFF,"* Reloading Interiors...");
  130.                 UnloadInteriors(); LoadInteriors();
  131.                 //////////////////////////
  132.                 Interior[InteriorCount+1][1][enterX]=0; Interior[InteriorCount+1][1][enterY]=0; Interior[InteriorCount+1][1][enterZ]=0;
  133.                 Interior[InteriorCount+1][1][enterSpawnX]=0; Interior[InteriorCount+1][1][enterSpawnY]=0; Interior[InteriorCount+1][1][enterSpawnZ]=0; Interior[InteriorCount+1][1][enterSpawnA]=0; Interior[InteriorCount+1][1][enterSpawnInt]=0;
  134.                 Interior[InteriorCount+1][1][exitX]=0; Interior[InteriorCount+1][1][exitY]=0; Interior[InteriorCount+1][1][exitZ]=0;
  135.                 Interior[InteriorCount+1][1][exitSpawnX]=0; Interior[InteriorCount+1][1][exitSpawnY]=0; Interior[InteriorCount+1][1][exitSpawnZ]=0; Interior[InteriorCount+1][1][exitSpawnA]=0; Interior[InteriorCount+1][1][exitSpawnInt]=0; }
  136.             return 1; }
  137.         return 0; }
  138.  
  139. //--> OnInteriorUpdate
  140.     public OnInteriorUpdate() {
  141.         for(new pid=0,mPlayers=GetMaxPlayers(); pid<mPlayers; pid++) {
  142.             for(new intid=0; intid<=MAX_INTERIORS; intid++) {
  143.                 if((Interior[intid][0][enterX]==0.0) && (Interior[intid][0][enterY]==0.0) && (Interior[intid][0][enterZ]==0.0)) { continue; }
  144.                 if(IsPlayerInRangeOfPoint(pid,1.0,Interior[intid][0][enterX],Interior[intid][0][enterY],Interior[intid][0][enterZ])) {
  145.                     SetPlayerPos(pid,Interior[intid][0][enterSpawnX],Interior[intid][0][enterSpawnY],Interior[intid][0][enterSpawnZ]);
  146.                     if(Interior[intid][0][enterSpawnA]) { SetPlayerFacingAngle(pid,Interior[intid][0][enterSpawnA]); }
  147.                     SetPlayerInterior(pid,Interior[intid][0][enterSpawnInt]);
  148.                     GameTextForPlayer(pid,Interior[intid][0][IntName],3000,1);
  149.                     SetCameraBehindPlayer(pid); }
  150.                 else if(IsPlayerInRangeOfPoint(pid,1.0,Interior[intid][0][exitX],Interior[intid][0][exitY],Interior[intid][0][exitZ])) {
  151.                     SetPlayerPos(pid,Interior[intid][0][exitSpawnX],Interior[intid][0][exitSpawnY],Interior[intid][0][exitSpawnZ]);
  152.                     if(Interior[intid][0][exitSpawnA]) { SetPlayerFacingAngle(pid,Interior[intid][0][exitSpawnA]); }
  153.                     SetPlayerInterior(pid,Interior[intid][0][exitSpawnInt]);
  154.                     SetCameraBehindPlayer(pid); } } }
  155.         return 1; }
  156.  
  157. //--> LoadInteriors
  158.     forward LoadInteriors();
  159.     public LoadInteriors() {
  160.         new string[256],File:intFile = fopen(FILE_INTERIORS,io_readwrite);
  161.         InteriorCount=0;
  162.         for(new i=0; fread(intFile,string); i++) {
  163.             if(!strlen(string)) { break; }
  164.             if(string[0]=='\r') { break; }
  165.             else if((string[0]=='>') && (string[1]=='>')) { continue; }
  166.             else if((string[0]=='/') && (string[1]=='/')) { i--; continue; }
  167.             InteriorCount++;
  168.             getPartOfStringEx(string,Interior[i][0][IntName],0,'|');
  169.             Interior[i][0][enterX]=floatstr(getPartOfString(string,1,'|'));
  170.             Interior[i][0][enterY]=floatstr(getPartOfString(string,2,'|'));
  171.             Interior[i][0][enterZ]=floatstr(getPartOfString(string,3,'|'));
  172.             Interior[i][0][enterSpawnX]=floatstr(getPartOfString(string,4,'|'));
  173.             Interior[i][0][enterSpawnY]=floatstr(getPartOfString(string,5,'|'));
  174.             Interior[i][0][enterSpawnZ]=floatstr(getPartOfString(string,6,'|'));
  175.             Interior[i][0][enterSpawnA]=floatstr(getPartOfString(string,7,'|'));
  176.             Interior[i][0][enterSpawnInt]=strval(getPartOfString(string,8,'|'));
  177.             Interior[i][0][exitX]=floatstr(getPartOfString(string,9,'|'));
  178.             Interior[i][0][exitY]=floatstr(getPartOfString(string,10,'|'));
  179.             Interior[i][0][exitZ]=floatstr(getPartOfString(string,11,'|'));
  180.             Interior[i][0][exitSpawnX]=floatstr(getPartOfString(string,12,'|'));
  181.             Interior[i][0][exitSpawnY]=floatstr(getPartOfString(string,13,'|'));
  182.             Interior[i][0][exitSpawnZ]=floatstr(getPartOfString(string,14,'|'));
  183.             Interior[i][0][exitSpawnA]=floatstr(getPartOfString(string,15,'|'));
  184.             Interior[i][0][exitSpawnInt]=strval(getPartOfString(string,16,'|'));
  185.             Interior[i][0][iEnterPickup] = AddStaticPickup(1559,23,Interior[i][0][enterX],Interior[i][0][enterY],Interior[i][0][enterZ],-1);
  186.             Interior[i][0][iExitPickup] = AddStaticPickup(1559,23,Interior[i][0][exitX],Interior[i][0][exitY],Interior[i][0][exitZ],-1); }
  187.         return fclose(intFile),print("[LOAD] Dynamic Interiors successfully loaded!"); }
  188.  
  189. //--> UnloadInteriors
  190.     forward UnloadInteriors();
  191.     public UnloadInteriors() {
  192.         for(new i=0;i<MAX_INTERIORS;i++) {
  193.             if(Interior[i][0][iEnterPickup]==-1) { break; }
  194.             Interior[i][0][IntName]=0;
  195.             Interior[i][0][enterX]=0; Interior[i][0][enterY]=0; Interior[i][0][enterZ]=0;
  196.             Interior[i][0][enterSpawnX]=0; Interior[i][0][enterSpawnY]=0; Interior[i][0][enterSpawnZ]=0; Interior[i][0][enterSpawnA]=0; Interior[i][0][enterSpawnInt]=0;
  197.             Interior[i][0][exitX]=0; Interior[i][0][exitY]=0; Interior[i][0][exitZ]=0;
  198.             Interior[i][0][exitSpawnX]=0; Interior[i][0][exitSpawnY]=0; Interior[i][0][exitSpawnZ]=0; Interior[i][0][exitSpawnA]=0; Interior[i][0][exitSpawnInt]=0;
  199.             Interior[i][0][iEnterPickup]=-1; Interior[i][0][iExitPickup]=-1; }
  200.         return print("[LOAD] Dynamic Interiors successfully unloaded!"); }
  201.  
  202. //--> Needed Functions to Use
  203.     stock getPartOfString(const string[], strpos=0, sep=' ',secondsep=256) {    //by FoxHound
  204.         new delstr[256],count[2]={0,...}; secondsep = (secondsep!=256) ? secondsep : sep;
  205.         format(delstr,256,"%s",string);
  206.         for(new i[2]={0,...}; i[0]<strlen(delstr); i[0]++) {
  207.             if(delstr[i[0]]==sep) {
  208.                 count[1]++;
  209.                 if(!strpos) { strdel(delstr,i[0],strlen(delstr)); break; }
  210.                 else if(((count[0]+1)==strpos) && !i[1]) { strdel(delstr,0,i[0]+1),i={0,1},sep=secondsep; continue; }
  211.                 else if(i[1]) { strdel(delstr,i[0],strlen(delstr)); }
  212.                 else { count[0]++; continue; } } }
  213.         if(count[1]<strpos) { delstr="\0"; }
  214.         return delstr; }
  215.     stock getPartOfStringEx(const string[], dest[], strpos=0, sep=' ', secondsep=256) { //by FoxHound
  216.         new delstr[256],count[2]={0,...}; secondsep = (secondsep!=256) ? secondsep : sep;
  217.         format(delstr,256,"%s",string);
  218.         for(new i[2]={0,...}; i[0]<strlen(delstr); i[0]++) {
  219.             if(delstr[i[0]]==sep) {
  220.                 count[1]++;
  221.                 if(!strpos) { strdel(delstr,i[0],strlen(delstr)); break; }
  222.                 else if(((count[0]+1)==strpos) && !i[1]) { strdel(delstr,0,i[0]+1),i={0,1},sep=secondsep; continue; }
  223.                 else if(i[1]) { strdel(delstr,i[0],strlen(delstr)); }
  224.                 else { count[0]++; continue; } } }
  225.         if(count[1]<strpos) { delstr="\0"; }
  226.         format(dest,64,"%s",delstr); }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement