'LuaEvents' Help

guyde

Chieftain
Joined
Dec 22, 2014
Messages
13
Location
South Korea
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.
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


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.:confused:
 
Probably a misunderstanding of the Lua : operator
Code:
LuaEvents[B][COLOR="red"]:[/COLOR][/B]CH_AttackUnit( pActPlayer, pActUnit, pDefPlayer, pDefUnit );
should probably be
Code:
LuaEvents[B][COLOR="Red"].[/COLOR][/B]CH_AttackUnit( pActPlayer, pActUnit, pDefPlayer, pDefUnit );
 
Probably a misunderstanding of the Lua : operator
Code:
LuaEvents[B][COLOR="red"]:[/COLOR][/B]CH_AttackUnit( pActPlayer, pActUnit, pDefPlayer, pDefUnit );
should probably be
Code:
LuaEvents[B][COLOR="Red"].[/COLOR][/B]CH_AttackUnit( pActPlayer, pActUnit, pDefPlayer, pDefUnit );

OK! It's working! Thanks a lot!
I will upload that script soon!
 
Back
Top Bottom