LUA weap problems - Freeze Gun....causes freezing

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
User avatar
Sky_216
Droid Pilot Assassin
Droid Pilot Assassin
Posts: 2086
Joined: Mon Feb 13, 2006 3:28 am
Projects :: No Mod project currently.
Games I'm Playing :: I have not listed any games yet
xbox live or psn: No gamertag set

LUA weap problems - Freeze Gun....causes freezing

Post by Sky_216 »

Well I have a problem. I made a carbonite gun and a carbonite grenade based off a weapon made by MasterSaitek009 - force stasis. The weapons work fine, but if too many people (about 5) get 'frozen' at once, the game freezes (not CTDs, completely freezes up). Anyone got any idea how to get around this problem??? Here's the relevent bit of my lua (with the 'stasis' bits highlighted):
Hidden/Spoiler:
--ADD THIS AFTER THE ScriptCB_DoFile SECTION
count = 0
--END


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

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"}
cp6 = CommandPost:New{name = "cp6"}
cp7 = CommandPost:New{name = "cp7"}
cp8 = CommandPost:New{name = "cp8"}



--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}

-- ADD THIS IN THE ScriptPostLoad SECTION

OnObjectDamage(
function(object, damager)
if GetObjectHealth(object) > 900000 then return end
if GetObjectLastHitWeaponClass(object) == "imp_weap_inf_carbonite" then
FreezeFor(object,3)
end
end
)
--END

--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:AddCommandPost(cp6)
conquest:AddCommandPost(cp7)
conquest:AddCommandPost(cp8)

conquest:Start()

EnableSPHeroRules()
Ambush("ambushpath", 6, 3)

end

--ADD THIS AFTER THE ScriptPostLoad SECTION
function FreezeFor(object, timercount)
--Freeze
print("--Freeze")
health = GetObjectHealth(object)
SetProperty(object, "CurHealth", 1000000)
DeactivateObject(object)
-- Wait for timercount
print("-- Wait for timercount")
CreateTimer("timer" .. count)
SetTimerValue("timer" .. count, timercount)
StartTimer("timer" .. count)
OnTimerElapse(
function(timer)
--Unfreeze
print("--Unfreeze")
ActivateObject(object)
SetProperty(object, "CurHealth", (GetObjectHealth(object) - 1000000) + health)
count = count + 1
end,
"timer" .. count
)
end
--END
User avatar
Maveritchell
Jedi Admin
Jedi Admin
Posts: 7366
Joined: Mon Aug 21, 2006 11:03 pm

Re: LUA weap problems - Freeze Gun....causes freezing

Post by Maveritchell »

There might be a maximum number of timers the game can keep track of at once. However, I think it's more likely that you're trying to use a weapon that's designed to only target one person at once (so it keeps trying to create the same timer again and again, because the timer's "number" doesn't increment until after the timer expires. I think that count should be set to increment (count = count + 1) at the beginning of the freeze function (it's what I would do, at least).

Take that all with a grain of salt because it's late, I'm tired, and I didn't really think this through very much. You're welcome to give it a try and see if it works, though.
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 weap problems - Freeze Gun....causes freezing

Post by [RDH]Zerted »

Sorry for not getting back to your PM, I'm been busy and am moving soon....

I agree with Maveritchell. The counter needs to be incremented before the timer is created. Also, you should be destroying the timer when it finishes. I don't know the max amount of timers you can have, but I bet there is a limit.

I don't know if you wanted this, but it looks like the weapon will freeze objects too. Meaning, you could freeze say a bridge control and the bridge will stay up until unfrozen and destroyed. I don't know what this will do to destructible CP. Does DeactivateObject() prevent you from spawning at it? If not, good luck trying to destroy a frozen shield generator or a space asset.
User avatar
Sky_216
Droid Pilot Assassin
Droid Pilot Assassin
Posts: 2086
Joined: Mon Feb 13, 2006 3:28 am
Projects :: No Mod project currently.
Games I'm Playing :: I have not listed any games yet
xbox live or psn: No gamertag set

Re: LUA weap problems - Freeze Gun....causes freezing

Post by Sky_216 »

No problem Zerted. So what you're saying is that it should be like this?

--ADD THIS AFTER THE ScriptPostLoad SECTION
function FreezeFor(object, timercount)
count = count + 1
--Freeze
print("--Freeze")
health = GetObjectHealth(object)
SetProperty(object, "CurHealth", 1000000)
DeactivateObject(object)
-- Wait for timercount
print("-- Wait for timercount")
CreateTimer("timer" .. count)
SetTimerValue("timer" .. count, timercount)
StartTimer("timer" .. count)
OnTimerElapse(
function(timer)
--Unfreeze
print("--Unfreeze")
ActivateObject(object)
SetProperty(object, "CurHealth", (GetObjectHealth(object) - 1000000) + health)
end,
"timer" .. count
)
end
--END

And yes freeze works against turrets and recon droids,. Dunno about vehicles....
User avatar
Maveritchell
Jedi Admin
Jedi Admin
Posts: 7366
Joined: Mon Aug 21, 2006 11:03 pm

Re: LUA weap problems - Freeze Gun....causes freezing

Post by Maveritchell »

Yeah, that's fine. As long as it's not in the nested "OnTimerElapse()" callback it should be ok.
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 weap problems - Freeze Gun....causes freezing

Post by [RDH]Zerted »

Almost, you still need DestroyTimer in OnTimerElapse
MasterSaitek009
Black Sun Slicer
Posts: 619
Joined: Wed Aug 23, 2006 4:10 pm

Re: LUA weap problems - Freeze Gun....causes freezing

Post by MasterSaitek009 »

Wow. There are some problems I never ran into or predicted. :shock:
Hehe... I'll be updating that code soon. :)

Thanks, Sky/Mav/Zerted.
User avatar
Sky_216
Droid Pilot Assassin
Droid Pilot Assassin
Posts: 2086
Joined: Mon Feb 13, 2006 3:28 am
Projects :: No Mod project currently.
Games I'm Playing :: I have not listed any games yet
xbox live or psn: No gamertag set

Re: LUA weap problems - Freeze Gun....causes freezing

Post by Sky_216 »

@Zerted: thanks.
@Saitek: yep I'm assuming that's cos your power only effects one person at a time?


EDIT
Sorry Zerted,/Mav, can you show me where the line 'DestroyTimer' goes???
User avatar
Maveritchell
Jedi Admin
Jedi Admin
Posts: 7366
Joined: Mon Aug 21, 2006 11:03 pm

Re: LUA weap problems - Freeze Gun....causes freezing

Post by Maveritchell »

You'll put "DestroyTimer(timer)" anywhere inside the function(timer) in the callback OnTimerElapse.
User avatar
Sky_216
Droid Pilot Assassin
Droid Pilot Assassin
Posts: 2086
Joined: Mon Feb 13, 2006 3:28 am
Projects :: No Mod project currently.
Games I'm Playing :: I have not listed any games yet
xbox live or psn: No gamertag set

Re: LUA weap problems - Freeze Gun....causes freezing

Post by Sky_216 »

Oh right, thanks....
Post Reply