Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "CustomFiberThread.h"
- #include "Scripting.h"
- #include "../ScriptHook/Log.h"
- #include <windows.h>
- #include <math.h>
- #include <fstream>
- #include <algorithm>
- using namespace Scripting;
- Ped ped,cPed,xped;
- Vehicle veh,cCar;
- 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;
- int netid = 0;
- bool pt1 = true, pt2 = true, pt3 = true, pt4 = true, pt5 = true, pt6 = true, pt7 = true, pt8 = true, pt9 = true, pt10 = true;
- bool startup=true,type1=false,type2=false,detection=false,found = false,xpress=false,change=true;
- Object portal1,portal2;
- Camera cam,pcam,gcam;
- f32 PIX = 3.14159265358979f/180.0f;
- f32 rad = 180.0f/3.14159265358979f;
- Vector3 CamVec,CamPos,cr;
- Object portal=portal1, side, front;
- eModel object=MODEL_CJ_GAME_CUBE_C1;
- const char *type="red";
- int aStuck=0;
- eModel model[]= {MODEL_CJ_GAME_CUBE_1,MODEL_CJ_GAME_CUBE_2,MODEL_CJ_GAME_CUBE_3,MODEL_CJ_GAME_CUBE_4,
- MODEL_CJ_GAME_CUBE_5,MODEL_CJ_GAME_CUBE_6, MODEL_CJ_GARAGE_DOOR_BIG,MODEL_CJ_PROC_PLUM};
- eModel pm1=model[0],pm2=model[1]; //portal models
- u32 p[5]={0,0,0,0,0};
- Object po[2];
- int full = 90000;
- f32 cx,cy,cz,cxx,cyy,czz;
- bool campan=false,waitcoll=false, firstdist=true;
- int u=0,c=0,a=0;
- f32 portalSize=0;
- f32 time =0, fdist=0,stime=0;
- int h=0, r=0, ps=20, tick=0;
- int ptfx[2]={0,0};
- bool ptset=false;
- bool gcheck=true;
- bool doPTFX=1, ptfxbool=0; //disable ptfx
- f32 intprint=0;
- ch *sound="", *sound2="FRONTEND_MENU_MONTAGE_MARKER_MT", *sound1="FRONTEND_MENU_MONTAGE_DELETE_MT";
- int myptfx = 0;
- f32 lag = 0;
- #define BUFSIZE 500
- int FireKey = 69;
- int redKey = 16;
- int blueKey = 18;
- int p1int = 0;
- int p2int = 1;
- b8 unstable = 0;
- b8 ownSound = 0;
- b8 mode = 1;
- b8 camzoom=0;
- b8 doLog=0;
- int gun = -1;
- ////////////////////////
- bool keys[255]={};
- int swap = 0;
- std::string myTxt = "";
- f32 fov=0;
- f32 sx=0,sy=0,sz=0;
- u32 R=0,G=0,B=0,A=0;
- f32 fcx=0,fcy=0,fcz=0;
- f32 bs=0.111f,hs=0.02f,as=0.0916f,ss=0.137f,off=0.0f;
- f32 xpos[]={0.1064f,0.021f,0.107f,0.1503f};
- f32 ypos[]={0.851f,0.945f,0.843f, 0.1796f};
- f32 max=1200.0f,amax=2460.0f,smax=amax;
- int usePower=0;
- f32 power=100;
- f32 whitefade=0;
- int TXD,U,radar[4],i=0;
- int xselect=false;
- b8 doChange=false;
- b8 displayHUD=true;
- f32 wx=0.91f,xoff=0.015f,wy=0.03f,pw=0.017f,ph=0.024f;
- //Startup routine
- CustomFiberThread::CustomFiberThread(){
- SetName("GTA V4IV");
- }
- Player CustomFiberThread::GetPlayer(){
- Player playerIndex = ConvertIntToPlayerIndex(GetPlayerId());
- return playerIndex;
- }
- Scripting::Ped CustomFiberThread::GetPlayerPed(){
- Ped ped;
- GetPlayerChar(GetPlayer(), &ped);
- return ped;
- }
- f32 ownDist3D(f32 dx, f32 dy, f32 dz, f32 dxx, f32 dyy, f32 dzz){
- return sqrtf(pow(dx-dxx,2)+pow(dy-dyy,2)+pow(dz-dzz,2));
- }
- f32 ownDist2D(f32 dx, f32 dy, f32 dxx, f32 dyy){
- return sqrtf(pow(dx-dxx,2)+pow(dy-dyy,2));
- }
- //own key press check func. will only trigger once on keypress. non-intrusive.
- b8 press(int key){
- if(GetKeyState(key)<0){ if(!keys[key]){keys[key]=true; return true;} }
- else if(keys[key]) keys[key]=false;
- return false;
- }
- int OwnRequestControlOfNetworkId(u32 netid)
- {
- if (NetworkGetGameMode() == -1) {
- return 2;
- }
- int attemptcounter = 0;
- SetNetworkIdCanMigrate(netid, true);
- while (!HasControlOfNetworkId(netid) && ((attemptcounter++) < 30)) {
- RequestControlOfNetworkId(netid);
- Wait(10);
- }
- return RequestControlOfNetworkId(netid);
- }
- void CustomFiberThread::GetCameraVector(Camera cam, Vector3 &CameraVector, f32 zRot) {
- Vector3 CamRot;
- f32 Sxy, Sz;
- if (DoesCamExist (cam)) {
- GetCamRot (cam, &CamRot.X, &CamRot.Y, &CamRot.Z);
- Sz = CamRot.X*PIX;
- Sxy = (CamRot.Z + 90.0f + zRot)*PIX;
- CameraVector.X = cos (Sxy) * cos (Sz);
- CameraVector.Y = sin (Sxy) * cos (Sz);
- CameraVector.Z = sin (Sz);
- }
- }
- void logg(const char *te){
- if(doLog){
- LogInfo(te);
- }
- }
- //print one float, debug
- void PRINTF( f32 num )
- {
- char buffer5[ 1024 ];
- sprintf_s( buffer5, "%.5f", num );
- PrintStringWithLiteralStringNow( "STRING", buffer5, 5000, 1 );
- }
- //print many floats together, debug
- void fprint(const char* name , f32 num)
- {
- char txt[ 1024 ];
- sprintf_s(txt, "%.3f", num );
- myTxt+=name;
- myTxt+=": ";
- myTxt+=txt;
- myTxt+=" ";
- PrintStringWithLiteralStringNow( "STRING", myTxt.c_str(), 6000, 1 );
- }
- //print string quickly
- void print(const char* st )
- {
- PrintStringWithLiteralStringNow( "STRING", st, 1000, 1 );
- }
- //Creates a temp obj to check coordinates, used for angle and wall debug. Not used in release.
- void debugObj(Object obj, int mod, f32 x, f32 y, f32 z) {
- if(!DoesObjectExist(obj)) CreateObject(model[mod], x,y,z, &obj,true);
- SetObjectCoordinates(obj,x,y,z);
- FreezeObjectPosition(obj,1);
- SetObjectCollision(obj,0);
- //MarkObjectAsNoLongerNeeded(&obj);
- }
- void CustomFiberThread::RunScript(){
- while(IsThreadAlive()){
- Player playerIndex = ConvertIntToPlayerIndex(GetPlayerId());
- GetPlayerChar(playerIndex, &ped);
- myTxt="";
- /////////////HUD
- if(startup){
- startup=false;
- TXD = GetTxd("blips");
- U = LoadTxd("blips");
- radar[0] = GetTexture(U, "RADAR_LEVEL"); //Aim circle
- radar[1] = GetTexture(U, "RADAR_POLICE_HELI"); //dead X
- TXD = GetTxd("buttons_360");
- U = LoadTxd("buttons_360");
- radar[2] = GetTexture(U, "UP_ARROW"); //map player arrow
- TXD = GetTxd("HUD");
- U = LoadTxd("HUD");
- radar[3] = GetTexture(U, "FAVORITE_STAR"); //wanted star
- }
- if(press(VK_F4)){ //ENABLE/DISABLE HUD
- displayHUD^=true;
- }
- if(displayHUD){
- if(power<100)power+=0.1f; //add power to special abilities
- u32 health, armour;
- GetCharHealth(ped, &health);
- GetCharArmour(ped, &armour);
- health-=100; if(health<=200 && health>=0){}else health=0;
- DrawRect(xpos[0], ypos[0], 0.18f, 0.21f, 0, 0, 0, 150); //BG
- DrawRect(xpos[0], ypos[2], 0.17f, ypos[3], 200, 200, 200, 150); //MAP BG
- DrawRect(xpos[1]+100/(max*2), ypos[1], 100/max, 0.01f, 95, 140, 105, 70); //health bg
- DrawRect(xpos[2]+100/(amax*2), ypos[1], 100/amax, 0.01f, 62, 160, 206,70); //armour bg
- DrawRect(xpos[3]+100/(smax*2), ypos[1], 100/smax, 0.01f, 229, 211, 78, 70); //power bg
- DrawRect(xpos[1]+health/(max*2), ypos[1], health/max, 0.01f, 95, 140, 105, 220); //health
- DrawRect(xpos[2]+armour/(amax*2), ypos[1], armour/amax, 0.01f, 62, 160, 206, 220); //armour
- DrawRect(xpos[3]+power/(smax*2), ypos[1], power/smax, 0.01f, 229, 211, 78, 220); //power
- HideHUDAndRadarThisFrame();
- GetGameCam(&cam);
- GetCamRot(cam,&rx,&ry,&rz);
- DrawSprite(radar[2], xpos[0], ypos[0], 0.03f, 0.03f, -rz,-1, -1, -1, 230); //map arrow, pointing cam direction
- //wanted stars
- if(IsWantedLevelGreater(playerIndex, 0)){DrawSprite(radar[3], wx+xoff*1, wy, pw,ph, 0.0f,-1, -1, -1, 200);
- if(IsWantedLevelGreater(playerIndex, 1)){DrawSprite(radar[3], wx+xoff*2, wy, pw,ph, 0.0f,-1, -1, -1, 200);
- if(IsWantedLevelGreater(playerIndex, 2)){DrawSprite(radar[3], wx+xoff*3, wy, pw,ph, 0.0f,-1, -1, -1, 200);
- if(IsWantedLevelGreater(playerIndex, 3)){DrawSprite(radar[3], wx+xoff*4, wy, pw,ph, 0.0f,-1, -1, -1, 200);
- if(IsWantedLevelGreater(playerIndex, 4)){DrawSprite(radar[3], wx+xoff*5, wy, pw,ph, 0.0f,-1, -1, -1, 200);
- }}}}}
- //////////////////POWERS
- if(usePower>0 && power>0){
- power-=0.7f;
- SetTimeScale(0.5f-power/300);
- SetTimecycleModifier("cabaret");
- }else if(usePower>0){
- usePower=0;
- SetTimeScale(1);
- ClearTimeCycleModifier();
- }
- if(press(VK_TAB)){ //Use power
- if(usePower==0){
- usePower=1;
- }else{
- usePower=0;
- SetTimeScale(1);
- ClearTimeCycleModifier();
- }
- }
- /////////////RETICULE
- if (GetKeyState(VK_RBUTTON)<0){
- f32 d=4,acc=0.2f,yoff=0;
- GetGameCam(&cam);
- GetCameraVector(cam, CamVec, 0);
- GetCamPos(cam, &x, &y, &z);
- int aim=0;
- while(d < maxdist){ //check area in front of vision/aim for peds
- X=x+d*CamVec.X;
- Y=y+d*CamVec.Y;
- Z=z+d*CamVec.Z;
- d+=acc*2;
- if(IsAreaOccupied(X-acc,Y-acc,Z-acc,X+acc,Y+acc,Z+acc,0,0,1,0,0)){
- GetClosestChar(X,Y,Z,1,1,1,&xped);
- if(1){//DoesCharExist(xped)){ //always returns false, can be because GetClosestChar is slow, do external check after one tick.
- if(IsPlayerFreeAimingAtChar(playerIndex,xped)){
- //if(IsCharDead(xped)){aim=1; print("doead");}
- //else{ aim=1;}
- if(usePower>0)SetTimeScale(0.1f); //make extra slo-mo if aiming at player and power is on
- aim=1;
- break;
- }
- }
- }
- }
- if(IsCharInAnyCar(ped))yoff=-0.041f; //offset reticule if in car.
- if(aim==0) DrawSprite(radar[0], 0.5f, 0.5f+yoff, 0.00304f, 0.0047f, 0.0f,-1, -1, -1, 230); //white
- else if(aim==1)DrawSprite(radar[0], 0.5f, 0.5f+yoff, 0.00304f, 0.0047f, 0.0f,50, 50, 50, 230); //gray
- //else if(aim==2)DrawSprite(radar[1], 0.5f, 0.5f, 0.003f, 0.003f, 50.0f,50, 50, 50, 230); //dead
- }
- }
- /////////////////CHAR SWITCH
- //The swap HUD, no proper textures yet, so disabled
- /* if (GetKeyState(VK_RCONTROL)<0){
- SetTimecycleModifier("binocular");
- SetTimeScale(0.1f);
- DrawRect(0,0,2,2,0,175,100,50);
- if(press(VK_LEFT))xselect=1;
- if(press(VK_RIGHT))xselect=2;
- if(press(VK_DOWN))xselect=0;
- p[0]=150;p[1]=150;p[2]=150;
- p[xselect]=230;
- DrawSprite(radar[7], 0.9f, 0.9f, 0.1f, 0.1f, 0.0f,-1, -1, -1, 230);
- DrawSprite(radar[6], 0.9f, 0.9f, 0.1f, 0.1f, 0.0f,-1, -1, -1, p[2]);
- DrawSprite(radar[5], 0.89f, 0.91f, 0.1f, 0.1f, 0.0f,-1, -1, -1, p[1]);
- DrawSprite(radar[4], 0.91f, 0.91f, 0.1f, 0.1f, 0.0f,-1, -1, -1, p[0]);
- }
- else if(xselect==0){
- SetTimeScale(1);
- ClearTimeCycleModifier();
- xselect=-1;
- }
- else if(xselect>0){
- doChange=true;
- xselect=0;
- }*/
- if(GetKeyState(VK_F3)<0 && swap==0){
- doChange=false;
- GenerateRandomFloatInRange(-1000,1000, &x);
- GenerateRandomFloatInRange(-1000,1000, &y);
- GetGroundZFor3DCoord(x,y,1000,&z);
- Wait(0);
- //GetSafePositionForChar(x,y,z, 0, &sx, &sy, &sz); //Gives non-existing coordinates, bugs game. fix!
- sx=x;sy=y;sz=z;
- GetDistanceBetweenCoords2D(sx,sy,cx,cy,&dist);
- //camera init
- GetGameCam(&gcam);
- GetCamPos(gcam, &cx, &cy, &cz);
- GetCamRot(gcam, &cxx, &cyy,&czz);
- GetCamFov(gcam, &fov);
- CreateCam(14, &pcam);
- SetCamPos(pcam, cx, cy, cz);
- SetCamRot(pcam, cxx, cyy, czz);
- SetCamPropagate(pcam, 1);
- ActivateScriptedCams(1, 1);
- SetTimecycleModifier("binocular");
- SetTimeScale(0.1f);
- R=0;
- G=175;
- B=100;
- A=50;
- h=5;
- swap=1;
- SetTimerA(0);
- whitefade=50;
- SetTimerB(0);
- }
- if(swap>0){
- DrawRect(0,0,2,2,R,G,B,A);
- }
- if(swap==1){ //the circular motion to top of player
- GetCharCoordinates(ped,&fcx,&fcy,&fcz);
- fcz+=h;
- cx+=(fcx-cx)/20;
- cy+=(fcy-cy)/20;
- cz+=(fcz-cz)/20;
- SetCamPos(pcam,cx,cy,cz);
- // PointCamAtCoord
- PointCamAtPed(pcam, ped); //replace with SetCamRot + math, or find a way to disable the pointing
- if(TimerA()>150){
- h=10;
- cz+=100;
- fcz+=130;
- SetTimerA(0);
- swap++;
- R+=20;
- G-=0;
- B+=30;
- whitefade=50;
- SetTimerB(0);
- //SetCharVisible(ped,0);
- SetCamPos(pcam,cx,cy,cz);
- SetCamRot(pcam,0,0,-90);
- SetTimerA(0);
- PointCamAtCoord(pcam,cx,cy,0);
- }
- }
- if(swap==2 || swap==3 || swap==4){ //the jumps up
- //SetCharCoordinates(ped,cx,cy,cz);
- cx+=(fcx-cx)/30;
- cy+=(fcy-cy)/30;
- cz+=(fcz-cz)/30;
- SetCamPos(pcam,cx,cy,cz);
- if(TimerA()>150){
- cz+=100;
- fcz+=140;
- whitefade=50;
- SetTimerB(0);
- SetCamPos(pcam,cx,cy,cz);
- SetTimerA(0);
- swap++;
- //R+=20;
- //G-=0;
- //B+=30;
- }
- }
- if(swap==5){ //the pan to new location
- cx+=(sx-cx)/50;
- cy+=(sy-cy)/50; //change the divide bit, so cam velocity is constant, not slowing so much down at end
- //SetCharCoordinates(ped, cx,cy,fcz);
- PointCamAtCoord(pcam,cx,cy,0);
- SetCamPos(pcam,cx,cy,cz);
- if(ownDist2D(cx,cy,sx,sy)<20){
- swap++;
- whitefade=50;
- SetTimerB(0);
- SetCamPos(pcam,cx,cy,cz);
- SetTimerA(0);
- SetCharCoordinates(ped,sx,sy,sz);
- fcz-=130;
- }
- }
- if(swap>5 && swap<8){ //down jumps
- cx+=(sx-cx)/30;
- cy+=(sy-cy)/30;
- cz+=(sz+fcz-cz)/30;
- SetCamPos(pcam,cx,cy,cz);
- if(TimerA()>150){
- cz-=130;
- fcz-=150;
- whitefade=50;
- SetTimerB(0);
- SetCamPos(pcam,cx,cy,cz);
- SetTimerA(0);
- swap++;
- GetGameCam(&gcam);
- GetCamPos(gcam, &X1, &Y1, &Z1);
- GetCamRot(gcam, &x3, &y3,&z3);
- }
- }
- if(swap==8){ //to game cam pos
- cx+=(X1-cx)/30;
- cy+=(Y1-cy)/30;
- cz+=(Z1-cz)/30;
- SetCamPos(pcam,cx,cy,cz);
- PointCamAtPed(pcam,ped);
- if(TimerA()>150){
- swap++;
- }
- }
- if(swap>8){ //done
- ActivateScriptedCams(0, 0);
- ClearTimeCycleModifier();
- SetTimeScale(1);
- swap=0;
- }
- if(whitefade>0){
- if(TimerB()<whitefade){
- DrawRect(0,0,2,2,255,255,255,u32((-255/whitefade)*TimerB()+255));
- }else whitefade=0;
- }
- Wait(0);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement