Advertisement
Guest User

GTA IV:V v0.02

a guest
Jul 29th, 2013
1,066
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 13.05 KB | None | 0 0
  1. #include "CustomFiberThread.h"
  2. #include "Scripting.h"
  3. #include "../ScriptHook/Log.h"
  4. #include <windows.h>
  5. #include <math.h>
  6. #include <fstream>
  7. #include <algorithm>
  8.  
  9. using namespace Scripting;
  10.  
  11. Ped ped,cPed,xped;
  12. Vehicle veh,cCar;
  13. f32 forceX,forceY,forceZ,x3,y3,z3,X1,Y1,Z1,X2,Y2,Z2,X,Y,Z,x,y,z,maxdist=100,diff,dist,hed,dFWD,dSIDE,rx,ry,rz,xx,yy,zz;
  14. int netid = 0;
  15. bool pt1 = true, pt2 = true, pt3 = true, pt4 = true, pt5 = true, pt6 = true, pt7 = true, pt8 = true, pt9 = true, pt10 = true;
  16. bool startup=true,type1=false,type2=false,detection=false,found = false,xpress=false,change=true;
  17. Object portal1,portal2;
  18. Camera cam,pcam,gcam;
  19. f32 PIX = 3.14159265358979f/180.0f;
  20. f32 rad = 180.0f/3.14159265358979f;
  21. Vector3 CamVec,CamPos,cr;  
  22. Object portal=portal1, side, front;
  23. eModel object=MODEL_CJ_GAME_CUBE_C1;
  24. const char *type="red";
  25. int aStuck=0;
  26. eModel model[]= {MODEL_CJ_GAME_CUBE_1,MODEL_CJ_GAME_CUBE_2,MODEL_CJ_GAME_CUBE_3,MODEL_CJ_GAME_CUBE_4,
  27.                  MODEL_CJ_GAME_CUBE_5,MODEL_CJ_GAME_CUBE_6, MODEL_CJ_GARAGE_DOOR_BIG,MODEL_CJ_PROC_PLUM};
  28. eModel pm1=model[0],pm2=model[1]; //portal models
  29. u32 p[5]={0,0,0,0,0};
  30. Object po[2];
  31. int full = 90000;
  32. f32 cx,cy,cz,cxx,cyy,czz;
  33. bool campan=false,waitcoll=false, firstdist=true;
  34. int u=0,c=0,a=0;
  35. f32 portalSize=0;
  36. f32 time =0, fdist=0,stime=0;
  37. int h=0, r=0, ps=20, tick=0;
  38. int ptfx[2]={0,0};
  39. bool ptset=false;
  40. bool gcheck=true;
  41. bool doPTFX=1, ptfxbool=0; //disable ptfx
  42. f32 intprint=0;
  43.  
  44. ch *sound="", *sound2="FRONTEND_MENU_MONTAGE_MARKER_MT", *sound1="FRONTEND_MENU_MONTAGE_DELETE_MT";
  45. int myptfx = 0;
  46. f32 lag = 0;
  47. #define BUFSIZE 500
  48. int FireKey = 69;
  49. int redKey = 16;
  50. int blueKey = 18;
  51. int p1int = 0;
  52. int p2int = 1;
  53. b8 unstable = 0;
  54. b8 ownSound = 0;
  55. b8 mode = 1;
  56. b8 camzoom=0;
  57. b8 doLog=0;
  58.  
  59. int gun = -1;
  60.  
  61. ////////////////////////
  62. bool keys[255]={};
  63. int swap = 0;
  64. std::string myTxt = "";
  65. f32 fov=0;
  66. f32 sx=0,sy=0,sz=0;
  67. u32 R=0,G=0,B=0,A=0;
  68. f32 fcx=0,fcy=0,fcz=0;
  69. f32 bs=0.111f,hs=0.02f,as=0.0916f,ss=0.137f,off=0.0f;
  70. f32 xpos[]={0.1064f,0.021f,0.107f,0.1503f};
  71. f32 ypos[]={0.851f,0.945f,0.843f, 0.1796f};
  72. f32 max=1200.0f,amax=2460.0f,smax=amax;
  73. int usePower=0;
  74. f32 power=100;
  75. f32 whitefade=0;
  76. int TXD,U,radar[4],i=0;
  77. int xselect=false;
  78. b8 doChange=false;
  79. b8 displayHUD=true;
  80. f32 wx=0.91f,xoff=0.015f,wy=0.03f,pw=0.017f,ph=0.024f;
  81.  
  82. //Startup routine
  83. CustomFiberThread::CustomFiberThread(){
  84.     SetName("GTA V4IV");
  85.    
  86. }
  87.  
  88. Player CustomFiberThread::GetPlayer(){
  89.     Player playerIndex = ConvertIntToPlayerIndex(GetPlayerId());
  90.     return playerIndex;
  91. }
  92.  
  93. Scripting::Ped CustomFiberThread::GetPlayerPed(){
  94.     Ped ped;
  95.     GetPlayerChar(GetPlayer(), &ped);
  96.     return ped;
  97. }
  98.  
  99. f32 ownDist3D(f32 dx, f32 dy, f32 dz, f32 dxx, f32 dyy, f32 dzz){
  100.     return sqrtf(pow(dx-dxx,2)+pow(dy-dyy,2)+pow(dz-dzz,2));
  101. }
  102.  
  103. f32 ownDist2D(f32 dx, f32 dy, f32 dxx, f32 dyy){
  104.     return sqrtf(pow(dx-dxx,2)+pow(dy-dyy,2));
  105. }
  106.  
  107. //own key press check func. will only trigger once on keypress. non-intrusive.
  108. b8 press(int key){
  109.     if(GetKeyState(key)<0){ if(!keys[key]){keys[key]=true; return true;} }
  110.     else if(keys[key]) keys[key]=false;
  111.     return false;
  112. }
  113.  
  114. int OwnRequestControlOfNetworkId(u32 netid)
  115. {
  116.     if (NetworkGetGameMode() == -1) {
  117.         return 2;
  118.     }
  119.     int attemptcounter = 0;
  120.     SetNetworkIdCanMigrate(netid, true);                   
  121.     while (!HasControlOfNetworkId(netid) && ((attemptcounter++) < 30)) {
  122.         RequestControlOfNetworkId(netid);                      
  123.         Wait(10);
  124.     }  
  125.     return RequestControlOfNetworkId(netid);
  126. }
  127.  
  128. void CustomFiberThread::GetCameraVector(Camera cam, Vector3 &CameraVector, f32 zRot) {
  129.     Vector3 CamRot;
  130.     f32 Sxy, Sz;
  131.     if (DoesCamExist (cam)) {
  132.         GetCamRot (cam, &CamRot.X, &CamRot.Y, &CamRot.Z);
  133.         Sz = CamRot.X*PIX;
  134.         Sxy = (CamRot.Z + 90.0f + zRot)*PIX;
  135.         CameraVector.X = cos (Sxy) * cos (Sz);
  136.         CameraVector.Y = sin (Sxy) * cos (Sz);
  137.         CameraVector.Z = sin (Sz);
  138.     }
  139. }
  140.  
  141. void logg(const char *te){
  142.     if(doLog){
  143.         LogInfo(te);
  144.     }
  145. }
  146.  
  147. //print one float, debug
  148. void PRINTF( f32 num )
  149. {
  150.     char buffer5[ 1024 ];
  151.     sprintf_s( buffer5, "%.5f", num );
  152.     PrintStringWithLiteralStringNow( "STRING", buffer5, 5000, 1 );
  153. }
  154.  
  155. //print many floats together, debug
  156. void fprint(const char* name , f32 num)
  157. {
  158.     char txt[ 1024 ];
  159.     sprintf_s(txt, "%.3f", num );
  160.     myTxt+=name;
  161.     myTxt+=": ";
  162.     myTxt+=txt;
  163.     myTxt+=" ";
  164.     PrintStringWithLiteralStringNow( "STRING", myTxt.c_str(), 6000, 1 );
  165. }
  166.  
  167. //print string quickly
  168. void print(const char* st )
  169. {
  170.     PrintStringWithLiteralStringNow( "STRING", st, 1000, 1 );
  171. }
  172.  
  173. //Creates a temp obj to check coordinates, used for angle and wall debug.   Not used in release.
  174. void debugObj(Object obj, int mod, f32 x, f32 y, f32 z) {
  175.     if(!DoesObjectExist(obj)) CreateObject(model[mod], x,y,z, &obj,true);
  176.     SetObjectCoordinates(obj,x,y,z);
  177.     FreezeObjectPosition(obj,1);
  178.     SetObjectCollision(obj,0);
  179.     //MarkObjectAsNoLongerNeeded(&obj);
  180. }
  181.  
  182.  
  183. void CustomFiberThread::RunScript(){
  184.     while(IsThreadAlive()){
  185.  
  186.         Player playerIndex = ConvertIntToPlayerIndex(GetPlayerId());
  187.         GetPlayerChar(playerIndex, &ped);
  188.         myTxt="";
  189.  
  190.  
  191.         /////////////HUD
  192.  
  193.         if(startup){
  194.             startup=false;
  195.             TXD = GetTxd("blips");
  196.             U = LoadTxd("blips");
  197.             radar[0] = GetTexture(U, "RADAR_LEVEL"); //Aim circle
  198.             radar[1] = GetTexture(U, "RADAR_POLICE_HELI"); //dead X
  199.  
  200.             TXD = GetTxd("buttons_360");
  201.             U = LoadTxd("buttons_360");
  202.             radar[2] = GetTexture(U, "UP_ARROW"); //map player arrow
  203.  
  204.             TXD = GetTxd("HUD");
  205.             U = LoadTxd("HUD");
  206.             radar[3] = GetTexture(U, "FAVORITE_STAR"); //wanted star
  207.  
  208.         }
  209.  
  210.  
  211.         if(press(VK_F4)){ //ENABLE/DISABLE HUD
  212.             displayHUD^=true;
  213.         }
  214.  
  215.         if(displayHUD){
  216.  
  217.                 if(power<100)power+=0.1f; //add power to special abilities
  218.  
  219.                 u32 health, armour;
  220.                 GetCharHealth(ped, &health);
  221.                 GetCharArmour(ped, &armour);
  222.  
  223.                 health-=100; if(health<=200 && health>=0){}else health=0;
  224.  
  225.                 DrawRect(xpos[0], ypos[0], 0.18f, 0.21f, 0, 0, 0, 150); //BG
  226.                 DrawRect(xpos[0], ypos[2], 0.17f, ypos[3], 200, 200, 200, 150); //MAP BG
  227.  
  228.                 DrawRect(xpos[1]+100/(max*2), ypos[1], 100/max, 0.01f, 95, 140, 105, 70); //health bg
  229.                 DrawRect(xpos[2]+100/(amax*2), ypos[1], 100/amax, 0.01f, 62, 160, 206,70); //armour bg
  230.                 DrawRect(xpos[3]+100/(smax*2), ypos[1], 100/smax, 0.01f, 229, 211, 78, 70); //power bg
  231.                
  232.                 DrawRect(xpos[1]+health/(max*2), ypos[1], health/max, 0.01f, 95, 140, 105, 220); //health
  233.                 DrawRect(xpos[2]+armour/(amax*2), ypos[1], armour/amax, 0.01f, 62, 160, 206, 220); //armour
  234.                 DrawRect(xpos[3]+power/(smax*2), ypos[1], power/smax, 0.01f, 229, 211, 78, 220); //power
  235.  
  236.                 HideHUDAndRadarThisFrame();
  237.  
  238.                 GetGameCam(&cam);
  239.                 GetCamRot(cam,&rx,&ry,&rz);
  240.  
  241.                 DrawSprite(radar[2], xpos[0], ypos[0], 0.03f, 0.03f, -rz,-1, -1, -1, 230); //map arrow, pointing cam direction
  242.  
  243.                 //wanted stars
  244.                 if(IsWantedLevelGreater(playerIndex, 0)){DrawSprite(radar[3], wx+xoff*1, wy, pw,ph, 0.0f,-1, -1, -1, 200);
  245.                 if(IsWantedLevelGreater(playerIndex, 1)){DrawSprite(radar[3], wx+xoff*2, wy, pw,ph, 0.0f,-1, -1, -1, 200);
  246.                 if(IsWantedLevelGreater(playerIndex, 2)){DrawSprite(radar[3], wx+xoff*3, wy, pw,ph, 0.0f,-1, -1, -1, 200);
  247.                 if(IsWantedLevelGreater(playerIndex, 3)){DrawSprite(radar[3], wx+xoff*4, wy, pw,ph, 0.0f,-1, -1, -1, 200);
  248.                 if(IsWantedLevelGreater(playerIndex, 4)){DrawSprite(radar[3], wx+xoff*5, wy, pw,ph, 0.0f,-1, -1, -1, 200);
  249.                 }}}}}
  250.  
  251.  
  252.         //////////////////POWERS
  253.  
  254.         if(usePower>0 && power>0){
  255.                 power-=0.7f;
  256.                 SetTimeScale(0.5f-power/300);
  257.                 SetTimecycleModifier("cabaret");
  258.         }else if(usePower>0){
  259.             usePower=0;
  260.             SetTimeScale(1);
  261.             ClearTimeCycleModifier();
  262.         }
  263.  
  264.         if(press(VK_TAB)){ //Use power
  265.             if(usePower==0){
  266.                 usePower=1;
  267.             }else{
  268.                 usePower=0;
  269.                 SetTimeScale(1);
  270.                 ClearTimeCycleModifier();
  271.             }
  272.         }
  273.  
  274.  
  275.         /////////////RETICULE
  276.  
  277.                 if (GetKeyState(VK_RBUTTON)<0){
  278.                     f32 d=4,acc=0.2f,yoff=0;
  279.                     GetGameCam(&cam);
  280.                     GetCameraVector(cam, CamVec, 0);
  281.                     GetCamPos(cam, &x, &y, &z);
  282.                     int aim=0;
  283.                     while(d < maxdist){ //check area in front of vision/aim for peds
  284.                         X=x+d*CamVec.X;
  285.                         Y=y+d*CamVec.Y;
  286.                         Z=z+d*CamVec.Z;
  287.                         d+=acc*2;
  288.                         if(IsAreaOccupied(X-acc,Y-acc,Z-acc,X+acc,Y+acc,Z+acc,0,0,1,0,0)){
  289.                             GetClosestChar(X,Y,Z,1,1,1,&xped);
  290.                             if(1){//DoesCharExist(xped)){ //always returns false, can be because GetClosestChar is slow, do external check after one tick.
  291.                                 if(IsPlayerFreeAimingAtChar(playerIndex,xped)){
  292.  
  293.                                     //if(IsCharDead(xped)){aim=1; print("doead");}
  294.                                     //else{ aim=1;}
  295.                                     if(usePower>0)SetTimeScale(0.1f); //make extra slo-mo if aiming at player and power is on
  296.                                     aim=1;
  297.                                     break;
  298.                                 }
  299.                             }
  300.                         }
  301.                     }
  302.  
  303.                     if(IsCharInAnyCar(ped))yoff=-0.041f; //offset reticule if in car.
  304.                     if(aim==0)     DrawSprite(radar[0], 0.5f, 0.5f+yoff, 0.00304f, 0.0047f, 0.0f,-1, -1, -1, 230); //white
  305.                     else if(aim==1)DrawSprite(radar[0], 0.5f, 0.5f+yoff, 0.00304f, 0.0047f, 0.0f,50, 50, 50, 230); //gray
  306.                     //else if(aim==2)DrawSprite(radar[1], 0.5f, 0.5f, 0.003f, 0.003f, 50.0f,50, 50, 50, 230); //dead
  307.                 }
  308.  
  309.         }
  310.  
  311.  
  312.         /////////////////CHAR SWITCH
  313.    
  314.         //The swap HUD, no proper textures yet, so disabled
  315.     /*  if (GetKeyState(VK_RCONTROL)<0){
  316.             SetTimecycleModifier("binocular");
  317.             SetTimeScale(0.1f);
  318.             DrawRect(0,0,2,2,0,175,100,50);
  319.             if(press(VK_LEFT))xselect=1;
  320.             if(press(VK_RIGHT))xselect=2;
  321.             if(press(VK_DOWN))xselect=0;
  322.             p[0]=150;p[1]=150;p[2]=150;
  323.             p[xselect]=230;
  324.             DrawSprite(radar[7], 0.9f, 0.9f, 0.1f, 0.1f, 0.0f,-1, -1, -1, 230);
  325.             DrawSprite(radar[6], 0.9f, 0.9f, 0.1f, 0.1f, 0.0f,-1, -1, -1, p[2]);
  326.             DrawSprite(radar[5], 0.89f, 0.91f, 0.1f, 0.1f, 0.0f,-1, -1, -1, p[1]);
  327.             DrawSprite(radar[4], 0.91f, 0.91f, 0.1f, 0.1f, 0.0f,-1, -1, -1, p[0]);
  328.         }
  329.         else if(xselect==0){
  330.             SetTimeScale(1);
  331.             ClearTimeCycleModifier();
  332.             xselect=-1;
  333.         }
  334.         else if(xselect>0){
  335.             doChange=true;
  336.             xselect=0;
  337.         }*/
  338.  
  339.  
  340.         if(GetKeyState(VK_F3)<0 && swap==0){
  341.             doChange=false;
  342.             GenerateRandomFloatInRange(-1000,1000, &x);
  343.             GenerateRandomFloatInRange(-1000,1000, &y);
  344.             GetGroundZFor3DCoord(x,y,1000,&z);
  345.             Wait(0);
  346.             //GetSafePositionForChar(x,y,z, 0, &sx, &sy, &sz); //Gives non-existing coordinates, bugs game. fix!
  347.             sx=x;sy=y;sz=z;
  348.             GetDistanceBetweenCoords2D(sx,sy,cx,cy,&dist);
  349.  
  350.  
  351.             //camera init
  352.             GetGameCam(&gcam);
  353.             GetCamPos(gcam, &cx, &cy, &cz);
  354.             GetCamRot(gcam, &cxx, &cyy,&czz);
  355.             GetCamFov(gcam, &fov);
  356.             CreateCam(14, &pcam);
  357.             SetCamPos(pcam, cx, cy, cz);
  358.             SetCamRot(pcam, cxx, cyy, czz);
  359.             SetCamPropagate(pcam, 1);
  360.             ActivateScriptedCams(1, 1);
  361.             SetTimecycleModifier("binocular");
  362.             SetTimeScale(0.1f);
  363.  
  364.            
  365.             R=0;
  366.             G=175;
  367.             B=100;
  368.             A=50;
  369.             h=5;
  370.             swap=1;
  371.             SetTimerA(0);
  372.             whitefade=50;
  373.             SetTimerB(0);
  374.         }
  375.  
  376.         if(swap>0){
  377.             DrawRect(0,0,2,2,R,G,B,A);
  378.         }
  379.  
  380.         if(swap==1){ //the circular motion to top of player
  381.             GetCharCoordinates(ped,&fcx,&fcy,&fcz);
  382.             fcz+=h;
  383.             cx+=(fcx-cx)/20;
  384.             cy+=(fcy-cy)/20;
  385.             cz+=(fcz-cz)/20;
  386.             SetCamPos(pcam,cx,cy,cz);
  387.         //  PointCamAtCoord
  388.             PointCamAtPed(pcam, ped); //replace with SetCamRot + math, or find a way to disable the pointing
  389.            
  390.             if(TimerA()>150){
  391.                 h=10;
  392.                 cz+=100;
  393.                 fcz+=130;
  394.                 SetTimerA(0);
  395.                 swap++;
  396.                 R+=20;
  397.                 G-=0;
  398.                 B+=30;
  399.                 whitefade=50;
  400.                 SetTimerB(0);
  401.                 //SetCharVisible(ped,0);
  402.                 SetCamPos(pcam,cx,cy,cz);
  403.                 SetCamRot(pcam,0,0,-90);
  404.                 SetTimerA(0);
  405.                 PointCamAtCoord(pcam,cx,cy,0);
  406.                
  407.             }
  408.         }
  409.  
  410.         if(swap==2 || swap==3 || swap==4){ //the jumps up
  411.             //SetCharCoordinates(ped,cx,cy,cz);
  412.             cx+=(fcx-cx)/30;
  413.             cy+=(fcy-cy)/30;
  414.             cz+=(fcz-cz)/30;
  415.             SetCamPos(pcam,cx,cy,cz);
  416.             if(TimerA()>150){
  417.                 cz+=100;
  418.                 fcz+=140;
  419.                 whitefade=50;
  420.                 SetTimerB(0);
  421.                 SetCamPos(pcam,cx,cy,cz);
  422.                 SetTimerA(0);
  423.                 swap++;
  424.                 //R+=20;
  425.                 //G-=0;
  426.                 //B+=30;
  427.             }
  428.         }
  429.  
  430.         if(swap==5){ //the pan to new location
  431.             cx+=(sx-cx)/50;
  432.             cy+=(sy-cy)/50; //change the divide bit, so cam velocity is constant, not slowing so much down at end
  433.             //SetCharCoordinates(ped, cx,cy,fcz);
  434.             PointCamAtCoord(pcam,cx,cy,0);
  435.             SetCamPos(pcam,cx,cy,cz);
  436.             if(ownDist2D(cx,cy,sx,sy)<20){
  437.                 swap++;
  438.                 whitefade=50;
  439.                 SetTimerB(0);
  440.                 SetCamPos(pcam,cx,cy,cz);
  441.                 SetTimerA(0);
  442.                 SetCharCoordinates(ped,sx,sy,sz);
  443.                 fcz-=130;
  444.             }
  445.         }
  446.  
  447.         if(swap>5 && swap<8){ //down jumps
  448.             cx+=(sx-cx)/30;
  449.             cy+=(sy-cy)/30;
  450.             cz+=(sz+fcz-cz)/30;
  451.             SetCamPos(pcam,cx,cy,cz);
  452.             if(TimerA()>150){
  453.                 cz-=130;
  454.                 fcz-=150;
  455.                 whitefade=50;
  456.                 SetTimerB(0);
  457.                 SetCamPos(pcam,cx,cy,cz);
  458.                 SetTimerA(0);
  459.                 swap++;
  460.                 GetGameCam(&gcam);
  461.                 GetCamPos(gcam, &X1, &Y1, &Z1);
  462.                 GetCamRot(gcam, &x3, &y3,&z3);
  463.             }
  464.         }
  465.  
  466.         if(swap==8){ //to game cam pos
  467.             cx+=(X1-cx)/30;
  468.             cy+=(Y1-cy)/30;
  469.             cz+=(Z1-cz)/30;
  470.             SetCamPos(pcam,cx,cy,cz);
  471.             PointCamAtPed(pcam,ped);
  472.             if(TimerA()>150){
  473.                 swap++;
  474.             }
  475.         }
  476.  
  477.         if(swap>8){ //done
  478.             ActivateScriptedCams(0, 0);
  479.             ClearTimeCycleModifier();
  480.             SetTimeScale(1);
  481.             swap=0;
  482.         }
  483.  
  484.         if(whitefade>0){
  485.             if(TimerB()<whitefade){
  486.                 DrawRect(0,0,2,2,255,255,255,u32((-255/whitefade)*TimerB()+255));
  487.             }else whitefade=0;
  488.         }
  489.  
  490.         Wait(0);
  491.     }
  492. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement