Deprecated: The behavior of unparenthesized expressions containing both '.' and '+'/'-' will change in PHP 8: '+'/'-' will take a higher precedence in /home/iano/public_html/tpforums-vb5/forum/includes/class_core.php on line 5842

PHP Warning: Use of undefined constant MYSQL_NUM - assumed 'MYSQL_NUM' (this will throw an Error in a future version of PHP) in ..../includes/init.php on line 165

PHP Warning: Use of undefined constant MYSQL_ASSOC - assumed 'MYSQL_ASSOC' (this will throw an Error in a future version of PHP) in ..../includes/init.php on line 165

PHP Warning: Use of undefined constant MYSQL_BOTH - assumed 'MYSQL_BOTH' (this will throw an Error in a future version of PHP) in ..../includes/init.php on line 165

PHP Warning: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? in ..../includes/functions_navigation.php on line 588

PHP Warning: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? in ..../includes/functions_navigation.php on line 612

PHP Warning: Use of undefined constant misc - assumed 'misc' (this will throw an Error in a future version of PHP) in ..../global.php(29) : eval()'d code(6) : eval()'d code on line 1

PHP Warning: Use of undefined constant index - assumed 'index' (this will throw an Error in a future version of PHP) in ..../global.php(29) : eval()'d code(6) : eval()'d code on line 1

PHP Warning: Use of undefined constant misc - assumed 'misc' (this will throw an Error in a future version of PHP) in ..../includes/class_bootstrap.php(1422) : eval()'d code(4) : eval()'d code on line 1

PHP Warning: Use of undefined constant index - assumed 'index' (this will throw an Error in a future version of PHP) in ..../includes/class_bootstrap.php(1422) : eval()'d code(4) : eval()'d code on line 1

PHP Warning: Use of undefined constant onlinestatusphrase - assumed 'onlinestatusphrase' (this will throw an Error in a future version of PHP) in ..../includes/class_core.php(4684) : eval()'d code on line 6

PHP Warning: Use of undefined constant onlinestatusphrase - assumed 'onlinestatusphrase' (this will throw an Error in a future version of PHP) in ..../includes/class_core.php(4684) : eval()'d code on line 6

PHP Warning: Use of undefined constant onlinestatusphrase - assumed 'onlinestatusphrase' (this will throw an Error in a future version of PHP) in ..../includes/class_core.php(4684) : eval()'d code on line 6

PHP Warning: Use of undefined constant onlinestatusphrase - assumed 'onlinestatusphrase' (this will throw an Error in a future version of PHP) in ..../includes/class_core.php(4684) : eval()'d code on line 6

PHP Warning: Use of undefined constant onlinestatusphrase - assumed 'onlinestatusphrase' (this will throw an Error in a future version of PHP) in ..../includes/class_core.php(4684) : eval()'d code on line 6

PHP Warning: Use of undefined constant onlinestatusphrase - assumed 'onlinestatusphrase' (this will throw an Error in a future version of PHP) in ..../includes/class_core.php(4684) : eval()'d code on line 6

PHP Warning: Use of undefined constant onlinestatusphrase - assumed 'onlinestatusphrase' (this will throw an Error in a future version of PHP) in ..../includes/class_core.php(4684) : eval()'d code on line 6

PHP Warning: Use of undefined constant onlinestatusphrase - assumed 'onlinestatusphrase' (this will throw an Error in a future version of PHP) in ..../includes/class_core.php(4684) : eval()'d code on line 6

PHP Warning: Use of undefined constant onlinestatusphrase - assumed 'onlinestatusphrase' (this will throw an Error in a future version of PHP) in ..../includes/class_core.php(4684) : eval()'d code on line 6

PHP Warning: Use of undefined constant onlinestatusphrase - assumed 'onlinestatusphrase' (this will throw an Error in a future version of PHP) in ..../includes/class_core.php(4684) : eval()'d code on line 6
how Neobot declared $hp, $level, etc?
Page 1 of 2 12 LastLast
Results 1 to 10 of 14

Thread: how Neobot declared $hp, $level, etc?

  1. #1
    Senior Member
    Join Date
    Oct 2010
    Posts
    146

    how Neobot declared $hp, $level, etc?

    I didn't know where to post this, so if this isn't the right place just move it as you want xD

    So this is the question: how did Neobot declare its bot's variables like $hp, $mp, $level, and so on?

    As you remember, when you used the variable "$hp" it called a function to get the hp of the character.

    I think it was hardcoded inside the bot, am I right? or can this be done in Lua?

    if anybody knows something about this, please, do post.

  2. #2
    Super Moderator
    Join Date
    May 2007
    Posts
    1,191
    I didn't use NeoBot, but assuming it was the same as ElfBot, a simple string/regex replace was used

  3. #3
    Senior Member
    Join Date
    Jan 2008
    Location
    Cambridge, England
    Posts
    725
    UpdateWorld()

    Code:
    public bool UpdateWorld()
    {
        try
        {
            SetVarInLuaEngine("$hp", Player.GetHealth(self));
        }
        catch (Exception ex)
        {
            MessageBox.Show("There was an error obtaining your characters hitpoints, ensure you are logged in and try again, if this message still displays, report this error on the forums");
            return false;
        }
    }
    Something like that, I believe. Basically the Lua engine has a set of variables which can be managed from within your program by simple commands such as that above. I believe it is also possible to only update the values when the variable is called, but although that would require less overall CPU usage, it would increase the stress demand (E.g if loads of mobs come at once the heal function may be called a lot more than otherwise, leading to increased CPU usage thus more "lag"), whereas if you call an UpdateWorld() function frequently (no more than 30 times per second, no less than 5 times per second is my advice) you will get constant amounts of "medium" CPU usage, but it should never burst, especially not when Tibia is under any strain.

    I would also point out that you'll need to be careful with your variable permissions, e.g if you're going to use my method above you will need to ensure that your Lua engine is ReadOnly, and that it confirms the value within to be reasonable before using it. Alternatively you could set a flag so that while the variable is being updated it cannot be read, but as soon as it is updated it is released again (this would effectively form an events queue for your variable reading, if there were enough events, leading to highly controllable resource management in extreme circumstances.) Basically you need to make sure that reading the value in Lua and writing it in your Lua engine don't conflict, if they do you're likely to get an AppCrash exception.

  4. #4
    Senior Member
    Join Date
    Jan 2012
    Posts
    417
    Quote Originally Posted by Puterin View Post
    I didn't know where to post this, so if this isn't the right place just move it as you want xD

    So this is the question: how did Neobot declare its bot's variables like $hp, $mp, $level, and so on?

    As you remember, when you used the variable "$hp" it called a function to get the hp of the character.

    I think it was hardcoded inside the bot, am I right? or can this be done in Lua?

    if anybody knows something about this, please, do post.
    Since '$' is not a valid lua identifier, you must regex it.

    I don't suggest you apply this php-like syntax to your lua app, because you'll need to create (if you want a reliable rule) a parser for lua strings (line and multiline) and it is not a simple task, IMHO.

  5. #5
    Senior Member
    Join Date
    Jan 2008
    Location
    Cambridge, England
    Posts
    725
    Quote Originally Posted by Blequi View Post
    Since '$' is not a valid lua identifier, you must regex it.

    I don't suggest you apply this php-like syntax to your lua app, because you'll need to create (if you want a reliable rule) a parser for lua strings (line and multiline) and it is not a simple task, IMHO.
    Good point, well made. I think the best thing to do would be to just make all your variables a generic type, and maintain a set of rules in them... It's very difficult to be generic with how you implement variables, since all the bots do it differently (Xeno: Self.Mana, iBot: mana, RBP GetMana() - I think). I much prefer the iBot method personally, but if you're going to do that you will need to release a list of all the Lua functions available, or everyone will refuse to make good quality scripts (like they have done for XB).

  6. #6
    Senior Member
    Join Date
    Dec 2011
    Posts
    249
    Quote Originally Posted by Blequi View Post
    Since '$' is not a valid lua identifier, you must regex it.

    I don't suggest you apply this php-like syntax to your lua app, because you'll need to create (if you want a reliable rule) a parser for lua strings (line and multiline) and it is not a simple task, IMHO.
    It's quite easy to edit the lua source to support the $.

  7. #7
    Senior Member
    Join Date
    Oct 2010
    Posts
    146
    Quote Originally Posted by ottizy View Post
    It's quite easy to edit the lua source to support the $.
    oh my, if you could tell me how to do it, or what to search in google to find it, it would be greatly appreciated
    this could be the best way to fix it (since I want to recreate neo, and that means to be able to use its scripts)

    Quote Originally Posted by XtrmJash View Post
    but if you're going to do that you will need to release a list of all the Lua functions available, or everyone will refuse to make good quality scripts (like they have done for XB).
    np about that bro, remember that I'm trying to recreate neo as much as possible, so I'll be using same variables (and I've kept the Help.txt of Neo where it's everything explained, which also helps me with the development XD)

    Quote Originally Posted by Blequi View Post
    Since '$' is not a valid lua identifier, you must regex it.
    thought about this, but doing a regex to get is kinda lame/poor programming, isn't it?

    Quote Originally Posted by Blequi View Post
    I don't suggest you apply this php-like syntax to your lua app, because you'll need to create (if you want a reliable rule) a parser for lua strings (line and multiline) and it is not a simple task, IMHO.
    I really have to if there isn't any other way... but why would it be so tedious? I mean, it's just regex, nothing complicated right?

  8. #8
    Senior Member
    Join Date
    Jan 2012
    Posts
    417
    Quote Originally Posted by Puterin View Post
    thought about this, but doing a regex to get is kinda lame/poor programming, isn't it?
    well, if ottizy point a straightforward way to do that, then you should stick with his point.

    If you don't want to touch lua sources (and eventually break it), you'll need regex or some kinda of grammar to parse and replace these "$hp" with your "hp()" function before this script is executed.

    tbh, I don't care about lame/poor programming, first I try to get something that works, later I try improve or make it better readable or "elegant".

    Quote Originally Posted by Puterin View Post
    I really have to if there isn't any other way... but why would it be so tedious? I mean, it's just regex, nothing complicated right?
    Well, depending on certain conditions, regex can turn into a hell. At this case especially, you need be very careful about this one, because it isn't your intent replace "$hp" for "hp()" in valid strings. The hell is in the multiline strings as I'll show some examples.

    Ex: just to show you a bit how multiline strings are painful, a valid multiline string follow some rules:

    1) starting with "[[" you can nest your string, i.e., "[[ asds [[ ashdiasdhsiahds]] sadhuhsud ]]" is a single multiline string

    2) when it matches the following regex "[=+[", you cannot nest it, i.e., "[===[ adasdashu [===[ asdhashud ]===] asdjasjiodjiasdjoajisdjassdji ]===]" the word " asdjasjiodjiasdjoajisdjassdji ]===]" is outside the string.

    I prefer to parse multiline strings in Lua analyzing each character in a for loop, in the past I tried that with regex only and I'd failed miserably.
    Last edited by Blequi; 05-17-2013 at 05:04 PM.

  9. #9
    Senior Member
    Join Date
    Dec 2011
    Posts
    249
    In llex.c lines 420 to 425.

    Change this
    Code:
            else if (isalpha(ls->current) || ls->current == '_') {
              /* identifier or reserved word */
              TString *ts;
              do {
                save_and_next(ls);
              } while (isalnum(ls->current) || ls->current == '_');
              ts = luaX_newstring(ls, luaZ_buffer(ls->buff),
    to this
    Code:
            else if (isalpha(ls->current) || ls->current == '_' || ls->current =='$') {
              /* identifier or reserved word */
              TString *ts;
              do {
                save_and_next(ls);
              } while (isalnum(ls->current) || ls->current == '_' || ls->current =='$');
              ts = luaX_newstring(ls, luaZ_buffer(ls->buff),
    However changing this will support of variables such as f$oo, bar$ etc.
    Last edited by ottizy; 05-17-2013 at 05:46 PM.

  10. #10
    Senior Member
    Join Date
    Oct 2010
    Posts
    146
    Quote Originally Posted by ottizy View Post
    In llex.c lines 420 to 425.

    Change(...)
    However changing this will support of variables such as f$oo, bar$ etc.
    oux, didn't think about that.... sht
    well, thx a lot for the info, didn't know I had to recompile the lua library for that :O

    Oks, so now with the information I have I can do the following:
    1) go through the process of recompiling the library to add the $ support. Add support in a .lua for the $variables so they update the result of their function ( $hp--> getPlayerHP() ) with http://stackoverflow.com/questions/16614456/
    Good things: performance will be pretty nice.

    2) I was taking a break of this, watching a serie, and suddenly something flied over my mind... It's about the regex and so on:
    let's see if I explain it right :S I'll divide the process in 3 parts as it would look the flow of data:
    Script in .xml
    PHP Code:
    if $mp 10 then ... 
    Delphi
    PHP Code:
    for each pos('$'ScriptInBuffer)[i] > do
    start:= pos('$'ScriptInBuffer)[i];
    end:= pos(' 'ScriptInBuffer, [from $])[i];
    str:= copy(start,end);
    case 
    str of
    mp
    :
    StringReplace(ScriptInBuffer'$mp''lua.getMP_Delphi()')
    hp:
    etc... 
    Lua
    PHP Code:
    lua_tostring(ScriptInBuffer
    or 
    lua_loadfile(ScriptInBuffer)
    or 
    w/e so it gets the info 
    -----------------------------------------------------------------------------


    lol, after writing all of this I just notticed that I could have done it easier.... just
    PHP Code:
    StringReplace(ScriptInBuffer'$mp''lua.getMP_Delphi()');
    StringReplace(ScriptInBuffer'$hp''lua.getHP_Delphi()');
    StringReplace(ScriptInBuffer'$cap''lua.getCapacity_Delphi()');
    etc... 
    what do you guys think? sorry for annoying you with this noobie stuff :S

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •