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.

Need help to make a script!!!

Here you can find answered ScriptAPI topics.
Forum rules
By using the forum you agree to the following rules.
Post Reply
User avatar
Mr Argon
Fighter
Fighter
Posts: 56
Joined: Sat Mar 09, 2019 2:22 am
SFD Account: Argón (steam)
SFD Alias: Mr. Argon
Started SFD: Pre-Alpha 1.8.2c
Location: Argentina
Gender:
Age: 20

Need help to make a script!!!

Post by Mr Argon » Sat Mar 09, 2019 3:09 am

Hi! This is my first post :D

Well... I'm making a custom campaign, and I configured it to set player profiles just like the tutorial (keeping the user's gender and skin)

It works very well on all bots except for "Benny" (and eventually any other player who has zombie, mech or frankenbear skin)

I copied a piece of the tutorial script, and then wrote another part.

My idea was to make Benny keep his bear skin instead of getting dressed with my custom profile, but it doesn't works. It keep spawning with all these clothes overlapping his bear skin (looks very bad)

This is all I have in the script editor, I'm just learning c# so I'm probably doing it a strange, difficult or dumb way...

Hope you can help me
private IPlayer player1 = null;
private IPlayer player2 = null;
private IPlayer player3 = null;
private IPlayer player4 = null;

private IProfile profile1 = null;
private IProfile profile2 = null;
private IProfile profile3 = null;
private IProfile profile4 = null;

private IProfile BearProfile = null;

public void OnStartup()
{
	player1 = Game.GetPlayers()[0];
	player2 = Game.GetPlayers()[1];
	player3 = Game.GetPlayers()[2];
	player4 = Game.GetPlayers()[3];
	
	profile1 = (Game.GetSingleObjectByCustomID("Profile1") as IObjectPlayerProfileInfo).GetProfile();
	profile2 = (Game.GetSingleObjectByCustomID("Profile2") as IObjectPlayerProfileInfo).GetProfile();
	profile3 = (Game.GetSingleObjectByCustomID("Profile3") as IObjectPlayerProfileInfo).GetProfile();
	profile4 = (Game.GetSingleObjectByCustomID("Profile4") as IObjectPlayerProfileInfo).GetProfile();

	BearProfile = (Game.GetSingleObjectByCustomID("BearProfile") as IObjectPlayerProfileInfo).GetProfile();

if (player1.GetProfile().Skin != BearProfile.Skin)
{
	IProfile newprofile1 = (Game.GetSingleObjectByCustomID("Profile1") as IObjectPlayerProfileInfo).GetProfile();
	newprofile1.Gender = player1.GetProfile().Gender;
	newprofile1.Skin = player1.GetProfile().Skin;
	profile1 = newprofile1;
	player1.SetProfile(newprofile1);
}
else if (player1.GetProfile().Skin == BearProfile.Skin)
{
	player1.SetProfile(BearProfile);
}

if (player2.GetProfile().Skin != BearProfile.Skin)
{
	IProfile newprofile2 = (Game.GetSingleObjectByCustomID("Profile2") as IObjectPlayerProfileInfo).GetProfile();
	newprofile2.Gender = player2.GetProfile().Gender;
	newprofile2.Skin = player2.GetProfile().Skin;
	profile2 = newprofile2;
	player2.SetProfile(newprofile2);
}
else if (player2.GetProfile().Skin == BearProfile.Skin)
{
	player2.SetProfile(BearProfile);
}

if (player3.GetProfile().Skin != BearProfile.Skin)
{
	IProfile newprofile3 = (Game.GetSingleObjectByCustomID("Profile3") as IObjectPlayerProfileInfo).GetProfile();
	newprofile3.Gender = player3.GetProfile().Gender;
	newprofile3.Skin = player3.GetProfile().Skin;
	profile3 = newprofile3;
	player3.SetProfile(newprofile3);
}
else if (player3.GetProfile().Skin == BearProfile.Skin)
{
	player3.SetProfile(BearProfile);
}

if (player4.GetProfile().Skin != BearProfile.Skin)
{
	IProfile newprofile4 = (Game.GetSingleObjectByCustomID("Profile4") as IObjectPlayerProfileInfo).GetProfile();
	newprofile4.Gender = player4.GetProfile().Gender;
	newprofile4.Skin = player4.GetProfile().Skin;
	profile4 = newprofile4;
	player4.SetProfile(newprofile4);
}
else if (player4.GetProfile().Skin == BearProfile.Skin)
{
	player4.SetProfile(BearProfile);
}

}
0 x
I'м д Liттlэ оdd... sтill саи livе шiтн тнат.

User avatar
Sree
Superfighter
Superfighter
Posts: 325
Joined: Sun May 08, 2016 8:19 pm
SFD Account: phasmic
SFD Alias: sree
Gender:
Age: 23

Post by Sree » Sat Mar 09, 2019 7:30 am

a good workaround is to just put the check on the skin names.

Code: Select all

if (player1.GetProfile().Skin.Name != BearProfile.Skin.Name)
{
	// rest
}
else 
{
	player1.SetProfile(BearProfile);
}
Off Topic
btw, if you are going to just use those profile instances once in the entire script, you could shorten the script much further using loops.

Code: Select all

public void OnStartup()
{   
        var bear = (Game.GetSingleObjectByCustomID("BearProfile") as IObjectPlayerProfileInfo).GetProfile();

	for (int i = 0; (i < Game.GetPlayers().Length && i < 4); i++)
	{
		var pr = (Game.GetSingleObjectByCustomID(String.Format("Profile{0}", i + 1)) as IObjectPlayerProfileInfo).GetProfile();

		var ply = Game.GetPlayers()[i];

		if (ply.GetProfile().Skin.Name != bear.Skin.Name)
                {
                        pr.Gender = ply.GetProfile().Gender;
			pr.Skin = ply.GetProfile().Skin;
			ply.SetProfile(pr);
                }
		else
		{
			ply.SetProfile(bear);
		}
	}				
}
2 x

User avatar
Mr Argon
Fighter
Fighter
Posts: 56
Joined: Sat Mar 09, 2019 2:22 am
SFD Account: Argón (steam)
SFD Alias: Mr. Argon
Started SFD: Pre-Alpha 1.8.2c
Location: Argentina
Gender:
Age: 20

Post by Mr Argon » Sat Mar 09, 2019 11:01 pm

Thank you very much! It works perfectly! I guess I can finish my campaign now...

PD: Sorry for my english level, I'm from Argentina, that means I'm not a native speaker, but I think it's ok...
0 x
I'м д Liттlэ оdd... sтill саи livе шiтн тнат.

Post Reply