Page 1 of 1

Re: ActivateObject()/DeactivateObject()

Posted: Sat Mar 01, 2008 7:24 pm
by [RDH]Zerted
I can't tell because you didn't post your exact, full code, but what you posted won't run because FreezeFor isn't defined before you use it. Also, put print() statements throughout your code to determine where it fails.

Re: ActivateObject()/DeactivateObject()

Posted: Sat Mar 01, 2008 11:17 pm
by MasterSaitek009
Sorry 'bout that.
Here's how it's setup in the Lua

Code: Select all

function ScriptPostLoad()	   
        EnableSPHeroRules()
		OnObjectDamage(
         function(object, damager)
		   if GetObjectTeam(object) == DEF then return end
               if GetCharacterTeam(damager) == DEF then
                 if GetCharacterClass(damager) == 1 then
					print("check 1")
					FreezeFor(object, 2)
					print("check 2")
                 end
             end  
          end
            )
   hunt = Objective:New{textDEF = "level.cor1.objectives.hunt.def", textATT = "level.cor1.objectives.hunt.att",}
    
    hunt.OnStart = function(self)
    	AddAIGoal(ATT, "Deathmatch", 1000)
    	AddAIGoal(DEF, "Deathmatch", 1000)
    end
    
    hunt_timer = CreateTimer("hunt_timer")
    SetTimerValue(hunt_timer, 300)
    StartTimer(hunt_timer)
    victory = OnTimerElapse(
    	function(timer)
    		MissionVictory(DEF)
    		ReleaseTimerElapse(victory)
    	end,
    	hunt_timer
    	)
    ShowTimer(hunt_timer)
		hunt:Start() 
end
function FreezeFor(object, timercount)
	print("check 3")
	--Freeze
	health = GetObjectHealth(object)
	SetProperty(object, "CurHealth", 1000000)
        DeactivateObject()
	-- Wait for timercount
	print("check 4")
	timer2 = CreateTimer("timer2")
	SetTimerValue(timer2, timercount)
	StartTimer(timer2)
	uf = OnTimerElapse(
	function(timer)
		print("check 5")
		--Unfreeze
                ActivateObject()
		print("check 6")
		SetProperty(object, "CurHealth", (GetObjectHealth(object) - 1000000) + health)
		print("check 7")
	end,
	timer2
	)
end
And I was wrong about it not working at all. It usually works once. But sometimes it doesn't work at all.
Here's the log for when it worked once.
--First use of the weapon: Worked
check 1
check 3
check 4
check 2
check 5
check 6
check 7
--Second use of the weapon: CTD
check 1
check 3
check 4
check 2
check 5
check 6
check 7
check 5
check 6
check 7

Re: ActivateObject()/DeactivateObject()

Posted: Wed Mar 05, 2008 1:39 am
by [RDH]Zerted
This is more what I meant. Theres no reason to store a timer in a variable. Reread the timer docs. You aren't fully understanding how the timer functions work. In my last post, by variable I meant the timer's name.
Hidden/Spoiler:
[code]-- load the gametype script
ScriptCB_DoFile("ObjectiveConquest")
ScriptCB_DoFile("setup_teams")
-- REP Attacking (attacker is always #1)
local CIS = 2
local REP = 1

-- These variables do not change
ATT = REP;
DEF = CIS;

--add these two lines
freeze_count = 0
freeze_name = "freeze_timer_"

function ScriptPostLoad()
--add this chunk to your ScriptPostLoad
OnObjectDamage(
function(object, damager)
if GetObjectLastHitWeaponClass(object) ~= "com_weap_inf_stasis" then return end
--Begin Freeze
--the second value is the amount of time that you would like the unit to stay frozen for
FreezeFor(object, 5)
end
)
-- end chunk
end

--add this chunk between ScriptPostLoad and ScriptInit or before OnObjectDamage
function FreezeFor(object, timercount)
if GetObjectHealth(object) >= 800000 then return end

--health is under limit
health = GetObjectHealth(object)
SetProperty(object, "CurHealth", 1000000)
DeactivateObject(object)

freeze_count = freeze_count + 1
local name = freeze_name .. freeze_count

CreateTimer( name )
SetTimerValue( name, timercount )
StartTimer( name )

--Wait for timercount
OnTimerElapse(
function(timer)
--Unfreeze
ActivateObject(object)
SetProperty(object, "CurHealth", (GetObjectHealth(object) - 1000000) + health)

--clean up timer
DestroyTimer( name )
end,
name )
end
--end chunk[/code]

Re: ActivateObject()/DeactivateObject()

Posted: Wed Mar 05, 2008 10:55 am
by SergeantShade
i wasnt even sure it was 'Freeze', thats how dann's jail cell came into action isnt it?
Though, I'm curious to know how the mustafar bridge works. It has animations, regions, scripts, and a whole bunch of stuff i still dont understand.

Re: ActivateObject()/DeactivateObject()

Posted: Wed Mar 05, 2008 11:23 am
by Maveritchell
MasterSaitek009 wrote:I feel kind of stupid being the only person asking questions about Lua.
Don't feel stupid, you probably know it as well or better than anyone short of Zerted. People aren't asking questions not because they know it well, but because most, I think, are intimidated by it.

I really enjoy seeing questions I can learn stuff from.

Re: ActivateObject()/DeactivateObject()

Posted: Wed Mar 05, 2008 11:40 am
by AceMastermind
My interest in this game is fairly simple, i'm an old fashioned conquest kind of guy, but I do take notes on whatever you guys discuss just incase one day I may need to know something, but I really have no use for advanced scripting so far.

Re: ActivateObject()/DeactivateObject()

Posted: Wed Mar 05, 2008 12:17 pm
by MandeRek
AceMastermind wrote:My interest in this game is fairly simple, i'm an old fashioned conquest kind of guy, but I do take notes on whatever you guys discuss just incase one day I may need to know something, but I really have no use for advanced scripting so far.
Off-topic: I really agree with Ace, especially since conquest can be sooo fun with a lot of new models and weapons to explore...