Page 1 of 1

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

Posted: Sun Nov 16, 2008 11:25 pm
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

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

Posted: Mon Nov 17, 2008 2:26 am
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.

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

Posted: Mon Nov 17, 2008 2:55 pm
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.

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

Posted: Mon Nov 17, 2008 3:00 pm
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....

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

Posted: Mon Nov 17, 2008 3:13 pm
by Maveritchell
Yeah, that's fine. As long as it's not in the nested "OnTimerElapse()" callback it should be ok.

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

Posted: Mon Nov 17, 2008 4:01 pm
by [RDH]Zerted
Almost, you still need DestroyTimer in OnTimerElapse

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

Posted: Mon Nov 17, 2008 11:11 pm
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.

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

Posted: Tue Nov 25, 2008 8:44 pm
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???

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

Posted: Tue Nov 25, 2008 10:05 pm
by Maveritchell
You'll put "DestroyTimer(timer)" anywhere inside the function(timer) in the callback OnTimerElapse.

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

Posted: Tue Nov 25, 2008 11:23 pm
by Sky_216
Oh right, thanks....