guyde
Chieftain
I'm trying to make combat hook script for sharing. ( combat hook script works fine to me )
but... I have serious problem to make 'combathooker.lua'
Here is part of my script.
It works fine... but problem is it's totally broken when call this 'LuaEvents' using other lua file with include method.
include("Combathook.lua");
function TestFunction( pActPlayer, pActUnit, pDefPlayer, pDefUnit )
print("Defender - " .. pDefUnit:GetName() .. " / Attacker - " .. pActUnit:GetName() );
local iFaith = ( pActUnit:GetBaseCombatStrength() * 2 );
pActPlayer:ChangeFaith( iFaith );
end
LuaEvents.CH_AttackUnit.Add( TestFunction );
It print not unit's name. but It print civilization's name! and all value is broken.
What am I suppose to do? Am I misunderstood about LuaEvents? I have totally no idea of those problem.
but... I have serious problem to make 'combathooker.lua'
Here is part of my script.
Spoiler :
function CH_OnUnitCombat( pDefPlayer, pDefUnit )
local pActPlayer = g_Act_pPlayer[ g_Act_iPlayer ];
if ( g_Act_bAttack[ g_Act_iPlayer ] ) then
CH_CityDetect();
if ( g_Act_pCity[ g_Act_iPlayer ] == nil ) then
return false;
end
local pActCity = g_Act_pCity[ g_Act_iPlayer ];
g_Act_pCity[ g_Act_iPlayer ] = nil;
print("Defender - " .. pDefUnit:GetName() .. " / Attacker - " .. pActCity:GetName() );
LuaEvents:CH_CityAttack( pActPlayer, pActCity, pDefPlayer, pDefUnit );
g_iFloatingDelay = 1.3;
return
end
local pActUnit = g_Act_pUnit[ g_Act_iPlayer ];
g_Act_bAttack[ g_Act_iPlayer ] = true; -- prevent fire twice.
print("Defender - " .. pDefUnit:GetName() .. " / Attacker - " .. pActUnit:GetName() );
LuaEvents:CH_AttackUnit( pActPlayer, pActUnit, pDefPlayer, pDefUnit );
g_iFloatingDelay = 1.3;
end
local pActPlayer = g_Act_pPlayer[ g_Act_iPlayer ];
if ( g_Act_bAttack[ g_Act_iPlayer ] ) then
CH_CityDetect();
if ( g_Act_pCity[ g_Act_iPlayer ] == nil ) then
return false;
end
local pActCity = g_Act_pCity[ g_Act_iPlayer ];
g_Act_pCity[ g_Act_iPlayer ] = nil;
print("Defender - " .. pDefUnit:GetName() .. " / Attacker - " .. pActCity:GetName() );
LuaEvents:CH_CityAttack( pActPlayer, pActCity, pDefPlayer, pDefUnit );
g_iFloatingDelay = 1.3;
return
end
local pActUnit = g_Act_pUnit[ g_Act_iPlayer ];
g_Act_bAttack[ g_Act_iPlayer ] = true; -- prevent fire twice.
print("Defender - " .. pDefUnit:GetName() .. " / Attacker - " .. pActUnit:GetName() );
LuaEvents:CH_AttackUnit( pActPlayer, pActUnit, pDefPlayer, pDefUnit );
g_iFloatingDelay = 1.3;
end
It works fine... but problem is it's totally broken when call this 'LuaEvents' using other lua file with include method.
Spoiler :
include("Combathook.lua");
function TestFunction( pActPlayer, pActUnit, pDefPlayer, pDefUnit )
print("Defender - " .. pDefUnit:GetName() .. " / Attacker - " .. pActUnit:GetName() );
local iFaith = ( pActUnit:GetBaseCombatStrength() * 2 );
pActPlayer:ChangeFaith( iFaith );
end
LuaEvents.CH_AttackUnit.Add( TestFunction );
It print not unit's name. but It print civilization's name! and all value is broken.
What am I suppose to do? Am I misunderstood about LuaEvents? I have totally no idea of those problem.
