Change character class on spawn [Solved]

In this forum you will find and post information regarding the modding of Star Wars Battlefront 2. DO NOT POST MOD IDEAS/REQUESTS.

Moderator: Moderators

Post Reply
xap4o
Filthy Thief
Filthy Thief
Posts: 23
Joined: Mon Jun 16, 2014 1:02 pm

Change character class on spawn [Solved]

Post by xap4o »

Hi! I want to change character class when he is spawning. I tried this code, but it doesn't work:

Code: Select all

OnCharacterSpawn(function(character)
    if GetCharacterTeam(character) == IMP and GetReinforcementCount(IMP) == 1 then
	SelectCharacterClass(character,"imp_hero_darthvader")	
    end
end)
What am I doing wrong? I will be grateful if you can help me.

EDIT
I tried this code:

Code: Select all

   vaderspawn = true
	
  OnCharacterSpawn(function(character)
      if GetCharacterTeam(character) == IMP and vaderspawn and GetReinforcementCount(IMP) == 1 then
		local loc = GetEntityMatrix(GetCharacterUnit(character))
		AddReinforcements(IMP, 1)
		KillObject(GetCharacterUnit(character))
		SelectCharacterTeam(character, IMP)
		SelectCharacterClass(character,"imp_hero_darthvader")	
		SpawnCharacter(character, loc)
		vaderspawn = false
      end
   end)
It doesn't work. But it works only if I change GetCharacterTeam(character) == IMP to GetCharacterTeam(character) == ALL. Of course, after that I need to spawn as Alliance to respawn as a Darth Vader. What am I doing wrong?

Double posting is against the RULES; please EDIT your post instead -Staff
razac920
2nd Lieutenant
2nd Lieutenant
Posts: 365
Joined: Sun Jan 16, 2011 12:42 am

Re: Change character class on spawn

Post by razac920 »

Why would you set the character's team to IMP, when you have as a condition that the character's team is IMP? And I think the issue is that it takes time for the game to process that the character has been killed, so it won't let you immediately spawn the character at a new location. Why don't you instead have a nested OnCharacterDeath callback inside your OnCharacterSpawn callback?
xap4o
Filthy Thief
Filthy Thief
Posts: 23
Joined: Mon Jun 16, 2014 1:02 pm

Re: Change character class on spawn

Post by xap4o »

Already found my mistake. I added to Vader nonzero PointsToUnlock parameter, so, the player cannot spawn as him. Stupid mistake...

And another question, how I can make bots spawn after the player has spawned?
razac920
2nd Lieutenant
2nd Lieutenant
Posts: 365
Joined: Sun Jan 16, 2011 12:42 am

Re: Change character class on spawn

Post by razac920 »

Code: Select all

  AllowAISpawn(IMP,false)
  AllowAISpawn(ALL,false)
  botspawn = OnCharacterSpawn(function(player)
    if IsCharacterHuman(player) then
      AllowAISpawn(ALL,true)
      AllowAISpawn(IMP,true)
      ReleaseCharacterSpawn(botspawn)
      botspawn = nil
    end
  end)
xap4o
Filthy Thief
Filthy Thief
Posts: 23
Joined: Mon Jun 16, 2014 1:02 pm

Re: Change character class on spawn

Post by xap4o »

Thank you!
Post Reply