LUA help needed

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
myers73
Lieutenant General
Lieutenant General
Posts: 690
Joined: Fri Apr 03, 2009 11:04 pm
Projects :: No Mod project currently.
Games I'm Playing :: I have not listed any games yet
xbox live or psn: No gamertag set
Location: Atlanta, GA xfire=myers73 IngameName=mYers

LUA help needed

Post by myers73 »

Hidden/Spoiler:
[code]

conquest:AddCommandPost(cp1)
conquest:AddCommandPost(cp2)
conquest:AddCommandPost(cp3)
conquest:AddCommandPost(cp4)
conquest:AddCommandPost(cp5)
conquest:AddCommandPost(cp6)

conquest:Start()

SetUberMode(1);

testFunction = OnCharacterDeath(
function(player, killer)
SetProperty(GetCharacterClass(killer), "AddHealth", 1000) --higher than maxhealth in order to fully replinish
end
end
)

EnableSPHeroRules()

end


[/code][/size]
gives me
Hidden/Spoiler:
C:\BF2_ModTools\ToolsFL\Bin\luac.exe: ..\..\common\scripts\DEF\DEFg_con.lua:50: `)' expected (to close `(' at line 46) near `end'
ERROR[scriptmunge scripts\DEF\DEFg_con.lua]:Could not read input file.ERROR[scriptmunge scripts\DEF\DEFg_con.lua]:Could not read input file. [continuing]
2 Errors 0 Warnings

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

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

ucft <--

2 Errors 0 Warnings
Deviss
Master of the Force
Master of the Force
Posts: 3772
Joined: Tue Aug 12, 2008 7:59 pm
Projects :: Clone Wars Extended
Games I'm Playing :: BF2

Re: LUA help needed

Post by Deviss »

myers73 wrote:
Hidden/Spoiler:
[code]

conquest:AddCommandPost(cp1)
conquest:AddCommandPost(cp2)
conquest:AddCommandPost(cp3)
conquest:AddCommandPost(cp4)
conquest:AddCommandPost(cp5)
conquest:AddCommandPost(cp6)

conquest:Start()

SetUberMode(1);

testFunction = OnCharacterDeath(
function(player, killer)
SetProperty(GetCharacterClass(killer), "AddHealth", 1000) --higher than maxhealth in order to fully replinish
end
end
)

EnableSPHeroRules()

end


[/code][/size]
gives me
Hidden/Spoiler:
C:\BF2_ModTools\ToolsFL\Bin\luac.exe: ..\..\common\scripts\DEF\DEFg_con.lua:50: `)' expected (to close `(' at line 46) near `end'
ERROR[scriptmunge scripts\DEF\DEFg_con.lua]:Could not read input file.ERROR[scriptmunge scripts\DEF\DEFg_con.lua]:Could not read input file. [continuing]
2 Errors 0 Warnings

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

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

ucft <--

2 Errors 0 Warnings
i had it many times xD, surely end words are bad placed try moving enableheroe line up of it :)
501st_commander
Master Bounty Hunter
Master Bounty Hunter
Posts: 1570
Joined: Wed Dec 10, 2008 7:48 pm

Re: LUA help needed

Post by 501st_commander »

Code: Select all

    
    conquest:AddCommandPost(cp1)
    conquest:AddCommandPost(cp2)
    conquest:AddCommandPost(cp3)
    conquest:AddCommandPost(cp4)
    conquest:AddCommandPost(cp5)
    conquest:AddCommandPost(cp6)     
    
    conquest:Start()

    SetUberMode(1);
   
    testFunction = OnCharacterDeath(
        function(player, killer)
            SetProperty(GetCharacterClass(killer), "AddHealth", 1000) --higher than maxhealth in order to fully replinish
        end
    )
    end
    
    EnableSPHeroRules()
    
end
maybe?
User avatar
Maveritchell
Jedi Admin
Jedi Admin
Posts: 7366
Joined: Mon Aug 21, 2006 11:03 pm

Re: LUA help needed

Post by Maveritchell »

You have too many "end" statements. It's good practice to write your code with a clear nesting, like you're doing, but I wonder why you thought it necessary to put your "end" (the extra one) in-line with your SetProperty command. If you meant to have an "if" statement there, you left it out.
myers73
Lieutenant General
Lieutenant General
Posts: 690
Joined: Fri Apr 03, 2009 11:04 pm
Projects :: No Mod project currently.
Games I'm Playing :: I have not listed any games yet
xbox live or psn: No gamertag set
Location: Atlanta, GA xfire=myers73 IngameName=mYers

Re: LUA help needed

Post by myers73 »

oh yeah, I had an if statement but then decided that not how I wanted it to work.

EDIT: it munges fine, but ingame when I kill someone I dont get health.
User avatar
[RDH]Zerted
Gametoast Staff
Gametoast Staff
Posts: 2982
Joined: Sun Feb 26, 2006 7:36 am
Projects :: Bos Wars AI - a RTS game
Games I'm Playing :: SWBF2 and Bos Wars
xbox live or psn: No gamertag set
Location: USA
Contact:

Re: LUA help needed

Post by [RDH]Zerted »

You want to add health to the killer's unit object not to its class.
myers73
Lieutenant General
Lieutenant General
Posts: 690
Joined: Fri Apr 03, 2009 11:04 pm
Projects :: No Mod project currently.
Games I'm Playing :: I have not listed any games yet
xbox live or psn: No gamertag set
Location: Atlanta, GA xfire=myers73 IngameName=mYers

Re: LUA help needed

Post by myers73 »

Code: Select all


    testFunction = OnCharacterDeath(
        function(player, killer)
            SetProperty(GetCharacterUnit(killer), "AddHealth", 10)
        end
    )

give the unit a +10 health/sec regen rate after the first kill.

how would I make it only give health once?

EDIT:
how could GetObjectHealth be used to add health

EDIT2:
Hidden/Spoiler:
[code]

function(killer)
-- if IsCharacterHuman(killer) == true then
SetProperty(GetCharacterUnit(killer), "AddHealth", 10)
timeoutTimer = CreateTimer("timeout")
SetTimerValue(timeoutTimer, 20)
ShowTimer(timeoutTimer)
StartTimer("timeout")

OnTimerElapse(
function(timer)
SetProperty(GetCharacterUnit(killer), "AddHealth", -10)
ShowTimer(true)
DestroyTimer(timer)
end,
timeoutTimer
)
-- end
end
)

[/code][/size]
was a code that attempted to give health regen or a certain amount for a certain period of time, to reward a kill. It did not work, and I cannot generate a debug log as my disc is at a friends house.
User avatar
Fiodis
Master of the Force
Master of the Force
Posts: 4145
Joined: Wed Nov 12, 2008 9:27 pm
Projects :: Rannoch + Tientia + Tools Programming

Re: LUA help needed

Post by Fiodis »

Why not use SetProperty(unit, "CurHealth", Curhealth+10)? Or something like that. It works for a single boost rather than a continue regen.
User avatar
[RDH]Zerted
Gametoast Staff
Gametoast Staff
Posts: 2982
Joined: Sun Feb 26, 2006 7:36 am
Projects :: Bos Wars AI - a RTS game
Games I'm Playing :: SWBF2 and Bos Wars
xbox live or psn: No gamertag set
Location: USA
Contact:

Re: LUA help needed

Post by [RDH]Zerted »

The game isn't crashing, so you don't need a debug log and you don't use a CD to get one too.

AddHealth is a health regen. If you want to directly change the health of an object, use CurHealth.

Follow what Fiodis said, but use GetObjectHealth(unit)+10

So you want:

Code: Select all

testFunction = OnCharacterDeath(
        function(player, killer)
            if killer == nil then return end --make sure there is a killer
            local unit = GetCharacterUnit(killer) --get the killer's unit object
            if unit == nil then return end --make sure the killer wasn't also killed
            SetProperty(unit, "CurHealth", GetObjectHealth(unit)+10) --increase the killer's unit's health by 10
        end
    )
User avatar
lucasfart
Sith
Sith
Posts: 1440
Joined: Tue Feb 24, 2009 5:32 am
Projects :: No Mod project currently.
Games I'm Playing :: I have not listed any games yet
xbox live or psn: No gamertag set
Location: Australia

Re: LUA help needed

Post by lucasfart »

Just curious, would anything happen if you received +10 health when you were at 100% health? Would it increase, or could you just not get anymore?
User avatar
Maveritchell
Jedi Admin
Jedi Admin
Posts: 7366
Joined: Mon Aug 21, 2006 11:03 pm

Re: LUA help needed

Post by Maveritchell »

lucasfart wrote:Just curious, would anything happen if you received +10 health when you were at 100% health? Would it increase, or could you just not get anymore?
It will roll over above 100% (when you have greater health than your maxhealth value it is stored in a lighter-blue flashing bar over your health bar). If you're being conscientious about your code, you'll make sure to check for hitting your maxhealth and making sure it doesn't get larger than that.
myers73
Lieutenant General
Lieutenant General
Posts: 690
Joined: Fri Apr 03, 2009 11:04 pm
Projects :: No Mod project currently.
Games I'm Playing :: I have not listed any games yet
xbox live or psn: No gamertag set
Location: Atlanta, GA xfire=myers73 IngameName=mYers

Re: LUA help needed

Post by myers73 »

Code: Select all

    testFunction = OnCharacterDeath(
        function(player, killer)
            if killer == nil then return end --make sure there is a killer
            local unit = GetCharacterUnit(killer) --get the killer's unit object
            if unit == nil then return end --make sure the killer wasn't also killed
            SetProperty(unit, "CurHealth", GetObjectHealth(unit)+(MaxHealth-CurHealth))
        end
    )
I tried that but nothing happened, but when I replaced (MaxHealth-CurHealth) with a number it worked.
User avatar
Maveritchell
Jedi Admin
Jedi Admin
Posts: 7366
Joined: Mon Aug 21, 2006 11:03 pm

Re: LUA help needed

Post by Maveritchell »

myers73 wrote:

Code: Select all

    testFunction = OnCharacterDeath(
        function(player, killer)
            if killer == nil then return end --make sure there is a killer
            local unit = GetCharacterUnit(killer) --get the killer's unit object
            if unit == nil then return end --make sure the killer wasn't also killed
            SetProperty(unit, "CurHealth", GetObjectHealth(unit)+(MaxHealth-CurHealth))
        end
    )
I tried that but nothing happened, but when I replaced (MaxHealth-CurHealth) with a number it worked.
That's because you used two variables that had no definition. "MaxHealth" by itself doesn't mean anything; neither does "CurHealth."
myers73
Lieutenant General
Lieutenant General
Posts: 690
Joined: Fri Apr 03, 2009 11:04 pm
Projects :: No Mod project currently.
Games I'm Playing :: I have not listed any games yet
xbox live or psn: No gamertag set
Location: Atlanta, GA xfire=myers73 IngameName=mYers

Re: LUA help needed

Post by myers73 »

can a local variable that is defined in one function be called in another function?
User avatar
[RDH]Zerted
Gametoast Staff
Gametoast Staff
Posts: 2982
Joined: Sun Feb 26, 2006 7:36 am
Projects :: Bos Wars AI - a RTS game
Games I'm Playing :: SWBF2 and Bos Wars
xbox live or psn: No gamertag set
Location: USA
Contact:

Re: LUA help needed

Post by [RDH]Zerted »

Only if that other function was created in the same scope/level as the local variable. As an example, this is ok:

Code: Select all

function sayHello()
    local message = "Hello"

    showMsg = function()
        print("showMsg() says: ", message)
    end

    showMsg()
end
But this won't work as expected:

Code: Select all

function sayHello()
    local message = "Hello"
end

showMsg = function()
    print("showMsg() says: ", message)
end

showMsg()
Post Reply