Page 1 of 1

Switching Weapons through .lua [Solved]

Posted: Thu Nov 26, 2015 2:58 pm
by thelegend
I know switching weapons through a lua command is not possible when the player is still alive nor rechanging the unit at any command post.
I used this code after an Objective is done, but the weapons don't switch:

Code: Select all

SetClassProperty("all_inf_survive1", "WeaponName2", all_weap_inf_rifle)
and
SetProperty("all_inf_survive1", "WeaponName2", all_weap_inf_rifle)
He first carries a pistol. Then after surviving two waves of enemies he should receive a rifle. Only if he respawns or spawing again at any CP.
But the weapon doesn't switch.

WeaponName is currently a fusion-cutter (named as Slot2).

I hope you can help me out with this.

Re: Switching Weapons through .lua

Posted: Thu Nov 26, 2015 11:55 pm
by Noobasaurus
Have you tried enclosing the weapon name in quotation marks, like so?

SetClassProperty("all_inf_survive1", "WeaponName2", "all_weap_inf_rifle")

Re: Switching Weapons through .lua

Posted: Fri Nov 27, 2015 9:46 am
by thelegend
Oh I didn't.
After I did the map crashes after I went to a Cp and "spawned" again as the same unit. I post my .lua here for more reference:
Hidden/Spoiler:
[code]
--
-- Copyright (c) 2005 Pandemic Studios, LLC. All rights reserved.
-- Tatooine At War by the_legend

ScriptCB_DoFile("MultiObjectiveContainer")
ScriptCB_DoFile("ObjectiveAssault")
ScriptCB_DoFile("ObjectiveConquest")
ScriptCB_DoFile("ObjectiveGoto")
ScriptCB_DoFile("ObjectiveCTF")
ScriptCB_DoFile("ObjectiveTDM")
ScriptCB_DoFile("Ambush")
ScriptCB_DoFile("setup_teams")


-- Empire Attacking (attacker is always #1)
local ALL = 1
local IMP = 2
-- These variables do not change
local ATT = 1
local DEF = 2

function ScriptPostLoad()

SetAIDifficulty(4, 4, "medium")
AllowAISpawn(IMP, true)
AllowAISpawn(3, true)
SetProperty("ammo_pad", "MaxHealth", 9999999999)
SetProperty("ammo_pad", "CurHealth", 0)

SetProperty("gun1", "MaxHealth", "9999999999")
SetClassProperty("gun1", "RespawnTime", "0")
SetProperty("gun1", "CurHealth", "0")

SetProperty("gun2", "MaxHealth", "9999999999")
SetClassProperty("gun2", "RespawnTime", "0")
SetProperty("gun2", "CurHealth", "0")

SetProperty("gun3", "MaxHealth", "9999999999")
SetClassProperty("gun3", "RespawnTime", "0")
SetProperty("gun3", "CurHealth", "0")

BlockPlanningGraphArcs("con1")
BlockPlanningGraphArcs("con2")


ScriptCB_SetGameRules("campaign")

onfirstspawn = OnCharacterSpawn(
function(character)
if character == 0 then
ReleaseCharacterSpawn(onfirstspawn)
onfirstspawn = nil
BeginObjectivesTimer()
ScriptCB_EnableCommandPostVO(0)

ScriptCB_PlayInGameMusic("imp_dea_immVict_01")
end
end)




--Objecive 1 - Survive First Wave of Enemies
--Kill a bunch of Stormtroopers


Stormtroopers = TargetType:New{classname = "imp_inf_rifleman", killLimit = 7, icon = "hud_objective_icon_circle"}

Objective1 = ObjectiveAssault:New{teamATT = ATT, teamDEF = DEF,
text = "level.taw.objectives.campaign.1", popupText = "level.1.objectives.campaign.1_popup", AIGoalWeight = 0}
Objective1:AddTarget(Stormtroopers)




Objective1.OnStart = function(self)
Ambush("path_wave_1", 8, 3)
wave_1_goal = AddAIGoal(3, "Deathmatch", 100)


end



Objective1.OnComplete = function(self)
ShowMessageText("game.objectives.complete", ATT)
DeleteAIGoal(wave_1_goal)
AllowAISpawn(IMP, false)
AllowAISpawn(3, false)


end

--Objective 1a - Prepare for next Wave
--Auto-Repair Ammo Droid
--Time-20 Seconds




Objective1aCP = CommandPost:New{name = "s_cp1", hideCPs = False}
Objective1a = ObjectiveConquest:New{teamATT = DEF, teamDEF = ATT, textDEF = "level.taw.objectives.Campaign.1a", timeLimit = 20, timeLimitWiningTeam = ATT}
Objective1a:AddCommandPost(Objective1aCP)


Objective1a.OnStart = function (self)


SetProperty("ammo_pad", "MaxHealth", 1200)
SetProperty("ammo_pad", "CurHealth", 1200)





end


Objective1a.OnComplete = function (self)




end











--Objecive 2 - Survive Second Wave of Enemies
--Kill more than a bunch of Stormtroopers


Stormtroopers2 = TargetType:New{classname = "imp_inf_rifleman", killLimit = 14, icon = "hud_objective_icon_circle"}

Objective2 = ObjectiveAssault:New{teamATT = ATT, teamDEF = DEF,
text = "level.taw.objectives.campaign.2", popupText = "level.1.objectives.campaign.2_popup", AIGoalWeight = 0}
Objective2:AddTarget(Stormtroopers2)




Objective2.OnStart = function(self)
Ambush("path_wave_2", 15, 4)
wave_2_goal = AddAIGoal(4, "Deathmatch", 100)
-- AllowAISpawn(IMP, true)
-- AllowAISpawn(4, true)
end



Objective2.OnComplete = function(self)
ShowMessageText("game.objectives.complete", ATT)
DeleteAIGoal(wave_2_goal)
-- AllowAISpawn(IMP, false)
-- AllowAISpawn(4, false)


end





--Objective 2a - Prepare for next Wave
--Time-20 Seconds
--Add Rifle




Objective2aCP = CommandPost:New{name = "s_cp1", hideCPs = False}
Objective2a = ObjectiveConquest:New{teamATT = DEF, teamDEF = ATT, textDEF = "level.taw.objectives.Campaign.2a", timeLimit = 50, timeLimitWiningTeam = ATT}
Objective2a:AddCommandPost(Objective2aCP)


Objective2a.OnStart = function (self)


SetClassProperty("all_inf_survive1", "WeaponName2", "all_weap_inf_rifle")




end


Objective2a.OnComplete = function (self)




end






function BeginObjectivesTimer()
beginobjectivestimer = CreateTimer("beginobjectivestimer")
OnTimerElapse(BeginObjectives, beginobjectivestimer)
SetTimerValue(beginobjectivestimer, 5)
StartTimer(beginobjectivestimer)
end

function BeginObjectives()
objectiveSequence = MultiObjectiveContainer:New{delayVictoryTime = 5}
objectiveSequence:AddObjectiveSet(Objective1)
objectiveSequence:AddObjectiveSet(Objective1a)
objectiveSequence:AddObjectiveSet(Objective2)
objectiveSequence:AddObjectiveSet(Objective2a)

objectiveSequence:Start()
end


end

---------------------------------------------------------------------------
-- FUNCTION: ScriptInit
-- PURPOSE: This function is only run once
-- INPUT:
-- OUTPUT:
-- NOTES: The name, 'ScriptInit' is a chosen convention, and each
-- mission script must contain a version of this function, as
-- it is called from C to start the mission.
---------------------------------------------------------------------------


function ScriptInit()

ReadDataFile("dc:Load\\common.lvl")


ReadDataFile("dc:ingame.lvl")


ReadDataFile("ingame.lvl")
ReadDataFile("dc:bmpKill.lvl")




SetMaxFlyHeight(500)
SetMaxPlayerFlyHeight(500)


SetMemoryPoolSize ("ClothData",20)
SetMemoryPoolSize ("Combo",50) -- should be ~ 2x number of jedi classes
SetMemoryPoolSize ("Combo::State",650) -- should be ~12x #Combo
SetMemoryPoolSize ("Combo::Transition",650) -- should be a bit bigger than #Combo::State
SetMemoryPoolSize ("Combo::Condition",650) -- should be a bit bigger than #Combo::State
SetMemoryPoolSize ("Combo::Attack",550) -- should be ~8-12x #Combo
SetMemoryPoolSize ("Combo::DamageSample",6000) -- should be ~8-12x #Combo::Attack
SetMemoryPoolSize ("Combo::Deflect",100) -- should be ~1x #combo

ReadDataFile("dc:sound\\taw.lvl;taw_gcw")
ReadDataFile("sound\\tat.lvl;tat2gcw")

ReadDataFile("dc:SIDE\\all.lvl",
"all_inf_survive1")

ReadDataFile("dc:SIDE\\imp.lvl",
"imp_inf_rifleman",
"imp_inf_rocketeer",
"imp_inf_engineer",
"imp_inf_sniper",
"imp_inf_officer",
"imp_hero_darthvader",
"imp_walk_atst" )



ReadDataFile("dc:SIDE\\tur.lvl",
"tur_bldg_laser",
"tur_bldg_chaingun",
"tur_bldg_beam",
"tur_bldg_recoilless_kas")

SetupTeams{
all = {
team = ALL,
units = 0,
reinforcements = 100,
soldier = { "all_inf_survive1",0, 0},

},
imp = {
team = IMP,
units = 0,
reinforcements = -1,
soldier = { "imp_inf_rifleman",0, 0},
assault = { "imp_inf_rocketeer",0,0},
engineer = { "imp_inf_engineer",0,0},
sniper = { "imp_inf_sniper",0,0},
},
}

--Setup Stormtroopers Team

SetTeamName (3, "Stormtroopers")
AddUnitClass(3, "imp_inf_rifleman", 8,8)
SetUnitCount(3, 8)


SetTeamAsEnemy(3, ATT)
SetTeamAsEnemy(ATT, 3)
SetTeamAsFriend(3, DEF)
SetTeamAsFriend(DEF, 3)


--Setup Stormtroopers2 Team

SetTeamName (4, "Stormtroopers2")
AddUnitClass(4, "imp_inf_rifleman", 15,15)
SetUnitCount(4, 15)


SetTeamAsEnemy(4, ATT)
SetTeamAsEnemy(ATT, 4)
SetTeamAsFriend(4, DEF)
SetTeamAsFriend(DEF, 4)




-- Level Stats
ClearWalkers()
AddWalkerType(0, 0) -- special -> droidekas
AddWalkerType(1, 4) -- 1x2 (1 pair of legs)
AddWalkerType(2, 0) -- 2x2 (2 pairs of legs)
AddWalkerType(3, 0) -- 3x2 (3 pairs of legs)

local weaponCnt = 1024
SetMemoryPoolSize("Aimer", 75)
SetMemoryPoolSize("AmmoCounter", weaponCnt)
SetMemoryPoolSize("BaseHint", 1024)
SetMemoryPoolSize("EnergyBar", weaponCnt)
SetMemoryPoolSize("EntityCloth", 32)
SetMemoryPoolSize("EntityFlyer", 40)
SetMemoryPoolSize("EntityHover", 14)
SetMemoryPoolSize("EntityLight", 200)
SetMemoryPoolSize("EntitySoundStream", 12)
SetMemoryPoolSize("EntitySoundStatic", 32)
SetMemoryPoolSize("MountedTurret", 32)
SetMemoryPoolSize("Navigator", 128)
SetMemoryPoolSize("Obstacle", 1024)
SetMemoryPoolSize("PathNode", 1024)
SetMemoryPoolSize("SoundSpaceRegion", 64)
SetMemoryPoolSize("TreeGridStack", 1024)
SetMemoryPoolSize("UnitAgent", 128)
SetMemoryPoolSize("UnitController", 128)
SetMemoryPoolSize("Weapon", weaponCnt)

SetSpawnDelay(10.0, 0.25)
ReadDataFile("dc:TAW\\TAW.lvl", "TAW_tdm")
SetDenseEnvironment("false")


-- Sound Stats

voiceSlow = OpenAudioStream("sound\\global.lvl", "all_unit_vo_slow")
AudioStreamAppendSegments("sound\\global.lvl", "imp_unit_vo_slow", voiceSlow)
AudioStreamAppendSegments("sound\\global.lvl", "des_unit_vo_slow", voiceSlow)
AudioStreamAppendSegments("sound\\global.lvl", "global_vo_slow", voiceSlow)

voiceQuick = OpenAudioStream("sound\\global.lvl", "all_unit_vo_quick")
AudioStreamAppendSegments("sound\\global.lvl", "imp_unit_vo_quick", voiceQuick)


OpenAudioStream("sound\\global.lvl", "gcw_music")
-- OpenAudioStream("dc:sound\\taw.lvl", "taw_gcw")
OpenAudioStream("sound\\tat.lvl", "tat2")
OpenAudioStream("sound\\tat.lvl", "tat2")
-- OpenAudioStream("sound\\global.lvl", "global_vo_quick")
-- OpenAudioStream("sound\\global.lvl", "global_vo_slow")

SetBleedingVoiceOver(ALL, ALL, "all_off_com_report_us_overwhelmed", 1)
SetBleedingVoiceOver(ALL, IMP, "all_off_com_report_enemy_losing", 1)
SetBleedingVoiceOver(IMP, ALL, "imp_off_com_report_enemy_losing", 1)
SetBleedingVoiceOver(IMP, IMP, "imp_off_com_report_us_overwhelmed", 1)

SetLowReinforcementsVoiceOver(ALL, ALL, "all_off_defeat_im", .1, 1)
SetLowReinforcementsVoiceOver(ALL, IMP, "all_off_victory_im", .1, 1)
SetLowReinforcementsVoiceOver(IMP, IMP, "imp_off_defeat_im", .1, 1)
SetLowReinforcementsVoiceOver(IMP, ALL, "imp_off_victory_im", .1, 1)

SetOutOfBoundsVoiceOver(2, "Allleaving")
SetOutOfBoundsVoiceOver(1, "Impleaving")

SetAmbientMusic(ALL, 1.0, "all_tat_amb_start", 0,1)
SetAmbientMusic(ALL, 0.8, "all_tat_amb_middle", 1,1)
SetAmbientMusic(ALL, 0.2, "all_tat_amb_end", 2,1)
SetAmbientMusic(IMP, 1.0, "imp_tat_amb_start", 0,1)
SetAmbientMusic(IMP, 0.8, "imp_tat_amb_middle", 1,1)
SetAmbientMusic(IMP, 0.2, "imp_tat_amb_end", 2,1)

SetVictoryMusic(ALL, "all_tat_amb_victory")
SetDefeatMusic (ALL, "all_tat_amb_defeat")
SetVictoryMusic(IMP, "imp_tat_amb_victory")
SetDefeatMusic (IMP, "imp_tat_amb_defeat")

SetSoundEffect("ScopeDisplayZoomIn", "binocularzoomin")
SetSoundEffect("ScopeDisplayZoomOut", "binocularzoomout")
--SetSoundEffect("WeaponUnableSelect", "com_weap_inf_weaponchange_null")
--SetSoundEffect("WeaponModeUnableSelect", "com_weap_inf_modechange_null")
SetSoundEffect("SpawnDisplayUnitChange", "shell_select_unit")
SetSoundEffect("SpawnDisplayUnitAccept", "shell_menu_enter")
SetSoundEffect("SpawnDisplaySpawnPointChange", "shell_select_change")
SetSoundEffect("SpawnDisplaySpawnPointAccept", "shell_menu_enter")
SetSoundEffect("SpawnDisplayBack", "shell_menu_exit")

SetAttackingTeam(ATT)

-- Camera Stats
-- Mos Eisley
AddCameraShot(0.997189, -0.057529, 0.047923, 0.002765, -242.154282, 123.914772, 206.124817);

end

[/code]
Thanks for your help.

Re: Switching Weapons through .lua

Posted: Fri Nov 27, 2015 1:08 pm
by DylanRocket
thelegend wrote:Oh I didn't.
After I did the map crashes after I went to a Cp and "spawned" again as the same unit.
You need to load "all_inf_rifleman" or any other unit that has "all_weap_inf_rifle".

For example:

Code: Select all

    ReadDataFile("dc:SIDE\\all.lvl",
                    "all_inf_survive1",
                    "all_inf_rifleman")

Re: Switching Weapons through .lua

Posted: Fri Nov 27, 2015 1:53 pm
by Teancum
AFAIK SetProperty() doesn't work on the fly. I remember Maveritchell did it, so I could be wrong, but I feel like he did something different.

Re: Switching Weapons through .lua

Posted: Fri Nov 27, 2015 2:01 pm
by [RDH]Zerted
If your map crashes you should post your debug log when asking for help.

If you're changing weapon properties the map won't work online. Keep that in mind. Don't add it to the MP mission selection list in your addme.lua.

Re: Switching Weapons through .lua

Posted: Fri Nov 27, 2015 2:33 pm
by thelegend
DylanRocket wrote: You need to load "all_inf_rifleman" or any other unit that has "all_weap_inf_rifle".

For example:

Code: Select all

    ReadDataFile("dc:SIDE\\all.lvl",
                    "all_inf_survive1",
                    "all_inf_rifleman")
This fixed it. But I am going to use weapons "borrowed" by the empire.
[RDH]Zerted wrote: If you're changing weapon properties the map won't work online. Keep that in mind. Don't add it to the MP mission selection list in your addme.lua.
I will look what can be done for online compatibilty.
Thanks for all the replies. I still have some questions about mission scripting.

1. Currently I am working on a wave mode and the other team (enemies) have to kill the player (That's me). I used the "Deathmatch" AI goal, but the bots are mostly running away (when they are far away). Their goal is to kill me (=They have to walk to my current location and must kill me).

I used this:

Code: Select all

(3, "Destroy", 100, "ATT")
But they now just stands and don't do anything. They don't even react when I shoot them.
I think it's because of "ATT". What's the name of all (Or only me) human players. So their goal is to kill all humans in Team ATT (ALLiance).

2. This is a question about limitaions. How many objectives can I put into one single campain. I plan to do a further project with a long storyline. And I was curious about the total amount of working objectives.

My theory: File size. Maybe there's a maximum of KB's. Like the 16mb limit for textures. But I might be wrong.


Thank you for helping me.

Re: Switching Weapons through .lua [Solved]

Posted: Fri Nov 27, 2015 8:46 pm
by [RDH]Zerted
The topic has been labeled solved so I assume you got #1 working. As for #2, I don't think there's a limit to the number of objectives. If the objectives are running one at a time then there shouldn't be a limit. If you're trying to run a bunch of objectives at the same time then you'll have the issue of there only being so many AI goals allowed. I don't know the limit off hand, but it's in the FAQ's SWBF2 limitations topic. You can delete AI goals when they're no longer needed, but you can't have more goals active than you're allowed.