I'm a non-programmer and absolute beginner using C#. I'm using C#.NET with VS 2019 to modify the video game GTA5 for scholastic purposes (albeit without the violence and swearing). I'm progressing well but would like some help with a new challenge. I have successfully written code below, that allows me on one key press to change the player in the game to another character - so this character becomes the player. For example I press L.
Pressing a second key binding, for example O, will allow me to go back to the original player. I currently have this working with two similar functions, each assigned a key press.
But if I press the same key twice it will freeze the game. I believe this happens because the game thinks there isn't any player.
I need help to prevent the error through a conditional statement, I suppose. Ideally it would be great if I could toggle from player to the other character and back again with only one key press? My code which works using what are called native functions of the RAGE game engine. Please ignore the last 2 booleans they are not relevant. In passing, the GTA5 community is quite dead with respect to coding which is why I'm here.
In summary I'm asking for help as to how to initialize the Teacher as player, and then if i hit the key again it goes to Student. Next key press would be back to Teacher.
My knowledge is very limited, my day job is a teacher. This project is to help my students learn through gaming as the pandemic has been very difficult for education.
if (e.KeyCode == Keys.L) //Switch from Player Teacher at start to new Player Student
{
Teacher = Game.Player.Character;
Function.Call(Hash.CHANGE_PLAYER_PED, Game.Player, Student, true, true); //Change Player Ped means change the Player to the student
}
if (e.KeyCode == Keys.O) //Switch from Student current player to Original Player Teacher
{
Student = Game.Player.Character;
Function.Call(Hash.CHANGE_PLAYER_PED, Game.Player, Teacher, true, true); //Change Player Ped here means change the Player back to the teacher
}
Pressing a second key binding, for example O, will allow me to go back to the original player. I currently have this working with two similar functions, each assigned a key press.
But if I press the same key twice it will freeze the game. I believe this happens because the game thinks there isn't any player.
I need help to prevent the error through a conditional statement, I suppose. Ideally it would be great if I could toggle from player to the other character and back again with only one key press? My code which works using what are called native functions of the RAGE game engine. Please ignore the last 2 booleans they are not relevant. In passing, the GTA5 community is quite dead with respect to coding which is why I'm here.
In summary I'm asking for help as to how to initialize the Teacher as player, and then if i hit the key again it goes to Student. Next key press would be back to Teacher.
My knowledge is very limited, my day job is a teacher. This project is to help my students learn through gaming as the pandemic has been very difficult for education.
if (e.KeyCode == Keys.L) //Switch from Player Teacher at start to new Player Student
{
Teacher = Game.Player.Character;
Function.Call(Hash.CHANGE_PLAYER_PED, Game.Player, Student, true, true); //Change Player Ped means change the Player to the student
}
if (e.KeyCode == Keys.O) //Switch from Student current player to Original Player Teacher
{
Student = Game.Player.Character;
Function.Call(Hash.CHANGE_PLAYER_PED, Game.Player, Teacher, true, true); //Change Player Ped here means change the Player back to the teacher
}
Last edited: