Jump to content

Converting Lua to c++


Recommended Posts

Posted

oke so my question is is it possible to convert lua scripts to c++ for mangos example like we all know mangos is more complicated then arc or whatever else so mabye someone wanna join me and lets starting converting lua custom scripts to c++ (for mangos) that mangos users can have some fun.. im not that good in c++ but mabye anyone is intrested helping out

Posted

Yeah, can you post an example?

I think the best thing would be for you to learn C++ and mangos scripting and do it yourself, because there aren't many people around here who are good at this and aren't busy with other stuff.

Posted

hehe thats awsome ye gonna learn full c++ and thanks for letting me know that its possible to convert it and btw mabye you have time to convert another one to c++ to thanks:D

Posted
hehe thats awsome ye gonna learn full c++ and thanks for letting me know that its possible to convert it and btw mabye you have time to convert another one to c++ to thanks:D

No I don't, sorry.

Posted
hehe thats awsome ye gonna learn full c++ and thanks for letting me know that its possible to convert it and btw mabye you have time to convert another one to c++ to thanks:D
!

Why do you ask this? You want to learn C++, go practice! :)

Posted
you could write a metacompiler that converts lua to C++

Though I think this would probably be more difficult than just converting the scripts themselves.

The languages are also very different. And given the quality of most of these Lua scripts, I would really hate to see what they look like in C++. I took a badly written 591 line Lua script and converted it 102 lines of reasonable C++, an automatic generator would have probably given around 500-600 lines of equally redundant code.

If you must run bad Lua scripts, than a Lua engine is probably easier. Otherwise, just redo what you need and get away from Lua altogether.

Posted
Well, here's an example of the first one converted into C++:

http://paste2.org/p/961690

Just to show what can be done with a rather poorly written Lua script.

I checked your script, racial abilities resets, but no new teach.

This should fix?

-pPlayer->learnSpell(spells[i].spell, false);
+pPlayer->learnSpell(spells[i].spell, true);

Posted
ofc im learning myself reading some books and some guides from net but im not that pro yet...

http://pastebin.com/TsH25AWv

http://pastebin.com/8vDdHPmZ

Instead, the second script you can use this.

/* ScriptData
SDName: item_levelplayer
SD%Complete: 100
SDComment: Used for Leveling characters Random
SDCategory: Items
EndScriptData */

#include"precompiled.h"

bool ItemUse_item_levelplayer(Player* pPlayer, Item* pItem, const SpellCastTargets &pTargets)
{
if ((pPlayer->isInCombat()) || (pPlayer->isInFlight()) || (pPlayer->isDead()))
{
     pPlayer->SendEquipError(EQUIP_ERR_NOT_IN_COMBAT, pItem, NULL);
       return false;
}
     pPlayer->RemoveSpellsCausingAura(SPELL_AURA_MOUNTED);

   outstring_log("player level %i",pPlayer->getLevel());
   if(((pPlayer->getLevel()) + 5) > 80)
   {
       outstring_log("playerlevel+5 > 80 (%i+5=%i)",pPlayer->getLevel(),pPlayer->getLevel()+5);
       if((80 - (pPlayer->getLevel())) > 0)
       {
           outstring_log("leveling for %i levels",(80-(pPlayer->getLevel())));
           pPlayer->GiveLevel(pPlayer->getLevel()+(80 - (pPlayer->getLevel())));  
       }
       else
       {
           outstring_log("level would be 81+, exiting function");
           return true;
       }
   }
   else
   {
       outstring_log("leveling for 5 levels");
       pPlayer->GiveLevel(pPlayer->getLevel()+5);
   }
   pPlayer->DestroyItemCount(pItem->GetEntry(),1,true);
   return true;
}
void AddSC_item_levelplayer()
{
   Script *newscript;

     newscript = new Script;
   newscript->Name="item_levelplayer";
   newscript->pItemUse = &ItemUse_item_levelplayer;
   newscript->RegisterSelf();
   outstring_log("SD2: item_levelplayer loaded");
}

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. Privacy Policy Terms of Use