Changeset 1153

Show
Ignore:
Timestamp:
02/10/2010 09:11:35 PM (7 months ago)
Author:
Paroxysm
Message:

ADDED :

  • New function for both go's and units. GetLocation?() - this returns the x,y,z,o coords as multiple results. Usage : x,y,z,o = unit:GetLocation()
  • LCF(Lua's Convinient Functions) - This one is similar to LSL for those who remember except these functions are treated as if they are part of the wow object functions. For example, to execute one of LCF's functions, you simply invoke it through a wow object : player:GetStrength/IsAlliance()/IsHorde().

Each function is stored based on the wow object type(players have their own, creatures have their own, gos...)

I will continue to expand these functions but feel free to contribute by writing your own wrappers that will aid in scripting.

Location:
Trunk
Files:
5 added
6 modified

Legend:

Unmodified
Added
Removed
  • Trunk/src/LuaEngine/FunctionTables.h

    r1147 r1153  
    518518        { "DisableTargeting", &luaUnit::DisableTargeting }, 
    519519        { "IsInGroup", &luaUnit::IsInGroup }, 
     520        { "GetLocation", &luaUnit::GetLocation }, 
    520521        { NULL, NULL }, 
    521522}; 
     
    615616        { "FullCastSpellOnTarget", &luaGameObject::FullCastSpellOnTarget }, 
    616617        { "CustomAnimate", &luaGameObject::CustomAnimate }, 
     618        { "GetLocation", &luaGameObject::GetLocation }, 
    617619        { NULL, NULL }, 
    618620}; 
  • Trunk/src/LuaEngine/GameobjectFunctions.h

    r1144 r1153  
    10531053                RET_BOOL(false); 
    10541054        } 
     1055        int GetLocation(lua_State * L, GameObject * ptr) 
     1056        { 
     1057                CHECK_TYPEID(TYPEID_GAMEOBJECT) 
     1058 
     1059                lua_pushnumber(L,ptr->GetPositionX()); 
     1060                lua_pushnumber(L,ptr->GetPositionZ()); 
     1061                lua_pushnumber(L,ptr->GetPositionZ()); 
     1062                lua_pushnumber(L,ptr->GetOrientation()); 
     1063                return 4; 
     1064        } 
    10551065} 
    10561066#endif 
  • Trunk/src/LuaEngine/GlobalFunctions.h

    r1122 r1153  
    500500                return 1; 
    501501        } 
    502  
    503         void Register(lua_State *L) { 
    504                 lua_pushcfunction(L, &PerformIngameSpawn); 
    505                 lua_setglobal(L, "PerformIngameSpawn"); 
    506  
    507                 lua_pushcfunction(L, &GetPlayer); 
    508                 lua_setglobal(L, "GetPlayer"); 
    509  
    510                 lua_pushcfunction(L, &GetLUAEngine); 
    511                 lua_setglobal(L, "GetLUAEngine"); 
    512  
    513                 lua_pushcfunction(L, &GetLUAEngine); 
    514                 lua_setglobal(L, "GetLuaEngine"); 
    515  
    516                 lua_pushcfunction(L, &GetLuaEngineVersion); 
    517                 lua_setglobal(L, "GetLuaEngineVersion"); 
    518  
    519                 lua_pushcfunction(L, &GetGameTime); 
    520                 lua_setglobal(L, "GetGameTime"); 
    521                  
    522                 lua_pushcfunction(L, &WorldDBQuery); 
    523                 lua_setglobal(L, "WorldDBQuery"); 
    524  
    525                 lua_pushcfunction(L, &CharDBQuery); 
    526                 lua_setglobal(L, "CharDBQuery"); 
    527  
    528                 lua_pushcfunction(L, &WorldDBQueryTable); 
    529                 lua_setglobal(L, "WorldDBQueryTable"); 
    530  
    531                 lua_pushcfunction(L, &CharDBQueryTable); 
    532                 lua_setglobal(L, "CharDBQueryTable"); 
    533                  
    534                 lua_pushcfunction(L, &SendWorldMessage); 
    535                 lua_setglobal(L, "SendWorldMessage"); 
    536  
    537                 lua_pushcfunction(L, &ReloadTable); 
    538                 lua_setglobal(L, "ReloadTable"); 
    539  
    540                 lua_pushcfunction(L, &ReloadLuaEngine); 
    541                 lua_setglobal(L, "ReloadLuaEngine"); 
    542  
    543                 lua_pushcfunction(L, &Rehash); 
    544                 lua_setglobal(L, "Rehash"); 
    545  
    546                 lua_pushcfunction(L, &logcol); 
    547                 lua_setglobal(L, "logcol"); 
    548  
    549                 lua_pushcfunction(L, &GetPlayersInWorld); 
    550                 lua_setglobal(L, "GetPlayersInWorld"); 
    551  
    552                 lua_pushcfunction(L, &GetArcemuRevision); 
    553                 lua_setglobal(L, "GetArcemuRevision"); 
    554  
    555                 /*lua_pushcfunction(L, &GetInstanceIdsByMap); 
    556                 lua_setglobal(L, "GetInstanceIdsByMap");*/ 
    557  
    558                 /* 
    559                 lua_pushcfunction(L, &SendPvPCaptureMessage); 
    560                 lua_setglobal(L, "SendPvPCaptureMessage"); 
    561                 */ 
    562                 lua_pushcfunction(L, &GetPlayersInMap); 
    563                 lua_setglobal(L, "GetPlayersInMap"); 
    564  
    565                 lua_pushcfunction(L, &GetPlayersInZone); 
    566                 lua_setglobal(L, "GetPlayersInZone"); 
    567  
    568                 /*lua_pushcfunction(L, &RegisterTimedEvent); 
    569                 lua_setglobal(L, "RemoveTimedEvent");*/ 
    570  
    571                 lua_pushcfunction(L, &SendMail); 
    572                 lua_setglobal(L, "SendMail"); 
    573  
    574                 lua_register(L, "GetTaxiPath", &GetTaxiPath); 
    575                 lua_register(L, "SetDBCSpellVar", &SetDBCSpellVar); 
    576                 lua_register(L, "GetDBCSpellVar", &GetDBCSpellVar); 
     502        int bit_and(lua_State *L) 
     503        { 
     504                uint32 left = CHECK_ULONG(L,1); 
     505                uint32 right = CHECK_ULONG(L,2); 
     506                lua_pushnumber(L,(left & right)); 
     507                return 1; 
     508        } 
     509        int bit_or(lua_State * L) 
     510        { 
     511                uint32 left = CHECK_ULONG(L,1); 
     512                uint32 right = CHECK_ULONG(L,2); 
     513                lua_pushnumber(L,(left | right)); 
     514                return 1; 
     515        } 
     516        int bit_xor(lua_State * L) 
     517        { 
     518                uint32 left = CHECK_ULONG(L,1); 
     519                uint32 right = CHECK_ULONG(L,2); 
     520                lua_pushnumber(L,(left ^ right)); 
     521                return 1; 
     522        } 
     523        int bit_not(lua_State * L) 
     524        { 
     525                uint32 left = CHECK_ULONG(L,1); 
     526                lua_pushnumber(L,(~left)); 
     527                return 1; 
    577528        } 
    578529} 
     
    652603        lua_register(L, "SetDBCSpellVar", &luaGlobalFunctions::SetDBCSpellVar); 
    653604        lua_register(L, "GetDBCSpellVar", &luaGlobalFunctions::GetDBCSpellVar); 
     605        //Lua's bit instructions 
     606        lua_register(L, "bit_and", &luaGlobalFunctions::bit_and); 
     607        lua_register(L, "bit_or", &luaGlobalFunctions::bit_or); 
     608        lua_register(L, "bit_xor", &luaGlobalFunctions::bit_xor); 
     609        lua_register(L, "bit_not", &luaGlobalFunctions::bit_not); 
    654610} 
    655611#endif 
  • Trunk/src/LuaEngine/LUAEngine.cpp

    r1144 r1153  
    15421542        LuaCreature(Creature* creature) : CreatureAIScript(creature) {}; 
    15431543        ~LuaCreature() 
    1544         { 
    1545                 typedef std::multimap<uint32,LuaCreature*> CMAP; 
    1546                 CMAP & cMap = sLuaMgr.getLuCreatureMap(); 
    1547                 CMAP::iterator itr = cMap.find(_unit->GetEntry()); 
    1548                 CMAP::iterator itend = cMap.upper_bound(_unit->GetEntry()); 
    1549                 CMAP::iterator it; 
    1550                 for(;itr != cMap.end() && itr != itend;) 
    1551                 { 
    1552                         it = itr++; 
    1553                         if(it->second != NULL && it->second == this) 
    1554                                 cMap.erase(it); 
    1555                 } 
    1556         } 
     1544        {} 
    15571545        ARCEMU_INLINE void SetUnit(Creature * ncrc) { _unit = ncrc; } 
    15581546        void OnCombatStart(Unit* mTarget) 
     
    19461934                sLuaMgr.ExecuteCall(args); 
    19471935                RELEASE_LOCK 
     1936        } 
     1937        void Destroy() 
     1938        { 
     1939                typedef std::multimap<uint32,LuaCreature*> CMAP; 
     1940                CMAP & cMap = sLuaMgr.getLuCreatureMap(); 
     1941                CMAP::iterator itr = cMap.find(_unit->GetEntry()); 
     1942                CMAP::iterator itend = cMap.upper_bound(_unit->GetEntry()); 
     1943                CMAP::iterator it; 
     1944                for(;itr != cMap.end() && itr != itend;) 
     1945                { 
     1946                        it = itr++; 
     1947                        if(it->second != NULL && it->second == this) 
     1948                                cMap.erase(it); 
     1949                } 
     1950                delete this; 
    19481951        } 
    19491952        LuaUnitBinding * m_binding; 
  • Trunk/src/LuaEngine/LUAEngine.h

    r1144 r1153  
    446446                        lua_setfield(L, metatable, "__metatable"); 
    447447 
    448                         lua_pushvalue(L, methods); 
     448                        lua_pushcfunction(L,index); 
    449449                        lua_setfield(L, metatable, "__index"); 
    450450 
     
    558558                        sprintf(buff,"%p",obj); 
    559559                } 
     560                static int index(lua_State * L)  
     561                { 
     562                        /*Paroxysm : the table obj and the missing key are currently on the stack(index 1 & 2) */ 
     563                        lua_getglobal(L,GetTClassName<T>()); 
     564                        // string form of the key. 
     565                        const char * key = lua_tostring(L,2); 
     566                        if(lua_istable(L,-1) ) 
     567                        { 
     568                                lua_pushvalue(L,2); 
     569                                lua_rawget(L,-2); 
     570                                //If the key were looking for is not in the table, retrieve its' metatables' index value. 
     571                                if(lua_isnil(L,-1)) 
     572                                { 
     573                                        lua_getmetatable(L,-2); 
     574                                        if(lua_istable(L,-1) ) 
     575                                        { 
     576                                                lua_getfield(L,-1,"__index"); 
     577                                                if(lua_isfunction(L,-1) ) 
     578                                                { 
     579                                                        lua_pushvalue(L,1); 
     580                                                        lua_pushvalue(L,2); 
     581                                                        lua_pcall(L,2,1,0); 
     582                                                } 
     583                                                else if(lua_istable(L,-1) ) 
     584                                                        lua_getfield(L,-1,key); 
     585                                                else 
     586                                                        lua_pushnil(L); 
     587                                        } 
     588                                        else 
     589                                                lua_pushnil(L); 
     590                                } 
     591                                else if(lua_istable(L,-1) ) 
     592                                { 
     593                                        lua_pushvalue(L,2); 
     594                                        lua_rawget(L,-2); 
     595                                } 
     596                        } 
     597                        else 
     598                                lua_pushnil(L); 
     599 
     600                        lua_insert(L,1); 
     601                        lua_settop(L,1); 
     602                        return 1; 
     603                } 
    560604        }; 
    561605        class GUID_MGR  
  • Trunk/src/LuaEngine/UnitFunctions.h

    r1144 r1153  
    59125912                RET_BOOL(false); 
    59135913        } 
     5914        int GetLocation(lua_State * L, Unit * ptr) 
     5915        { 
     5916                if(ptr != NULL) 
     5917                { 
     5918                        lua_pushnumber(L,ptr->GetPositionX()); 
     5919                        lua_pushnumber(L,ptr->GetPositionY()); 
     5920                        lua_pushnumber(L,ptr->GetPositionY()); 
     5921                        lua_pushnumber(L,ptr->GetOrientation()); 
     5922                        return 4; 
     5923                } 
     5924                lua_pushnil(L); 
     5925                return 1; 
     5926        } 
    59145927} 
    59155928#endif