Advertisement
garfield

[INC]: Manage Attached Objects (dev)

Nov 3rd, 2013
400
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 6.97 KB | None | 0 0
  1. enum E_ATTACH{
  2.  
  3.  
  4.     Float: E_OFFSETX,
  5.     Float: E_OFFSETY,
  6.     Float: E_OFFSETZ,
  7.    
  8.     Float: E_SCALEX,
  9.     Float: E_SCALEY,
  10.     Float: E_SCALEZ,
  11.  
  12.     Float: E_ROTX,
  13.     Float: E_ROTY,
  14.     Float: E_ROTZ,
  15.  
  16.  
  17.     E_COLOR1,
  18.     E_COLOR2,
  19.     E_MODEL,
  20.     E_BONE
  21.    
  22. };
  23.  
  24.  
  25. stock
  26.     Attach[MAX_PLAYERS][10][E_ATTACH]
  27. ;
  28.  
  29.  
  30.  
  31. forward OnPlayerAttachUpdate(playerid, index, modelid, bone, Float:fOffsetX, Float:fOffsetY, Float:fOffsetZ, Float:fRotX, Float:fRotY, Float:fRotZ, Float:fScaleX, Float:fScaleY, Float:fScaleZ, color1, color2);
  32.  
  33.  
  34.  
  35. stock _SetPlayerAttachedObject(playerid, index, modelid, bone, Float:fOffsetX = 0.0,Float:fOffsetY = 0.0, Float:fOffsetZ = 0.0, Float:fRotX = 0.0, Float:fRotY = 0.0, Float:fRotZ = 0.0,Float:fScaleX = 1.0, Float:fScaleY = 1.0, Float:fScaleZ = 1.0,  color1 = 0, color2 = 0){
  36.    
  37.     Attach[playerid][index][E_OFFSETX]  = fOffsetX;
  38.     Attach[playerid][index][E_OFFSETY]  = fOffsetY;
  39.     Attach[playerid][index][E_OFFSETZ]  = fOffsetZ;
  40.    
  41.     Attach[playerid][index][E_SCALEX]   = fScaleX;
  42.     Attach[playerid][index][E_SCALEY]   = fScaleY;
  43.     Attach[playerid][index][E_SCALEZ]   = fScaleZ;
  44.    
  45.     Attach[playerid][index][E_ROTX]     = fRotX;
  46.     Attach[playerid][index][E_ROTY]     = fRotY;
  47.     Attach[playerid][index][E_ROTZ]     = fRotZ;
  48.    
  49.     Attach[playerid][index][E_MODEL]    = modelid;
  50.     Attach[playerid][index][E_COLOR1]   = color1;
  51.     Attach[playerid][index][E_COLOR2]   = color2;
  52.     Attach[playerid][index][E_BONE]     = bone;
  53.    
  54.    
  55.     return SetPlayerAttachedObject(playerid, index, modelid, bone, Float:fOffsetX, Float:fOffsetY, Float:fOffsetZ, Float:fRotX, Float:fRotY, Float:fRotZ, Float:fScaleX, Float:fScaleY, Float:fScaleZ, color1, color2);
  56. }
  57.  
  58. stock SaveAttached(pid){
  59.  
  60.     static _file[100];
  61.     static _fr[100];
  62.     static _n[24];
  63.     static File:_f;
  64.  
  65.  
  66.     for(new i; i != 10; ++i){
  67.         if(Attach[pid][i][E_MODEL] != 0){
  68.        
  69.             format(_file, 100, "Pached_%s_%d.ini", (GetPlayerName(pid, _n, 24), _n), i);
  70.            
  71.             _f = fopen(_file, io_write);
  72.            
  73.             format(_fr, 100,"E_OFFSETX=%f\r\n", Attach[pid][i][E_OFFSETX]); fwrite(_f, _fr);
  74.             format(_fr, 100,"E_OFFSETY=%f\r\n", Attach[pid][i][E_OFFSETY]); fwrite(_f, _fr);
  75.             format(_fr, 100,"E_OFFSETZ=%f\r\n", Attach[pid][i][E_OFFSETZ]); fwrite(_f, _fr);
  76.            
  77.             format(_fr, 100,"E_SCALEX=%f\r\n", Attach[pid][i][E_SCALEX]); fwrite(_f, _fr);
  78.             format(_fr, 100,"E_SCALEY=%f\r\n", Attach[pid][i][E_SCALEX]); fwrite(_f, _fr);
  79.             format(_fr, 100,"E_SCALEZ=%f\r\n", Attach[pid][i][E_SCALEX]); fwrite(_f, _fr);
  80.            
  81.             format(_fr, 100,"E_ROTX=%f\r\n", Attach[pid][i][E_ROTX]); fwrite(_f, _fr);
  82.             format(_fr, 100,"E_ROTY=%f\r\n", Attach[pid][i][E_ROTY]); fwrite(_f, _fr);
  83.             format(_fr, 100,"E_ROTY=%f\r\n", Attach[pid][i][E_ROTZ]); fwrite(_f, _fr);
  84.  
  85.             format(_fr, 100,"E_COLOR1=%d\r\n", Attach[pid][i][E_COLOR1]); fwrite(_f, _fr);
  86.             format(_fr, 100,"E_COLOR2=%d\r\n", Attach[pid][i][E_COLOR2]); fwrite(_f, _fr);
  87.             format(_fr, 100,"E_MODEL=%d\r\n", Attach[pid][i][E_MODEL]); fwrite(_f, _fr);
  88.             format(_fr, 100,"E_BONE=%d\r\n", Attach[pid][i][E_BONE]); fwrite(_f, _fr);
  89.            
  90.             fclose(_f);
  91.         }
  92.     }
  93. }
  94.  
  95. stock LoadAttached(pid){
  96.  
  97.     static
  98.         _file[100],
  99.         _n[24]
  100.     ;
  101.    
  102.     for(new i; i != 10; ++i){
  103.  
  104.             format(_file, 100, "Pached_%s_%d.ini", (GetPlayerName(pid, _n, 24), _n), i);
  105.  
  106.             if(fexist(_file))
  107.             {
  108.                 Attach[pid][i][E_OFFSETX]   = floatstr( _get(_file, "E_OFFSETX") );
  109.                 Attach[pid][i][E_OFFSETY]   = floatstr( _get(_file, "E_OFFSETY") );
  110.                 Attach[pid][i][E_OFFSETZ]   = floatstr( _get(_file, "E_OFFSETZ") );
  111.  
  112.                 Attach[pid][i][E_SCALEX]    = floatstr( _get(_file, "E_SCALEX") );
  113.                 Attach[pid][i][E_SCALEY]    = floatstr( _get(_file, "E_SCALEY") );
  114.                 Attach[pid][i][E_SCALEZ]    = floatstr( _get(_file, "E_SCALEZ") );
  115.  
  116.                 Attach[pid][i][E_ROTX]  = floatstr( _get(_file, "E_ROTX") );
  117.                 Attach[pid][i][E_ROTY]  = floatstr( _get(_file, "E_ROTY") );
  118.                 Attach[pid][i][E_ROTZ]      = floatstr( _get(_file, "E_ROTZ") );
  119.  
  120.                 Attach[pid][i][E_MODEL]     = strval( _get(_file, "E_MODEL") );
  121.                 Attach[pid][i][E_COLOR1]    = strval( _get(_file, "E_COLOR1") );
  122.                 Attach[pid][i][E_COLOR2]    = strval( _get(_file, "E_COLOR2") );
  123.                 Attach[pid][i][E_BONE]      = strval( _get(_file, "E_BONE") );
  124.  
  125.  
  126.                 SetPlayerAttachedObject(pid, i, Attach[pid][i][E_MODEL], Attach[pid][i][E_BONE],
  127.                 Attach[pid][i][E_OFFSETX], Attach[pid][i][E_OFFSETY], Attach[pid][i][E_OFFSETZ], Attach[pid][i][E_ROTX],
  128.                 Attach[pid][i][E_ROTY], Attach[pid][i][E_ROTZ],
  129.                 Attach[pid][i][E_SCALEX], Attach[pid][i][E_SCALEY], Attach[pid][i][E_SCALEZ], Attach[pid][i][E_COLOR1], Attach[pid][i][E_COLOR2]);
  130.             }
  131.    
  132.     }
  133.    
  134. }
  135.  
  136. stock _get(filename[], line[]){
  137.     static
  138.         _buffer[128],
  139.         File: _file,
  140.         _size
  141.     ;
  142.  
  143.     _file = fopen(filename, io_read);
  144.  
  145.     while(fread(_file, _buffer)){
  146.         if(!strfind(_buffer, line)){
  147.  
  148.             _size = strfind(_buffer, "=");
  149.  
  150.             strdel(_buffer, 0, _size + 1);
  151.  
  152.             _size = strlen(_buffer);
  153.  
  154.             strdel(_buffer, _size-2, _size);
  155.  
  156.             return _buffer;
  157.         }
  158.     }
  159.  
  160.  
  161.     return _buffer;
  162. }
  163.  
  164.  
  165.  
  166. stock _RemovePlayerAttachedObject(playerid, index){
  167.  
  168.     Attach[playerid][index][E_OFFSETX]  = 0.0;
  169.     Attach[playerid][index][E_OFFSETY]  = 0.0;
  170.     Attach[playerid][index][E_OFFSETZ]  = 0.0;
  171.  
  172.     Attach[playerid][index][E_SCALEX]   = 0.0;
  173.     Attach[playerid][index][E_SCALEY]   = 0.0;
  174.     Attach[playerid][index][E_SCALEZ]   = 0.0;
  175.  
  176.     Attach[playerid][index][E_ROTX]     = 0.0;
  177.     Attach[playerid][index][E_ROTY]     = 0.0;
  178.     Attach[playerid][index][E_ROTZ]     = 0.0;
  179.  
  180.     Attach[playerid][index][E_MODEL]    = 0;
  181.     Attach[playerid][index][E_COLOR1]   = 0;
  182.     Attach[playerid][index][E_COLOR2]   = 0;
  183.     Attach[playerid][index][E_BONE]     = 0;
  184.    
  185.     RemovePlayerAttachedObject(playerid, index);
  186. }
  187.  
  188.  
  189. stock GetAttachedObjectPos(playerid, index, Float:fOffsetX, Float:fOffsetY, Float:fOffsetZ, Float:fRotX, Float:fRotY, Float:fRotZ, Float:fScaleX, Float:fScaleY, Float:fScaleZ){
  190.  
  191.     fOffsetX = Attach[playerid][index][E_OFFSETX];
  192.     fOffsetY = Attach[playerid][index][E_OFFSETY];
  193.     fOffsetZ = Attach[playerid][index][E_OFFSETZ];
  194.  
  195.     fScaleX  = Attach[playerid][index][E_SCALEX];
  196.     fScaleY  = Attach[playerid][index][E_SCALEY];
  197.     fScaleZ  = Attach[playerid][index][E_SCALEZ];
  198.  
  199.     fRotX = Attach[playerid][index][E_ROTX];
  200.     fRotY = Attach[playerid][index][E_ROTY];
  201.     fRotZ = Attach[playerid][index][E_ROTZ];
  202.  
  203. }
  204.  
  205.    
  206. stock GetAttachedInfo(playerid, modelid, bone, color, color2){
  207.  
  208.     modelid = Attach[playerid][index][E_MODEL];
  209.     color   = Attach[playerid][index][E_COLOR1];
  210.     color2  = Attach[playerid][index][E_COLOR2];
  211.     bone    = Attach[playerid][index][E_BONE];
  212.    
  213. }
  214.  
  215. saveAttach(playerid){
  216.  
  217.  
  218. //      if(IsPlayerAttachedObjectSlotUsed(if(IsPlayerAttachedObjectSlotUsed(playerid, i))
  219.  
  220.  
  221.     new
  222.         _Nm[ 45 ],
  223.         _st[ 32 ]
  224.     ;
  225.  
  226.    
  227.     // "Acessorios/Nome.ini"
  228.     strcat(_Nm, "Acessorios/");
  229.     GetPlayerName(playerid, _Nm, 24);
  230.     strcat(_Nm, ".ini");
  231.    
  232.    
  233.  
  234.     for(
  235.         new i; i != 9; ++i
  236.     )
  237.     {
  238.         if(IsPlayerAttachedObjectSlotUsed(playerid, i)){ //
  239.  
  240.         }
  241.     }
  242. }
  243.  
  244.  
  245. #define SetPlayerAttachedObject _SetPlayerAttachedObject
  246. #define RemovePlayerAttachedObject _RemovePlayerAttachedObject
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement