Guest User

toccovender

a guest
Jun 22nd, 2009
568
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 15.30 KB | None | 0 0
  1. #include <a_samp>
  2.  
  3. /*
  4. This script was made by toccovender,
  5. you do NOT have permission to redistrubute this script unless you got permission directly from toccovender.
  6. do NOT remove this comment from the script.
  7. if it is found that you have broken any of those rules, you will be punished in whatever ways possible.
  8. kthxbai.
  9. */
  10.  
  11. forward CheckKeys(playerid);
  12.  
  13. enum objdata
  14. {
  15.     obj_exists,
  16.     obj_model_id,
  17.     obj_desc[100],
  18.     Float:obj_x,
  19.     Float:obj_y,
  20.     Float:obj_z,
  21.     Float:obj_rx,
  22.     Float:obj_ry,
  23.     Float:obj_rz,
  24. }
  25. new Objects[MAX_OBJECTS][objdata];
  26. new curobjid[MAX_PLAYERS];
  27. new mode[MAX_PLAYERS] = 0;
  28. new Float:editinc[MAX_PLAYERS] = 0.1;
  29. new PlayerIsEditing[MAX_PLAYERS];
  30. new PlayerAttached[MAX_PLAYERS];
  31. new timers[MAX_PLAYERS];
  32.  
  33. /*
  34. XY=0
  35. Z=1
  36. R_XY=2
  37. R_Z=3
  38. */
  39.  
  40. strtok(const string[], &index)
  41. {
  42.     new length = strlen(string);
  43.     while ((index < length) && (string[index] <= ' '))
  44.     {
  45.         index++;
  46.     }
  47.  
  48.     new offset = index;
  49.     new result[20];
  50.     while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
  51.     {
  52.         result[index - offset] = string[index];
  53.         index++;
  54.     }
  55.     result[index - offset] = EOS;
  56.     return result;
  57. }
  58.  
  59. public CheckKeys(playerid)
  60. {
  61.     new keys, updown, leftright;
  62.     GetPlayerKeys(playerid,keys,updown,leftright);
  63.     if(PlayerIsEditing[playerid])
  64.     {
  65.         if(updown == KEY_UP)
  66.         {
  67.             if(mode[playerid]==0)
  68.             {
  69.                 Objects[curobjid[playerid]][obj_y] += editinc[playerid];
  70.             }
  71.             if(mode[playerid]==1)
  72.             {
  73.                 Objects[curobjid[playerid]][obj_z] += editinc[playerid];
  74.             }
  75.             if(mode[playerid]==2)
  76.             {
  77.                 Objects[curobjid[playerid]][obj_ry] += editinc[playerid];
  78.             }
  79.             if(mode[playerid]==3)
  80.             {
  81.                 Objects[curobjid[playerid]][obj_rz] += editinc[playerid];
  82.             }
  83.         }
  84.         if(updown ==  KEY_DOWN)
  85.         {
  86.             if(mode[playerid]==0)
  87.             {
  88.                 Objects[curobjid[playerid]][obj_y] -= editinc[playerid];
  89.             }
  90.             if(mode[playerid]==1)
  91.             {
  92.                 Objects[curobjid[playerid]][obj_z] -= editinc[playerid];
  93.             }
  94.             if(mode[playerid]==2)
  95.             {
  96.                 Objects[curobjid[playerid]][obj_ry] -= editinc[playerid];
  97.             }
  98.             if(mode[playerid]==3)
  99.             {
  100.                 Objects[curobjid[playerid]][obj_rz] -= editinc[playerid];
  101.             }
  102.         }
  103.         if(leftright == KEY_LEFT)
  104.         {
  105.             if(mode[playerid]==0)
  106.             {
  107.                 Objects[curobjid[playerid]][obj_x] -= editinc[playerid];
  108.             }
  109.             if(mode[playerid]==2)
  110.             {
  111.                 Objects[curobjid[playerid]][obj_rx] -= editinc[playerid];
  112.             }
  113.             if(mode[playerid]==3)
  114.             {
  115.                 Objects[curobjid[playerid]][obj_rz] -= editinc[playerid];
  116.             }
  117.         }
  118.         if(leftright == KEY_RIGHT)
  119.         {
  120.             if(mode[playerid]==0)
  121.             {
  122.                 Objects[curobjid[playerid]][obj_x] += editinc[playerid];
  123.             }
  124.             if(mode[playerid]==2)
  125.             {
  126.                 Objects[curobjid[playerid]][obj_rx] += editinc[playerid];
  127.             }
  128.             if(mode[playerid]==3)
  129.             {
  130.                 Objects[curobjid[playerid]][obj_rz] += editinc[playerid];
  131.             }
  132.         }
  133.         SetObjectPos(curobjid[playerid],Objects[curobjid[playerid]][obj_x],Objects[curobjid[playerid]][obj_y],Objects[curobjid[playerid]][obj_z]);
  134.         SetObjectRot(curobjid[playerid],Objects[curobjid[playerid]][obj_rx],Objects[curobjid[playerid]][obj_ry],Objects[curobjid[playerid]][obj_rz]);
  135.         new Float:x, Float:y, Float:z;
  136.         GetPlayerPos(playerid,x,y,z);
  137.         SetPlayerCameraPos(playerid,x,y,z + 2);
  138.         SetPlayerCameraLookAt(playerid,Objects[curobjid[playerid]][obj_x],Objects[curobjid[playerid]][obj_y],Objects[curobjid[playerid]][obj_z]);
  139.     }
  140. }
  141.  
  142. public OnFilterScriptInit()
  143. {
  144.     print("\n--------------------------------------");
  145.     print(" InGame Object Editor by tocco");
  146.     print("--------------------------------------\n");
  147.     new sfile[100] = "savedobjects.txt";
  148.     if(!fexist(sfile))
  149.     {
  150.         print("Save file not found, creating new one.");
  151.         new File:ntxt = fopen("savedobjects.txt",io_write);
  152.         fclose(ntxt);
  153.         print("Save file creation success!");
  154.     }
  155.     return 1;
  156. }
  157.  
  158. public OnFilterScriptExit()
  159. {
  160.     return 1;
  161. }
  162.  
  163.  
  164. public OnPlayerCommandText(playerid, cmdtext[])
  165. {
  166.     new cmd[100],idx;
  167.     cmd = strtok(cmdtext,idx);
  168.     if (strcmp("/newobj", cmd, true) == 0)
  169.     {
  170.         new objid[100];
  171.         objid = strtok(cmdtext,idx);
  172.         new objdesc[100];
  173.         strmid(objdesc,cmdtext[strfind(cmdtext," ",true,8) + 1],0,100,100);
  174.         new Float:px, Float:py, Float:pz, Float:pr;
  175.         GetPlayerPos(playerid,px,py,pz);
  176.         GetPlayerFacingAngle(playerid,pr);
  177.         new newobjid = CreateObject(strval(objid),px,py,pz,0.0,0.0,pr);
  178.         curobjid[playerid] = newobjid;
  179.         AttachObjectToPlayer(newobjid,playerid,0.0,0.0,0.0,0.0,0.0,pr);
  180.         Objects[newobjid][obj_desc] = objdesc;
  181.         Objects[newobjid][obj_exists] = 1;
  182.         Objects[newobjid][obj_model_id] = strval(objid);
  183.         PlayerIsEditing[playerid] = 0;
  184.         PlayerAttached[playerid] = 1;
  185.         return 1;
  186.     }
  187.  
  188.     if (strcmp("/dupobj", cmd, true) == 0)
  189.     {
  190.         new newobjid = CreateObject(Objects[curobjid[playerid]][obj_model_id],Objects[curobjid[playerid]][obj_x],Objects[curobjid[playerid]][obj_y],Objects[curobjid[playerid]][obj_z],Objects[curobjid[playerid]][obj_rx],Objects[curobjid[playerid]][obj_ry],Objects[curobjid[playerid]][obj_rz]);
  191.         Objects[newobjid][obj_desc] = cmdtext[8];
  192.         Objects[newobjid][obj_exists] = 1;
  193.         Objects[newobjid][obj_model_id] = Objects[curobjid[playerid]][obj_model_id];
  194.         curobjid[playerid] = newobjid;
  195.         PlayerIsEditing[playerid] = 0;
  196.         PlayerAttached[playerid] = 1;
  197.         return 1;
  198.     }
  199.  
  200.     if(strcmp("/detach", cmd, true) == 0)
  201.     {
  202.         if(PlayerAttached[playerid] == 1)
  203.         {
  204.             DestroyObject(curobjid[playerid]);
  205.             Objects[curobjid[playerid]][obj_exists] = 0;
  206.             new Float:px, Float:py, Float:pz, Float:pr;
  207.             GetPlayerPos(playerid,px,py,pz);
  208.             GetPlayerFacingAngle(playerid,pr);
  209.             new newobjid = CreateObject(Objects[curobjid[playerid]][obj_model_id],px,py,pz,0.0,0.0,pr);
  210.             Objects[newobjid][obj_desc] = Objects[curobjid[playerid]][obj_desc];
  211.             Objects[curobjid[playerid]][obj_exists] = 1;
  212.             Objects[curobjid[playerid]][obj_x] = px;
  213.             Objects[curobjid[playerid]][obj_y] = py;
  214.             Objects[curobjid[playerid]][obj_z] = pz;
  215.             Objects[curobjid[playerid]][obj_rz] = pr;
  216.             curobjid[playerid] = newobjid;
  217.             PlayerIsEditing[playerid] = 1;
  218.             PlayerAttached[playerid] = 0;
  219.             TogglePlayerControllable(playerid,0);
  220.             timers[playerid] = SetTimerEx("CheckKeys",10,true,"%i",playerid);
  221.             return 1;
  222.         }
  223.         return 1;
  224.     }
  225.  
  226.     if(strcmp("/stopediting",cmd,true) == 0)
  227.     {
  228.         TogglePlayerControllable(playerid,1);
  229.         PlayerIsEditing[playerid] = 0;
  230.         KillTimer(timers[playerid]);
  231.         SetCameraBehindPlayer(playerid);
  232.         return 1;
  233.     }
  234.  
  235.     if(strcmp("/objlist",cmd,true) == 0)
  236.     {
  237.         SendClientMessage(playerid,0xFFFFFFFF,"--------------------");
  238.         new i;
  239.         for(i=0; i<MAX_OBJECTS; i++)
  240.         {
  241.             if(Objects[i][obj_exists])
  242.             {
  243.                 new msg[110];
  244.                 format(msg,110,"ObjectID: %i, ModelID: %i, Description: %s",i,Objects[i][obj_model_id],Objects[i][obj_desc]);
  245.                 SendClientMessage(playerid,0x0000FFFF,msg);
  246.              }
  247.         }
  248.         SendClientMessage(playerid,0xFFFFFFFF,"--------------------");
  249.         SendClientMessage(playerid,0xFFFFFFFF,"You may have to use Pg Up and Pg Down to view all objects.");
  250.         return 1;
  251.     }
  252.  
  253.     if(strcmp("/editobj",cmd,true) == 0)
  254.     {
  255.         new objid[100];
  256.         objid = strtok(cmdtext,idx);
  257.         if(Objects[strval(objid)][obj_exists])
  258.         {
  259.             curobjid[playerid] = strval(objid);
  260.             PlayerIsEditing[playerid] = 1;
  261.             PlayerAttached[playerid] = 0;
  262.             TogglePlayerControllable(playerid,0);
  263.             timers[playerid] = SetTimerEx("CheckKeys",100,true,"%i",playerid);
  264.         }
  265.         else
  266.         {
  267.             SendClientMessage(playerid,0xFF0000FF,"Couldn't find object in memory.");
  268.         }
  269.         return 1;
  270.     }
  271.  
  272.     if(strcmp("/editinc",cmd,true) == 0)
  273.     {
  274.         new edit[100];
  275.         edit = strtok(cmdtext,idx);
  276.         editinc[playerid] = floatstr(edit);
  277.         return 1;
  278.     }
  279.  
  280.     if(strcmp("/mode",cmd,true) == 0)
  281.     {
  282.         new nmode[100];
  283.         nmode = strtok(cmdtext,idx);
  284.         if(strcmp(nmode,"XY",true) == 0)
  285.         {
  286.             mode[playerid] = 0;
  287.             SendClientMessage(playerid,0x0000FFFF,"Mode set to XY");
  288.             return 1;
  289.         }
  290.         if(strcmp(nmode,"Z",true) == 0)
  291.         {
  292.             mode[playerid] = 1;
  293.             SendClientMessage(playerid,0x0000FFFF,"Mode set to Z");
  294.             return 1;
  295.         }
  296.         if(strcmp(nmode,"R_XY",true) == 0)
  297.         {
  298.             mode[playerid] = 2;
  299.             SendClientMessage(playerid,0x0000FFFF,"Mode set to R_XY");
  300.             return 1;
  301.         }
  302.         if(strcmp(nmode,"R_Z",true) == 0)
  303.         {
  304.             mode[playerid] = 3;
  305.             SendClientMessage(playerid,0x0000FFFF,"Mode set to R_Z");
  306.             return 1;
  307.         }
  308.         SendClientMessage(playerid,0xFF0000FF,"Invalid mode.");
  309.         return 1;
  310.     }
  311.  
  312.     if(strcmp("/delobj",cmd,true) == 0)
  313.     {
  314.         DestroyObject(curobjid[playerid]);
  315.         Objects[curobjid[playerid]][obj_exists] = 0;
  316.         TogglePlayerControllable(playerid,1);
  317.         PlayerIsEditing[playerid] = 0;
  318.         KillTimer(timers[playerid]);
  319.     }
  320.  
  321.     if(strcmp("/saveobj",cmd,true) == 0)
  322.     {
  323.         if(fexist("savedobjects.txt"))
  324.         {
  325.             new File:sfile=fopen("savedobjects.txt",io_append);
  326.             new objtext[255];
  327.             format(objtext,255,"CreateObject(%i,%f,%f,%f,%f,%f,%f); //%s \r\n",Objects[curobjid[playerid]][obj_model_id],Objects[curobjid[playerid]][obj_x],Objects[curobjid[playerid]][obj_y],Objects[curobjid[playerid]][obj_z],Objects[curobjid[playerid]][obj_rx],Objects[curobjid[playerid]][obj_ry],Objects[curobjid[playerid]][obj_rz],Objects[curobjid[playerid]][obj_desc]);
  328.             fwrite(sfile,objtext);
  329.             fclose(sfile);
  330.             SendClientMessage(playerid,0x0000FFFF,"Object data saved to /savedobjects.txt");
  331.         }
  332.         else
  333.         {
  334.             new File:cfile=fopen("savedobjects.txt",io_write);
  335.             fclose(cfile);
  336.             new File:sfile=fopen("savedobjects.txt",io_append);
  337.             new objtext[255];
  338.             format(objtext,255,"CreateObject(%i,%f,%f,%f,%f,%f,%f); //%s \r\n",Objects[curobjid[playerid]][obj_model_id],Objects[curobjid[playerid]][obj_x],Objects[curobjid[playerid]][obj_y],Objects[curobjid[playerid]][obj_z],Objects[curobjid[playerid]][obj_rx],Objects[curobjid[playerid]][obj_ry],Objects[curobjid[playerid]][obj_rz],Objects[curobjid[playerid]][obj_desc]);
  339.             fwrite(sfile,objtext);
  340.             fclose(sfile);
  341.             SendClientMessage(playerid,0x0000FFFF,"Object data saved to /savedobjects.txt");
  342.         }
  343.         return 1;
  344.     }
  345.  
  346.     if(strcmp("/moveobjtome",cmd,true) == 0)
  347.     {
  348.         new Float:px, Float:py, Float:pz;
  349.         GetPlayerPos(playerid,px,py,pz);
  350.         SetObjectPos(curobjid[playerid],px,py,pz);
  351.         Objects[curobjid[playerid]][obj_x] = px;
  352.         Objects[curobjid[playerid]][obj_y] = py;
  353.         Objects[curobjid[playerid]][obj_z] = pz;
  354.         return 1;
  355.     }
  356.  
  357.     if(strcmp("/attach",cmd,true) == 0)
  358.     {
  359.         new Float:pr;
  360.         GetPlayerFacingAngle(playerid,pr);
  361.         AttachObjectToPlayer(curobjid[playerid],playerid,0,0,0,0,0,pr);
  362.         PlayerAttached[playerid] = 1;
  363.         PlayerIsEditing[playerid] = 0;
  364.         SetCameraBehindPlayer(playerid);
  365.         return 1;
  366.     }
  367.  
  368.     //--------------------------------------------------------------
  369.     if(strcmp("/setobjx",cmd,true) == 0)
  370.     {
  371.         new x[100];
  372.         x = strtok(cmdtext,idx);
  373.         Objects[curobjid[playerid]][obj_x] = floatstr(x);
  374.         SetObjectPos(curobjid[playerid],floatstr(x),Objects[curobjid[playerid]][obj_y],Objects[curobjid[playerid]][obj_z]);
  375.         return 1;
  376.     }
  377.     if(strcmp("/setobjy",cmd,true) == 0)
  378.     {
  379.         new y[100];
  380.         y = strtok(cmdtext,idx);
  381.         Objects[curobjid[playerid]][obj_y] = floatstr(y);
  382.         SetObjectPos(curobjid[playerid],Objects[curobjid[playerid]][obj_x],floatstr(y),Objects[curobjid[playerid]][obj_z]);
  383.         return 1;
  384.     }
  385.     if(strcmp("/setobjz",cmd,true) == 0)
  386.     {
  387.         new z[100];
  388.         z = strtok(cmdtext,idx);
  389.         Objects[curobjid[playerid]][obj_z] = floatstr(z);
  390.         SetObjectPos(curobjid[playerid],Objects[curobjid[playerid]][obj_x],Objects[curobjid[playerid]][obj_y],floatstr(z));
  391.         return 1;
  392.     }
  393.     if(strcmp("/setobjrx",cmd,true) == 0)
  394.     {
  395.         new x[100];
  396.         x = strtok(cmdtext,idx);
  397.         Objects[curobjid[playerid]][obj_rx] = floatstr(x);
  398.         SetObjectRot(curobjid[playerid],floatstr(x),Objects[curobjid[playerid]][obj_ry],Objects[curobjid[playerid]][obj_rz]);
  399.         return 1;
  400.     }
  401.     if(strcmp("/setobjry",cmd,true) == 0)
  402.     {
  403.         new y[100];
  404.         y = strtok(cmdtext,idx);
  405.         Objects[curobjid[playerid]][obj_ry] = floatstr(y);
  406.         SetObjectRot(curobjid[playerid],Objects[curobjid[playerid]][obj_rx],floatstr(y),Objects[curobjid[playerid]][obj_rz]);
  407.         return 1;
  408.     }
  409.     if(strcmp("/setobjrz",cmd,true) == 0)
  410.     {
  411.         new z[100];
  412.         z = strtok(cmdtext,idx);
  413.         Objects[curobjid[playerid]][obj_rz] = floatstr(z);
  414.         SetObjectRot(curobjid[playerid],Objects[curobjid[playerid]][obj_rx],Objects[curobjid[playerid]][obj_ry],floatstr(z));
  415.         return 1;
  416.     }
  417.  
  418.     //----------------------------------------------
  419.     if(strcmp("/x",cmd,true) == 0)
  420.     {
  421.         new x[100];
  422.         x = strtok(cmdtext,idx);
  423.         Objects[curobjid[playerid]][obj_x] += floatstr(x);
  424.         SetObjectPos(curobjid[playerid],Objects[curobjid[playerid]][obj_x],Objects[curobjid[playerid]][obj_y],Objects[curobjid[playerid]][obj_z]);
  425.         return 1;
  426.     }
  427.     if(strcmp("/y",cmd,true) == 0)
  428.     {
  429.         new y[100];
  430.         y = strtok(cmdtext,idx);
  431.         Objects[curobjid[playerid]][obj_y] += floatstr(y);
  432.         SetObjectPos(curobjid[playerid],Objects[curobjid[playerid]][obj_x],Objects[curobjid[playerid]][obj_y],Objects[curobjid[playerid]][obj_z]);
  433.         return 1;
  434.     }
  435.     if(strcmp("/z",cmd,true) == 0)
  436.     {
  437.         new z[100];
  438.         z = strtok(cmdtext,idx);
  439.         Objects[curobjid[playerid]][obj_z] += floatstr(z);
  440.         SetObjectPos(curobjid[playerid],Objects[curobjid[playerid]][obj_x],Objects[curobjid[playerid]][obj_y],Objects[curobjid[playerid]][obj_z]);
  441.         return 1;
  442.     }
  443.  
  444.     if(strcmp("/rx",cmd,true) == 0)
  445.     {
  446.         new x[100];
  447.         x = strtok(cmdtext,idx);
  448.         Objects[curobjid[playerid]][obj_rx] += floatstr(x);
  449.         SetObjectRot(curobjid[playerid],Objects[curobjid[playerid]][obj_rx],Objects[curobjid[playerid]][obj_ry],Objects[curobjid[playerid]][obj_rz]);
  450.         return 1;
  451.     }
  452.     if(strcmp("/ry",cmd,true) == 0)
  453.     {
  454.         new y[100];
  455.         y = strtok(cmdtext,idx);
  456.         Objects[curobjid[playerid]][obj_ry] += floatstr(y);
  457.         SetObjectRot(curobjid[playerid],Objects[curobjid[playerid]][obj_rx],Objects[curobjid[playerid]][obj_ry],Objects[curobjid[playerid]][obj_rz]);
  458.         return 1;
  459.     }
  460.     if(strcmp("/rz",cmd,true) == 0)
  461.     {
  462.         new z[100];
  463.         z = strtok(cmdtext,idx);
  464.         Objects[curobjid[playerid]][obj_rz] += floatstr(z);
  465.         SetObjectRot(curobjid[playerid],Objects[curobjid[playerid]][obj_rx],Objects[curobjid[playerid]][obj_ry],Objects[curobjid[playerid]][obj_z]);
  466.         return 1;
  467.     }
  468.    
  469.     if(strcmp("/objsearch",cmd,true) == 0)
  470.     {
  471.         new searchterm[100];
  472.         searchterm = strtok(cmdtext,idx);
  473.         new fname[100]="/objlist.txt";
  474.         if(fexist(fname))
  475.         {
  476.             if(strlen(searchterm) > 0)
  477.             {
  478.                 new File:objlist = fopen(fname,io_read);
  479.                 new numfound;
  480.                 new lstring[100];
  481.                 SendClientMessage(playerid,0x00FF00FF,"Search initializing.");
  482.                 while(fread(objlist,lstring))
  483.                 {
  484.                     if(strfind(lstring,searchterm,true) != -1)
  485.                     {
  486.                         SendClientMessage(playerid,0x0000FFFF,lstring);
  487.                         numfound+=1;
  488.                     }
  489.                 }
  490.                 new msg[255];
  491.                 format(msg,255,"Search complete, %i results, you might need to use PG Up and PG Down to view all results, there may be too many results to display.",numfound);
  492.                 SendClientMessage(playerid,0x00FF00FF,msg);
  493.             }
  494.             else
  495.             {
  496.                 SendClientMessage(playerid,0xFF0000FF,"You must enter a search term, example: /objsearch waterjump");
  497.             }
  498.         }
  499.         else
  500.         {
  501.             SendClientMessage(playerid,0xFF0000FF,"Object list file not found, search aborted.");
  502.         }
  503.         return 1;
  504.     }
  505.     return 0;
  506. }
Advertisement
Add Comment
Please, Sign In to add comment