C# Sharp Help - Alien Shape Shifting Script
-
For fun only, I cobbled together a very short script that allows the player to change his/her model to that of the closest ped on a key bind. The code is actually a bit longer because the player will also take on exactly the same clothes as the ped.
So as you get within a pre-defined (hard coded) radius of a ped, hitting the key will change to that model with its ped components (I didn't add accessories but I could ofc).
However if you are out of the radius, for example too far, the player will become invisible until back in radius and with a second key press. Can I trap and prevent this and how? Currently I check 2 conditions, does the ped exist (which I thought would trap this) and the ped is not the player. I don't check for ped is alive, the script will change the model even with a dead ped which is fine by me anyway. Allows Alien to kill ped and take over their shape.
In the video i set the radius high to avoid the invisible issue.
-
Got the source code?
-
@ikt Hi. SHVDN3. Can be key bound as in video but code below is triggered as LemonUI selection.
private void ChangeClosestToCurrent(object sender, EventArgs e) { Vector3 PlayerPosition = Game.Player.Character.GetOffsetPosition(new Vector3(0.0f, 10f, 0.0f)); Ped ClosestPed = World.GetClosestPed(PlayerPosition, 15.0f); if (ClosestPed.Exists() && ClosestPed != Game.Player.Character) CurrentPed = ClosestPed; ChangePlayerToCurrent(); }
-
Your problem is that you forgot to use curly braces {} for your if statement. It should look like this:
private void ChangeClosestToCurrent(object sender, EventArgs e) { Vector3 PlayerPosition = Game.Player.Character.GetOffsetPosition(new Vector3(0.0f, 10f, 0.0f)); Ped ClosestPed = World.GetClosestPed(PlayerPosition, 15.0f); if (ClosestPed.Exists() && ClosestPed != Game.Player.Character) { CurrentPed = ClosestPed; ChangePlayerToCurrent(); } }
When you don't use curly braces, only the very next statement will be included in the if statement, which would be the
CurrentPed = ClosestPed;
statement. TheChangePlayerToCurrent();
statement was not in the if statement.
-
@Jitnaught Beginner mistake. Thanks again once more!
-
@JohnFromGWN Looking forward to seeing this mod in the wild.
-
@Bet-Nimrod Not a mod. If interested I'll post the complete code here so it can just be dropped in the scripts folder.
-
@JohnFromGWN A script isn't a mod?
-
@Bet-Nimrod It is. I believe he means it won't be an uploaded mod, a mod meant for others, etc.
-
@Jitnaught Oh.
-
Exactly. Not a mod as in for distribution, just for personal use - free roam/sandboxing. Can be run on keybind or attached to menu.
-
@JohnFromGWN Sandbox is exactly what I use the game for.
-
@Bet-Nimrod That's all I do. Never played the game, only 1 or 2 missions. I created my own Menu with LemonUI (still have Menyoo as well) which allows me 100% customization on teleport locations, vehicles, and peds - all customized at spawn and further customizable through my Menu or Menyoo. The additional scripting (ped tasks) is for fun and to improve my scripting skills. I also created a completely new file structure where I have 9 or 10 different Mod folders (Liberty City, San Andreas, Chicago, Dubai, Cayo Perico, Spa, etc) all sharing the same game files and same DLC folder - all this to ensure stability and minimize file duplication and maintenance.
I launch, modify, all from a mega batch file (Dos).
-
I've played the story twice, a few years apart.