Guest User

Untitled

a guest
Sep 12th, 2012
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 4.24 KB | None | 0 0
  1. #define FILTERSCRIPT
  2. #include <a_samp>
  3. #include <YSI\y_commands>
  4. #include <YSI\y_master>
  5. #include <sscanf2>
  6.  
  7. #define MAX_OBJ_PER_VEHICLE 20
  8.  
  9. new AttachingObjects[MAX_PLAYERS];
  10. new AttachedObjects[MAX_VEHICLES][MAX_OBJ_PER_VEHICLE];
  11. new strout[128];
  12.  
  13. public OnScriptInit()
  14. {
  15.     printf("Attach object to Vehicle by Siralos");
  16.     return 1;
  17. }
  18.  
  19. public OnScriptExit()
  20. {
  21.     //Clear all objects created
  22.     for(new i=0; i<MAX_VEHICLES; i++)
  23.     {
  24.         if(GetVehicleModel(i) > 0)
  25.         {
  26.             for(new j=0; j<MAX_OBJ_PER_VEHICLE; j++)
  27.             {
  28.                 if(IsValidObject(AttachedObjects[i][j]))
  29.                 {
  30.                     DestroyObject(AttachedObjects[i][j]);
  31.                 }
  32.             }
  33.         }
  34.     }
  35.     return 1;
  36. }
  37.  
  38. YCMD:mycarid(playerid, params[], help)
  39. {
  40.     #pragma unused help
  41.     #pragma unused params
  42.     new car = GetPlayerVehicleID(playerid);
  43.     if(car == 0) return SendClientMessage(playerid, 0xfce80cFF, "You are not in a car");
  44.     format(strout, sizeof(strout), "Car ID: %d", car);
  45.     return SendClientMessage(playerid, 0xfce80cFF, strout);
  46. }
  47.  
  48. YCMD:deleteobject(playerid, params[], help)
  49. {
  50.     #pragma unused help
  51.     new arrayid, car;
  52.     if(sscanf(params, "ii", arrayid, car))
  53.     {
  54.         SendClientMessage(playerid, 0xfce80cFF, "Use: /deleteobject [arrayid] [SAMP Car ID]");
  55.         return 1;
  56.     }
  57.     if(0 <= arrayid < 20)
  58.     {
  59.         if(0 < car < MAX_VEHICLES)
  60.         {
  61.             if(!IsValidObject(AttachedObjects[car][arrayid]))
  62.             {
  63.                 SendClientMessage(playerid, 0xfce80cFF, "No object found at position");
  64.                 return 1;
  65.             }
  66.             DestroyObject(AttachedObjects[car][arrayid]);
  67.             SendClientMessage(playerid, 0xfce80cFF, "Object removed");
  68.             return 1;
  69.         }
  70.         else
  71.         {
  72.             SendClientMessage(playerid, 0xfce80cFF, "Invalid vehicle");
  73.         }
  74.     }
  75.     else
  76.     {
  77.         SendClientMessage(playerid, 0xfce80cFF, "No object found at position");
  78.     }
  79.     return 1;
  80. }
  81.  
  82. YCMD:attachobject(playerid, params[], help)
  83. {
  84.     #pragma unused help
  85.     new objectmodel, car;
  86.     if(sscanf(params, "ii", objectmodel, car))
  87.     {
  88.         SendClientMessage(playerid, 0xfce80cFF, "Use: /attachobject [object model] [SAMP Car ID]");
  89.         return 1;
  90.     }
  91.     if(0 < car < MAX_VEHICLES)
  92.     {
  93.         new Float:px, Float:py, Float:pz;
  94.         GetPlayerPos(playerid, px, py, pz);
  95.         AttachingObjects[playerid] = CreateObject(objectmodel, px, py, pz, 0.0, 0.0, 0.0);
  96.         SendClientMessage(playerid, 0xfce80cFF, "Object created. Editing...");
  97.         EditObject(playerid, AttachingObjects[playerid]);
  98.         SetPVarInt(playerid, "AttachingTo", car);
  99.     }
  100.     else
  101.     {
  102.         SendClientMessage(playerid, 0xfce80cFF, "Invalid vehicle");
  103.     }
  104.     return 1;
  105. }
  106.  
  107. public OnPlayerEditObject(playerid, playerobject, objectid, response, Float:fX, Float:fY, Float:fZ, Float:fRotX, Float:fRotY, Float:fRotZ)
  108. {
  109.     if(!IsValidObject(objectid)) return 0;
  110.     MoveObject(objectid, fX, fY, fZ, 10.0, fRotX, fRotY, fRotZ);
  111.    
  112.     new car = GetPVarInt(playerid, "AttachingTo");
  113.     if(car != 0)
  114.     {  
  115.         if(response == EDIT_RESPONSE_FINAL)
  116.         {
  117.             SendClientMessage(playerid, 0xfce80cFF, "Finished Edition.");
  118.             new carslot = FindFreeObjectSlotInCar(car);
  119.             if(carslot == -1)
  120.             {
  121.                 SendClientMessage(playerid, 0xfce80cFF, "No more objects can be added to the car.");
  122.                 DestroyObject(AttachingObjects[playerid]);
  123.                 DeletePVar(playerid, "AttachingTo");
  124.                 return 1;
  125.             }
  126.             new Float:ofx, Float:ofy, Float:ofz, Float:ofaz;
  127.             new Float:finalx, Float:finaly;
  128.             new Float:px, Float:py, Float:pz, Float:roz;
  129.             GetVehiclePos(car, px, py, pz);
  130.             GetVehicleZAngle(car, roz);
  131.             ofx = fX-px;
  132.             ofy = fY-py;
  133.             ofz = fZ-pz;
  134.             ofaz = fRotZ-roz;
  135.             finalx = ofx*floatcos(roz, degrees)+ofy*floatsin(roz, degrees);
  136.             finaly = -ofx*floatsin(roz, degrees)+ofy*floatcos(roz, degrees);
  137.             AttachObjectToVehicle(AttachingObjects[playerid], car, finalx, finaly, ofz, fRotX, fRotY, ofaz);
  138.             AttachedObjects[car][carslot] = AttachingObjects[playerid];
  139.             format(strout, sizeof(strout), "Created in array slot %d of car %d", carslot, car);
  140.             SendClientMessage(playerid, 0xfce80cFF, strout);
  141.             DeletePVar(playerid, "AttachingTo");
  142.             return 1;
  143.         }
  144.         if(response == EDIT_RESPONSE_CANCEL)
  145.         {
  146.             DestroyObject(AttachingObjects[playerid]);
  147.             DeletePVar(playerid, "AttachingTo");
  148.             return 1;
  149.         }
  150.     }
  151.     return 0;
  152. }
  153.  
  154. stock FindFreeObjectSlotInCar(vehid)
  155. {
  156.     for(new i=0; i<MAX_OBJ_PER_VEHICLE; i++)
  157.     {
  158.         if(!IsValidObject(AttachedObjects[vehid][i])) return i;
  159.     }
  160.     return -1;
  161. }
Advertisement
Add Comment
Please, Sign In to add comment