måndag 15 november 2021

Unity - How to get access and change the camera distance while using Cinemachine "3rd person follow" (C#)

Cinemachine https://unity.com/unity/features/editor/art-and-design/cinemachine

saves time by letting you create difference kinds of cameras.


Let's say you want to use the input system and scroll the mouse to change the camera distance.

I couldn't find a clear solution online so I thought I share:


First make sure you have:

A player GameObject.

A GameObject with a CinemachineVirtualCamera, set to: 

* follow the player.

* its "Body" set to "3rd Person Follow".


Note: You have other body properties as well to chose from:

3rd Person follow

Framing Transposer

Hard Lock to Target

Orbital Transposer

Tracked Dolly

Transposer


We are focusing on the "3rd Person Follow" now.


In the script that you add as component to the player GameObject:


Declaration: 

private GameObject _playerFollowCamera;

public CinemachineVirtualCamera _cinemachineVirtualCamera;


In private void Start() :

_playerFollowCamera = GameObject.Find("PlayerFollowCamera");

_cinemachineVirtualCamera = _playerFollowCamera.GetComponent<CinemachineVirtualCamera>();


          In your method, called when scrolling for example: 

CinemachineComponentBase cinemachineComponentBase = _cinemachineVirtualCamera.GetCinemachineComponent(CinemachineCore.Stage.Body);


if (cinemachineComponentBase is Cinemachine3rdPersonFollow)

{

(cinemachineComponentBase as Cinemachine3rdPersonFollow).CameraDistance = yourCameraDistanceValue;

}


Or as one line:

(GameObject.Find("PlayerFollowCamera").GetComponent<CinemachineVirtualCamera>().GetCinemachineComponent(CinemachineCore.Stage.Body) 

as Cinemachine3rdPersonFollow).CameraDistance = yourCameraDistanceValue;


"Cinemachine3rdPersonFollow" above is changed depending on which body property you are using.


måndag 4 januari 2016

GTA V: Change vehicle sounds on any vehicle to any sound

It's really easy to change the sounds on any vehicle to any other vehicle sound in GTA V.

Before we start, make sure to use OpenIV with the mods folder for safety: http://openiv.com/?p=1132

This is how you do it:
1. Go to update\update.rpf\common\data\levels\gta5 with OpenIV
2. Right click on vehicles.meta and press "Save content/ Export".
3. Open the file that you exported with notepad.
4. Find the vehicle model you want to change (CTRL+F and then search for modelName). If you are unsure which model it is you can use Native Trainer to spawn them and find out.
5. Look for "<audioNameHash />" under your model name. Replace it with "<audioNameHash>PutYourModelNameHere</audioNameHash>" and instead of "PutYourModelNameHere" you write the name of the model you want to use the sound from. Here are all model names: http://pastebin.com/i4AX8kBY (taken from Alexander Blades Native Trainer source).
6. Save the file, go back to OpenIV and replace the vehicles.meta with your version of it.
7. Start GTA V try it out :)

Tip: A sound that I like a lot is the engine sound of Stirling GT with model name FELTZER3. That would be <audioNameHash>FELTZER3</audioNameHash>

Play GTA V without violence

Family Friendly Free Roaming has been out for a while now. FFFR is a modification for Grand Theft Auto 5 that disables violence in the game. The latest versions has made it even less violent. This means that even children can play it.

Except making the game less violent, the purpose of the mod is to make it more fun exploring the amazing world without interrupting elements.

There are also features like entering vehicles as passenger and busing pedestrians around.

You can read more and get the latest version of FFFR here: https://www.gta5-mods.com/scripts/family-friendly-free-roaming


onsdag 22 juli 2015

GTA V Scripting PC Part 3: Keyboard and Controller support

Keyboard support example

For keyboard support you need these functions:

bool get_key_pressed(int nVirtKey)
{
    return (GetAsyncKeyState(nVirtKey) & 0x8000) != 0;
}

We need to check if the key is valid with isprint(): http://www.cplusplus.com/reference/cctype/isprint/
We also want a delay between possible keystrokes. We use GetTickCount() for this:

DWORD trainerResetTim;

void reset_mod_switch()
{
    trainerResetTime = GetTickCount();
}

We want to get the key pressed every 400 milliseconds. Insert is used as key if activateKeyChar is not a valid key:

bool on_off_switch_pressed(){
    if (isprint(activateKeyChar)){ // activateKeyChar is your key
        return ((GetTickCount() > trainerResetTime + 400) &&   get_key_pressed(activateKeyChar));
    }
    else{
        return ((GetTickCount() > trainerResetTime + 400) && get_key_pressed(0x2D));
    }
}

Read the previous post about how to read from the .ini file. You can in this way let the user choose a key code from here: https://msdn.microsoft.com/en-us/library/windows/desktop/dd375731(v=vs.85).aspx and write it in the .ini file so that your mod can get it and use it.

Now you can in your script loop check if your button is pressed:

if (on_off_switch_pressed()){
// do something
}

Controller support example

Controller support is similar:

bool on_off_mod_with_controller_switch_pressed(){
    return ((GetTickCount() > trainerResetTime + 400) && isControllButtonPressed(activateControllerButtonChar)
        && canActivateWithController);
}

canActivateWithController is a bool used to make it so that the controller only is usable when wanted.

Controller button keys:http://pastebin.com/X6X2hUB7

int xInputIndex = 2; // always 2
bool isControllButtonPressed(int controllerButton){
    if (canActivateWithController){
        if (CONTROLS::IS_CONTROL_PRESSED(xInputIndex, controllerButton)){
            return true;
        }
    }
    return false;
}



fredag 10 juli 2015

GTA V Scripting PC Part 2: How to read and write from configuration files (.ini).

Often you want your script to be customizable. This can be done by reading and writing to a configuration file that the script uses.

Files can be set to be read from continuously, which lets you make changes while playing and those changes to be updated directly without having to restart the game.

First, lets create a new file in your GTA5 folder where your GTA5.exe is located. Name it "VehicleColor.ini". Make sure the file ends with .ini and not .txt.
 Open the file and add this:

[Vehicle_Color]
red=50
green=50
blue=200

Save the file and start Visual Studio. For this new project you need a new copy of the Script Hook SDK. You can go back and watch the installation tutorial that Johnny Manson made if you like, linked to in my last post.

Inside the SDK, open up the project called "NativeTrainer.sln" inside the samples folder. Now, replace everything inside the "script.cpp" file with the code here.

With this simple mod we want to change the color of the vehicle we are currently using. So we need to get a reference to the players car. Replace this line "PED::SET_PED_CAN_BE_DRAGGED_OUT(playerPed, false);"
with
if (PED::IS_PED_IN_ANY_VEHICLE(PLAYER::PLAYER_PED_ID(), true)){
Vehicle playerVeh;
}

Now we need the RGB values from our .ini file so that we can paint our vehicle.

Add these values and function to the top of the script.

int red, green, blue;

void updateConfigValues(){
    red = GetPrivateProfileInt("Vehicle_Color", "red", -1, ".\\VehicleColor.ini");
    green = GetPrivateProfileInt("Vehicle_Color", "green", -1, ".\\VehicleColor.ini");
    blue = GetPrivateProfileInt("Vehicle_Color", "blue", -1, ".\\VehicleColor.ini");
}

Now it's time to do something with our RGB value.

VEHICLE::SET_VEHICLE_CUSTOM_PRIMARY_COLOUR(playerVeh, red, green, blue);
VEHICLE::SET_VEHICLE_CUSTOM_SECONDARY_COLOUR(playerVeh, red, green, blue);
VEHICLE::SET_VEHICLE_TYRE_SMOKE_COLOR(playerVeh, red, green, blue);    VEHICLE::_SET_VEHICLE_NEON_LIGHTS_COLOUR(playerVeh, red, green, blue);

There's no need to run this too often so we tell the script to wait for 2 seconds. Under update_features(); in the while loop add "WAIT(2000);"

Now it should look something like this

Now when you're done, build the solution in Visual Studio and place the .asi file into your GTA5 folder where your GTA5.exe is located. TAB down during gameplay, open up your VehicleColor.ini file and change the three numbers/colors to something else (0-255). Save the file and TAB back into the game. Your vehicles color should now have been changed.

Now it's time to test it and add more code to it. :)

Writing to a file is pretty straight forward, it looks something like this:

WritePrivateProfileString(TEXT("Vehicle_Color"),
    TEXT("red"),
    TEXT("255"),
    TEXT(".\\VehicleColor.ini");
    }

Next post about support for keyboard and controller http://mwasteson.blogspot.se/2015/07/gta-v-scripting-pc-part-3-keyboard-and.html

How to make scripts for GTA V PC

Scripting mods for GTA V is actually quite easy. I will show you how to create some neat stuff. First, let's watch this GTA V scripting tutorial made by Johnny Manson, about how to get started and making your first script.


Johnny is directly using C++ to code with. You can also add scripts that let you write in .NET and LUA. In this tutorial we will only write in C++

So, Jonny gave us a template to start with. I made it even smaller and you can check it out here: code.
Mods are of course usually larger. You can remove the line "PED::SET_PED_CAN_BE_DRAGGED_OUT(playerPed, false);" and replace with something else.
Download the latest Script Hook SDK and replace everything in the file "script.cpp" with the contents of code.

Before you TAB down from the game to make changes in your code in visual studio, hold CTRL and press R. A small beep will sound which means that all mods are inactivated. You can now create a new version of your mod and replace the old one with it. When you're done press CTRL+R again to reload all your mods. You should hear three beeps. Note that for this to work you need an empty file named "ScripthookV.dev" in your game folder.

When you start scripting you need some sources and information about how to do different things. The above all most important source is Alexander Blades http://www.dev-c.com with the native database /nativedb/. Not everything is known about how functions work or which parameters are used. Sometimes you need to guess or try and error.

When your mod is ready for it's first release you can publish it on sites like gta5-mods.com and gtainside.com.

In the next post we will look into how to read and write to configuration files (.ini).





fredag 20 juni 2014

Revive your old computer, with Chromium OS

Do you only need your computer to browse the web? Then Chromium OS might be for you.

Chromium OS is a lightweight and fast operating system focused entirely on the web and basically is a web-browser. Chromium OS is the open source version of the operating system found in Chromebooks, Chrome OS.

How to get it

You need to get Chromium OS bootable from a USB-stick. You will need to download a ISO-file for this and burn it to a 4 GB or bigger USB-memory stick.

Arnold the bat makes Chromium OS builds and is very active in releasing new versions.

WiFi supported version: If you are dependable on a wireless network card. This version is from the end of 2013:
http://chromium.arnoldthebat.co.uk/special/Cx86OS_R33-5111_broadcom.7z

Latest version, but might not work with your wireless network card:
http://chromium.arnoldthebat.co.uk/index.php?dir=daily%2F Take the x86 version if you are unsure which to choose.

Now you need to burn your ISO- file to an USB-memory stick. Just Google how to do this. For example, in Windows you can use Win32 image burner: http://sourceforge.net/projects/win32diskimager/

Start Chromium OS

You need to boot (start) your computer from the USB-memory stick that you just put Chromium OS on. You can Google how to do this. Insert the USB-memory stick into the computer and start. You should now repeatedly press F12 (key may vary depending on model) until a menu with start options appear. Choose the USB-memory stick and press Enter. Chromium OS should now start.

If Chromium OS doesn't start but instead halt with a error message try this:
Press Esc repeatedly after choosing USB-memory stick in the start option menu. "aborted. boot:" will now be shown on the screen. Press Tab and then type this command:

chromeos-usb.A root=/dev/sdc3
Still wont work? Try changing the c in sdc3 to b,d, etc:
chromeos-usb.A root=/dev/sdb3  

Install Chromium OS to your harddrive

This is optional. You can continue to run Chromium OS from your USB-memory stick if you want. When installing Chromium OS to your harddrive all data (files) will be lost! Make sure you have made a backup of your files before doing this.

Press Ctrl + Alt + F2 to get to command line (Ctrl + Alt + F1 to get back). Login as chronos with the password "password". Type this command to install: 
sudo /usr/sbin/chromeos-install
If this doesn't work you can go head and copy the whole USB-installation to your harddrive. You may for example get an error message like "Source does not look like a removable device".
dd if=/dev/sda of=/dev/sdb conv=notrunc

Get WiFi to work on the broadcom version

Make sure you are logged in to Chromium OS. To do this and to access the Internet you have to connect your computer to a Internetconnected ethernetcable. Download this sh-file: http://www.speedyshare.com/JsXqS/broadcom.sh (from the link on the website). Now go to the command line and log in as mentioned above. Type these commands:
sudo su
mount -o remount, rw /
cd /home/chronos/user/Downloads
sh broadcom.sh

Install plugins (Flash, Hangouts, PDF, Netflix, MP3, MP4)

Make sure you are logged in to Chromium OS. Then right click on the link below and click on save link/target as.
https://gist.github.com/rikels/4031126/raw/a76eb212f9dbc3c59b0799020ff0be16906fd889/data.sh

Now go to the command line and login as mentioned above. Type these commands: 
sudo su
cd /home/chronos/user/Downloads
sh data.sh

To check if the plugins installed successfully go to chrome://plugins/. I haven't got Netflix to work. If you have found a way please let us know.

Get the touchpad to work
If the touchpad isn't working for you have a go with these commands:
sudo su
wget -qO- http://goo.gl/1VWycc | sh

Upgrade to Chrome OS

If you don't mind the WiFi and instead go with Ethernet then this might be for you. Note that all data will be lost. Type these commands:
sudo su
bash <(curl -s -L http://goo.gl/eIAcL5)
Now choose a version number to upgrade. The upgrade is fast and you can try different versions to find one that works for you.

Sources

http://arnoldthebat.co.uk/
https://gist.githubusercontent.com/rikels/4031126/raw/a76eb212f9dbc3c59b0799020ff0be16906fd889/data.sh%20
https://github.com/zhaostu/chromium-os-touchpad
http://zzsethzz.blogspot.se/2013/02/install-chromium-upgrade-it-to-chrome.html