Weapon ODF troubles - And now LUA issues, too

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
Fiodis
Master of the Force
Master of the Force
Posts: 4145
Joined: Wed Nov 12, 2008 9:27 pm
Projects :: Rannoch + Tientia + Tools Programming

Weapon ODF troubles - And now LUA issues, too

Post by Fiodis »

I'm trying to make a turret fire at you only if you stand up against it for a while. To this aim, I've decreased LockOnTime to 3.0, LockOnRange to 1.0, and some other tweaks:
Hidden/Spoiler:
[code][WeaponClass]
ClassLabel = "cannon"

[Properties]

OrdnanceName = "rep_weap_inf_autoturret_ord"

MuzzleFlash = "med_muzzle_flash"
Discharge = "med_smoke_effect"

RoundsPerClip = "0"

HeatPerShot = "0.0"
HeatRecoverRate = "0.0"
HeatThreshold = "0.0"

MinRange = "0"
OptimalRange = "1"
MaxRange = "1.1"

RecoilLengthLight = "0.1"
RecoilStrengthLight = "1"
RecoilLengthHeavy = "0.05"
RecoilStrengthHeavy = "1"

ZoomMin = "2.0"
ZoomMax = "8.0"
ZoomRate = "2.0"

ShotDelay = "1.7"

LockOnRange = "1.0"
LockTime = "3.0"
MinSpread = "0.1"
MaxSpread = "0.35"
AutoAimSize = "30.0"

TargetEnemy = "1"
TargetNeutral = "1"
TargetFriendly = "1"

TargetPerson = "1"
TargetAnimal = "1"
TargetDroid = "1"
TargetVehicle = "0"
TargetBuilding = "0"

SalvoCount = "1"
SalvoDelay = ".1"

//**********************************************
//****************** SOUND *********************
//**********************************************

FireSound = "com_weap_turret_fire_mini"


FoleyFXGroup = "metal_foley"
[/code][/size]
However, it doesn't work; the turrets fire at me even if I'm farther away from them, and they don't wait. Am I changing the wrong values?
Last edited by Fiodis on Sun May 23, 2010 1:38 pm, edited 1 time in total.
myers73
Lieutenant General
Lieutenant General
Posts: 690
Joined: Fri Apr 03, 2009 11:04 pm
Projects :: No Mod project currently.
Games I'm Playing :: I have not listed any games yet
xbox live or psn: No gamertag set
Location: Atlanta, GA xfire=myers73 IngameName=mYers

Re: Weapon ODF troubles

Post by myers73 »

MinRange = "0"
OptimalRange = "0.5"
MaxRange = "1"
ExtremeRange = "1"

these tell the AI how far away to target with each gun. you could also give the turret a slow projectile, and have it transition to zero damage, but I have a feeling you are making an LUA gun...
User avatar
Fiodis
Master of the Force
Master of the Force
Posts: 4145
Joined: Wed Nov 12, 2008 9:27 pm
Projects :: Rannoch + Tientia + Tools Programming

Re: Weapon ODF troubles

Post by Fiodis »

myers73 wrote:you could also give the turret a slow projectile, and have it transition to zero damage, but I have a feeling you are making an LUA gun...
I have a feeling you're right.... :wink:
Thanks for the ExtremeRange. It worked.

EDIT: But the lua code didn't. I may as well continue this thread rather than start a new one, as the issue pertains to the same weapon.
Hidden/Spoiler:
[code] getturretcoordinates = OnCharacterDispenseControllable(
function(dropper, thing)
if GetEntityClass(thing) == FindEntityClass("rep_bldg_inf_blueturret") then
SetObjectTeam(thing, 3)
local bluematrix = GetEntityMatrix(thing)
elseif GetEntityClass(thing) == FindEntityClass("rep_bldg_inf_goldturret") then
SetObjectTeam(thing, 3)
local goldmatrix = GetEntitMatrix(thing)
end
end
)

turretswitchandmatrixget = OnObjectDamage(
function(tobeteleported, teleporter)
if GetEntityClass(teleporter) == FindEntityClass("rep_bldg_inf_blueturret") then
local movedguy = GetCharacterUnit(tobeteleported)
SetEntityMatrix(movedguy, goldmatrix)
elseif GetEntityClass(teleporter) == FindEntityClass("rep_bldg_inf_goldturret") then
local movedguy = GetCharacterUnit(tobeteleported)
SetEntityMatrix(movedguy, bluematrix)
end
end
)[/code][/size]
I get this in the error log:
Hidden/Spoiler:
[code]Message Severity: 3
.\Source\LuaHelper.cpp(312)
CallProc failed: (none):0: attempt to call global `GetEntitMatrix' (a nil value)
stack traceback:
(none): in function <(none):60>


Message Severity: 3
.\Source\LuaHelper.cpp(312)
CallProc failed: bad argument #1 to `GetEntityClass' (string expected, got nil)
stack traceback:
[C]: in function `GetEntityClass'
(none): in function <(none):72>


Message Severity: 3
.\Source\LuaHelper.cpp(312)
CallProc failed: bad argument #1 to `GetEntityClass' (string expected, got nil)
stack traceback:
[C]: in function `GetEntityClass'
(none): in function <(none):72>


Message Severity: 3
.\Source\LuaHelper.cpp(312)
CallProc failed: bad argument #1 to `GetEntityClass' (string expected, got nil)
stack traceback:
[C]: in function `GetEntityClass'
(none): in function <(none):72>


Message Severity: 3
.\Source\LuaHelper.cpp(312)
CallProc failed: bad argument #1 to `GetEntityClass' (string expected, got nil)
stack traceback:
[C]: in function `GetEntityClass'
(none): in function <(none):72>


Message Severity: 3
.\Source\LuaHelper.cpp(312)
CallProc failed: bad argument #1 to `GetEntityClass' (string expected, got nil)
stack traceback:
[C]: in function `GetEntityClass'
(none): in function <(none):72>


Message Severity: 3
.\Source\LuaHelper.cpp(312)
CallProc failed: bad argument #1 to `GetEntityClass' (string expected, got nil)
stack traceback:
[C]: in function `GetEntityClass'
(none): in function <(none):72>


Message Severity: 3
.\Source\LuaHelper.cpp(312)
CallProc failed: bad argument #1 to `GetEntityClass' (string expected, got nil)
stack traceback:
[C]: in function `GetEntityClass'
(none): in function <(none):72>


Message Severity: 3
.\Source\LuaHelper.cpp(312)
CallProc failed: bad argument #1 to `GetEntityClass' (string expected, got nil)
stack traceback:
[C]: in function `GetEntityClass'
(none): in function <(none):72>


Message Severity: 3
.\Source\LuaHelper.cpp(312)
CallProc failed: bad argument #1 to `GetEntityClass' (string expected, got nil)
stack traceback:
[C]: in function `GetEntityClass'
(none): in function <(none):72>


Message Severity: 3
.\Source\LuaHelper.cpp(312)
CallProc failed: bad argument #1 to `GetEntityClass' (string expected, got nil)
stack traceback:
[C]: in function `GetEntityClass'
(none): in function <(none):72>


Message Severity: 3
.\Source\LuaHelper.cpp(312)
CallProc failed: bad argument #1 to `GetEntityClass' (string expected, got nil)
stack traceback:
[C]: in function `GetEntityClass'
(none): in function <(none):72>


Message Severity: 3
.\Source\LuaHelper.cpp(312)
CallProc failed: bad argument #1 to `GetEntityClass' (string expected, got nil)
stack traceback:
[C]: in function `GetEntityClass'
(none): in function <(none):72>


Message Severity: 3
.\Source\LuaHelper.cpp(312)
CallProc failed: bad argument #1 to `GetEntityClass' (string expected, got nil)
stack traceback:
[C]: in function `GetEntityClass'
(none): in function <(none):72>


Message Severity: 3
.\Source\LuaHelper.cpp(312)
CallProc failed: bad argument #1 to `GetEntityClass' (string expected, got nil)
stack traceback:
[C]: in function `GetEntityClass'
(none): in function <(none):72>


Message Severity: 3
.\Source\LuaHelper.cpp(312)
CallProc failed: bad argument #1 to `GetEntityClass' (string expected, got nil)
stack traceback:
[C]: in function `GetEntityClass'
(none): in function <(none):72>


Message Severity: 3
.\Source\LuaHelper.cpp(312)
CallProc failed: bad argument #1 to `GetEntityClass' (string expected, got nil)
stack traceback:
[C]: in function `GetEntityClass'
(none): in function <(none):72>
[/code]
I'm trying to make it so that when the player is shot by the gold turret, he's moved to the blue one, and vice versa. In-game, though, nothing happens when he's shot. I'm pretty sure I got the GetEntityClass part right....
myers73
Lieutenant General
Lieutenant General
Posts: 690
Joined: Fri Apr 03, 2009 11:04 pm
Projects :: No Mod project currently.
Games I'm Playing :: I have not listed any games yet
xbox live or psn: No gamertag set
Location: Atlanta, GA xfire=myers73 IngameName=mYers

Re: Weapon ODF troubles - And now LUA issues, too

Post by myers73 »

GetEntityClass() wants a string and you are giving it a variable, at least I think that is the problem
User avatar
Fiodis
Master of the Force
Master of the Force
Posts: 4145
Joined: Wed Nov 12, 2008 9:27 pm
Projects :: Rannoch + Tientia + Tools Programming

Re: Weapon ODF troubles - And now LUA issues, too

Post by Fiodis »

Isn't that line supposed to check if teleporter's class is equal to rep_bldg_in_blueturret?
myers73
Lieutenant General
Lieutenant General
Posts: 690
Joined: Fri Apr 03, 2009 11:04 pm
Projects :: No Mod project currently.
Games I'm Playing :: I have not listed any games yet
xbox live or psn: No gamertag set
Location: Atlanta, GA xfire=myers73 IngameName=mYers

Re: Weapon ODF troubles - And now LUA issues, too

Post by myers73 »

if so then it looks fine to me
CressAlbane
Master Bounty Hunter
Master Bounty Hunter
Posts: 1519
Joined: Fri Dec 18, 2009 8:02 am
Projects :: CTF Arenas
Games I'm Playing :: Steam- cressalbane2
Location: ¿uoıʇɐɔoן ʎɯ sıɥʇ sı

Re: Weapon ODF troubles - And now LUA issues, too

Post by CressAlbane »

rep_bldg_in_blueturret
Is this supposed to be rep_bldg_inf_blueturret ?
myers73
Lieutenant General
Lieutenant General
Posts: 690
Joined: Fri Apr 03, 2009 11:04 pm
Projects :: No Mod project currently.
Games I'm Playing :: I have not listed any games yet
xbox live or psn: No gamertag set
Location: Atlanta, GA xfire=myers73 IngameName=mYers

Re: Weapon ODF troubles - And now LUA issues, too

Post by myers73 »

i dont see that typo anywhere...
User avatar
StarkillerMarek
Rebel Colonel
Rebel Colonel
Posts: 611
Joined: Wed Aug 12, 2009 4:42 pm
Location: I may be back.

Re: Weapon ODF troubles - And now LUA issues, too

Post by StarkillerMarek »

Fiodis wrote:Isn't that line supposed to check if teleporter's class is equal to rep_bldg_in_blueturret?
Fiodis just wrote it in his post. He didn't make that mistake in the Lua.
CressAlbane
Master Bounty Hunter
Master Bounty Hunter
Posts: 1519
Joined: Fri Dec 18, 2009 8:02 am
Projects :: CTF Arenas
Games I'm Playing :: Steam- cressalbane2
Location: ¿uoıʇɐɔoן ʎɯ sıɥʇ sı

Re: Weapon ODF troubles - And now LUA issues, too

Post by CressAlbane »

/slap
I feel dumb.
User avatar
Fiodis
Master of the Force
Master of the Force
Posts: 4145
Joined: Wed Nov 12, 2008 9:27 pm
Projects :: Rannoch + Tientia + Tools Programming

Re: Weapon ODF troubles - And now LUA issues, too

Post by Fiodis »

Ah - could this be the problem?
myers73 wrote:can a local variable that is defined in one function be called in another function?
[RDH]Zerted wrote:Only if that other function was created in the same scope/level as the local variable. As an example, this is ok:

Code: Select all

function sayHello()
    local message = "Hello"

    showMsg = function()
        print("showMsg() says: ", message)
    end

    showMsg()
end
But this won't work as expected:

Code: Select all

function sayHello()
    local message = "Hello"
end

showMsg = function()
    print("showMsg() says: ", message)
end

showMsg()
Would I have to put one function inside the other?
myers73
Lieutenant General
Lieutenant General
Posts: 690
Joined: Fri Apr 03, 2009 11:04 pm
Projects :: No Mod project currently.
Games I'm Playing :: I have not listed any games yet
xbox live or psn: No gamertag set
Location: Atlanta, GA xfire=myers73 IngameName=mYers

Re: Weapon ODF troubles - And now LUA issues, too

Post by myers73 »

yes, just write it into one big function with the two functions inside of it. these are deployable turrets right? if not then just use an OnEnterRegion() teleport
User avatar
Fiodis
Master of the Force
Master of the Force
Posts: 4145
Joined: Wed Nov 12, 2008 9:27 pm
Projects :: Rannoch + Tientia + Tools Programming

Re: Weapon ODF troubles - And now LUA issues, too

Post by Fiodis »

This, however:
Hidden/Spoiler:
[code] combinedfunctions = OnCharacterDispenseControllable(
function(dropper, thing)
if GetEntityClass(thing) == FindEntityClass("rep_bldg_inf_blueturret") then
SetObjectTeam(thing, 3)
local bluematrix = GetEntityMatrix(thing)
elseif GetEntityClass(thing) == FindEntityClass("rep_bldg_inf_goldturret") then
SetObjectTeam(thing, 3)
local goldmatrix = GetEntitMatrix(thing)
end
end
turretswitchandmatrixget = OnObjectDamage(
function(tobeteleported, teleporter)
if GetEntityClass(teleporter) == FindEntityClass("rep_bldg_inf_blueturret") then
local movedguy = GetCharacterUnit(tobeteleported)
SetEntityMatrix(movedguy, goldmatrix)
elseif GetEntityClass(teleporter) == FindEntityClass("rep_bldg_inf_goldturret") then
local movedguy = GetCharacterUnit(tobeteleported)
SetEntityMatrix(movedguy, bluematrix)
end
end
)
)[/code][/size]
Gets me this:

Code: Select all

C:\BF2_ModTools\data_FTG\_BUILD\Common\..\..\..\ToolsFL\Bin\luac.exe: ..\..\common\scripts\FTG\FTGc_con.lua:93: `)' expected (to close `(' at line 83) near `turretswitchandmatrixget'
ERROR[scriptmunge scripts\FTG\FTGc_con.lua]:Could not read input file.ERROR[scriptmunge scripts\FTG\FTGc_con.lua]:Could not read input file. [continuing]
   2 Errors    0 Warnings
Am I nesting it wrong?
501st_commander
Master Bounty Hunter
Master Bounty Hunter
Posts: 1570
Joined: Wed Dec 10, 2008 7:48 pm

Re: Weapon ODF troubles - And now LUA issues, too

Post by 501st_commander »

Code: Select all

combinedfunctions = OnCharacterDispenseControllable(
	function(dropper, thing)
		if GetEntityClass(thing) == FindEntityClass("rep_bldg_inf_blueturret") then
			SetObjectTeam(thing, 3)
			local bluematrix = GetEntityMatrix(thing)
		elseif GetEntityClass(thing) == FindEntityClass("rep_bldg_inf_goldturret") then
			SetObjectTeam(thing, 3)
			local goldmatrix = GetEntitMatrix(thing)
		end
	end
)
turretswitchandmatrixget = OnObjectDamage(
      	function(tobeteleported, teleporter)
         		if GetEntityClass(teleporter) == FindEntityClass("rep_bldg_inf_blueturret") then
            			local movedguy = GetCharacterUnit(tobeteleported)
            			SetEntityMatrix(movedguy, goldmatrix)	
		elseif GetEntityClass(teleporter) == FindEntityClass("rep_bldg_inf_goldturret") then
			local movedguy = GetCharacterUnit(tobeteleported)
			SetEntityMatrix(movedguy, bluematrix)
		end
	end
)
^would work
myers73
Lieutenant General
Lieutenant General
Posts: 690
Joined: Fri Apr 03, 2009 11:04 pm
Projects :: No Mod project currently.
Games I'm Playing :: I have not listed any games yet
xbox live or psn: No gamertag set
Location: Atlanta, GA xfire=myers73 IngameName=mYers

Re: Weapon ODF troubles - And now LUA issues, too

Post by myers73 »

no it wont, the local variables have to be defined at at the same level, so the two functions have to be part of a bigger function.
Post Reply