Quantcast

Jump to content

» «
Photo

How to use Aru's C++ ScriptHook SDK

44 replies to this topic
Skorpro
  • Skorpro

    GTAholic

  • Members
  • Joined: 19 Jul 2009
  • Germany

#1

Posted 24 August 2013 - 09:40 AM Edited by Skorpro, 07 April 2015 - 07:47 AM.

Hi modders,

after some requests I decided to post here my small instruction how to use Aru's C++ ScriptHook SDK. I wrote this "HOW TO" some time ago for friends smile.gif

Let's go! Simply follow the instructions biggrin.gif

  • First install Visual C++ 2010 Express and Aru's C++ Script Hook SDK 0.4.0!
  • Then run ScriptHook.sln (C++ ScriptHook SDK)... alter loading double click on SampleCustomFiber (left menu) >> Source Files >> CustomFiberThread.cpp
  • Edit the script like YOU want smile.gif(You can find examples in SDK!)
  • Right click on SampleCustomFiber (left menu) and choose "Set as StartUp Project"!
  • At the top of the window you can see a green PLAYbutton! Besides ("DEBUG") choose "RELEASE" and press PLAY!
  • You get a message like an error >> ignore this and press OK.
  • Go to ScriptHook SDK main folder and you will see a folder called Release. There you can find this file: SampleCustomFiber.dll
    Rename it to "myTestMod.asi" (NOT myTestMod.asi.dll !!!!) and copy it to your GTA game dir (root dir)!
  • Congratulations! Your first mod is ready now!
  • Start the game to test it... Have fun smile.gif

Here is a list with about 250 450 natives that I have edited! You must edit your "ScriptingNatives.h" too, so download both HERE!

 

Spoiler

 

Feel free to edit/use anything! If you have more edited natives post it here. Small code examples are welcome too.
Always respect the hard work of other coders/modders -> please make a small notation like "Thanks to Aru, Alexander Blade, Skorpro" if you use this in own mods! THANX
biggrin.gif


Hope it's helpful - have fun now smile.gif


Special thanx to:

  • Alexander Blade for ASI Loader & SCOCL natives list
  • Aru for C++ ScriptHook SDK

 

EDIT: over 200 new edited natives

  • jpm1, byteMe420 and GRAX like this

AXLiberty
  • AXLiberty

    Player Hater

  • Members
  • Joined: 07 Sep 2011
  • Russia

#2

Posted 24 August 2013 - 10:49 AM

Thank you for this! smile.gif

Skorpro
  • Skorpro

    GTAholic

  • Members
  • Joined: 19 Jul 2009
  • Germany

#3

Posted 24 December 2013 - 04:17 AM Edited by Skorpro, 24 December 2013 - 04:22 AM.

Hi guys!

 

It's been a long time...

 

LetsPlayOrDy has looked for a method to set a vehicle to a position just a couple of feet in front of player.
This is a small example to do this in C++
.

Car Spawn Example:

 

CustomFiberThread.h

Scripting::Vehicle SpawnCar(Scripting::eModel model, f32 x, f32 y, f32 z, f32 h);

CustomFiberThread.cpp

...
...
...

// Global vars
Vehicle spawnCar;
f32 sx, sy, sz, sh;
b8 delcar = 0;


Scripting::Vehicle CustomFiberThread::SpawnCar(Scripting::eModel model, f32 x, f32 y, f32 z, f32 h)
{
	// Local vars
	Vehicle retVeh;
	eInteriorRoomKey carRoomKey;
	// Load model
	RequestModel(model);
	while(!HasModelLoaded(model)) { Wait(0); }
	// Spawn vehicle
	ClearArea(x, y, z, 3.01f, 1);
	Wait(0);
	CreateCar(model, x, y, z, &retVeh, true);
	GetKeyForCharInRoom(GetPlayerPed(), &carRoomKey);
	SetCarOnGroundProperly(retVeh);
	SetRoomForCarByKey(retVeh, carRoomKey);
	SetCarHeading(retVeh, h);
	MarkModelAsNoLongerNeeded(model);

	return retVeh;
}


void CustomFiberThread::RunScript()
{
	// This is a fiber thread, so we use an loop to run the contents of this script.
	// The thread will terminate when we return from this function.
	
	Wait(2000);

	while(IsThreadAlive())		// MAIN LOOP
	{
		if (GetKeyState(116)<0)	// Press <F5> to spawn vehicle (F5 = 116)
		{
			if (delcar == 0)
			{
				GetOffsetFromCharInWorldCoords(GetPlayerPed(), 0.0f, 5.0f, 0.0f, &sx, &sy, &sz); // 5 steps from player (y coord!)
				GetCharHeading(GetPlayerPed(), &sh);
				spawnCar = SpawnCar(MODEL_ORACLE, sx, sy, sz, sh); // Check "ScriptingEnums.h" for models...
				ChangeCarColour(spawnCar, 0, 1);
				SetExtraCarColours(spawnCar, 0, 0);
				SetVehicleDirtLevel(spawnCar, 0.0f);
				WashVehicleTextures(spawnCar, 255);
				PrintStringWithLiteralStringNow("STRING", "Car spawned!", 2000, 1);
				delcar = 1;
			}
			else if (delcar == 1)
			{ 
				if ( (DoesVehicleExist(spawnCar)) && (!IsCharInCar(GetPlayerPed(), spawnCar)) ) // To delete car exit it first...
				{
					DeleteCar(&spawnCar); 
					PrintStringWithLiteralStringNow("STRING", "Car deleted!", 2000, 1);
					delcar = 0;
				}
				else PrintStringWithLiteralStringNow("STRING", "Can't delete car...", 2000, 1);
			}
			Wait(200);
		}
		Wait(0);
	}
}

Any questions? Post it here! :)

 

Merry Christmas and a Happy New Year! :D


Skorpro
  • Skorpro

    GTAholic

  • Members
  • Joined: 19 Jul 2009
  • Germany

#4

Posted 31 October 2014 - 11:57 PM Edited by Skorpro, 28 November 2014 - 11:58 PM.

Hi guys,

 

it's been a long time... but I want to bring this topic back to life... (Hope Silent - or another moderator -  can move this to GTA IV section again @Silent thanx for moving:))

 

Anyway... here is a simple way to switch the vehicle engine:

 

C++

Vehicle car;

...

GetCarCharIsUsing(GetPlayerPed(), &car);
if (t_engine == 0) 
{
	SetCarEngineOn(car, 0, 0);
	SetPetrolTankHealth(car, 0.0f);
	PrintStringWithLiteralStringNow("STRING","Engine OFF!",1200,1);
	t_engine = 1;
}
else if (t_engine == 1) 
{
	SetPetrolTankHealth(car, 1000.0f);
	SetCarEngineOn(car, 0, 0);
	Wait(500);
	SetCarEngineOn(car, 1, 1);
	PrintStringWithLiteralStringNow("STRING","Engine ON!",1200,1);
	t_engine = 0;
}

To switch the engine on it's better to use SetCarEngineOn twice (yes, you could use SetCarEngineOn(car, 1, 0) but sometimes it does not work!).

 

Have fun :)

  • jpm1 likes this

Skorpro
  • Skorpro

    GTAholic

  • Members
  • Joined: 19 Jul 2009
  • Germany

#5

Posted 01 November 2014 - 01:52 AM

Another example: SCO Loader!

 

Add this to "Scripting.h" or download my files (first post):

static u32 StartNewScript(const ch *scriptName, u32 stacksize) { return NativeInvoke::Invoke<NATIVE_START_NEW_SCRIPT, u32>(scriptName, stacksize); }

C++ SCO Loader:

void SKP::skpp(const char *printText, u32 printTime, b8 printWait)
{
	PrintStringWithLiteralStringNow("STRING", printText, printTime, 1);
	if (printWait == 1) { Wait(printTime); }
}


bool SKP::SCO_Loader(int sco_num1toX, const ch *sco_name, u32 sco_stacksize_0, b8 sco_info, u32 sco_wait)
{
	// Copy your own SCO scripts into "script.img"
	// -------------------------------------------
	// GTA IV	:	C:\Program Files (x86)\Rockstar Games\Grand Theft Auto IV\common\data\cdimages\script.img
	// TBOGT	:	C:\Program Files (x86)\Rockstar Games\EFLC\TBoGT\common\data\cdimages\script.img
	// TLAD		:	C:\Program Files (x86)\Rockstar Games\EFLC\TLAD\common\data\cdimages\script.img
	
	b8 sco_ok = 0;

	if ( (DoesScriptExist(sco_name)) && (sco_num1toX > 0) )
	{
		if (GetNumberOfInstancesOfStreamedScript(sco_name) == 0)
		{
			RequestScript(sco_name);
			while (!HasScriptLoaded(sco_name)) Wait(0);
			if (sco_num1toX == 1) { if (sco_stacksize_0 == 0) sco_stacksize_0 = 8192; }	// sco_stacksize_0 = 0 -> 8192 (first script)
			else if (sco_num1toX > 1) { if (sco_stacksize_0 == 0) sco_stacksize_0 = 1024; }	// sco_stacksize_0 = 0 -> 1024 (other scripts)
			u32 sco_scriptnum;
			sco_scriptnum = StartNewScript(sco_name, sco_stacksize_0);
			MarkScriptAsNoLongerNeeded(sco_name);
			if (sco_info == 1) 
			{
				char infotext[64];
				strncpy_s(infotext, "~COL_NET_3~'~COL_NET_4~ ", 26);
				strncat_s(infotext, sco_name, strlen(sco_name));
				strncat_s(infotext, " ~COL_NET_3~' loaded!", 22);
				skpp(infotext, 2000, 0);
			}
			sco_ok = 1;
		}
		else skpp("SCO Script already loaded!", 3000, 0);
	}
	else skpp("Unknown SCO Script or Number!", 3000, 0);

	if (sco_wait > 0) Wait(sco_wait);

	return sco_ok;
}

Hint: Never simply copy & paste! You must adapt this code to your own.

 

 

Usage:

SCO_Loader(1, "z_heliblock", 0, 1, 1000);
SCO_Loader(2, "z_traffic", 0, 1, 1000);
SCO_Loader(3, "z_worldprops", 0, 1, 1000);
SCO_Loader(4, "z_zombgen", 0, 1, 1000);

Note: All my scripts are for free use! Be fair: Please make a small credit like "Thanx to Skorpro" if you want to use them! Thanx :)

  • AgentWD40 and GRAX like this

tall70
  • tall70

    Player Hater

  • Members
  • Joined: 03 Jan 2009

#6

Posted 27 November 2014 - 05:57 AM Edited by tall70, 27 November 2014 - 05:59 AM.

Uhhh, little too much for me to get just quickly involved in, i was hopping for little simpler editing. I'm using almost all your scripts since it doesn't bug rain effects without use of ScriptHookDotNet, thanks for all of it. But those tutorials... they very nice for people with deeper interest an knowledge which i have total zero. I better stick with things i have some experience already before i get whole weekends tied up with another hobby.


stef538
  • stef538

    It's just me, going 88 MPH.

  • Members
  • Joined: 06 Oct 2012
  • Netherlands

#7

Posted 27 November 2014 - 02:22 PM

how do we use this native : GetVehicleDirtLevel

 

I tried it this way : 

GetVehicleDirtLevel(thecurrentvehicle, dirtyness);

 

thecurrentvehicle is the vehicle we currently use, and dirtyness is a float, but whenever I try to echo the value of dirtyness it always returns with a 0.


jpm1
  • jpm1

    Vice city citizen

  • Members
  • Joined: 26 Sep 2005
  • European-Union

#8

Posted 27 November 2014 - 03:39 PM Edited by jpm1, 27 November 2014 - 03:42 PM.

always happy when i find a gold mine :colgate: . You should upload your engine off to some downloads sites i think it would be successful


Jitnaught
  • Jitnaught

    ✰✰✰✰✰✰

  • Members
  • Joined: 24 Aug 2013
  • United-States

#9

Posted 28 November 2014 - 04:34 PM Edited by LetsPlayOrDy, 28 November 2014 - 11:57 PM.

how do we use this native : GetVehicleDirtLevel
 
I tried it this way : 

GetVehicleDirtLevel(thecurrentvehicle, dirtyness);
 
thecurrentvehicle is the vehicle we currently use, and dirtyness is a float, but whenever I try to echo the value of dirtyness it always returns with a 0.

GET_VEHICLE_DIRT_LEVEL(Vehicle vehicle, float* pIntensity);

f32 dirtLevel;
GetVehicleDirtLevel(yourVeh, &dirtLevel);

Is this how you are using it?

stef538
  • stef538

    It's just me, going 88 MPH.

  • Members
  • Joined: 06 Oct 2012
  • Netherlands

#10

Posted 28 November 2014 - 09:59 PM

yeah..


Skorpro
  • Skorpro

    GTAholic

  • Members
  • Joined: 19 Jul 2009
  • Germany

#11

Posted 28 November 2014 - 11:38 PM

@stef538

Your code is fine! But you have to use DisplayTextWithFloat to show float values :)

f32 fDirt = 0.0f;
Vehicle veh;


while(IsThreadAlive())
{
	if (IsCharInAnyCar(GetPlayerPed()))
	{
		GetCarCharIsUsing(GetPlayerPed(), &veh);
		GetVehicleDirtLevel(veh, &fDirt);
		DisplayTextWithFloat(0.5f, 0.9f, "NUMBER", fDirt, 3); // decimal places = 3
	}

	Wait(0);
}
  • stef538 likes this

Skorpro
  • Skorpro

    GTAholic

  • Members
  • Joined: 19 Jul 2009
  • Germany

#12

Posted 28 November 2014 - 11:52 PM

Uhhh, little too much for me to get just quickly involved in, i was hopping for little simpler editing. I'm using almost all your scripts since it doesn't bug rain effects without use of ScriptHookDotNet, thanks for all of it. But those tutorials... they very nice for people with deeper interest an knowledge which i have total zero. I better stick with things i have some experience already before i get whole weekends tied up with another hobby.

Thanx :D

Believe me it's easier than it looks. But I have the same problem: Too many ideas/hobbies and not enough time... ;)

 

 

 

always happy when i find a gold mine :colgate: . You should upload your engine off to some downloads sites i think it would be successful

You're welcome :) Maybe I will make a Mods Pack Vol.2 (with some 'unpublished' mods) before GTA V comes out.


Skorpro
  • Skorpro

    GTAholic

  • Members
  • Joined: 19 Jul 2009
  • Germany

#13

Posted 29 November 2014 - 12:35 AM

@DaBOSS54320 (referring to: "how to disable a vehicle from spawning in traffic")

 

How to suppress a vehicle:

// Global
Vehicle veh;
eModel model;

. . .


while(IsThreadAlive())
{
	if (IsCharInAnyCar(GetPlayerPed()))
	{
		GetCarCharIsUsing(GetPlayerPed(), &veh);
		GetCarModel(veh, &model);
		SuppressCarModel(model);
	}
	else DontSuppressCarModel(model);

	Wait(0);
}

Note:

Add this to "Scripting.h" or download my files (first post):

static void SuppressCarModel(eModel model) { NativeInvoke::Invoke<NATIVE_SUPPRESS_CAR_MODEL, ScriptVoid>(model); }
static void DontSuppressCarModel(eModel carmodel) { NativeInvoke::Invoke<NATIVE_DONT_SUPPRESS_CAR_MODEL, ScriptVoid>(carmodel); }
  • AgentWD40 likes this

stef538
  • stef538

    It's just me, going 88 MPH.

  • Members
  • Joined: 06 Oct 2012
  • Netherlands

#14

Posted 29 November 2014 - 10:26 AM Edited by stef538, 29 November 2014 - 11:39 AM.

 

@stef538

Your code is fine! But you have to use DisplayTextWithFloat to show float values :)

f32 fDirt = 0.0f;
Vehicle veh;


while(IsThreadAlive())
{
	if (IsCharInAnyCar(GetPlayerPed()))
	{
		GetCarCharIsUsing(GetPlayerPed(), &veh);
		GetVehicleDirtLevel(veh, &fDirt);
		DisplayTextWithFloat(0.5f, 0.9f, "NUMBER", fDirt, 3); // decimal places = 3
	}

	Wait(0);
}

 

Thank you!! But whenever I use the GET_VEHICLE_DIRT_LEVEL it gives me an error... "Attempted to read or write protected memory"


Skorpro
  • Skorpro

    GTAholic

  • Members
  • Joined: 19 Jul 2009
  • Germany

#15

Posted 30 November 2014 - 10:34 AM

Thank you!! But whenever I use the GET_VEHICLE_DIRT_LEVEL it gives me an error... "Attempted to read or write protected memory"

I don't know why you got this error?!

 

I checked it in SCO too. The script works!

#define PP GetPlayerPed()
Vehicle veh;
float fDirt;

. . .

if (IS_CHAR_IN_ANY_CAR(PP))
{
	GET_CAR_CHAR_IS_USING(PP, &veh);
	GET_VEHICLE_DIRT_LEVEL(veh, &fDirt);
	DISPLAY_TEXT_WITH_FLOAT(0.5, 0.9, "NUMBER", fDirt, 3);
}

Hint: If you use .Net don't call this native like this "GTA.Native.Function.Call("GET_VEHICLE_DIRT_LEVEL", veh, fDirt);"! Better use Hazard's classes:

// Taken from Hazard's Vehicle.cpp!
float Vehicle::Dirtyness::get()
{
	NON_EXISTING_CHECK(0.0f);
	f32 res;
	Scripting::GetVehicleDirtLevel(pHandle,&res);
	return res;
}
void Vehicle::Dirtyness::set(float value)
{
	NON_EXISTING_CHECK();
	Scripting::SetVehicleDirtLevel(pHandle,value);
}

Hope it works for you :)

 

  • stef538 likes this

rodd1981
  • rodd1981

    Player Hater

  • Members
  • Joined: 24 Dec 2012
  • Brazil

#16

Posted 03 December 2014 - 03:58 AM

Another example: SCO Loader!

 

Add this to "Scripting.h" or download my files (first post):

static u32 StartNewScript(const ch *scriptName, u32 stacksize) { return NativeInvoke::Invoke<NATIVE_START_NEW_SCRIPT, u32>(scriptName, stacksize); }

C++ SCO Loader:


 

Usage:

SCO_Loader(1, "z_heliblock", 0, 1, 1000);
SCO_Loader(2, "z_traffic", 0, 1, 1000);
SCO_Loader(3, "z_worldprops", 0, 1, 1000);
SCO_Loader(4, "z_zombgen", 0, 1, 1000);

Note: All my scripts are for free use! Be fair: Please make a small credit like "Thanx to Skorpro" if you want to use them! Thanx :)

 

@Skorpro

 

I am a real fan of your work. I've used your bombmod on a SCO mission that was released for PS3 back in 2012 (see video below - and of course, I've given you the credit for the mod in the video):

 

https://www.youtube....h?v=3GejxqYjyKw

 

I'm currently working on a bigger project now (VC++ app to build your own GTA missions) and I am desperately looking for some help with SCO/.NET

 

I usually code only in native SCO because I started doing mods on PS3 (so I don't have skills to code script hook stuff). Basically, I want to know if it's possible to create a ASI/DLL script to load external SCO files (like the DLL ones that are loaded via script hook console on /scripts dir). That would boost my dev work a lot (and of course would be f**kin' great, lol).

 

Right now I have to rebuild script.img on OpenIV everytime I do changes on my C SCO project (and load up the game afterwards). That takes me around 5 mins (I'd love to speed things up).

 

Let me know if you have any ideas in mind.

 

Thx,

 

- rodd1981


Jitnaught
  • Jitnaught

    ✰✰✰✰✰✰

  • Members
  • Joined: 24 Aug 2013
  • United-States

#17

Posted 03 December 2014 - 09:12 PM

Basically, I want to know if it's possible to create a ASI/DLL script to load external SCO files (like the DLL ones that are loaded via script hook console on /scripts dir). That would boost my dev work a lot (and of course would be f**kin' great, lol).

I don't think that would be possible

  • rodd1981 likes this

Skorpro
  • Skorpro

    GTAholic

  • Members
  • Joined: 19 Jul 2009
  • Germany

#18

Posted 04 December 2014 - 03:36 PM

I am a real fan of your work.

Thanx :D

 

I usually code only in native SCO because I started doing mods on PS3 (so I don't have skills to code script hook stuff). Basically, I want to know if it's possible to create a ASI/DLL script to load external SCO files (like the DLL ones that are loaded via script hook console on /scripts dir). That would boost my dev work a lot (and of course would be f**kin' great, lol).

 

Right now I have to rebuild script.img on OpenIV everytime I do changes on my C SCO project (and load up the game afterwards). That takes me around 5 mins (I'd love to speed things up).

AFAIK it's impossible, because SCO scripts must be included in a IMG file, otherwise GTA couldn't find them!

Example: The "DoesScriptExist" native checks the known IMG files.

 

 


Skorpro
  • Skorpro

    GTAholic

  • Members
  • Joined: 19 Jul 2009
  • Germany

#19

Posted 12 December 2014 - 05:06 PM

@stef538 (referring to: "Convert GTA IV model hash to string")

 

Here is an example how to convert a model string to a hash string:

char cHash[16];

...

char *SKP::ModelStringToHashString(char *key, int IHBU)
{
	if (IHBU == 0) { _ltoa_s(GetHashKey(key), cHash, 10); }	// Int=10
	if (IHBU == 1) { _ltoa_s(GetHashKey(key), cHash, 16); }	// Hex=16
	if (IHBU == 2) { _ltoa_s(GetHashKey(key), cHash, 2); }	// Bin=2
	if (IHBU == 3) { _ultoa_s(GetHashKey(key), cHash, 10); }// Unsigned Int=10

	return cHash;
}

Here is the native to convert a model string to a hash:

u32 GetHashKey(const ch *value) // native
// or
eModel GetModelHash(const ch *name) // this is NOT a 'regular native' - this function is done by Aru!
  • stef538 likes this

Skorpro
  • Skorpro

    GTAholic

  • Members
  • Joined: 19 Jul 2009
  • Germany

#20

Posted 23 January 2015 - 11:33 PM

Hi guys,

 

here are my file/INI functions:

 

C++

// INI/FILE FUNCTIONS

#define INI_Name "./test mod.ini"


// STRING
char* SKP::SkorproReadString(char* Section, char* Key, const char* DefaultString)
{
	char* Result = new char[255];
	memset(Result, 0x00, 255);
	GetPrivateProfileStringA(Section, Key, DefaultString, Result, 255, INI_Name); 
	return Result;
}

void SKP::SkorproWriteString(char* Section, char* Key, const char* ValueString)
{
	WritePrivateProfileStringA(Section, Key, ValueString, INI_Name);
}


// INT
int SKP::SkorproReadInteger(char* Section, char* Key, int DefaultInt)
{
	 int Result = GetPrivateProfileIntA(Section,  Key, DefaultInt, INI_Name); 
	 return Result;
}

void SKP::SkorproWriteInteger(char* Section, char* Key, int ValueInt, b8 DecHex)
{
	char tmpValue[255];
	if (DecHex == 0) { sprintf_s(tmpValue, 255, "%d", ValueInt); } // %d = DEC
	if (DecHex == 1) { sprintf_s(tmpValue, 255, "%x", ValueInt); } // %x = HEX
	WritePrivateProfileStringA(Section, Key, tmpValue, INI_Name); 
}


// FLOAT
float SKP::SkorproReadFloat(char* szSection, char* szKey, float DefaultFloat)
{
	char szResult[255];
	char szDefault[255];
	double dResult;
	float fResult;
	sprintf_s(szDefault, "%f",DefaultFloat);
	GetPrivateProfileStringA(szSection,  szKey, szDefault, szResult, 255, INI_Name); 
	dResult =  atof(szResult);
	fResult = (f32) dResult;
	return fResult;
}

void SKP::SkorproWriteFloat(char* szSection, char* szKey, float ValueFloat, int Nachkommastellen)
{
	char szValue[255];
	if (Nachkommastellen <= 1) sprintf_s(szValue, "%.1f", ValueFloat);
	else if (Nachkommastellen == 2) sprintf_s(szValue, "%.2f", ValueFloat);
	else if (Nachkommastellen == 3) sprintf_s(szValue, "%.3f", ValueFloat);
	else if (Nachkommastellen == 4) sprintf_s(szValue, "%.4f", ValueFloat);
	else if (Nachkommastellen == 5) sprintf_s(szValue, "%.5f", ValueFloat);
	else if (Nachkommastellen == 6) sprintf_s(szValue, "%.6f", ValueFloat);
	else if (Nachkommastellen >= 7) sprintf_s(szValue, "%.7f", ValueFloat);
	WritePrivateProfileStringA(szSection, szKey, szValue, INI_Name); 
}


// Backup
void SKP::SkorproBackupINI()
{
	char BackupINI[64];
	strncpy_s(BackupINI, INI_Name, 54);
	strncat_s(BackupINI, ".backup", 10);
	CopyFileA(INI_Name, BackupINI, false); // "false" überschreibt "BackupINI", falls diese existiert!
}

Have fun :)

  • GRAX likes this

GRAX
  • GRAX

    c++ beginner

  • Members
  • Joined: 27 Jan 2015
  • European-Union

#21

Posted 27 January 2015 - 03:11 PM

wow dude thank you for this thread!!!
  • Skorpro likes this

Skorpro
  • Skorpro

    GTAholic

  • Members
  • Joined: 19 Jul 2009
  • Germany

#22

Posted 02 February 2015 - 05:40 AM

wow dude thank you for this thread!!!

You're welcome :)

Any questions? Post it here :)


Skorpro
  • Skorpro

    GTAholic

  • Members
  • Joined: 19 Jul 2009
  • Germany

#23

Posted 02 February 2015 - 08:03 AM

How to read the carcols.dat

 

Hi,

@ALL & @ClareXoBearrx3   (referring to: "C++ getline()")

 

Here is a way (there are many others in C++ ;)) how to read particular parts of a line taken from a file (here the carcols.dat as example!):

// GTA 4 & TLAD = 134 colors // TBOGT = 137 colors!
#define MAX_COLORS 137
ifstream iFile;
string strLine;
int col_temp[3] = { 999, 999, 999 };
int col_array[MAX_COLORS][3];
int col_count = 0;
Vehicle veh;
u32 uCol[4];


// . . .


bool SKP::ColorFile()
{
   bool bOk = 0;

   iFile.open("./common/data/carcols.dat", ios::in);

   if (iFile.fail() || iFile.bad())
   {
      skpp("Carcols.dat READ ERROR!", 5000, 0);
   }
   else
   {
      iFile.seekg(0L, ios::beg);

      while (!iFile.eof())
      {
         getline(iFile, strLine);
         if (strLine.find("col") == 0) // find 'col' and start reading!
         {
            while (true)
            {
               getline(iFile, strLine);

               stringstream ss(strLine);
               for (int i = 0; i < 3; i++) col_temp[i] = 999;
               string token;
               int iToken = 0;

               while (getline(ss, token, ','))
               {
                  col_temp[iToken] = atoi(token.c_str());
                  iToken++;
                  if (iToken == 3) break;
               }
               ss.clear();

               // Check
               if (col_temp[0] != 999 && col_temp[1] != 999 && col_temp[2] != 999)
               {
                  for (int i = 0; i < 3; i++) col_array[col_count][i] = col_temp[i];                  
                  col_count++;
               }

               if (strLine.find("end") == 0) break; // read until 'end'!
            }
         }
      }
      bOk = 1;
   }
   iFile.close();

   return bOk;
}


// . . .


void SKP::RunScript()
{

   // read carcols.dat
   ColorFile();
   
   
   // . . .

   
   while(IsThreadAlive())
   {
      // . . .
      
      if (IsCharInAnyCar(GetPlayerPed()))
      {
         GetCarCharIsUsing(GetPlayerPed(), &veh);
         GetCarColours(veh, &uCol[0], &uCol[1]);
         GetExtraCarColours(veh, &uCol[2], &uCol[3]);
         
         SkorproText("COLOR 1", 0.40f, 0.95f, 0, col_array[uCol[0]][0], col_array[uCol[0]][1], col_array[uCol[0]][2]);
         SkorproText("COLOR 2", 0.47f, 0.95f, 0, col_array[uCol[1]][0], col_array[uCol[1]][1], col_array[uCol[1]][2]);
         SkorproText("COLOR 3", 0.54f, 0.95f, 0, col_array[uCol[2]][0], col_array[uCol[2]][1], col_array[uCol[2]][2]);
         SkorproText("COLOR 4", 0.61f, 0.95f, 0, col_array[uCol[3]][0], col_array[uCol[3]][1], col_array[uCol[3]][2]);
      }
      
      Wait(0);
   }
}

Note: All my scripts are for free use! Be fair: Please make a small credit like "Thanx to Skorpro" if you want to use them! Thanx :D

Hint: Never simply copy & paste! You must adapt this code to your own.

  • GRAX likes this

GRAX
  • GRAX

    c++ beginner

  • Members
  • Joined: 27 Jan 2015
  • European-Union

#24

Posted 05 February 2015 - 02:41 PM

hi skorpro!
could you post your "SkorproText" function? im still a c++ noob.
TXL!

Skorpro
  • Skorpro

    GTAholic

  • Members
  • Joined: 19 Jul 2009
  • Germany

#25

Posted 07 February 2015 - 09:58 AM

How to play MP3 with C++ ScriptHook:   (referring to: "(C++) Playing External Sound")

#include <windows.h>
#include <MMSystem.h>
#pragma comment(lib, "winmm.lib")


. . . .


mciSendString(TEXT("open Test.mp3"),NULL,0,0);
mciSendString(TEXT("play Test.mp3 repeat"),NULL,0,0);
mciSendString(TEXT("setaudio Test.mp3 output volume to 500"),NULL,0,0);  // Volume = 500 (0 - 1000)

Have fun :D

  • leftas likes this

Skorpro
  • Skorpro

    GTAholic

  • Members
  • Joined: 19 Jul 2009
  • Germany

#26

Posted 07 February 2015 - 10:19 AM

could you post your "SkorproText" function? im still a c++ noob.

Here you are :)

void SKP::SkorproText(const char *text, f32 x, f32 y, int iFont, int iRed, int iGreen, int iBlue)
{
	SetTextFont( (eTextFont) iFont); // 0=SMOOTH_DEFAULT / 1=LED / 2=FAT (Nicht nutzen!) / 3=UNKNOWN (Nicht nutzen!) / 4=SMOOTH_ALT
	SetTextBackground(0);
	SetTextScale(0.22f, 0.27f);
	SetTextColour(iRed, iGreen, iBlue, 255);
	SetTextRightJustify(0);
	SetTextDropshadow(0, 255, 255, 255, 255);
	DisplayTextWithLiteralString(x, y, "STRING", text);
}
  • GRAX likes this

yoloman
  • yoloman

    Crackhead

  • Members
  • Joined: 21 Jul 2014
  • None

#27

Posted 07 February 2015 - 01:27 PM Edited by yoloman, 08 February 2015 - 10:48 PM.

Another example: SCO Loader!
 
Add this to "Scripting.h" or download my files (first post):

static u32 StartNewScript(const ch *scriptName, u32 stacksize) { return NativeInvoke::Invoke<NATIVE_START_NEW_SCRIPT, u32>(scriptName, stacksize); }
C++ SCO Loader:
void SKP::skpp(const char *printText, u32 printTime, b8 printWait)
{
	PrintStringWithLiteralStringNow("STRING", printText, printTime, 1);
	if (printWait == 1) { Wait(printTime); }
}


bool SKP::SCO_Loader(int sco_num1toX, const ch *sco_name, u32 sco_stacksize_0, b8 sco_info, u32 sco_wait)
{
	// Copy your own SCO scripts into "script.img"
	// -------------------------------------------
	// GTA IV	:	C:\Program Files (x86)\Rockstar Games\Grand Theft Auto IV\common\data\cdimages\script.img
	// TBOGT	:	C:\Program Files (x86)\Rockstar Games\EFLC\TBoGT\common\data\cdimages\script.img
	// TLAD		:	C:\Program Files (x86)\Rockstar Games\EFLC\TLAD\common\data\cdimages\script.img
	
	b8 sco_ok = 0;

	if ( (DoesScriptExist(sco_name)) && (sco_num1toX > 0) )
	{
		if (GetNumberOfInstancesOfStreamedScript(sco_name) == 0)
		{
			RequestScript(sco_name);
			while (!HasScriptLoaded(sco_name)) Wait(0);
			if (sco_num1toX == 1) { if (sco_stacksize_0 == 0) sco_stacksize_0 = 8192; }	// sco_stacksize_0 = 0 -> 8192 (first script)
			else if (sco_num1toX > 1) { if (sco_stacksize_0 == 0) sco_stacksize_0 = 1024; }	// sco_stacksize_0 = 0 -> 1024 (other scripts)
			u32 sco_scriptnum;
			sco_scriptnum = StartNewScript(sco_name, sco_stacksize_0);
			MarkScriptAsNoLongerNeeded(sco_name);
			if (sco_info == 1) 
			{
				char infotext[64];
				strncpy_s(infotext, "~COL_NET_3~'~COL_NET_4~ ", 26);
				strncat_s(infotext, sco_name, strlen(sco_name));
				strncat_s(infotext, " ~COL_NET_3~' loaded!", 22);
				skpp(infotext, 2000, 0);
			}
			sco_ok = 1;
		}
		else skpp("SCO Script already loaded!", 3000, 0);
	}
	else skpp("Unknown SCO Script or Number!", 3000, 0);

	if (sco_wait > 0) Wait(sco_wait);

	return sco_ok;
}
Hint: Never simply copy & paste! You must adapt this code to your own.
 
 
Usage:
SCO_Loader(1, "z_heliblock", 0, 1, 1000);
SCO_Loader(2, "z_traffic", 0, 1, 1000);
SCO_Loader(3, "z_worldprops", 0, 1, 1000);
SCO_Loader(4, "z_zombgen", 0, 1, 1000);
Note: All my scripts are for free use! Be fair: Please make a small credit like "Thanx to Skorpro" if you want to use them! Thanx :)
So I have a few questions about this. 
 
1. What to do with this Sco Loader code? Should I do it like in the instructions from the first post? 
2. (Never simply copy & paste) What should I edit or change in the code? Maybe something like sco_name and sco_stacksize?
3.And where to add the last code (with these SCO_Loader(1, z_heliblock,...))?
 
sry for bad english :D

GRAX
  • GRAX

    c++ beginner

  • Members
  • Joined: 27 Jan 2015
  • European-Union

#28

Posted 07 February 2015 - 09:49 PM

Here you are :)

thank you again!

ceedj
  • ceedj

    PEDS Creator

  • Feroci
  • Joined: 21 May 2005
  • United-States

#29

Posted 20 February 2015 - 10:38 PM

Hey Skorp, quickie question, what was the difference between using CustomThread and CustomFiberThread again? Is it the hash conversion? I have some ideas for rebuilding my studios code, but want to test on IV first.

 

Nice work here!


NTAuthority
  • NTAuthority

    hell, no, tunnel, no

  • Feroci
  • Joined: 09 Sep 2008
  • European-Union
  • Best Conversion 2014 [ViIV for GTANY]
    Most Knowledgeable [Tech] 2013
    Best Map 2013 [ViceCityStories PC Edition]
    Contribution Award [Mods]

#30

Posted 21 February 2015 - 04:41 AM

Hey Skorp, quickie question, what was the difference between using CustomThread and CustomFiberThread again? Is it the hash conversion? I have some ideas for rebuilding my studios code, but want to test on IV first.
 
Nice work here!

FiberThread allows one to use an equivalent of the native scripting 'WAIT' command to suspend the 'script', whereas the regular thread only exposes a tick method.
  • ceedj and Skorpro like this




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users