when i access a member an exception occurs. (CTrackManiaPlayer.RaceState)
Code: Select all
ERaceState currentRaceState = player.RaceState;
this happens when a map is loaded and switching to ERaceState::BeforeStart or the script is started while in race.
I'm using this Code:
Code: Select all
#name "Gauge"
#author "Derfuhr aka ClumsySmurf"
#category "Clumsy's Plugins"
bool debug = true; // developer option
[Setting name="Active" description="Addon activation-state"]
bool active = false;
[Setting name="Position X" description="base position X"]
float positionX = 500.0f;
[Setting name="Position Y" description="base position Y"]
float positionY = 150.0f;;
[Setting name="Color R" description="Color R value"]
float r = 1.0f;
[Setting name="Color G" description="Color G value"]
float g = 0.0f;
[Setting name="Color B" description="Color B value"]
float b = 0.0f;
[Setting name="Color A" description="Color A value"]
float a = 1.0f;
bool windowIsVisible = false;
bool raceIsRunning = false;
int speed = 0;
string login = "";
void main()
{
}
void RenderMenu()
{
if (UI::MenuItem("Gauge", "", active))
{
windowIsVisible = !windowIsVisible;
}
}
void Render()
{
if(active || UI::IsOverlayShown())
{
CGameCtnApp@ app = cast<CGameCtnApp>(GetApp());
if(app !is null)
{
CGamePlayerProfile@ CurrentProfile = app.CurrentProfile;
if(CurrentProfile !is null)
{
CGamePlayerProfileChunk_AccountSettings@ AccountSettings = CurrentProfile.AccountSettings;
if(AccountSettings !is null)
{
login = AccountSettings.OnlineLogin;
if(login != "")
{
CTrackManiaRaceNew@ PlaygroundScript = cast<CTrackManiaRaceNew>(app.CurrentPlayground);
if(PlaygroundScript !is null)
{
MwBuffer<CGamePlayer@> Players = PlaygroundScript.Players;
for(uint i = 0; i < Players.get_Length(); i++)
{
CTrackManiaPlayer@ player = cast<CTrackManiaPlayer>(Players[i]);
if(player !is null)
{
CTrackManiaPlayerInfo@ playerInfo = cast<CTrackManiaPlayerInfo>(player.User);
if(playerInfo.Login == login)
{
//raceIsRunning = (player.RaceState == ERaceState::Running)
ERaceState currentRaceState = player.RaceState;
//if(state == player.RaceState)
//{
//raceIsRunning = true;
//}
//else
//{
//raceIsRunning = false;
//}
//speed = player.DisplaySpeed;
}
}
else
{
onError("player null");
}
}
}
else
{
onError("PlaygroundScript null");
}
}
else
{
onError("Login string empty");
}
}
else
{
onError("accountsetting null");
}
}
else
{
onError("CurrentProfile null");
}
}
else
{
onError("app null");
}
if((active && raceIsRunning) || (UI::IsOverlayShown() && windowIsVisible))
{
vec2 pos = vec2(positionX, positionY);
vec4 color = vec4(r, g, b, a);
//Drawing.....
}
}
}
void RenderInterface()
{
if(!windowIsVisible)
{
return;
}
UI::SetNextWindowPos(40, 40);
UI::SetNextWindowSize(350, 350);
UI::Begin("Gauge by ClumsySmurf", windowIsVisible, UI::WindowFlags::NoResize);
active = UI::Checkbox("Plugin active", active);
UI::Text("Position: (Center of the Gauge)");
positionX = UI::InputFloat("X", positionX, 0.5f);
positionY = UI::InputFloat("Y", positionY, 0.5f);
positionX = checkRange(positionX, 0.0f, float(Draw::GetWidth()));
positionY = checkRange(positionY, 0.0f, float(Draw::GetHeight()));
UI::Text("Color:");
r = UI::InputFloat("R", r, 0.001f);
g = UI::InputFloat("G", g, 0.001f);
b = UI::InputFloat("B", b, 0.001f);
a = UI::InputFloat("A", a, 0.001f);
r = checkRange(r, 0.0f, 1.0f);
g = checkRange(g, 0.0f, 1.0f);
b = checkRange(b, 0.0f, 1.0f);
a = checkRange(a, 0.0f, 1.0f);
UI::End();
}
int checkRange(int value, int min, int max)
{
if(value < min)
{
value = min;
}
if(value > max)
{
value = max;
}
return value;
}
float checkRange(float value, float min, float max)
{
if(value < min)
{
value = min;
}
if(value > max)
{
value = max;
}
return value;
}
void onError(string text)
{
if(debug)
{
print(text);
}
}