Dear forum users! In compliance with the new European GDPR regulations, we'd just like to inform you that if you have an account, your email address is stored in our database. We do not share your information with third parties, and your email address and password are encrypted for security reasons.

New to the forum? Say hello in this topic! Also make sure to read the rules.

A script to get the total amount of dmg a player has taken

Here you can find answered ScriptAPI topics.
Forum rules
By using the forum you agree to the following rules.
Post Reply
jamisco
Superfighter
Superfighter
Posts: 67
Joined: Sun Nov 06, 2016 11:34 pm
Title: Da God
SFD Account: Jamisco
SFD Alias: Jamisco
Started SFD: either late 2015 or early 2016
Location: Somewhere in the east of the United states
Gender:
Age: 103

A script to get the total amount of dmg a player has taken

Post by jamisco » Mon Feb 20, 2017 7:07 pm

So far here is mine ...

public void GetPlayer() // get player is just a normal method that will be called somewhere else..fyi
{

foreach (IPlayer playr in Game.GetPlayers())
{
IPlayerStatistics dmg1 = null;

float dmg = dmg1.TotalDamageTaken;

Game.ShowPopupMessage(dmg.ToString());

}
}

now my problem here is in the line ..IPlayerStatistic dmg1 = null; ..... if i were to run this in the game, i get an error msg. this error message .....

Script Error
Error in method 'Profiles(TriggerArgs)' in map script. See the exception for more details:
/* btw the reason it says in method 'Profiles(TriggerArgs)" is because the method GetPlayer() was called in a Method Profiles (TriggerArgs)*/
--- Exception ---
Object reference not set to an instance of an object.
System.NullReferenceException: Object reference not set to an instance of an object.
at SFDScript.GameScript.GetPlayer()
at SFDScript.GameScript.Profiles(TriggerArgs pro)

now my problem is if i don't use null to initialize "IPlayerStatistic dmg1", then i cant write any line of code having to do with this statement ... "dm1.TotalDamageTaken" because i get the error code CS0165 .. which is an error code in visual studio meaning the dmg1 was never initialized. Additionally, i tried doing this dmg = dmg.TotalDamageTaken; ... but it said it cant convert from float to IPlayerStatistics since IPlayerStatics is a type and i doubt it has a parse method... so any one of you guys got a workaround for this. It would be great if you answer would be an improvement on my code but i don't mind if you have to create a whole new code. Thanks
0 x
Is it better to be feared or respected... please, is it too much to ask for both?

User avatar
ShutDownMan
Fighter
Fighter
Posts: 32
Joined: Sat Mar 19, 2016 7:17 pm
Title: Yeah, science!
SFD Alias: ShutDownMan, Devil Shut
Started SFD: 1.2.something
Location: Hu3, Brazil
Gender:
Age: 24
Contact:

Post by ShutDownMan » Mon Feb 20, 2017 10:09 pm

You can't get a property of a null value...

if:
IPlayerStatistics dmg1 = null;

then
float dmg = dmg1.TotalDamageTaken;
is the same as saying:
float dmg = null.TotalDamageTaken;

the fix is simple just replace your "IPlayerStatistics dmg1 = null;" with:
IPlayerStatistics dmg1 = playr.Statistics;

(try to use proper variable naming)
1 x
~ShutDownMan

Post Reply