Page 1 of 2

My code doesn't work <Solved happily>

Posted: Sat Sep 05, 2009 10:09 am
by General_Nate
Ok, here is my code:

Code: Select all

   OnObjectKill("your object here")
         text= ("your text here")
    end

Re: My code doesn't work

Posted: Sat Sep 05, 2009 10:22 am
by RepSharpshooter
Probably doesn't work because it is the completely wrong syntax. Don't make up (wrong) code off the top of your head, you wont get very far in programming if you do that.


Here is an example of how to use OnObjectKill correctly:

Code: Select all

OnObjectKill(
   function(object, killer)
      local name = GetEntityName(object)
      if name == "wave_reset" then
        --do stuff here
      end
 end
)

Re: My code doesn't work

Posted: Sat Sep 05, 2009 11:17 am
by General_Nate
Wow! I looked at the mission scripture and the stock mission luas and thought that was relatively how you would do it.

So then would this work?

Code: Select all

OnObjectKill(
   function(object, killer)
      local name = GetEntityName(Gate1)
      if name == "Gate1" then
        text= ("THE PRISONERS ARE FREE")
      end
end
EDIT: Nope, here is my munge log:
Hidden/Spoiler:
C:\BF2_ModTools\ToolsFL\Bin\luac.exe: ..\..\common\scripts\TTT\TTTc_con.lua:57: `)' expected (to close `(' at line 48) near `end'
ERROR[scriptmunge scripts\TTT\TTTc_con.lua]:Could not read input file.ERROR[scriptmunge scripts\TTT\TTTc_con.lua]:Could not read input file. [continuing]
2 Errors 0 Warnings

ERROR[levelpack mission\TTTc_con.req]:Expecting bracket, but none was found.
File : munged\pc\tttc_con.script.req(1)...

ucft <--
ERROR[levelpack mission\TTTc_con.req]:Expecting bracket, but none was found.
File : munged\pc\tttc_con.script.req(1)...

ucft <--

2 Errors 0 Warnings

Re: My code doesn't work

Posted: Sat Sep 05, 2009 11:22 am
by Xavious
Yes, but you're missing a closing ')' at the end.

Re: My code doesn't work

Posted: Sat Sep 05, 2009 11:23 am
by General_Nate
the first or last 'end'?

EDIT: ok, I think I have it I'll get back to you after munging.

Re: My code doesn't work

Posted: Sat Sep 05, 2009 11:27 am
by Xavious
By 'end' I meant the end of your posted section of code. So after the second 'end', just like Rep has it.

Re: My code doesn't work

Posted: Sat Sep 05, 2009 11:28 am
by General_Nate
Yeah, I missed that. :oops: Ok, I'll go test.

EDIT: Well the munge liked it, but ingame there is no text. Is this: text= ("THE PRISONERS ARE FREE") even a command? Or is there something more? What I want is once an object gets destroyed, I want text to show up in the chat corner.

Re: My code doesn't work

Posted: Sat Sep 05, 2009 1:07 pm
by [RDH]Zerted
Yes that is a real command, but it doesn't do what you want it to do. To get text displayed ingame, use ShowMessageText(msg, team) where msg is the localised string (such as mods.mymap.arefree) and team is the team which will see the message. If you want both teams to see the message, just don't include team.

Also, change GetEntityName(Gate1) to GetEntityName("Gate1")

Re: My code doesn't work

Posted: Sat Sep 05, 2009 1:23 pm
by General_Nate
Thanks a lot! But one more question.
[RDH]Zerted wrote:where msg is the localised string (such as mods.mymap.arefree)
You lost me there. So, am I to open editlocalize.bat file and rename something: "THE PRISONERS ARE FREE"?

Re: My code doesn't work

Posted: Sat Sep 05, 2009 1:35 pm
by [RDH]Zerted
Yes, but you don't need to rename anything. You can just create a new entry for the string you want.

Re: My code doesn't work

Posted: Sat Sep 05, 2009 2:33 pm
by General_Nate
Hm, it still doesn't work. Here is my lua:
Hidden/Spoiler:
--
-- Copyright (c) 2005 Pandemic Studios, LLC. All rights reserved.
--

-- load the gametype script
ScriptCB_DoFile("ObjectiveConquest")
ScriptCB_DoFile("setup_teams")

-- REP Attacking (attacker is always #1)
REP = 1;
CIS = 2;
-- These variables do not change
ATT = REP;
DEF = CIS;


function ScriptPostLoad()


--This defines the CPs. These need to happen first
cp1 = CommandPost:New{name = "cp1"}
cp2 = CommandPost:New{name = "cp2"}
cp3 = CommandPost:New{name = "cp3"}
cp4 = CommandPost:New{name = "cp4"}
cp5 = CommandPost:New{name = "cp5"}



--This sets up the actual objective. This needs to happen after cp's are defined
conquest = ObjectiveConquest:New{teamATT = ATT, teamDEF = DEF,
textATT = "game.modes.con",
textDEF = "game.modes.con2",
multiplayerRules = true}

--This adds the CPs to the objective. This needs to happen after the objective is set up
conquest:AddCommandPost(cp1)
conquest:AddCommandPost(cp2)
conquest:AddCommandPost(cp3)
conquest:AddCommandPost(cp4)
conquest:AddCommandPost(cp5)

conquest:Start()

SetUberMode(1);

EnableSPHeroRules()

OnObjectKill(
function(object, killer)
local name = GetEntityName("Gate1")
if name == "Gate1" then
ShowMessageText(mods.mymap.arefree)
end
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("ingame.lvl")


SetMaxFlyHeight(200)
SetMaxPlayerFlyHeight (200)

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("sound\\yav.lvl;yav1cw")
ReadDataFile("SIDE\\rep.lvl",
"rep_inf_ep3_rifleman",
"rep_inf_ep3_rocketeer",
"rep_inf_ep3_engineer",
"rep_inf_ep3_sniper",
"rep_inf_ep3_officer",
"rep_inf_ep3_jettrooper",
"rep_hover_fightertank",
"rep_hero_anakin",
"rep_hover_barcspeeder")
ReadDataFile("SIDE\\cis.lvl",
"cis_inf_rifleman",
"cis_inf_rocketeer",
"cis_inf_engineer",
"cis_inf_sniper",
"cis_inf_officer",
"cis_inf_droideka",
"cis_hero_darthmaul",
"cis_hover_aat")


ReadDataFile("SIDE\\tur.lvl",
"tur_bldg_laser",
"tur_bldg_tower")

ReadDataFile("dc:SIDE\\res.lvl",
"res_inf_trooper",
"res_inf_medic",
"res_inf_commander",
"res_inf_mine",
"res_inf_swordsman")

ReadDataFile("dc:SIDE\\ter.lvl",
"ter_inf_trooper",
"ter_inf_commander",
"ter_inf_sneak",
"ter_inf_super")

ReadDataFile("dc:SIDE\\pri.lvl",
"pri_inf_guy1",
"pri_inf_guy2")

SetupTeams{
rep = {
team = REP,
units = 20,
reinforcements = 150,
soldier = { "res_inf_trooper",0, 25},
sniper = { "res_inf_swordsman",0, 2},
engineer = { "res_inf_medic",0, 10},
special = { "res_inf_commander",0, 5}

},
cis = {
team = CIS,
units = 20,
reinforcements = 210,
soldier = { "ter_inf_trooper",0, 25},
sniper = { "ter_inf_commander",0, 7},
special = { "ter_inf_super",0, 5},

}
}

SetTeamName(1, "RESISTANCE")
SetTeamName(2, "SKYNET")


SetTeamAggressiveness(CIS, 1.99)


SetTeamName (3, "Prisoners")
AddUnitClass (3, "pri_inf_guy1", 0,10)
AddUnitClass (3, "pri_inf_guy2", 0,10)
SetUnitCount (3, 15)
AddAIGoal(3, "Deathmatch", 100)

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





-- Level Stats
-- ClearWalkers()
AddWalkerType(0, 4) -- special -> droidekas
AddWalkerType(1, 0) -- 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", 32)
SetMemoryPoolSize("EntityHover", 32)
SetMemoryPoolSize("EntityLight", 200)
SetMemoryPoolSize("EntitySoundStream", 4)
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:TTT\\TTT.lvl", "TTT_conquest")
ReadDataFile("dc:TTT\\TTT.lvl", "TTT_conquest")
SetDenseEnvironment("false")




-- Sound

SetSoundEffect("ScopeDisplayZoomIn", "binocularzoomin")
SetSoundEffect("ScopeDisplayZoomOut", "binocularzoomout")

voiceSlow = OpenAudioStream("sound\\global.lvl", "rep_unit_vo_slow")
AudioStreamAppendSegments("sound\\global.lvl", "cis_unit_vo_slow", voiceSlow)
AudioStreamAppendSegments("sound\\global.lvl", "global_vo_slow", voiceSlow)

voiceQuick = OpenAudioStream("sound\\global.lvl", "rep_unit_vo_quick")
AudioStreamAppendSegments("sound\\global.lvl", "cis_unit_vo_quick", voiceQuick)

OpenAudioStream("sound\\global.lvl", "cw_music")
-- OpenAudioStream("sound\\global.lvl", "global_vo_quick")
-- OpenAudioStream("sound\\global.lvl", "global_vo_slow")
OpenAudioStream("sound\\yav.lvl", "yav1")
OpenAudioStream("sound\\yav.lvl", "yav1")
OpenAudioStream("sound\\yav.lvl", "yav1_emt")

SetBleedingVoiceOver(REP, REP, "rep_off_com_report_us_overwhelmed", 1)
SetBleedingVoiceOver(REP, CIS, "rep_off_com_report_enemy_losing", 1)
SetBleedingVoiceOver(CIS, REP, "cis_off_com_report_enemy_losing", 0)
SetBleedingVoiceOver(CIS, CIS, "cis_off_com_report_us_overwhelmed", 0)

SetOutOfBoundsVoiceOver(2, "")
SetOutOfBoundsVoiceOver(1, "repleaving")

SetAmbientMusic(REP, 1.0, "rep_yav_amb_start", 0,1)
SetAmbientMusic(REP, 0.8, "rep_yav_amb_middle", 1,1)
SetAmbientMusic(REP, 0.2, "rep_yav_amb_end", 2,1)
SetAmbientMusic(CIS, 1.0, "cis_yav_amb_start", 0,1)
SetAmbientMusic(CIS, 0.8, "cis_yav_amb_middle", 1,1)
SetAmbientMusic(CIS, 0.2, "cis_yav_amb_end", 2,1)

SetVictoryMusic(REP, "rep_yav_amb_victory")
SetDefeatMusic (REP, "rep_yav_amb_defeat")
SetVictoryMusic(CIS, "cis_yav_amb_victory")
SetDefeatMusic (CIS, "cis_yav_amb_defeat")

SetSoundEffect("ScopeDisplayZoomIn", "binocularzoomin")
SetSoundEffect("ScopeDisplayZoomOut", "binocularzoomout")
--SetSoundEffect("BirdScatter", "birdsFlySeq1")
--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")


--OpeningSateliteShot
AddCameraShot(0.908386, -0.209095, -0.352873, -0.081226, -45.922508, -19.114113, 77.022636);

AddCameraShot(-0.481173, 0.024248, -0.875181, -0.044103, 14.767292, -30.602322, -144.506851);
AddCameraShot(0.999914, -0.012495, -0.004416, -0.000055, 1.143253, -33.602314, -76.884430);
AddCameraShot(0.839161, 0.012048, -0.543698, 0.007806, 19.152437, -49.802273, 24.337317);
AddCameraShot(0.467324, 0.006709, -0.883972, 0.012691, 11.825212, -49.802273, -7.000720);
AddCameraShot(0.861797, 0.001786, -0.507253, 0.001051, -11.986043, -59.702248, 23.263165);
AddCameraShot(0.628546, -0.042609, -0.774831, -0.052525, 20.429928, -48.302277, 9.771714);
AddCameraShot(0.765213, -0.051873, 0.640215, 0.043400, 57.692474, -48.302277, 16.540724);
AddCameraShot(0.264032, -0.015285, -0.962782, -0.055734, -16.681797, -42.902290, 129.553268);
AddCameraShot(-0.382320, 0.022132, -0.922222, -0.053386, 20.670977, -42.902290, 135.513001);
end
And here is what I did:
[*]I made a scope in the localize bat file and called it mods.
[*]I made another scope inside of that and called it mymap.
[*]I then made a key inside of that and called it arefree.
[*]Then I selected the key arefree and in the white space I put "THE PRISONERS ARE FREE".
[*]And then I updated my code to what is shown above.

Any ideas?

Re: My code doesn't work

Posted: Sat Sep 05, 2009 2:49 pm
by kinetosimpetus
the lua says mymap, you said mymaps is the scope you made

Re: My code doesn't work

Posted: Sat Sep 05, 2009 2:53 pm
by General_Nate
Oh, no I just checked. They mach up the same. Sorry for the typo...

Re: My code doesn't work

Posted: Sat Sep 05, 2009 5:27 pm
by Xavious
Try setting up your localize path to be

Code: Select all

level.modID.arefree
EDIT: Ah, Mav's right. Disregard what I said.

Re: My code doesn't work

Posted: Sat Sep 05, 2009 5:33 pm
by Maveritchell
Xavious wrote:Try setting up your localize path to be

Code: Select all

level.modID.arefree
Unnecessary. Put your localize string in quotation marks - strings should always be in quotation marks; variables will not be.

Re: My code doesn't work

Posted: Sat Sep 05, 2009 9:50 pm
by [RDH]Zerted

Code: Select all

OnObjectKill(
    function(object, killer)
        local name = GetEntityName(object)
        print("OnObjectKill():",name)
        if name == "Gate1" then
            ShowMessageText("mods.mymap.arefree")
        end
    end
)
Try the above code. If it doesn't work, post the debug log.

Re: My code doesn't work

Posted: Sun Sep 06, 2009 10:44 am
by General_Nate
Nope, it didn't work.

Here is the only different thing in my error log:
Hidden/Spoiler:
fakeconsole_functions: AddCommand: Not adding command: Unlock Vehicles
fakeconsole_functions: AddCommand: Not adding command: Force No Views
fakeconsole_functions: AddCommand: Not adding command: Allow CP Capture
fakeconsole_functions: AddCommand: Not adding command: Not Immune To Mines
fakeconsole_functions: AddCommand: Not adding command: Disable Tumble Recovery
fakeconsole_functions: AddCommand: Not adding command: Allow AI Spawn 1
fakeconsole_functions: AddCommand: Not adding command: Allow AI Spawn 2
fakeconsole_functions: AddCommand: Not adding command: Team Auto-assign On
fakeconsole_functions: AddCommand: Not adding command: Heros SP Rules Off
fakeconsole_functions: AddCommand: Not adding command: Heros SP Scripted Off
fakeconsole_functions: AddCommand: Not adding command: Menu Sounds On
fakeconsole_functions: AddCommand: Not adding command: No Flee Just Die
fakeconsole_functions: AddCommand: Not adding command: Restore Award Effects
fakeconsole_functions: AddCommand: Not adding command: Allow Victory
fakeconsole_functions: AddCommand: Not adding command: AI AutoBalance Off
fakeconsole_functions: AddCommand: Not adding command: AI BlindJetJumps Off
fakeconsole_functions: AddCommand: Not adding command: Hide Team Points
fakeconsole_functions: AddCommand: Not adding command: Remove JetPacks
ifs_fakeconsole: Is runnable: Common Commands function: 03CDC2E8
uf_applyFunctionOnTeamUnits(): Team, Unit: 1 0
uf_applyFunctionOnTeamUnits(): Team, Unit: 1 1
uf_applyFunctionOnTeamUnits(): Team, Unit: 1 2
uf_applyFunctionOnTeamUnits(): Team, Unit: 1 3
uf_applyFunctionOnTeamUnits(): Team, Unit: 1 4
uf_applyFunctionOnTeamUnits(): Team, Unit: 1 5
uf_applyFunctionOnTeamUnits(): Team, Unit: 1 6
uf_applyFunctionOnTeamUnits(): Team, Unit: 1 7
uf_applyFunctionOnTeamUnits(): Team, Unit: 1 8
uf_applyFunctionOnTeamUnits(): Team, Unit: 1 9
uf_applyFunctionOnTeamUnits(): Team, Unit: 1 10
uf_applyFunctionOnTeamUnits(): Team, Unit: 1 11
uf_applyFunctionOnTeamUnits(): Team, Unit: 1 12
uf_applyFunctionOnTeamUnits(): Team, Unit: 1 13
uf_applyFunctionOnTeamUnits(): Team, Unit: 1 14
uf_applyFunctionOnTeamUnits(): Team, Unit: 1 15
uf_applyFunctionOnTeamUnits(): Team, Unit: 1 16
uf_applyFunctionOnTeamUnits(): Team, Unit: 1 17
uf_applyFunctionOnTeamUnits(): Team, Unit: 1 18
uf_applyFunctionOnTeamUnits(): Team, Unit: 2 0
uf_applyFunctionOnTeamUnits(): Team, Unit: 2 1
uf_applyFunctionOnTeamUnits(): Team, Unit: 2 2
uf_applyFunctionOnTeamUnits(): Team, Unit: 2 3
uf_applyFunctionOnTeamUnits(): Team, Unit: 2 4
uf_applyFunctionOnTeamUnits(): Team, Unit: 2 5
uf_applyFunctionOnTeamUnits(): Team, Unit: 2 6
uf_applyFunctionOnTeamUnits(): Team, Unit: 2 7
uf_applyFunctionOnTeamUnits(): Team, Unit: 2 8
uf_applyFunctionOnTeamUnits(): Team, Unit: 2 9
uf_applyFunctionOnTeamUnits(): Team, Unit: 2 10
uf_applyFunctionOnTeamUnits(): Team, Unit: 2 11
uf_applyFunctionOnTeamUnits(): Team, Unit: 2 12
uf_applyFunctionOnTeamUnits(): Team, Unit: 2 13
uf_applyFunctionOnTeamUnits(): Team, Unit: 2 14
uf_applyFunctionOnTeamUnits(): Team, Unit: 2 15
uf_applyFunctionOnTeamUnits(): Team, Unit: 2 16
uf_applyFunctionOnTeamUnits(): Team, Unit: 2 17
uf_applyFunctionOnTeamUnits(): Team, Unit: 2 18
uf_applyFunctionOnTeamUnits(): Team, Unit: 2 19
uf_applyFunctionOnTeamUnits(): Team, Unit: 2 20
OnObjectKill(): gate1

Re: My code doesn't work

Posted: Sun Sep 06, 2009 12:50 pm
by [RDH]Zerted
OnObjectKill(): gate1
It seems the gate's name is in lower case. Fix the if statement for lower case and it should work. After it is working, you can remove the print() line

Re: My code doesn't work

Posted: Sun Sep 06, 2009 12:56 pm
by General_Nate
It works! Zeterd, your the man! This can be solved, thanks guys.

Re: My code doesn't work <Solved happily>

Posted: Sun Sep 06, 2009 4:02 pm
by Frisbeetarian
Now that this is solved, I want to make a comment on efficiency. Filters are built into event calls for a reason and it's a good idea to use them. If you don't understand them, go read the scripting document and look at campaign scripts for examples. With Rep's example, this:

Code: Select all

OnObjectKill(
   function(object, killer)
      local name = GetEntityName(object)
      if name == "wave_reset" then
        --do stuff here
      end
end
)
turns into this:

Code: Select all

OnObjectKillName(
   function(object, killer)
        --do stuff here
   end,
"wave_reset")
It should be noted, however, that the scripting document leaves out the fact that object events can have filters; they can.