Page 1 of 1

Change character class on spawn [Solved]

Posted: Sat May 09, 2015 6:53 am
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

Re: Change character class on spawn

Posted: Sat May 09, 2015 12:11 pm
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?

Re: Change character class on spawn

Posted: Sat May 09, 2015 12:20 pm
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?

Re: Change character class on spawn

Posted: Sat May 09, 2015 12:41 pm
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)

Re: Change character class on spawn

Posted: Sat May 09, 2015 12:43 pm
by xap4o
Thank you!