SHARE
TWEET

w_baumV2

a guest Dec 7th, 2014 221 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <a_samp>
  2. #include <wcmd>
  3. #include <dini>
  4.  
  5. //Dialoge
  6. #define WBAUM_HOME 1000
  7. #define WBAUM_DELETE 1001
  8. #define WBAUM_EDIT 1002
  9. #define WBAUM_EDIT_MANUEL 1003
  10. #define WBAUM_EDIT_MANUEL1 1004
  11. #define WBAUM_EDIT_MANUEL2 1005
  12.  
  13. #define MAX_PLAYER_IP 64
  14. #define MAX_BAUM 5
  15.  
  16. #define OBJECT_MODEL_BAUM 19076
  17.  
  18. #define WBAUM_DINI "/WBAUM/%d.txt"
  19.  
  20. new MAXPLAYERS;
  21. new PIP[MAX_PLAYERS][MAX_PLAYER_IP];
  22. new PlayerEditManuelObject[MAX_PLAYERS];
  23. new CanSelectedObject[MAX_PLAYERS];
  24. new PlayerSelectedObject[MAX_PLAYERS];
  25.  
  26. enum wbaumenum
  27. {
  28.         id,
  29.         baum_model,
  30.         Float:baum_posx,
  31.         Float:baum_posy,
  32.         Float:baum_posz,
  33.         Float:baum_rotx,
  34.         Float:baum_roty,
  35.         Float:baum_rotz,
  36.         baum_edit
  37. }
  38. new wbaum[MAX_BAUM][wbaumenum];
  39.  
  40. #define WELCOME_MESSAGE "[W_BAUM INFO]Hallo, mit dem Befehl '/wbaum', kannst du WeinachtsbÀume erstellen, bearbeiten und Löschen"
  41. #define INVALID_OBJECT_MESSAGE "[W_BAUM ERROR]Du hast eine falsche Onjekt ID angegeben oder in der zwischen Zeit wurde das Objekt, von ein Kollegen von dir gelöscht"
  42. #define OBJECT_SAVED "[W_BAUM INFO] Der Weinachtsbaum %d wurde jetzt gespeichert, du kannst ihm jetzt wieder bearbeiten"
  43. #define OBJECT_EDIT_NOT_SAVED "[W_BAUM ERROR] Der Weinachtsbaum, wurde innerhalb von den Letzten 5 Minuten schon bearbeitet."
  44.  
  45. #define OBJECT_EDIT_NO_BY_PLAYER "[W_BAUM ERROR]Dieses Object wurde nicht von dir Bearbeitet"
  46. #define SELECT_OBJECT "[W_BAUM INFO]WÀhle nun das Objekt aus, was du bearbeiten möchtest"
  47. #define OBJECT_EDIT_BY_PLAYER "[W_BAUM INFO]Du hast erfolgreich den %d Weinachtsbaum bearbeitet"
  48. #define OBJECT_NOT_FREE_SLOT "[W_Baum ERROR]Es sind keine Freien Slots mehr verfĂŒgbar, bitte im Filterscript 'MAX_BAUM' anpassen!"
  49. #define OBJECT_DELETE "[W_Baum Info]Der Weinachtsbaum wurde gelöscht"
  50.  
  51. public OnFilterScriptInit()
  52. {
  53.         print("\n--------------------------------------");
  54.         print(" Blank Filterscript by your name here");
  55.         print("--------------------------------------\n");
  56.         MAXPLAYERS = GetMaxPlayers();
  57.         LoadWBaum();
  58.         return 1;
  59. }
  60.  
  61. public OnFilterScriptExit()
  62. {
  63.         return 1;
  64. }
  65.  
  66. public OnPlayerConnect(playerid)
  67. {
  68.         GetPlayerIp(playerid,PIP[playerid],MAX_PLAYER_IP);
  69.         return 1;
  70. }
  71.  
  72. public OnRconLoginAttempt(ip[], password[], success)
  73. {
  74.         new playerid;
  75.         for(new i=0; i<MAXPLAYERS; i++)
  76.         {
  77.             if(!strcmp(PIP[i],ip)) continue;
  78.                 playerid = i;
  79.                 break;
  80.         }
  81.         if(success) SendClientMessage(playerid,-1,WELCOME_MESSAGE);
  82.         return 1;
  83. }
  84.  
  85. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  86. {
  87.         if(dialogid == WBAUM_HOME) return DIALOG_WBAUM_HOME(playerid,response,listitem);
  88.         if(dialogid == WBAUM_DELETE) return DIALOG_WBAUM_DELETE(playerid,response);
  89.         if(dialogid == WBAUM_EDIT) return DIALOG_WBAUM_EDIT(playerid,response,listitem);
  90.         if(dialogid == WBAUM_EDIT_MANUEL) return DIALOG_WBAUM_EDIT_MANUEL(playerid,response);
  91.         if(dialogid == WBAUM_EDIT_MANUEL1) return DIALOG_WBAUM_EDIT_MANUEL1(playerid,response,listitem);
  92.         if(dialogid == WBAUM_EDIT_MANUEL2) return DIALOG_WBAUM_EDIT_MANUEL2(playerid,response,inputtext);
  93.         return 1;
  94. }
  95.  
  96. public OnPlayerEditObject(playerid, playerobject, objectid, response, Float:fX, Float:fY, Float:fZ, Float:fRotX, Float:fRotY, Float:fRotZ)
  97. {
  98.         printf("OnPlayerEditObject(playerid=%d, playerobject=%d, objectid=%d, response=%d, fX=%f, fY=%f, fZ=%f, fRotX=%f, fRotY=%f, fRotZ=%f)",playerid, playerobject, objectid, response, fX, fY, fZ, fRotX, fRotY, fRotZ);
  99.         if(!playerobject)
  100.         {
  101.             if(!IsValidObject(objectid)) return SendClientMessage(playerid,-1, INVALID_OBJECT_MESSAGE);
  102.         SetObjectPos(objectid, fX, fY, fZ);
  103.         SetObjectRot(objectid, fRotX, fRotY, fRotZ);
  104.         new i = FindWBaumbyObjectID(objectid);
  105.         wbaum[i][baum_posx] = fX;
  106.                 wbaum[i][baum_posy] = fY;
  107.                 wbaum[i][baum_posz] = fZ;
  108.                 wbaum[i][baum_rotx] = fRotX;
  109.                 wbaum[i][baum_roty] = fRotY;
  110.                 wbaum[i][baum_rotz] = fRotZ;
  111.        
  112.         new string[128];
  113.         format(string,128,OBJECT_EDIT_BY_PLAYER,objectid);
  114.         SendClientMessage(playerid,-1,string);
  115.         if(wbaum[i][baum_edit] == 0) SetTimerEx("SaveWBaum",1000*60*5,0,"dd",playerid,i);
  116.         wbaum[i][baum_edit]=1;
  117.         }
  118.         return 1;
  119. }
  120.  
  121. public OnPlayerSelectObject(playerid, type, objectid, modelid, Float:fX, Float:fY, Float:fZ)
  122. {
  123.         new tempCanSelectedObject;
  124.         if(CanSelectedObject[playerid] == 1 ||CanSelectedObject[playerid] == 2)
  125.         {
  126.             new i = FindWBaumbyObjectID(objectid);
  127.             PlayerSelectedObject[playerid] = i;
  128.             tempCanSelectedObject = CanSelectedObject[playerid];
  129.             CanSelectedObject[playerid] = 0;
  130.             CancelEdit(playerid);
  131.         }
  132.         if(tempCanSelectedObject == 1) return DIALOG_WBAUM_EDIT_MANUEL1(playerid,0,0,1);
  133.         if(tempCanSelectedObject == 2) return DIALOG_WBAUM_DELETE(playerid,0,1);
  134.     printf("OnPlayerSelectObject(playerid=%d, type=%d, objectid=%d, modelid=%d, fX=%f, fY=%f, fZ=%f)", playerid, type, objectid, modelid, fX, fY, fZ);
  135.     if(type == SELECT_OBJECT_GLOBAL_OBJECT)
  136.     {
  137.         new i = FindWBaumbyObjectID(objectid);
  138.         if(wbaum[i][baum_edit] == 1) return SendClientMessage(playerid,-1,OBJECT_EDIT_NOT_SAVED);
  139.         EditObject(playerid, objectid);
  140.         printf("Object ausgewĂ€hlt %d",objectid);
  141.     }
  142.     return 1;
  143. }
  144. forward SaveWBaum(playerid,wbaumid);
  145. public SaveWBaum(playerid,wbaumid)
  146. {
  147.     wbaum[wbaumid][baum_edit] = 0;
  148.         new pfad[30];
  149.     format(pfad,30,WBAUM_DINI,wbaumid);
  150.     if(!dini_Exists(pfad)) return 1;
  151.         dini_IntSet(pfad,"baum_model",wbaum[wbaumid][baum_model]);
  152.         dini_FloatSet(pfad,"baum_posx",wbaum[wbaumid][baum_posx]);
  153.         dini_FloatSet(pfad,"baum_posy",wbaum[wbaumid][baum_posy]);
  154.         dini_FloatSet(pfad,"baum_posz",wbaum[wbaumid][baum_posz]);
  155.         dini_FloatSet(pfad,"baum_rotx",wbaum[wbaumid][baum_rotx]);
  156.         dini_FloatSet(pfad,"baum_roty",wbaum[wbaumid][baum_roty]);
  157.         dini_FloatSet(pfad,"baum_rotz",wbaum[wbaumid][baum_rotz]);
  158.        
  159.         new string[128];
  160.     format(string,128,OBJECT_SAVED,wbaumid);
  161.         SendClientMessage(playerid,-1,string);
  162.         return 1;
  163. }
  164. stock FindWBaumbyObjectID(objectid)
  165. {
  166.         for(new i=0; i<MAX_BAUM; i++)
  167.         {
  168.             if(wbaum[i][id] != objectid) continue;
  169.                 return i;
  170.         }
  171.         return -1;
  172. }
  173. stock FindFreeWBaum()
  174. {
  175.         for(new i=0; i<MAX_BAUM; i++)
  176.         {
  177.             if(wbaum[i][id] != 0) continue;
  178.                 return i;
  179.         }
  180.         return -1;
  181. }
  182. stock LoadWBaum()
  183. {
  184.         for(new i=0; i<MAX_BAUM; i++)
  185.         {
  186.             new pfad[30];
  187.             format(pfad,30,WBAUM_DINI,i);
  188.             if(!dini_Exists(pfad)) continue;
  189.  
  190.             wbaum[i][baum_edit]=0;
  191.                 wbaum[i][baum_model]=dini_Int(pfad,"baum_model");
  192.                 wbaum[i][baum_posx]=dini_Float(pfad,"baum_posx");
  193.                 wbaum[i][baum_posy]=dini_Float(pfad,"baum_posy");
  194.                 wbaum[i][baum_posz]=dini_Float(pfad,"baum_posz");
  195.                 wbaum[i][baum_rotx]=dini_Float(pfad,"baum_rotx");
  196.                 wbaum[i][baum_roty]=dini_Float(pfad,"baum_roty");
  197.                 wbaum[i][baum_rotz]=dini_Float(pfad,"baum_rotz");
  198.                 wbaum[i][id]=CreateObject(wbaum[i][baum_model], wbaum[i][baum_posx], wbaum[i][baum_posy], wbaum[i][baum_posz], wbaum[i][baum_rotx], wbaum[i][baum_roty], wbaum[i][baum_rotz]);
  199.         }
  200.         return 1;
  201. }
  202.  
  203. WhiitetiigerCommand:[playerid,params[]];wbaum
  204. {
  205.         DIALOG_WBAUM_HOME(playerid,0,0,1);
  206.         return 1;
  207. }
  208.  
  209. stock DIALOG_WBAUM_HOME(playerid,response,listitem,show=0)
  210. {
  211.     CanSelectedObject[playerid] = 0;
  212.         if(show) return ShowPlayerDialog(playerid,WBAUM_HOME,DIALOG_STYLE_LIST,"Weinachtsbaum - Home","Weinachtsbaum erstellen\nWeinachtsbaum löschen\nWeinachtsbaum bearbeiten","Weiter","Abbruch");
  213.         if(!response) return 1;
  214.         switch(listitem)
  215.         {
  216.             case 0: {
  217.                         new Float:Pos[3];
  218.                         GetPlayerPos(playerid,Pos[0],Pos[1],Pos[2]);
  219.                         SetPlayerPos(playerid,Pos[0]+2,Pos[1]+2,Pos[2]);
  220.                         new i = FindFreeWBaum();
  221.                         if(i==-1) return SendClientMessage(playerid,-1,OBJECT_NOT_FREE_SLOT);
  222.                         wbaum[i][baum_edit]=0;
  223.                         wbaum[i][baum_model]=OBJECT_MODEL_BAUM;
  224.                         wbaum[i][baum_posx]=Pos[0];
  225.                         wbaum[i][baum_posy]=Pos[1];
  226.                         wbaum[i][baum_posz]=Pos[2];
  227.                         wbaum[i][baum_rotx]=0.0;
  228.                         wbaum[i][baum_roty]=0.0;
  229.                         wbaum[i][baum_rotz]=0.0;
  230.                         wbaum[i][id]=CreateObject(wbaum[i][baum_model], wbaum[i][baum_posx], wbaum[i][baum_posy], wbaum[i][baum_posz], wbaum[i][baum_rotx], wbaum[i][baum_roty], wbaum[i][baum_rotz]);
  231.             for(new u=0; u<MAX_BAUM; u++)
  232.             {
  233.                 new pfad[30];
  234.                 format(pfad,30,WBAUM_DINI,i);
  235.                             if(dini_Exists(pfad)) continue;
  236.                                 dini_Create(pfad);
  237.  
  238.                                 dini_IntSet(pfad,"baum_model",wbaum[i][baum_model]);
  239.                                 dini_FloatSet(pfad,"baum_posx",wbaum[i][baum_posx]);
  240.                                 dini_FloatSet(pfad,"baum_posy",wbaum[i][baum_posy]);
  241.                                 dini_FloatSet(pfad,"baum_posz",wbaum[i][baum_posz]);
  242.                                 dini_FloatSet(pfad,"baum_rotx",wbaum[i][baum_rotx]);
  243.                                 dini_FloatSet(pfad,"baum_roty",wbaum[i][baum_roty]);
  244.                                 dini_FloatSet(pfad,"baum_rotz",wbaum[i][baum_rotz]);
  245.                                 DIALOG_WBAUM_HOME(playerid,0,0,1);
  246.                         }
  247.                 }
  248.                 case 1: {
  249.                         CanSelectedObject[playerid] = 2;
  250.                         SendClientMessage(playerid,-1,SELECT_OBJECT);
  251.                         SelectObject(playerid);
  252.                 }
  253.                 case 2: {
  254.             DIALOG_WBAUM_EDIT(playerid,0,0,1);
  255.                 }
  256.         }
  257.         return 1;
  258. }
  259. stock DIALOG_WBAUM_DELETE(playerid,response,show=0)
  260. {
  261.         new i=PlayerSelectedObject[playerid];
  262.         if(show) {
  263.                 ShowPlayerDialog(playerid,WBAUM_DELETE,DIALOG_STYLE_MSGBOX,"Weinachtsbaum - Löschen","Möchtest du diesen Weinachtsbaum wirklich Löschen,\num kein Falschen zu Löschen,\nwird dieser dir jetzt per Checkpoint gezeigt.","Ja","ZurĂŒck");
  264.                 return SetPlayerCheckpoint(playerid,wbaum[i][baum_posx],wbaum[i][baum_posy],wbaum[i][baum_posz],5.0);
  265.         }
  266.         if(!response) return DIALOG_WBAUM_HOME(playerid,0,0,1);
  267.         wbaum[i][baum_edit]=0;
  268.         wbaum[i][baum_model]=0;
  269.         wbaum[i][baum_posx]=0.0;
  270.         wbaum[i][baum_posy]=0.0;
  271.         wbaum[i][baum_posz]=0.0;
  272.         wbaum[i][baum_rotx]=0.0;
  273.         wbaum[i][baum_roty]=0.0;
  274.         wbaum[i][baum_rotz]=0.0;
  275.         DestroyObject(wbaum[i][id]);
  276.         wbaum[i][id] = 0;
  277.         DisablePlayerCheckpoint(playerid);
  278.         SendClientMessage(playerid,-1,OBJECT_DELETE);
  279.         new pfad[30];
  280.         format(pfad,30,WBAUM_DINI,i);
  281.         dini_Remove(pfad);
  282.         return 1;
  283. }
  284. stock DIALOG_WBAUM_EDIT(playerid,response,listitem,show=0)
  285. {
  286.         if(show) return ShowPlayerDialog(playerid,WBAUM_EDIT,DIALOG_STYLE_LIST,"Weinachtsbaum - Editieren","Position Manuel eingeben\nMit dem Mapeditor","Weiter","ZurĂŒck");
  287.         if(!response) return DIALOG_WBAUM_HOME(playerid,0,0,1);
  288.         switch(listitem)
  289.         {
  290.             case 0: {
  291.             DIALOG_WBAUM_EDIT_MANUEL(playerid,0,1);
  292.                 }
  293.                 case 1: {
  294.                     CanSelectedObject[playerid] = 0;
  295.             SendClientMessage(playerid,-1,SELECT_OBJECT);
  296.                 SelectObject(playerid);
  297.                 }
  298.         }
  299.         return 1;
  300. }
  301.  
  302. stock DIALOG_WBAUM_EDIT_MANUEL(playerid,response,show=0)
  303. {
  304.     if(show) {
  305.                 CanSelectedObject[playerid] = 1;
  306.                 SendClientMessage(playerid,-1,SELECT_OBJECT);
  307.                 SelectObject(playerid);
  308.                 return 1;
  309.         if(!response) return DIALOG_WBAUM_EDIT(playerid,0,0,1);
  310.         return 1;
  311. }
  312.  
  313. stock DIALOG_WBAUM_EDIT_MANUEL1(playerid,response,listitem,show=0)
  314. {
  315.         if(show) return ShowPlayerDialog(playerid,WBAUM_EDIT_MANUEL1,DIALOG_STYLE_LIST,"Weinachtsbaum - Editieren - Manuel","Position X\nPosition Y\nPosition Z\n\nRotation X\nRotation Y\nRotation Z","Weiter","ZurĂŒck");
  316.         if(!response) return DIALOG_WBAUM_EDIT_MANUEL(playerid,0,1);
  317.         PlayerEditManuelObject[playerid] = listitem+1;
  318.         DIALOG_WBAUM_EDIT_MANUEL2(playerid,0,"",1);
  319.         return 1;
  320. }
  321.  
  322. stock DIALOG_WBAUM_EDIT_MANUEL2(playerid,response,inputtext[],show=0)
  323. {
  324.         new string1[60],string2[60],Poslistitem = PlayerEditManuelObject[playerid], i = PlayerSelectedObject[playerid];
  325.         if(Poslistitem == 1) format(string1,60,"Position X");
  326.         else if(Poslistitem == 2) format(string1,60,"Position Y");
  327.         else if(Poslistitem == 3) format(string1,60,"Position Z");
  328.         else if(Poslistitem == 4) format(string1,60,"Rotation X");
  329.         else if(Poslistitem == 5) format(string1,60,"Rotation Y");
  330.         else if(Poslistitem == 6) format(string1,60,"Rotation Z");
  331.         format(string2,60,"Weinachtsbaum - Editieren - Baum %d - Manuel - %s",i,string1);
  332.         if(show) return ShowPlayerDialog(playerid,WBAUM_EDIT_MANUEL2,DIALOG_STYLE_INPUT,string2,"Gebe nun die Position ein.\n\nAchtung: dieser input muss nach dem Schema sein '0.0'","Weiter","ZurĂŒck");
  333.         if(!response) return DIALOG_WBAUM_EDIT_MANUEL1(playerid,0,0,1);
  334.        
  335.         if(Poslistitem == 1) wbaum[i][baum_posx] = floatstr(inputtext);
  336.         else if(Poslistitem == 2) wbaum[i][baum_posy] = floatstr(inputtext);
  337.         else if(Poslistitem == 3) wbaum[i][baum_posz] = floatstr(inputtext);
  338.         else if(Poslistitem == 4) wbaum[i][baum_rotx] = floatstr(inputtext);
  339.         else if(Poslistitem == 5) wbaum[i][baum_roty] = floatstr(inputtext);
  340.         else if(Poslistitem == 6) wbaum[i][baum_rotz] = floatstr(inputtext);
  341.         SetObjectPos(wbaum[i][id], wbaum[i][baum_posx], wbaum[i][baum_posy], wbaum[i][baum_posz]);
  342.         SetObjectRot(wbaum[i][id], wbaum[i][baum_rotx], wbaum[i][baum_roty], wbaum[i][baum_rotz]);
  343.        
  344.         new pfad[30];
  345.     format(pfad,30,WBAUM_DINI,i);
  346.         dini_IntSet(pfad,"baum_model",wbaum[i][baum_model]);
  347.         dini_FloatSet(pfad,"baum_posx",wbaum[i][baum_posx]);
  348.         dini_FloatSet(pfad,"baum_posy",wbaum[i][baum_posy]);
  349.         dini_FloatSet(pfad,"baum_posz",wbaum[i][baum_posz]);
  350.         dini_FloatSet(pfad,"baum_rotx",wbaum[i][baum_rotx]);
  351.         dini_FloatSet(pfad,"baum_roty",wbaum[i][baum_roty]);
  352.         dini_FloatSet(pfad,"baum_rotz",wbaum[i][baum_rotz]);
  353.        
  354.        
  355.         DIALOG_WBAUM_EDIT_MANUEL1(playerid,0,0,1);
  356.         return 1;
  357. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top