helps to create function

Runes of Magic/Radiant Arcana (http://www.runesofmagic.com)
Message
Author
User avatar
Lamkefyned
Posts: 348
Joined: Thu May 23, 2013 11:38 am
Location: Spain

helps to create function

#1 Post by Lamkefyned » Mon May 05, 2014 4:45 pm

How to make a function that look if connected characters and invite the connected... ??
If you think something is right just because everyone else believes,you're not thinking.

User avatar
BlubBlab
Posts: 948
Joined: Fri Nov 30, 2012 11:33 pm
Location: My little Pony cafe

Re: helps to create function

#2 Post by BlubBlab » Mon May 05, 2014 6:35 pm

This will invite a char until the char accepts

Code: Select all

if(RoMScript("GetNumPartyMembers()") == 0)then
	repeat
		RoMScript("InviteByName('Yourchar');");
	until RoMScript("GetNumPartyMembers()") ~= 0
end
Jack-of-all-trades, but master-of-only of a few :D

My Reps:
https://github.com/BlubBlab/Micromacro-with-OpenCV (My version of MM2 with OpenCV and for MS Visual Studio)
https://github.com/BlubBlab/rom-bot (rombot with no stop WP and advanced human emulation mode and some other extensions)
https://github.com/BlubBlab/Micromacro-2-Bot-Framework ( A work in progress )
My Tools : viewtopic.php?f=10&t=6226

User avatar
Lamkefyned
Posts: 348
Joined: Thu May 23, 2013 11:38 am
Location: Spain

Re: helps to create function

#3 Post by Lamkefyned » Wed May 07, 2014 3:37 pm

Hi, thanks

But if I have multiple characters? 12 for example
If you think something is right just because everyone else believes,you're not thinking.

User avatar
lisa
Posts: 8332
Joined: Tue Nov 09, 2010 11:46 pm
Location: Australia

Re: helps to create function

#4 Post by lisa » Wed May 07, 2014 6:46 pm

If you try to invite the characters that are offline it wouldn't hurt, you would just get a message saying that character is offline. I don't see why you can't just use a table of names and invite them all.
Remember no matter you do in life to always have a little fun while you are at it ;)

wiki here http://www.solarstrike.net/wiki/index.php?title=Manual

User avatar
Lamkefyned
Posts: 348
Joined: Thu May 23, 2013 11:38 am
Location: Spain

Re: helps to create function

#5 Post by Lamkefyned » Thu May 08, 2014 2:16 pm

Is there any tutorial by hai how to make tables?
If you think something is right just because everyone else believes,you're not thinking.

User avatar
lisa
Posts: 8332
Joined: Tue Nov 09, 2010 11:46 pm
Location: Australia

Re: helps to create function

#6 Post by lisa » Thu May 08, 2014 6:28 pm

There is some light reading here http://www.lua.org/manual/5.1/manual.ht ... ble.concat but that is to do with the actual table functions, like table.insert.

Simple ways to use tables if you already know what you want in the table goes like this.

sometablename = { "string1","string2", number1, number2, "string3"}

Note strings have " " and numbers don't, those are just examples and you can have anything you want in the table.
and to use the table information you do

Code: Select all

for k,v in pairs(sometablename) do

-- in this case k is a number value and starts at 1 and goes up.
-- v would be the values you have in the table, "string1" and so on
-- so if you did a simple print here

print(v)

-- it would print all the values of the table
end
the k and v are like arguments in a function and can be what ever you want to call them.

Code: Select all

for slot,names in pairs(sometablename) do
print(names)
end
Remember no matter you do in life to always have a little fun while you are at it ;)

wiki here http://www.solarstrike.net/wiki/index.php?title=Manual

User avatar
rock5
Posts: 12173
Joined: Tue Jan 05, 2010 3:30 am
Location: Australia

Re: helps to create function

#7 Post by rock5 » Thu May 08, 2014 8:43 pm

I might add that all tables are made up of keys and values. In this example
lisa wrote:sometablename = { "string1","string2", number1, number2, "string3"}
is equivalent to

Code: Select all

sometablename = { [1]="string1",[2]="string2", [3]=number1, [4]=number2, [5]="string3"}
The numbers in the square brackets are the keys, and the strings and numbers are the values.

In Lisas example
lisa wrote:for k,v in pairs(sometablename) do
the k is the key and the v is the value.

BTW, this is what I call an indexed table. In such a table I would call the keys indexes. An indexed table is a table where all the keys are numerical starting from 1 and having no breaks. Also the keys have no meaning to the program being run. They are just placeholders for the values. Functions such as table.insert and table.remove should only be used with indexed tables.

You can also use the keys to mean something by giving them a name. Eg

Code: Select all

customer={name="someone", address="123 solarstrike boulevard, net",phone="1234 5678"}
The reason why you need to use square brackets with numbers is because lua wont let you use numbers like named keys without them.

To further confuse you, there are different ways you can refer to individual elements in a table.
  • customer.name
    customer["name"]
    tmp="name"; customer[tmp]
These will all yield the same result.

With numbers you can't use
  • sometablename.1
but you can use
  • sometablename[1]
    tmp = 1; sometablename[tmp]
I hope that helps but you should probably do a search for "lua table beginners" and do a bit of further reading.
  • Please consider making a small donation to me to support my continued contributions to the bot and this forum. Thank you. Donate
  • I check all posts before reading PMs. So if you want a fast reply, don't PM me but post a topic instead. PM me for private or personal topics only.
  • How to: copy and paste in micromacro
    ________________________
    Quote:
    • “They say hard work never hurt anybody, but I figure, why take the chance.”
          • Ronald Reagan

User avatar
Lamkefyned
Posts: 348
Joined: Thu May 23, 2013 11:38 am
Location: Spain

Re: helps to create function

#8 Post by Lamkefyned » Fri May 09, 2014 3:17 pm

for example this officer?

Code: Select all

		nameTable =
{
'larinja','example'
};

		function LTU_group()
if(RoMScript("GetNumPartyMembers()") == 0)then
   repeat
      RoMScript("InviteByName(nameTable);");
   until RoMScript("GetNumPartyMembers()") ~= 0
end
end
If you think something is right just because everyone else believes,you're not thinking.

User avatar
lisa
Posts: 8332
Joined: Tue Nov 09, 2010 11:46 pm
Location: Australia

Re: helps to create function

#9 Post by lisa » Fri May 09, 2014 5:59 pm

Code: Select all

      nameTable =
{
'larinja','example'
};

      function LTU_group()
if(RoMScript("GetNumPartyMembers()") == 0)then
   for k,v in pairs(nameTable) do
      RoMScript("InviteByName('"..v.."');");
   end
end
end
Remember no matter you do in life to always have a little fun while you are at it ;)

wiki here http://www.solarstrike.net/wiki/index.php?title=Manual

User avatar
rock5
Posts: 12173
Joined: Tue Jan 05, 2010 3:30 am
Location: Australia

Re: helps to create function

#10 Post by rock5 » Fri May 09, 2014 10:26 pm

Lamkefyned wrote: RoMScript("InviteByName(nameTable);");
Let me try to explain. RoMScript sends code/commands to the game to be executed. "InviteByName(nameTable);" is literally just a string that it sends to the game which the ingamefunctions addon (igf) converts to code and runs. igf literally receives "InviteByName(nameTable);", makes it executable and runs it. nameTable has no value in the game, that variable only exists in the bot. If you want to send variable values to the bot you have to append them to the string you are sending to the bot.

So for example

Code: Select all

var="somename"
RoMScript("InviteByName('"..var..'");")
"InviteByName('"..var..'");" is 3 strings attached together. InviteByName(' and somename and '); which makes the string InviteByName('somename'); which is what the game receives. So you can't send variables, you can only send the variable contents.

And of course, because RoMScript only accepts strings, you can't send the contents of a table, you have to iterate through the table and use each string name separately. Although you can theoretically recreate a small bot table in game by converting it to a string first.

Hm... you know I could probably make a function for moving tables into the game. Could be useful. So for example if you need to execute an in game function on a long list of names you could move the long list into the game first then use 1 RoMScript to iterate though the ingame table to executes those commands. Instead of iterating though the table in the bot and executing a RoMScript for every name. The code for converting tables to strings already exist. All I would have to do is modify it for this purpose and find some way to move the table strings longer than 255 into the game. Sounds like a worthwhile project.
  • Please consider making a small donation to me to support my continued contributions to the bot and this forum. Thank you. Donate
  • I check all posts before reading PMs. So if you want a fast reply, don't PM me but post a topic instead. PM me for private or personal topics only.
  • How to: copy and paste in micromacro
    ________________________
    Quote:
    • “They say hard work never hurt anybody, but I figure, why take the chance.”
          • Ronald Reagan

User avatar
rock5
Posts: 12173
Joined: Tue Jan 05, 2010 3:30 am
Location: Australia

Re: helps to create function

#11 Post by rock5 » Sat May 10, 2014 5:33 am

Cool. I just modified RoMScript to take any length command. That's going to be so useful. In this case, when I create a tableToString function you'll be able to do something like this.

Code: Select all

namestoinvite={"name1","name2","name3"}
RoMCode("t="..tableToString(namestoinvite).." for k,v in pairs(t) do InviteByName(v) end")
And that should work with any length list. Cool, huh?

I can think of 2 places I can use this new feature to simplify the bot. The autosell sells blocks of items at a time and is limited to the 255 character length. With this, I'll be able to just create 1 big sell command and execute it instead of the complex code to break it up into blocks. The other is the itemtypes table creation. It does blocks of TEXT commands. Hm... Why don't we use memory reads with getTEXT for that? I'll have to look into that.

By the way Lamkefyned, sorry for hijacking your topic. Don't let me stop you from asking any more questions about lisas solution if you have any.
  • Please consider making a small donation to me to support my continued contributions to the bot and this forum. Thank you. Donate
  • I check all posts before reading PMs. So if you want a fast reply, don't PM me but post a topic instead. PM me for private or personal topics only.
  • How to: copy and paste in micromacro
    ________________________
    Quote:
    • “They say hard work never hurt anybody, but I figure, why take the chance.”
          • Ronald Reagan

User avatar
Lamkefyned
Posts: 348
Joined: Thu May 23, 2013 11:38 am
Location: Spain

Re: helps to create function

#12 Post by Lamkefyned » Sat May 10, 2014 5:40 am

don't worry rock5 in awhile I will put to the bargain. If I update all my scripts with userfunction_lamkefyned-tools and find new functions and if this works.
If you think something is right just because everyone else believes,you're not thinking.

User avatar
Lamkefyned
Posts: 348
Joined: Thu May 23, 2013 11:38 am
Location: Spain

Re: helps to create function

#13 Post by Lamkefyned » Sat May 10, 2014 12:03 pm

Code: Select all

		function LTU_Hoss_group()
			if(RoMScript("GetNumPartyMembers()") == 0)then
				for k,v in pairs(invite) do
				  RoMScript("InviteByName('"..v.."');");
				end
			end
		end
If not hai nobody connected the code continues, back to repeat the code
If you think something is right just because everyone else believes,you're not thinking.

User avatar
BlubBlab
Posts: 948
Joined: Fri Nov 30, 2012 11:33 pm
Location: My little Pony cafe

Re: helps to create function

#14 Post by BlubBlab » Sat May 10, 2014 2:13 pm

The loop looks fine you must have called the function somewhere again.

You might at some yrest between the calls because else it would get laggy and maybe you have need for this function if you don't want to invite somebody which is already in the group http://runesofmagic.gamepedia.com/API:InPartyByName
Jack-of-all-trades, but master-of-only of a few :D

My Reps:
https://github.com/BlubBlab/Micromacro-with-OpenCV (My version of MM2 with OpenCV and for MS Visual Studio)
https://github.com/BlubBlab/rom-bot (rombot with no stop WP and advanced human emulation mode and some other extensions)
https://github.com/BlubBlab/Micromacro-2-Bot-Framework ( A work in progress )
My Tools : viewtopic.php?f=10&t=6226

User avatar
Lamkefyned
Posts: 348
Joined: Thu May 23, 2013 11:38 am
Location: Spain

Re: helps to create function

#15 Post by Lamkefyned » Sun May 11, 2014 8:27 am

I can create another function that look if hai someone in Group and if there is it that back... I feel well sleep XDDD
If you think something is right just because everyone else believes,you're not thinking.

User avatar
Lamkefyned
Posts: 348
Joined: Thu May 23, 2013 11:38 am
Location: Spain

Re: helps to create function

#16 Post by Lamkefyned » Sun May 11, 2014 1:25 pm

Code: Select all

		function LTU_Hoss_group()
			if(RoMScript("GetNumPartyMembers()") == 0)then
			   repeat
				for k,v in pairs(invite) do
				  RoMScript("InviteByName('"..v.."');");
				end
               until RoMScript("GetNumPartyMembers()") ~= 0
			end
		end
Created function

How I can do to wait five seconds between recurrence and repetition without affecting the first invitation.
If you think something is right just because everyone else believes,you're not thinking.

ZZZZZ
Posts: 513
Joined: Sun Oct 21, 2012 1:42 am

Re: helps to create function

#17 Post by ZZZZZ » Sun May 11, 2014 8:07 pm

Code: Select all

function LTU_Hoss_group()
         if(RoMScript("GetNumPartyMembers()") == 0)then
            repeat
            for k,v in pairs(invite) do
              RoMScript("InviteByName('"..v.."');");
            end
          yrest(5000);
               until RoMScript("GetNumPartyMembers()") ~= 0
         end
      end
Will wait 5 seconds after sending first set of invites before trying them all again. At least I think that's what you were after.

User avatar
BlubBlab
Posts: 948
Joined: Fri Nov 30, 2012 11:33 pm
Location: My little Pony cafe

Re: helps to create function

#18 Post by BlubBlab » Sun May 11, 2014 9:06 pm

That I think too, but I would make sure you don't bother doing think you don't need.

Code: Select all

      function LTU_Hoss_group()
         if(RoMScript("GetNumPartyMembers()") == 0)then
            repeat
                for k,v in pairs(invite) do
                     if(not RoMScript("InPartyByName ( "..v.." );")then
                      RoMScript("InviteByName('"..v.."');");
                       yrest(5000)
                    end
               end
               until RoMScript("GetNumPartyMembers()") ~= 0
         end
      end
	
	
Jack-of-all-trades, but master-of-only of a few :D

My Reps:
https://github.com/BlubBlab/Micromacro-with-OpenCV (My version of MM2 with OpenCV and for MS Visual Studio)
https://github.com/BlubBlab/rom-bot (rombot with no stop WP and advanced human emulation mode and some other extensions)
https://github.com/BlubBlab/Micromacro-2-Bot-Framework ( A work in progress )
My Tools : viewtopic.php?f=10&t=6226

User avatar
Lamkefyned
Posts: 348
Joined: Thu May 23, 2013 11:38 am
Location: Spain

Re: helps to create function

#19 Post by Lamkefyned » Mon May 12, 2014 1:06 pm

Thank you BlubBlab and all
If you think something is right just because everyone else believes,you're not thinking.

User avatar
Lamkefyned
Posts: 348
Joined: Thu May 23, 2013 11:38 am
Location: Spain

Re: helps to create function

#20 Post by Lamkefyned » Mon May 12, 2014 1:29 pm

only one thing...

Gives this error code.

Error.jpg
If you think something is right just because everyone else believes,you're not thinking.

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest