LUA weap problems - Freeze Gun....causes freezing
Moderator: Moderators
- Sky_216
- Droid Pilot Assassin

- Posts: 2086
- Joined: Mon Feb 13, 2006 3:28 am
- Projects :: No Mod project currently.
- xbox live or psn: No gamertag set
LUA weap problems - Freeze Gun....causes freezing
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:
- Maveritchell
- Jedi Admin

- Posts: 7366
- Joined: Mon Aug 21, 2006 11:03 pm
Re: LUA weap problems - Freeze Gun....causes freezing
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.
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.
- [RDH]Zerted
- Gametoast Staff

- Posts: 2982
- Joined: Sun Feb 26, 2006 7:36 am
- Projects :: Bos Wars AI - a RTS game
- xbox live or psn: No gamertag set
- Location: USA
- Contact:
Re: LUA weap problems - Freeze Gun....causes freezing
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.
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.
- Sky_216
- Droid Pilot Assassin

- Posts: 2086
- Joined: Mon Feb 13, 2006 3:28 am
- Projects :: No Mod project currently.
- xbox live or psn: No gamertag set
Re: LUA weap problems - Freeze Gun....causes freezing
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....
--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....
- Maveritchell
- Jedi Admin

- Posts: 7366
- Joined: Mon Aug 21, 2006 11:03 pm
Re: LUA weap problems - Freeze Gun....causes freezing
Yeah, that's fine. As long as it's not in the nested "OnTimerElapse()" callback it should be ok.
- [RDH]Zerted
- Gametoast Staff

- Posts: 2982
- Joined: Sun Feb 26, 2006 7:36 am
- Projects :: Bos Wars AI - a RTS game
- xbox live or psn: No gamertag set
- Location: USA
- Contact:
Re: LUA weap problems - Freeze Gun....causes freezing
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
Wow. There are some problems I never ran into or predicted.
Hehe... I'll be updating that code soon.
Thanks, Sky/Mav/Zerted.
Hehe... I'll be updating that code soon.
Thanks, Sky/Mav/Zerted.
- Sky_216
- Droid Pilot Assassin

- Posts: 2086
- Joined: Mon Feb 13, 2006 3:28 am
- Projects :: No Mod project currently.
- xbox live or psn: No gamertag set
Re: LUA weap problems - Freeze Gun....causes freezing
@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???
@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???
- Maveritchell
- Jedi Admin

- Posts: 7366
- Joined: Mon Aug 21, 2006 11:03 pm
Re: LUA weap problems - Freeze Gun....causes freezing
You'll put "DestroyTimer(timer)" anywhere inside the function(timer) in the callback OnTimerElapse.
- Sky_216
- Droid Pilot Assassin

- Posts: 2086
- Joined: Mon Feb 13, 2006 3:28 am
- Projects :: No Mod project currently.
- xbox live or psn: No gamertag set
Re: LUA weap problems - Freeze Gun....causes freezing
Oh right, thanks....
