Page 1 of 2

helps to create function

Posted: Mon May 05, 2014 4:45 pm
by Lamkefyned
How to make a function that look if connected characters and invite the connected... ??

Re: helps to create function

Posted: Mon May 05, 2014 6:35 pm
by BlubBlab
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

Re: helps to create function

Posted: Wed May 07, 2014 3:37 pm
by Lamkefyned
Hi, thanks

But if I have multiple characters? 12 for example

Re: helps to create function

Posted: Wed May 07, 2014 6:46 pm
by lisa
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.

Re: helps to create function

Posted: Thu May 08, 2014 2:16 pm
by Lamkefyned
Is there any tutorial by hai how to make tables?

Re: helps to create function

Posted: Thu May 08, 2014 6:28 pm
by lisa
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

Re: helps to create function

Posted: Thu May 08, 2014 8:43 pm
by rock5
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.

Re: helps to create function

Posted: Fri May 09, 2014 3:17 pm
by Lamkefyned
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

Re: helps to create function

Posted: Fri May 09, 2014 5:59 pm
by lisa

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

Re: helps to create function

Posted: Fri May 09, 2014 10:26 pm
by rock5
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.

Re: helps to create function

Posted: Sat May 10, 2014 5:33 am
by rock5
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.

Re: helps to create function

Posted: Sat May 10, 2014 5:40 am
by Lamkefyned
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.

Re: helps to create function

Posted: Sat May 10, 2014 12:03 pm
by Lamkefyned

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

Re: helps to create function

Posted: Sat May 10, 2014 2:13 pm
by BlubBlab
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

Re: helps to create function

Posted: Sun May 11, 2014 8:27 am
by Lamkefyned
I can create another function that look if hai someone in Group and if there is it that back... I feel well sleep XDDD

Re: helps to create function

Posted: Sun May 11, 2014 1:25 pm
by Lamkefyned

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.

Re: helps to create function

Posted: Sun May 11, 2014 8:07 pm
by ZZZZZ

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.

Re: helps to create function

Posted: Sun May 11, 2014 9:06 pm
by BlubBlab
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
	
	

Re: helps to create function

Posted: Mon May 12, 2014 1:06 pm
by Lamkefyned
Thank you BlubBlab and all

Re: helps to create function

Posted: Mon May 12, 2014 1:29 pm
by Lamkefyned
only one thing...

Gives this error code.

Error.jpg