Login  Register
 



Post new topicReply to topic Go to page 1, 2  Next
 
Author Message
 PostPosted: 23 Mar, 2012 
 

Joined: 31 Mar, 2011
Posts: 128
Location: Hanoi, Vietnam
Offline
Hi, how can we check if a bone is hidden by script self:HideBone('Bone_Name', true)?


Top
 Profile  
 PostPosted: 23 Mar, 2012 
 

Joined: 05 Oct, 2007
Posts: 16445
Location: camping near the biggest power-up
Offline
I'm going to assume that there's no function that already exists for checking. I couldn't see any in the LuaDoc, so I think we're going to add one.

The first thing you will need to do is hook the existing HideBone function so it does some new things.

Code:
HideBone = function(self, bone, h)
    oldUnit.HideBone(oldUnit, bone, h) -- Do the original action, so that the bone actually becomes hidden.

    if not self.__hiddenBones then
        self.__hiddenBones = {}
    end

    self.__hiddenBones[bone] = h -- When we un/hide a bone, we add it to this table.
end,


Next, you'll want to be able to ask if the bone is hidden. We'll add a new function for that.

Code:
IsBoneHidden = function(self, bone)
    return self.__hiddenBones[bone] or false -- "or false" is so that we can safely ask about bones that we haven't hidden before.
end,

_________________
Nephylim wrote:
But, an FA army in an FA environment just looks... right.
help wrote:
Does anyone know how to use air transports? I cant get them to pick up troops.


Top
 Profile  
 PostPosted: 23 Mar, 2012 
 

Joined: 31 Mar, 2011
Posts: 128
Location: Hanoi, Vietnam
Offline
BulletMagnet wrote:
I'm going to assume that there's no function that already exists for checking. I couldn't see any in the LuaDoc, so I think we're going to add one.

The first thing you will need to do is hook the existing HideBone function so it does some new things.

Code:
HideBone = function(self, bone, h)
    oldUnit.HideBone(oldUnit, bone, h) -- Do the original action, so that the bone actually becomes hidden.

    if not self.__hiddenBones then
        self.__hiddenBones = {}
    end

    self.__hiddenBones[bone] = h -- When we un/hide a bone, we add it to this table.
end,


Next, you'll want to be able to ask if the bone is hidden. We'll add a new function for that.

Code:
IsBoneHidden = function(self, bone)
    return self.__hiddenBones[bone] or false -- "or false" is so that we can safely ask about bones that we haven't hidden before.
end,

I tried to find where is the existing HideBone function but can't see them.


Top
 Profile  
 PostPosted: 23 Mar, 2012 
 

Joined: 05 Oct, 2007
Posts: 16445
Location: camping near the biggest power-up
Offline
The original one is part of the engine. You can access it from Unit, but you'll never be able to find the function in any of the Lua files.

[PS:] It is 100% okay to hook engine functions. They don't particularly mind at all.

_________________
Nephylim wrote:
But, an FA army in an FA environment just looks... right.
help wrote:
Does anyone know how to use air transports? I cant get them to pick up troops.


Top
 Profile  
 PostPosted: 23 Mar, 2012 
 

Joined: 31 Mar, 2011
Posts: 128
Location: Hanoi, Vietnam
Offline
BulletMagnet wrote:
The original one is part of the engine. You can access it from Unit, but you'll never be able to find the function in any of the Lua files.

[PS:] It is 100% okay to hook engine functions. They don't particularly mind at all.

And...your code is ok to paste and run? I don't understand it very much so if it cause error, I don't know how to fix it :)


Top
 Profile  
 PostPosted: 23 Mar, 2012 
 

Joined: 05 Oct, 2007
Posts: 16445
Location: camping near the biggest power-up
Offline
What is the error?

I have a pretty damn good idea what it's going to be, but I want you to find it for yourself.

_________________
Nephylim wrote:
But, an FA army in an FA environment just looks... right.
help wrote:
Does anyone know how to use air transports? I cant get them to pick up troops.


Top
 Profile  
 PostPosted: 24 Mar, 2012 
 

Joined: 31 Mar, 2011
Posts: 128
Location: Hanoi, Vietnam
Offline
BulletMagnet wrote:
What is the error?

I have a pretty damn good idea what it's going to be, but I want you to find it for yourself.

It caused error. Here is in my unit file(not a specific unit script file):
Code:
   HideBone = function(self, bone, h)
      Unit.HideBone(Unit, bone, h) -- Do the original action, so that the bone actually becomes hidden.
      if not self.__hiddenBones then
         self.__hiddenBones = {}
      end
      self.__hiddenBones[bone] = h -- When we un/hide a bone, we add it to this table.
   end,
   
   IsBoneHidden = function(self, bone)
      return self.__hiddenBones[bone] or false -- "or false" is so that we can safely ask about bones that we haven't hidden before.
   end,

It's all your code
And here is my script in my weapon file:
Code:
         local bone = bp.RackBones[1].MuzzleBone[1]
         if not self:IsBoneHidden(bone) then

Moho Log say I called a nonexistance variable "IsBoneHidden".
I don't understand about programing very much so please explain to me some words how to use IsBoneHidden in all lua file. Thank you.


Top
 Profile  
 PostPosted: 24 Mar, 2012 
 

Joined: 26 Feb, 2009
Posts: 2997
Offline
Hmm,

BM, when i look at the luadoc i see

Code:
HideBone(self,bone,affectChildren)


which indicates to me that self:HideBone('bonename') would work
the affectChildren implies that its an extra param
and not the bool to actual show/hide the bone..

for instance we have bones like this..

bone1 is connected to bone2 which is connect to bone3

we do

Code:
self:HideBone('bone2', false)


would just hide bone2 BUT doing

Code:
self:HideBone('bone2', true)


would hide bone2 and bone3, obviously

Code:
self:HideBone('bone1', true)


would hide all 3 bones.

the same implies to me that ShowBone acts in the same way.

what im trying to say is that h is not a bool to show/hide the bone
so in your code in some cases it will return an incorrect bool.

unless the luadoc is giving false information and that is not how it works..
in DMS ive set it up from the luadoc as i stated here..

http://pastebin.com/eLvVnfY5


ok,

now on with the actual problem, pressuming bulletmagnet is correct,
where are you putting the code, it either goes in the units script or
better yet in a hooked unit.lua to make the function available to all units..

_________________
Domino.
______________


Top
 Profile  
 PostPosted: 24 Mar, 2012 
 

Joined: 05 Oct, 2007
Posts: 16445
Location: camping near the biggest power-up
Offline
You are 100% correct. I just looked at the function in the OP, and just assumed it was for showing/hiding.

Oops.

_________________
Nephylim wrote:
But, an FA army in an FA environment just looks... right.
help wrote:
Does anyone know how to use air transports? I cant get them to pick up troops.


Top
 Profile  
 PostPosted: 25 Mar, 2012 
 

Joined: 31 Mar, 2011
Posts: 128
Location: Hanoi, Vietnam
Offline
Domino wrote:
...where are you putting the code, it either goes in the units script or better yet in a hooked unit.lua to make the function available to all units..

First of all, thank you Domino for your detail instruction and BulletMagnet for your idea. It's very brilliant.
I just have another question: Is it OK when I paste your code in hooked Unit.lua and call it in hooked DefaultWeapons.lua? Or I must only call it in unit's specific script file?


Last edited by phong1892 on 25 Mar, 2012, edited 1 time in total.

Top
 Profile  
 PostPosted: 25 Mar, 2012 
 

Joined: 31 Mar, 2011
Posts: 128
Location: Hanoi, Vietnam
Offline
Never mind this comment, I've just made a mistake :)


Top
 Profile  
 PostPosted: 25 Mar, 2012 
 

Joined: 26 Feb, 2009
Posts: 2997
Offline
Hi,

you can call it in defaultweapons BUT you have to understand something..

in each "Class" lua files like

AIBrain.lua
Weapon.lua
DefaultWeapons.lua
Unit.lua

the self object is the object in said lua file..

for instance:
if your in unit.lua and your calling

Code:
self:HideBone(self,bone,affectChildren)


its the unit its self that is calling this function
if your in DefaultWeapons.lua and you want to call the same function
self is the weapon so it will not work, what you have to do is get a handle to the unit because the function resides in the units script (unit.lua) so to get the unit object you have to use self.unit which is the unit identifier in defaultweapons.lua

Code:
self.unit:HideBone('bonename', affectchildren)


basicly look through which ever class file your in to get the handle set for the unit if
you want to affect the unit in some way.. obviosly if you want to affect the weapon then self is correct.. because this is the weapon object..

_________________
Domino.
______________


Top
 Profile  
 PostPosted: 25 Mar, 2012 
 

Joined: 31 Mar, 2011
Posts: 128
Location: Hanoi, Vietnam
Offline
It's so cool.
For example: I defined a function in WeaponClass in DefaultWeapons.lua file named WeaponFunction(). If I want to call WeaponFunction() in TerranUnits.lua, I must use:

Code:
self.WeaponClass:WeaponFunction()


And also define in TerranUnits.lua :

Code:
local WeaponClass = import('/lua/sim/DefaultWeapons.lua').WeaponClass


Is it right?


Top
 Profile  
 PostPosted: 25 Mar, 2012 
 

Joined: 26 Feb, 2009
Posts: 2997
Offline
well that depends on what the function does..

if it effects the weapon in some way then you can use
from terranunits.lua

local wep = self:GetWeaponByLabel('weaponname')
wep:WeaponFunction()

the function in default weapons would need the self weapon object identifier..

so

WeaponFunction = function(self)
--do cool stuff
end,

be carefull in defaultweapons there are alot of weapon state functions which if not hooked correctly will break all unit weapons :)

what were doing here is the opposite of the last post, instead of getting the unit handle in self.unit were getting the weapon handle because the function you want to call is in the weapons file so

self:GetWeaponByLabel('weaponname') with return the weapon just like in defaultweapons.lua self.unit returns the unit.

_________________
Domino.
______________


Top
 Profile  
 PostPosted: 25 Mar, 2012 
 

Joined: 31 Mar, 2011
Posts: 128
Location: Hanoi, Vietnam
Offline
Domino wrote:
well that depends on what the function does..

if it effects the weapon in some way then you can use
from terranunits.lua

local wep = self:GetWeaponByLabel('weaponname')
wep:WeaponFunction()

the function in default weapons would need the self weapon object identifier..

so

WeaponFunction = function(self)
--do cool stuff
end,

be carefull in defaultweapons there are alot of weapon state functions which if not hooked correctly will break all unit weapons :)

what were doing here is the opposite of the last post, instead of getting the unit handle in self.unit were getting the weapon handle because the function you want to call is in the weapons file so

self:GetWeaponByLabel('weaponname') with return the weapon just like in defaultweapons.lua self.unit returns the unit.

Ya, I got it.
Code:
    RackSalvoFiringState = State {
        WeaponWantEnabled = true,
        WeaponAimWantEnabled = true,

        RenderClockThread = function(self, rof)
            local clockTime = rof
            local totalTime = clockTime
            while clockTime > 0.0 and
                  not self:BeenDestroyed() and
                  not self.unit:IsDead() do
                self.unit:SetWorkProgress( 1 - clockTime / totalTime )
                clockTime = clockTime - 0.1
                WaitSeconds(0.1)                           
            end
        end,
   
        Main = function(self)
            self.unit:SetBusy(true)
            local bp = self:GetBlueprint()
            #LOG("Weapon " .. bp.DisplayName .. " entered RackSalvoFiringState.")
            self:DestroyRecoilManips()
            local numRackFiring = self.CurrentRackSalvoNumber
            #This is done to make sure that when racks fire together, they fire together.
            if bp.RackFireTogether == true then
                numRackFiring = table.getsize(bp.RackBones)
            end

            # Fork timer counter thread carefully....
            if not self:BeenDestroyed() and
               not self.unit:IsDead() then
                if bp.RenderFireClock and bp.RateOfFire > 0 then
                    local rof = 1 / bp.RateOfFire               
                    self:ForkThread(self.RenderClockThread, rof)               
                end
            end
end,
}

Ehh...I can't understand why they need to call self.RenderClockThread instead of RenderClockThread. It's already a function in this state.


Top
 Profile  
 PostPosted: 25 Mar, 2012 
 

Joined: 31 Mar, 2011
Posts: 128
Location: Hanoi, Vietnam
Offline
Hi, this is error I got when running your code, Domino:
Code:
INFO: Hooked /lua/sim/unit.lua with /mods/testmod/hook/lua/sim/unit.lua
INFO: Hooked /lua/sim/weapon.lua with /schook/lua/sim/weapon.lua
WARNING: Error running OnCreate script in Entity uel0001 at 23d92808: ... - forged alliance\gamedata\lua.scd\lua\sim\unit.lua(3745): attempt to call method `GetUnitParam' (a nil value)
         stack traceback:
            ... - forged alliance\gamedata\lua.scd\lua\sim\unit.lua(3745): in function `HideBone'
            ...\gamedata\units.scd\units\uel0001\uel0001_script.lua(110): in function <...\gamedata\units.scd\units\uel0001\uel0001_script.lua:107>
            [C]: in function `CreateInitialArmyUnit'
            ...\gamedata\mohodata.scd\lua\sim\scenarioutilities.lua(338): in function `CreateInitialArmyGroup'
            ...\gamedata\mohodata.scd\lua\sim\scenarioutilities.lua(469): in function `InitializeArmies'
            ... - forged alliance\maps\scmp_019\scmp_019_script.lua(5): in function `OnPopulate'
            ...orged alliance\gamedata\mohodata.scd\lua\siminit.lua(145): in function <...orged alliance\gamedata\mohodata.scd\lua\siminit.lua:137>
            ...orged alliance\gamedata\mohodata.scd\lua\siminit.lua(273): in function `BeginSession'
WARNING: Error running lua script: ... - forged alliance\gamedata\lua.scd\lua\sim\unit.lua(3729): attempt to call method `GetUnitParam' (a nil value)
         stack traceback:
            ... - forged alliance\gamedata\lua.scd\lua\sim\unit.lua(3729): in function `ShowBone'
            ...orged alliance\gamedata\lua.scd\lua\defaultunits.lua(316): in function <...orged alliance\gamedata\lua.scd\lua\defaultunits.lua:311>


As we can see engine hooked successfully Unit.lua in my TestMod mod but GetUnitParam caused error.


Top
 Profile  
 PostPosted: 25 Mar, 2012 
 

Joined: 26 Feb, 2009
Posts: 2997
Offline
hehe,

the code i posted from DMS was not meant to be used by you, unless your using DMS,
in which case you can call the functions directly pal..

the functions i posted only contain partail code fragments, so they will not work for you..

what you have to do is..

hook unit.lua

and hook the function HideBone and ShowBone.

Code:
HideBone = function(self, Bone, AffectChild)
oldUnit.HideBone(self, Bone, AffectChild)
self.__HiddenBones[Bone] = true
end,

ShowBone = function(self, Bone, AffectChild)
oldUnit.ShowBone(self, Bone, AffectChild)
self.__HiddenBones[Bone] = nil
end,

IsBoneHidden = function(self, Bone)
if self.__HiddenBones[Bone] then
return true
else
return false
end
end,


make sure your hooking the lua files... your defaultweapons lua is not hooked its overridden pal, also make sure you specify the correct bone name as i didnt add checks if the bone is valid or not.

the read they use self.RenderClockThread and a ForkThread to the function is beacuse it has a while and Wait, you cnnot call functions with WaitSeconds or WaitTicks directly you have to ForkThread to them, they use self.RenderClockThread so they have a handle to the thread so they can kill it if needed, so it doesnt run constantly ..

_________________
Domino.
______________


Top
 Profile  
 PostPosted: 25 Mar, 2012 
 

Joined: 31 Mar, 2011
Posts: 128
Location: Hanoi, Vietnam
Offline
hahaha, I've found that myself. I tried to find GetUnitParam in original game but got no result, when I find it in DMS, I found it(you defined in hooked SimSync.lua and UserSync.lua). I'm wondering why I am such a ingenuity guy, lol. Thank you for all :))


Top
 Profile  
 PostPosted: 25 Mar, 2012 
 

Joined: 31 Mar, 2011
Posts: 128
Location: Hanoi, Vietnam
Offline
Hi Domino, I got this error:
Code:
WARNING: Error running OnCreate script in Entity uel0001 at 28620608: ... - forged alliance\gamedata\lua.scd\lua\sim\unit.lua(9890): Attempt to set attribute 'Right_Upgrade' on nil
         stack traceback:
            [C]: in function `error'
            ...alliance\gamedata\mohodata.scd\lua\system\config.lua(12): in function <...alliance\gamedata\mohodata.scd\lua\system\config.lua:11>
            ... - forged alliance\gamedata\lua.scd\lua\sim\unit.lua(9890): in function `HideBone'
            ...\gamedata\units.scd\units\uel0001\uel0001_script.lua(110): in function <...\gamedata\units.scd\units\uel0001\uel0001_script.lua:107>
            [C]: in function `CreateInitialArmyUnit'
            ...\gamedata\mohodata.scd\lua\sim\scenarioutilities.lua(338): in function `CreateInitialArmyGroup'
            ...\gamedata\mohodata.scd\lua\sim\scenarioutilities.lua(469): in function `InitializeArmies'
            ... - forged alliance\maps\scmp_019\scmp_019_script.lua(5): in function `OnPopulate'
            ...orged alliance\gamedata\mohodata.scd\lua\siminit.lua(145): in function <...orged alliance\gamedata\mohodata.scd\lua\siminit.lua:137>
            ...orged alliance\gamedata\mohodata.scd\lua\siminit.lua(273): in function `BeginSession'
WARNING: Error running lua script: ... - forged alliance\gamedata\lua.scd\lua\sim\unit.lua(9895): Attempt to set attribute '0' on nil
         stack traceback:
            [C]: in function `error'
            ...alliance\gamedata\mohodata.scd\lua\system\config.lua(12): in function <...alliance\gamedata\mohodata.scd\lua\system\config.lua:11>
            ... - forged alliance\gamedata\lua.scd\lua\sim\unit.lua(9895): in function `ShowBone'
            ...orged alliance\gamedata\lua.scd\lua\defaultunits.lua(316): in function <...orged alliance\gamedata\lua.scd\lua\defaultunits.lua:311>
WARNING: Error running lua script: ...ed alliance\mods\testmod\lua\sim\aircraftweapons.lua(133): attempt to call method `HideBone' (a nil value)
         stack traceback:
            ...ed alliance\mods\testmod\lua\sim\aircraftweapons.lua(133): in function `CreateProjectileFunction'
            ...ed alliance\mods\testmod\lua\sim\aircraftweapons.lua(603): in function <...ed alliance\mods\testmod\lua\sim\aircraftweapons.lua:545>
WARNING: Error running OnStopBuild script in Entity uel0001 at 28620608: ...\gamedata\units.scd\units\uel0001\uel0001_script.lua(253): attempt to call method `SetPrecedence' (a nil value)
         stack traceback:
            ...\gamedata\units.scd\units\uel0001\uel0001_script.lua(253): in function <...\gamedata\units.scd\units\uel0001\uel0001_script.lua:246>
WARNING: Error running OnPrepareArmToBuild script in Entity uel0001 at 28620608: ...\gamedata\units.scd\units\uel0001\uel0001_script.lua(124): attempt to call method `SetPrecedence' (a nil value)
         stack traceback:
            ...\gamedata\units.scd\units\uel0001\uel0001_script.lua(124): in function <...\gamedata\units.scd\units\uel0001\uel0001_script.lua:120>
WARNING: Error running OnHealthChanged script in Entity ueb0102 at 34a79a08: ... - forged alliance\gamedata\lua.scd\lua\sim\unit.lua(827): attempt to loop over field `?' (a nil value)
         stack traceback:
            ... - forged alliance\gamedata\lua.scd\lua\sim\unit.lua(827): in function `ManageDamageEffects'
            ... - forged alliance\gamedata\lua.scd\lua\sim\unit.lua(865): in function <... - forged alliance\gamedata\lua.scd\lua\sim\unit.lua:864>


I enable my mod and DMS. My mod doesn't hook anything in weapon field, all are created new(for example: In newweapon.lua I created AircraftWeapon = class(Weapon)). I just hooked unit.lua for bone related issue as you recommended, and TerrainTypes.lua for some my new effect.


Top
 Profile  
 PostPosted: 25 Mar, 2012 
 

Joined: 05 Oct, 2007
Posts: 16445
Location: camping near the biggest power-up
Offline
Bet you a dollar that there's an error message earlier in the log that you've missed.

Try to find that one, and post it up.

Alternatively, post the entire log to pastebin and we'll find it for you.

_________________
Nephylim wrote:
But, an FA army in an FA environment just looks... right.
help wrote:
Does anyone know how to use air transports? I cant get them to pick up troops.


Top
 Profile  
 PostPosted: 25 Mar, 2012 
 

Joined: 31 Mar, 2011
Posts: 128
Location: Hanoi, Vietnam
Offline
I think WARN message from Moho Log is enough but carefully I pasted all my Moho Log in here http://pastebin.com/GUiEaizU
If you can't find errors, just tell me, I'll send you my mod source code. Thank you!


Top
 Profile  
 PostPosted: 25 Mar, 2012 
 

Joined: 05 Oct, 2007
Posts: 16445
Location: camping near the biggest power-up
Offline
Yeah, post up your source. I had a look at the log and can't see anything wrong (yet).

ALSO (and this, I think, is very important);

viewtopic.php?p=939416#p939416

Your hooks are using Unit.

Code:
   HideBone = function(self, bone, h)
      Unit.HideBone(Unit, bone, h) -- Do the original action, so that the bone actually becomes hidden.
      if not self.__hiddenBones then
         self.__hiddenBones = {}
      end
      self.__hiddenBones[bone] = h -- When we un/hide a bone, we add it to this table.
   end,


99% chance that that is very very bad for the mod.

_________________
Nephylim wrote:
But, an FA army in an FA environment just looks... right.
help wrote:
Does anyone know how to use air transports? I cant get them to pick up troops.


Top
 Profile  
 PostPosted: 26 Mar, 2012 
 

Joined: 31 Mar, 2011
Posts: 128
Location: Hanoi, Vietnam
Offline
Ya, it's unit.lua caused error even ì I deleted all function using hide bone related function. The game run well when I deleted hooked unit.lua file


Top
 Profile  
 PostPosted: 26 Mar, 2012 
 

Joined: 31 Mar, 2011
Posts: 128
Location: Hanoi, Vietnam
Offline
Ehhh...I found that no need to hook Unit.lua to use IsBoneHidden function because Domind has already defined in his DMS. Why do I have to hook HideBone, ShowBone and IsBoneHidden function anymore? I could use DMS's IsBoneHidden successfully with no error found. That's funny but we no need to study this error anymore.
Thank you for helping, Domino and BulletMagnet. All of you are such a kind person.


Top
 Profile  
 PostPosted: 26 Mar, 2012 
 

Joined: 26 Feb, 2009
Posts: 2997
Offline
Aha,

i didnt realise you were using DMS, yeah i already added those functions to DMS,
if i new you were using it is would have just said, i just didnt want to plug DMS in yet another thread lol. sorry..

_________________
Domino.
______________


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic Go to page 1, 2  Next



Quick Tools

Search for:
Jump to:  

© 2002-2010 Gas Powered Games Corp. All Rights Reserved. Gas Powered Games is the exclusive trademark of Gas Powered Games Corp.
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
 
Home| Games | Company | News & Press | Support
  Terms of Use   |    Copyright Information   |    Privacy Policy