ActivateObject()/DeactivateObject()

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
[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: ActivateObject()/DeactivateObject()

Post 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.
MasterSaitek009
Black Sun Slicer
Posts: 619
Joined: Wed Aug 23, 2006 4:10 pm

Re: ActivateObject()/DeactivateObject()

Post 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
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: ActivateObject()/DeactivateObject()

Post 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]
SergeantShade

Re: ActivateObject()/DeactivateObject()

Post 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.
User avatar
Maveritchell
Jedi Admin
Jedi Admin
Posts: 7366
Joined: Mon Aug 21, 2006 11:03 pm

Re: ActivateObject()/DeactivateObject()

Post 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.
User avatar
AceMastermind
Gametoast Staff
Gametoast Staff
Posts: 3285
Joined: Mon Aug 21, 2006 6:23 am
Contact:

Re: ActivateObject()/DeactivateObject()

Post 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.
MandeRek
Sith Master
Sith Master
Posts: 2766
Joined: Tue Oct 02, 2007 10:51 am
Projects :: Battlefront Zer0
Games I'm Playing :: SWTOR
xbox live or psn: No gamertag set
Location: Ghosting around GT
Contact:

Re: ActivateObject()/DeactivateObject()

Post 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...
Post Reply