Page 1 of 1

Weapon ODF troubles - And now LUA issues, too

Posted: Sun May 23, 2010 12:20 pm
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?

Re: Weapon ODF troubles

Posted: Sun May 23, 2010 12:51 pm
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...

Re: Weapon ODF troubles

Posted: Sun May 23, 2010 1:12 pm
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....

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

Posted: Sun May 23, 2010 2:30 pm
by myers73
GetEntityClass() wants a string and you are giving it a variable, at least I think that is the problem

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

Posted: Sun May 23, 2010 2:37 pm
by Fiodis
Isn't that line supposed to check if teleporter's class is equal to rep_bldg_in_blueturret?

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

Posted: Sun May 23, 2010 2:40 pm
by myers73
if so then it looks fine to me

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

Posted: Mon May 24, 2010 3:58 pm
by CressAlbane
rep_bldg_in_blueturret
Is this supposed to be rep_bldg_inf_blueturret ?

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

Posted: Mon May 24, 2010 4:09 pm
by myers73
i dont see that typo anywhere...

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

Posted: Mon May 24, 2010 5:34 pm
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.

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

Posted: Mon May 24, 2010 5:36 pm
by CressAlbane
/slap
I feel dumb.

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

Posted: Mon May 31, 2010 10:28 am
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?

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

Posted: Mon May 31, 2010 2:56 pm
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

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

Posted: Mon May 31, 2010 6:19 pm
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?

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

Posted: Mon May 31, 2010 7:38 pm
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

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

Posted: Mon May 31, 2010 8:54 pm
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.