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.

How to Apply Clothes in This Script

Here you can find answered ScriptAPI topics.
Forum rules
By using the forum you agree to the following rules.
Post Reply
MrWheatley
Fighter
Fighter
Posts: 13
Joined: Wed Jun 06, 2018 7:36 am

How to Apply Clothes in This Script

Post by MrWheatley » Tue Jun 26, 2018 8:05 pm

So I modded this class script to work because it was made before the GetBorderArea change and was wondering how would I apply a custom profile to each class. I already wrote all the clothing items. Also, is it possible to change a player's name temporarily in game to something like, "Red Spy" when they press a button? Thanks.

Code: Select all

public const int MAXTIME = 20; //max time allowed to choose a class 

public enum CharType { Scout, Soldier, Pyro, Demo, Heavy, Engineer, Medic, Sniper, Spy, NONE };

public class PlayerData
{

    public IPlayer player { get; private set; }
    public IUser user { get; private set; }
    public PlayerTeam team { get; private set; }
    public CharType characterClass { get; set; }

    public PlayerData (IPlayer in_player)
    {
        this.player = in_player;
        this.team = in_player.GetTeam ();
        this.user = in_player.GetUser ();
        this.characterClass = CharType.NONE;
    }

    public void GiveWeapon ()
    {
        WeaponItem[] weps = { };
        switch (this.characterClass)
        {

            case CharType.Scout:
                IProfile ScoutProfile = new IProfile ();
                ScoutProfile.Accesory = new IProfileClothingItem ("DogTag", "ClothingGray");
                ScoutProfile.Head = new IProfileClothingItem ("Cap", "ClothingGray");
                ScoutProfile.ChestOver = new IProfileClothingItem ("None", "ClothingGray");
                ScoutProfile.ChestUnder = new IProfileClothingItem ("TShirt", "ClothingRed");
                ScoutProfile.Hands = new IProfileClothingItem ("FingerlessGloves", "ClothingLightGray");
                ScoutProfile.Legs = new IProfileClothingItem ("Pants", "ClothingGray");
                ScoutProfile.Feet = new IProfileClothingItem ("ShoesBlack", "ClothingLightGray");
                weps = new WeaponItem[] { WeaponItem.SAWED_OFF, WeaponItem.PISTOL, WeaponItem.BAT };
                break;

            case CharType.Soldier:
                IProfile SoldierProfile = new IProfile ();
                SoldierProfile.Accesory = new IProfileClothingItem ("Cigar", "ClothingDarkGray");
                SoldierProfile.Head = new IProfileClothingItem ("Helmet2", "ClothingGray");
                SoldierProfile.ChestOver = new IProfileClothingItem ("GrenadeBelt", "ClothingGray");
                SoldierProfile.ChestUnder = new IProfileClothingItem ("Shirt", "ClothingRed");
                SoldierProfile.Hands = new IProfileClothingItem ("None", "ClothingLightGray");
                SoldierProfile.Legs = new IProfileClothingItem ("PantsBlack", "ClothingDarkGray");
                SoldierProfile.Feet = new IProfileClothingItem ("BootsBlack", "ClothingDarkGray");
                weps = new WeaponItem[] { WeaponItem.BAZOOKA };
                break;

            case CharType.Pyro:
                IProfile PyroProfile = new IProfile ();
                PyroProfile.Accesory = new IProfileClothingItem ("GasMask2", "ClothingDarkGray", "ClothingLightGray");
                PyroProfile.Head = new IProfileClothingItem ("None", "ClothingGray");
                PyroProfile.ChestOver = new IProfileClothingItem ("GrenadeBelt", "ClothingGray");
                PyroProfile.ChestUnder = new IProfileClothingItem ("Shirt", "ClothingRed");
                PyroProfile.Hands = new IProfileClothingItem ("Gloves", "ClothingDarkGray");
                PyroProfile.Legs = new IProfileClothingItem ("Pants", "ClothingDarkRed");
                PyroProfile.Feet = new IProfileClothingItem ("BootsBlack", "ClothingDarkGray");
                weps = new WeaponItem[] { WeaponItem.FLAMETHROWER, WeaponItem.FLAREGUN, WeaponItem.AXE };
                break;

            case CharType.Demo:
                IProfile DemoProfile = new IProfile ();
                DemoProfile.Accesory = new IProfileClothingItem ("None", "ClothingDarkGray");
                DemoProfile.Head = new IProfileClothingItem ("Beret", "ClothingGray", "ClothingGray");
                DemoProfile.ChestOver = new IProfileClothingItem ("GrenadeBelt", "ClothingGray");
                DemoProfile.ChestUnder = new IProfileClothingItem ("Shirt", "ClothingRed");
                DemoProfile.Hands = new IProfileClothingItem ("None", "ClothingLightGray");
                DemoProfile.Legs = new IProfileClothingItem ("Pants", "ClothingDarkRed");
                DemoProfile.Feet = new IProfileClothingItem ("BootsBlack", "ClothingDarkGray");
                weps = new WeaponItem[] { WeaponItem.GRENADE_LAUNCHER, WeaponItem.BOTTLE, WeaponItem.MINES };
                break;

            case CharType.Heavy:
                IProfile HeavyProfile = new IProfile ();
                HeavyProfile.Accesory = new IProfileClothingItem ("None", "ClothingDarkGray");
                HeavyProfile.Head = new IProfileClothingItem ("None", "ClothingGray");
                HeavyProfile.ChestOver = new IProfileClothingItem ("AmmoBelt", "ClothingDarkGray");
                HeavyProfile.ChestUnder = new IProfileClothingItem ("TShirt", "ClothingRed");
                HeavyProfile.Hands = new IProfileClothingItem ("FingerlessGloves", "ClothingDarkGray");
                HeavyProfile.Legs = new IProfileClothingItem ("Pants", "ClothingGray");
                HeavyProfile.Feet = new IProfileClothingItem ("BootsBlack", "ClothingDarkGray");
                weps = new WeaponItem[] { WeaponItem.M60 };
                break;

            case CharType.Engineer:
                IProfile EngineerProfile = new IProfile ();
                EngineerProfile.Accesory = new IProfileClothingItem ("Goggles", "ClothingDarkGray", "ClothingLightGray");
                EngineerProfile.Head = new IProfileClothingItem ("Helmet", "ClothingYellow");
                EngineerProfile.ChestOver = new IProfileClothingItem ("Vest", "ClothingLightBrown", "ClothingLightGray");
                EngineerProfile.ChestUnder = new IProfileClothingItem ("TShirt", "ClothingRed");
                EngineerProfile.Hands = new IProfileClothingItem ("Gloves", "ClothingYellow");
                EngineerProfile.Legs = new IProfileClothingItem ("Pants", "ClothingLightBrown");
                EngineerProfile.Feet = new IProfileClothingItem ("Boots", "ClothingDarkBrown");
                weps = new WeaponItem[] { WeaponItem.SHOTGUN, WeaponItem.PISTOL, WeaponItem.PIPE };
                break;

            case CharType.Medic:
                IProfile MedicProfile = new IProfile ();
                MedicProfile.Accesory = new IProfileClothingItem ("Glasses", "ClothingLightGray", "ClothingLightGray");
                MedicProfile.Head = new IProfileClothingItem ("BucketHat", "ClothingDarkRed", "ClothingYellow");
                MedicProfile.ChestOver = new IProfileClothingItem ("Coat", "ClothingLightGray", "ClothingDarkRed");
                MedicProfile.ChestUnder = new IProfileClothingItem ("ShirtWithBowtie", "ClothingLightGray", "ClothingRed");
                MedicProfile.Hands = new IProfileClothingItem ("Gloves", "ClothingRed");
                MedicProfile.Legs = new IProfileClothingItem ("Pants", "ClothingBrown");
                MedicProfile.Feet = new IProfileClothingItem ("BootsBlack", "ClothingDarkGray");
                weps = new WeaponItem[] { WeaponItem.TEAPOT };
                break;

            case CharType.Sniper:
                IProfile SniperProfile = new IProfile ();
                SniperProfile.Accesory = new IProfileClothingItem ("Glasses", "ClothingOrange", "ClothingLightGray");
                SniperProfile.Head = new IProfileClothingItem ("CowboyHat", "ClothingBrown", "ClothingDarkGray");
                SniperProfile.ChestOver = new IProfileClothingItem ("Vest", "ClothingBrown", "ClothingLightBrown");
                SniperProfile.ChestUnder = new IProfileClothingItem ("TShirt", "ClothingLightPurple");
                SniperProfile.Hands = new IProfileClothingItem ("FingerlessGloves", "ClothingLightBrown");
                SniperProfile.Legs = new IProfileClothingItem ("Pants", "ClothingDarkPurple");
                SniperProfile.Feet = new IProfileClothingItem ("Shoes", "ClothingDarkBrown");
                weps = new WeaponItem[] { WeaponItem.SNIPER, WeaponItem.MACHETE, WeaponItem.UZI };
                break;

            case CharType.Spy:
                IProfile SpyProfile = new IProfile ();
                SpyProfile.Accesory = new IProfileClothingItem ("Balaclava", "ClothingDarkRed");
                SpyProfile.Head = new IProfileClothingItem ("None", "ClothingBrown");
                SpyProfile.ChestOver = new IProfileClothingItem ("StripedSuitJacket", "ClothingDarkRed");
                SpyProfile.ChestUnder = new IProfileClothingItem ("ShirtWithTie", "ClothingLightGray", "ClothingDarkRed");
                SpyProfile.Hands = new IProfileClothingItem ("GlovesBlack", "ClothingDarkGray");
                SpyProfile.Legs = new IProfileClothingItem ("StripedPants", "ClothingDarkRed");
                SpyProfile.Feet = new IProfileClothingItem ("ShoesBlack", "ClothingDarkGray");
                weps = new WeaponItem[] { WeaponItem.KNIFE, WeaponItem.REVOLVER };
                break;
        }
        foreach (WeaponItem w in weps)
        {
            this.player.GiveWeaponItem (w);
        }
    }
}

public const float PI = 3.141592f;

public int time = MAXTIME;

public Dictionary<IPlayer, PlayerData> dataList = new Dictionary<IPlayer, PlayerData> ();
public List<Vector2> startingPositions = new List<Vector2> ();

public Random rnd = new Random ();

public Area mapCameraArea;
public Area mapBorderArea;

public void OnStartup ()
{
    foreach (IObject obj in Game.GetObjectsByName ("SpawnPlayer"))
    {
        startingPositions.Add (obj.GetWorldPosition ());
    }
    Game.SetMapType (MapType.Custom);
    InitializeMap ();
}

public void InitializeMap ()
{
    float f = Game.GetCameraMaxArea ().Top;
    Vector2 tempVec = new Vector2 (Game.GetCameraMaxArea ().Right + 500f, Game.GetCameraMaxArea ().Top + 500f);

    InitializeCamera (tempVec);

    CreateMap (tempVec);

    InitializePlayers (tempVec);
}

public void InitializeCamera (Vector2 tempVec)
{
    mapCameraArea = Game.GetCameraArea ();
    mapBorderArea = Game.GetCameraMaxArea ();
    Area tempArea = new Area (tempVec, new Vector2 (200f, 200f) + tempVec);
    Game.SetCameraArea (tempArea);
    Game.SetCameraArea (tempArea);
    Game.SetCurrentCameraMode (CameraMode.Dynamic);
    Game.SetCurrentCameraMode (CameraMode.Static);
}

public void CreateMap (Vector2 tempVec)
{
    Game.CreateObject ("Concrete01A", tempVec + new Vector2 (25f, 46f)).SetSizeFactor (new Point (29, 1));
    Game.CreateObject ("Concrete01A", tempVec + new Vector2 (25f, 146f)).SetSizeFactor (new Point (29, 1));
    Game.CreateObject ("Concrete02B", tempVec + new Vector2 (20f, 150f)).SetSizeFactor (new Point (1, 14));
    Game.CreateObject ("Concrete02C", tempVec + new Vector2 (20f, 42f));
    Game.CreateObject ("Concrete02A", tempVec + new Vector2 (20f, 152f));
    Game.CreateObject ("Concrete02B", tempVec + new Vector2 (252f, 150f)).SetSizeFactor (new Point (1, 14));
    Game.CreateObject ("Concrete02C", tempVec + new Vector2 (252f, 42f));
    Game.CreateObject ("Concrete02A", tempVec + new Vector2 (252f, 152f));

    CreateButtons (tempVec);

    CreateTimer (1000, 0, "TickTime", "ClassScriptClock");
}

public void CreateButtons (Vector2 tempVec)
{
    int i = 0;
    foreach (string name in Enum.GetNames (typeof (CharType)))
    {
        string str = name;
        if (name != "NONE")
        {
            Vector2 pos = tempVec + new Vector2 (40f + i * 24f, 70f);
            IObjectTrigger button = ((IObjectTrigger) Game.CreateObject ("Button00", pos));
            button.SetScriptMethod ("ChooseClass");
            button.CustomId = str;

            IObjectText label = (IObjectText) Game.CreateObject ("Text", pos + new Vector2 (-8f, 8f), PI / 4);
            label.SetText (str);

            i++;
        }
    }
}

public void InitializePlayers (Vector2 tempVec)
{
    foreach (IPlayer ply in Game.GetPlayers ())
    {
        ply.SetWorldPosition (tempVec + new Vector2 (100f, 100f));
        dataList.Add (ply, new PlayerData (ply));
    }
}

public void ChooseClass (TriggerArgs args)
{
    IPlayer ply = (IPlayer) args.Sender;
    PlayerData data = dataList[ply];
    data.characterClass = (CharType) Enum.Parse (typeof (CharType), ((IObject) args.Caller).CustomId);

    CheckStartGame ();
}

public void TickTime (TriggerArgs args)
{
    time--;
    Game.ShowPopupMessage ("Choose a class ! Time remaining : " + time + "s");
    CheckStartGame ();
}

public void CheckStartGame ()
{
    bool start = true;
    foreach (PlayerData data in dataList.Values)
    {
        if (data.characterClass == CharType.NONE && !data.player.IsDead) start = false;
    }
    if (time < 0) start = true;
    if (start) StartGame ();
}

public void StartGame ()
{
    Game.GetSingleObjectByCustomId ("ClassScriptClock").Remove ();
    Game.ShowPopupMessage ("Let the fight begins !");
    CreateTimer (5000, 1, "HidePopupMessage", "");

    EquipPlayers ();
    SetBackCamera ();
    Game.SetMapType (MapType.Versus);
}

public void EquipPlayers ()
{
    //Wether or not spawns are present on the map
    bool nostart = false;
    if (startingPositions.Count <= 0)
    {
        nostart = true;
    }
    foreach (IPlayer ply in Game.GetPlayers ())
    {
        if (!ply.IsDead)
        {
            PlayerData data = dataList[ply];
            data.GiveWeapon ();
            Vector2 v;
            if (nostart)
            {
                v = new Vector2 ();
            }
            else
            {
                // === all spawn as already been used ===
                if (startingPositions.Count <= 0)
                {
                    foreach (IObject obj in Game.GetObjectsByName ("SpawnPlayer"))
                    {
                        startingPositions.Add (obj.GetWorldPosition ());
                    }
                }
                v = startingPositions[rnd.Next (startingPositions.Count)];
            }
            ply.SetWorldPosition (v);
            startingPositions.Remove (v);
        }
    }
}

public void SetBackCamera ()
{
    Game.SetCameraArea (mapCameraArea);
    Game.SetCameraArea (mapBorderArea);
    Game.SetCurrentCameraMode (CameraMode.Dynamic);
    Game.SetCurrentCameraMode (CameraMode.Static);
}

private void CreateTimer (int interval, int count, string method, string id)
{
    IObjectTimerTrigger timerTrigger = (IObjectTimerTrigger) Game.CreateObject ("TimerTrigger");
    timerTrigger.SetIntervalTime (interval);
    timerTrigger.SetRepeatCount (count);
    timerTrigger.SetScriptMethod (method);
    timerTrigger.CustomId = id;
    timerTrigger.Trigger ();
}

public void HidePopupMessage (TriggerArgs args)
{
    Game.HidePopupMessage ();
}
0 x

User avatar
Gurt
Lead Programmer
Lead Programmer
Posts: 1884
Joined: Sun Feb 28, 2016 3:22 pm
Title: Lead programmer
Started SFD: Made it!
Location: Sweden
Gender:
Age: 34

Post by Gurt » Wed Jun 27, 2018 7:46 pm

You can not change a player's name that's controlled by a real user.
Changing a bot's name will be possible in the release version.
0 x
Gurt

MrWheatley
Fighter
Fighter
Posts: 13
Joined: Wed Jun 06, 2018 7:36 am

Post by MrWheatley » Sat Jun 30, 2018 6:59 pm

Nvm, I figured it out. But what I can't figure out is how to change the skin color.
0 x

User avatar
JakSparro98
Superfighter
Superfighter
Posts: 530
Joined: Fri Jul 15, 2016 7:56 pm
Started SFD: PreAlpha 1.0.5
Location: Rome, Italy
Gender:
Age: 25

Post by JakSparro98 » Wed Jul 04, 2018 5:59 pm

MrWheatley wrote:
Sat Jun 30, 2018 6:59 pm
Nvm, I figured it out. But what I can't figure out is how to change the skin color.
The Skin attribute in the IProfile class can change the skin color, you need to copy the current player profile, change the copy and then re-assing the latter to the player with SetProfile. You will only get the skin color changed keeping the clothings.

Provide your current code if you need help about implementing this function.
0 x

MrWheatley
Fighter
Fighter
Posts: 13
Joined: Wed Jun 06, 2018 7:36 am

Post by MrWheatley » Wed Jul 04, 2018 8:44 pm

JakSparro98 wrote:
Wed Jul 04, 2018 5:59 pm
MrWheatley wrote:
Sat Jun 30, 2018 6:59 pm
Nvm, I figured it out. But what I can't figure out is how to change the skin color.
The Skin attribute in the IProfile class can change the skin color, you need to copy the current player profile, change the copy and then re-assing the latter to the player with SetProfile. You will only get the skin color changed keeping the clothings.

Provide your current code if you need help about implementing this function.
So I have to get they player's profile or the custom one, and what exactly do I have to change?
This is what I came up with but it only changes the skin to the default color.

Code: Select all

        public void ButtonPressed (TriggerArgs args)
        {
            foreach (IPlayer ply in Game.GetPlayers ())
            {
                if (args.Sender is IPlayer)
                {
                    IObject a = Game.CreateObject ("PlayerProfileInfo", new Vector2 (0, 0));
                    a.CustomId = "a";
                    ply.SetProfile (((IObjectPlayerProfileInfo) Game.GetSingleObjectByCustomId ("a")).GetProfile ());
                    IProfile ScoutProfile = new IProfile ();
                    ScoutProfile.Accesory = new IProfileClothingItem ("DogTag", "ClothingGray");
                    ScoutProfile.Head = new IProfileClothingItem ("Cap", "ClothingGray");
                    ScoutProfile.ChestUnder = new IProfileClothingItem ("TShirt", "ClothingRed");
                    ScoutProfile.Hands = new IProfileClothingItem ("FingerlessGloves", "ClothingLightGray");
                    ScoutProfile.Legs = new IProfileClothingItem ("Pants", "ClothingGray");
                    ScoutProfile.Feet = new IProfileClothingItem ("ShoesBlack", "ClothingLightGray");
                    ply.SetProfile (ScoutProfile);
                }
            }
        }
0 x

User avatar
JakSparro98
Superfighter
Superfighter
Posts: 530
Joined: Fri Jul 15, 2016 7:56 pm
Started SFD: PreAlpha 1.0.5
Location: Rome, Italy
Gender:
Age: 25

Post by JakSparro98 » Sat Jul 07, 2018 9:41 pm

MrWheatley wrote:
Wed Jul 04, 2018 8:44 pm
JakSparro98 wrote:
Wed Jul 04, 2018 5:59 pm
MrWheatley wrote:
Sat Jun 30, 2018 6:59 pm
Nvm, I figured it out. But what I can't figure out is how to change the skin color.
The Skin attribute in the IProfile class can change the skin color, you need to copy the current player profile, change the copy and then re-assing the latter to the player with SetProfile. You will only get the skin color changed keeping the clothings.

Provide your current code if you need help about implementing this function.
So I have to get they player's profile or the custom one, and what exactly do I have to change?
This is what I came up with but it only changes the skin to the default color.

Code: Select all

        public void ButtonPressed (TriggerArgs args)
        {
            foreach (IPlayer ply in Game.GetPlayers ())
            {
                if (args.Sender is IPlayer)
                {
                    IObject a = Game.CreateObject ("PlayerProfileInfo", new Vector2 (0, 0));
                    a.CustomId = "a";
                    ply.SetProfile (((IObjectPlayerProfileInfo) Game.GetSingleObjectByCustomId ("a")).GetProfile ());
                    IProfile ScoutProfile = new IProfile ();
                    ScoutProfile.Accesory = new IProfileClothingItem ("DogTag", "ClothingGray");
                    ScoutProfile.Head = new IProfileClothingItem ("Cap", "ClothingGray");
                    ScoutProfile.ChestUnder = new IProfileClothingItem ("TShirt", "ClothingRed");
                    ScoutProfile.Hands = new IProfileClothingItem ("FingerlessGloves", "ClothingLightGray");
                    ScoutProfile.Legs = new IProfileClothingItem ("Pants", "ClothingGray");
                    ScoutProfile.Feet = new IProfileClothingItem ("ShoesBlack", "ClothingLightGray");
                    ply.SetProfile (ScoutProfile);
                }
            }
        }
Since you're changing the entire player profile with a costum one you only need to add ScoutProfile.Skin=new IProfileClothingItem("Normal","Skin4"); before ply.SetProfile (ScoutProfile);

You can choose the skin type from Skin0 to Skin4.
1 x

Post Reply