Jump to content

How to remove output of recipe from Recipe lua


ORMtnMan

Recommended Posts

I want to ask if anyone knows if it is possible (and if so how) to remove the result of a recipe from the lua that is tagged in the recipe?

 

OR, is there a way to test when an item is added to inventory from a recipe?

 

Finally, is there a way to control what modData is copied over into the recipe result?

 

thank you in advance!

Link to comment
Share on other sites

I want to ask if anyone knows if it is possible (and if so how) to remove the result of a recipe from the lua that is tagged in the recipe?

OR, is there a way to test when an item is added to inventory from a recipe?

Finally, is there a way to control what modData is copied over into the recipe result?

thank you in advance!

Truthfully, there's nothing saying that recipes have to be used. You could handle the whole thing through timedActions like your unloading script.

Link to comment
Share on other sites

 

I want to ask if anyone knows if it is possible (and if so how) to remove the result of a recipe from the lua that is tagged in the recipe?

OR, is there a way to test when an item is added to inventory from a recipe?

Finally, is there a way to control what modData is copied over into the recipe result?

thank you in advance!

Truthfully, there's nothing saying that recipes have to be used. You could handle the whole thing through timedActions like your unloading script.

 

 

I know, it is just easier to tie the object to the result via recipe, so I am trying to exhaust that possibility first.

 

Do you know of a function to find an object in an array? That way I can tie two arrays together using an index number. Just in case the recipe thing doesn't work out.

Link to comment
Share on other sites

I want to ask if anyone knows if it is possible (and if so how) to remove the result of a recipe from the lua that is tagged in the recipe?

OR, is there a way to test when an item is added to inventory from a recipe?

Finally, is there a way to control what modData is copied over into the recipe result?

thank you in advance!

Truthfully, there's nothing saying that recipes have to be used. You could handle the whole thing through timedActions like your unloading script.

I know, it is just easier to tie the object to the result via recipe, so I am trying to exhaust that possibility first.

Do you know of a function to find an object in an array? That way I can tie two arrays together using an index number. Just in case the recipe thing doesn't work out.

You mean like a search algorithm? Arrays are probably short enough that a linear search will work. It's really just a for loop.

Link to comment
Share on other sites

 

 

 

I want to ask if anyone knows if it is possible (and if so how) to remove the result of a recipe from the lua that is tagged in the recipe?

OR, is there a way to test when an item is added to inventory from a recipe?

Finally, is there a way to control what modData is copied over into the recipe result?

thank you in advance!

Truthfully, there's nothing saying that recipes have to be used. You could handle the whole thing through timedActions like your unloading script.

I know, it is just easier to tie the object to the result via recipe, so I am trying to exhaust that possibility first.

Do you know of a function to find an object in an array? That way I can tie two arrays together using an index number. Just in case the recipe thing doesn't work out.

You mean like a search algorithm? Arrays are probably short enough that a linear search will work. It's really just a for loop.

 

 

YEs something like this:

 

2 arrays

Array 1                                          Array 2

AR10                                            AR10308

AR10308                                      AR10

AR15                                            AR15556

AR15556                                      AR15

 

T have a AR 15 so it would find the index on the first array (3) and go to the same index on the second array and give me AR15556.

 

I will google it and do some experiments after work.

Link to comment
Share on other sites

I want to ask if anyone knows if it is possible (and if so how) to remove the result of a recipe from the lua that is tagged in the recipe?

OR, is there a way to test when an item is added to inventory from a recipe?

Finally, is there a way to control what modData is copied over into the recipe result?

thank you in advance!

Truthfully, there's nothing saying that recipes have to be used. You could handle the whole thing through timedActions like your unloading script.
I know, it is just easier to tie the object to the result via recipe, so I am trying to exhaust that possibility first.

Do you know of a function to find an object in an array? That way I can tie two arrays together using an index number. Just in case the recipe thing doesn't work out.

You mean like a search algorithm? Arrays are probably short enough that a linear search will work. It's really just a for loop.

YEs something like this:

2 arrays

Array 1 Array 2

AR10 AR10308

AR10308 AR10

AR15 AR15556

AR15556 AR15

T have a AR 15 so it would find the index on the first array (3) and go to the same index on the second array and give me AR15556.

I will google it and do some experiments after work.

I'm not the best at lua, but:

function(key, list)  for i, obj in ipairs(list) do    if obj == key then      return i; --Return key index    end  end  return -1; --Key not foundend
Link to comment
Share on other sites

 

 

 

 

 

I want to ask if anyone knows if it is possible (and if so how) to remove the result of a recipe from the lua that is tagged in the recipe?

OR, is there a way to test when an item is added to inventory from a recipe?

Finally, is there a way to control what modData is copied over into the recipe result?

thank you in advance!

Truthfully, there's nothing saying that recipes have to be used. You could handle the whole thing through timedActions like your unloading script.
I know, it is just easier to tie the object to the result via recipe, so I am trying to exhaust that possibility first.

Do you know of a function to find an object in an array? That way I can tie two arrays together using an index number. Just in case the recipe thing doesn't work out.

You mean like a search algorithm? Arrays are probably short enough that a linear search will work. It's really just a for loop.
YEs something like this:

2 arrays

Array 1 Array 2

AR10 AR10308

AR10308 AR10

AR15 AR15556

AR15556 AR15

T have a AR 15 so it would find the index on the first array (3) and go to the same index on the second array and give me AR15556.

I will google it and do some experiments after work.

I'm not the best at lua, but:

function(key, list)  for i, obj in ipairs(list) do    if obj == key then      return i; --Return key index    end  end  return -1; --Key not foundend

 

 

That looks to be about what I was going to work on when I got off work,

 

The array would also serve as the test to see if the context menu option will pop up.

 

Key in the case of the above would be the item type?

 

So I would getModData of the item right-clicked and use the getType()?

 

Then compare it to the arra like in your code above.

 

I would need to re-look-at my unload menu stuff to reacquaint myself with how the script works but I would follow along those lines.

 

Also, I looked into the recipe code and I found out all I would really need to transfer in the process is the weapon mods (through those getXX() calls, the condition via a condition test and set condition code found there, then test to see if a mag is inserted and transfer that over (only if the mag was not inserted as guns spawn with their mags in place).

 

I don't have my files in  front of me so, I can't get into specifics on how I'll do it until later.

 

Fuji, I do not know what I would do without you :mrgreen:

Link to comment
Share on other sites

I want to ask if anyone knows if it is possible (and if so how) to remove the result of a recipe from the lua that is tagged in the recipe?

OR, is there a way to test when an item is added to inventory from a recipe?

Finally, is there a way to control what modData is copied over into the recipe result?

thank you in advance!

Truthfully, there's nothing saying that recipes have to be used. You could handle the whole thing through timedActions like your unloading script.
I know, it is just easier to tie the object to the result via recipe, so I am trying to exhaust that possibility first.

Do you know of a function to find an object in an array? That way I can tie two arrays together using an index number. Just in case the recipe thing doesn't work out.

You mean like a search algorithm? Arrays are probably short enough that a linear search will work. It's really just a for loop.
YEs something like this:

2 arrays

Array 1 Array 2

AR10 AR10308

AR10308 AR10

AR15 AR15556

AR15556 AR15

T have a AR 15 so it would find the index on the first array (3) and go to the same index on the second array and give me AR15556.

I will google it and do some experiments after work.

I'm not the best at lua, but:

function(key, list)  for i, obj in ipairs(list) do    if obj == key then      return i; --Return key index    end  end  return -1; --Key not foundend

That looks to be about what I was going to work on when I got off work,

The array would also serve as the test to see if the context menu option will pop up.

Key in the case of the above would be the item type?

So I would getModData of the item right-clicked and use the getType()?

Then compare it to the arra like in your code above.

I would need to re-look-at my unload menu stuff to reacquaint myself with how the script works but I would follow along those lines.

Also, I looked into the recipe code and I found out all I would really need to transfer in the process is the weapon mods (through those getXX() calls, the condition via a condition test and set condition code found there, then test to see if a mag is inserted and transfer that over (only if the mag was not inserted as guns spawn with their mags in place).

I don't have my files in front of me so, I can't get into specifics on how I'll do it until later.

Fuji, I do not know what I would do without you :mrgreen:

The search script should work with any key variable type as long as it matches the types in the array thanks to Lua variables having undefined types.

Considering you're planning on putting every convertable weapon in the array, though, it might be a bit slow, so I'll see if I can write a more efficient search script when I can get my hands on a computer.

Link to comment
Share on other sites

 

 

 

 

 

 

 

I want to ask if anyone knows if it is possible (and if so how) to remove the result of a recipe from the lua that is tagged in the recipe?

OR, is there a way to test when an item is added to inventory from a recipe?

Finally, is there a way to control what modData is copied over into the recipe result?

thank you in advance!

Truthfully, there's nothing saying that recipes have to be used. You could handle the whole thing through timedActions like your unloading script.
I know, it is just easier to tie the object to the result via recipe, so I am trying to exhaust that possibility first.

Do you know of a function to find an object in an array? That way I can tie two arrays together using an index number. Just in case the recipe thing doesn't work out.

You mean like a search algorithm? Arrays are probably short enough that a linear search will work. It's really just a for loop.
YEs something like this:

2 arrays

Array 1 Array 2

AR10 AR10308

AR10308 AR10

AR15 AR15556

AR15556 AR15

T have a AR 15 so it would find the index on the first array (3) and go to the same index on the second array and give me AR15556.

I will google it and do some experiments after work.

I'm not the best at lua, but:

function(key, list)  for i, obj in ipairs(list) do    if obj == key then      return i; --Return key index    end  end  return -1; --Key not foundend

That looks to be about what I was going to work on when I got off work,

The array would also serve as the test to see if the context menu option will pop up.

Key in the case of the above would be the item type?

So I would getModData of the item right-clicked and use the getType()?

Then compare it to the arra like in your code above.

I would need to re-look-at my unload menu stuff to reacquaint myself with how the script works but I would follow along those lines.

Also, I looked into the recipe code and I found out all I would really need to transfer in the process is the weapon mods (through those getXX() calls, the condition via a condition test and set condition code found there, then test to see if a mag is inserted and transfer that over (only if the mag was not inserted as guns spawn with their mags in place).

I don't have my files in front of me so, I can't get into specifics on how I'll do it until later.

Fuji, I do not know what I would do without you :mrgreen:

The search script should work with any key variable type as long as it matches the types in the array thanks to Lua variables having undefined types.

Considering you're planning on putting every convertable weapon in the array, though, it might be a bit slow, so I'll see if I can write a more efficient search script when I can get my hands on a computer.

 

 

Or  could we break up the arrays with another test, like... 3d model, or, somthing else multiple guns would share or would the searching through multiple shorter arrays not add much efficiency?

Link to comment
Share on other sites

I want to ask if anyone knows if it is possible (and if so how) to remove the result of a recipe from the lua that is tagged in the recipe?

OR, is there a way to test when an item is added to inventory from a recipe?

Finally, is there a way to control what modData is copied over into the recipe result?

thank you in advance!

Truthfully, there's nothing saying that recipes have to be used. You could handle the whole thing through timedActions like your unloading script.
I know, it is just easier to tie the object to the result via recipe, so I am trying to exhaust that possibility first.

Do you know of a function to find an object in an array? That way I can tie two arrays together using an index number. Just in case the recipe thing doesn't work out.

You mean like a search algorithm? Arrays are probably short enough that a linear search will work. It's really just a for loop.
YEs something like this:

2 arrays

Array 1 Array 2

AR10 AR10308

AR10308 AR10

AR15 AR15556

AR15556 AR15

T have a AR 15 so it would find the index on the first array (3) and go to the same index on the second array and give me AR15556.

I will google it and do some experiments after work.

I'm not the best at lua, but:

function(key, list)  for i, obj in ipairs(list) do    if obj == key then      return i; --Return key index    end  end  return -1; --Key not foundend

That looks to be about what I was going to work on when I got off work,

The array would also serve as the test to see if the context menu option will pop up.

Key in the case of the above would be the item type?

So I would getModData of the item right-clicked and use the getType()?

Then compare it to the arra like in your code above.

I would need to re-look-at my unload menu stuff to reacquaint myself with how the script works but I would follow along those lines.

Also, I looked into the recipe code and I found out all I would really need to transfer in the process is the weapon mods (through those getXX() calls, the condition via a condition test and set condition code found there, then test to see if a mag is inserted and transfer that over (only if the mag was not inserted as guns spawn with their mags in place).

I don't have my files in front of me so, I can't get into specifics on how I'll do it until later.

Fuji, I do not know what I would do without you :mrgreen:

The search script should work with any key variable type as long as it matches the types in the array thanks to Lua variables having undefined types.

Considering you're planning on putting every convertable weapon in the array, though, it might be a bit slow, so I'll see if I can write a more efficient search script when I can get my hands on a computer.

Or could we break up the arrays with another test, like... 3d model, or, somthing else multiple guns would share or would the searching through multiple shorter arrays not add much efficiency?5GKZPU8.jpg

This should run fast enough that it shouldn't matter how long the array is, just make sure you format the tables right.

Typing code on a cellphone is a pain, so I hope you can read my squiggles.

Link to comment
Share on other sites

 

Clippy
5GKZPU8.jpg

This should run fast enough that it shouldn't matter how long the array is, just make sure you format the tables right.

Typing code on a cellphone is a pain, so I hope you can read my squiggles.

 

 

Whoah, dang! Well, it is a bit above my current coding pay grade :razz:. But following it through it makes definite sense.

 

The min and max is that a limiter on where in the index to look? or  who does that come into play? I am an accountant by trade so all this coding has be mostly blindly beating at code until it works... so...

Link to comment
Share on other sites

-Death to the great pyramid-

Whoah, dang! Well, it is a bit above my current coding pay grade :razz:. But following it through it makes definite sense.

The min and max is that a limiter on where in the index to look? or who does that come into play? I am an accountant by trade so all this coding has be mostly blindly beating at code until it works... so...

It's called a recursive function, meaning its a function that contains itself as part of its operations. This one works by splitting the list into sublists which split off into others and so on. The min and max values are there to simulate these smaller lists (Each half of the original list sans floored average) so you can pass the real list through the recursion while preserving index values.

Link to comment
Share on other sites

 

-Death to the great pyramid-

Whoah, dang! Well, it is a bit above my current coding pay grade :razz:. But following it through it makes definite sense.

The min and max is that a limiter on where in the index to look? or who does that come into play? I am an accountant by trade so all this coding has be mostly blindly beating at code until it works... so...

It's called a recursive function, meaning its a function that contains itself as part of its operations. This one works by splitting the list into sublists which split off into others and so on. The min and max values are there to simulate these smaller lists (Each half of the original list sans floored average) so you can pass the real list through the recursion while preserving index values.

 

 

How do we tie the min/max to the item being clicked?

Link to comment
Share on other sites

-Death to the great pyramid-

Whoah, dang! Well, it is a bit above my current coding pay grade :razz:. But following it through it makes definite sense.

The min and max is that a limiter on where in the index to look? or who does that come into play? I am an accountant by trade so all this coding has be mostly blindly beating at code until it works... so...

It's called a recursive function, meaning its a function that contains itself as part of its operations. This one works by splitting the list into sublists which split off into others and so on. The min and max values are there to simulate these smaller lists (Each half of the original list sans floored average) so you can pass the real list through the recursion while preserving index values.

How do we tie the min/max to the item being clicked?

It's at the bottom of the page, running the function with the min 0, and the max of table.maxn(tablename)-1 (array range is from 0 to the max value) is all you need to do. It's only really in with the function variables so it can be edited through the recursion without having to deal with global variables.

The min and max describe the table (kind of like a 2d array). Just make sure your table is formatted right, same as an array, but with each element as ["weaponname"]=index#.

Link to comment
Share on other sites

 

 

 

-Death to the great pyramid-

Whoah, dang! Well, it is a bit above my current coding pay grade :razz:. But following it through it makes definite sense.

The min and max is that a limiter on where in the index to look? or who does that come into play? I am an accountant by trade so all this coding has be mostly blindly beating at code until it works... so...

It's called a recursive function, meaning its a function that contains itself as part of its operations. This one works by splitting the list into sublists which split off into others and so on. The min and max values are there to simulate these smaller lists (Each half of the original list sans floored average) so you can pass the real list through the recursion while preserving index values.

How do we tie the min/max to the item being clicked?

It's at the bottom of the page, running the function with the min 0, and the max of table.maxn(tablename)-1 (array range is from 0 to the max value) is all you need to do. It's only really in with the function variables so it can be edited through the recursion without having to deal with global variables.

The min and max describe the table (kind of like a 2d array). Just make sure your table is formatted right, same as an array, but with each element as ["weaponname"]=index#.

 

 

Alright, I will actually process that in my mind after work, thanks! :-D

Link to comment
Share on other sites

 

 

Clipped

It's at the bottom of the page, running the function with the min 0, and the max of table.maxn(tablename)-1 (array range is from 0 to the max value) is all you need to do. It's only really in with the function variables so it can be edited through the recursion without having to deal with global variables.

The min and max describe the table (kind of like a 2d array). Just make sure your table is formatted right, same as an array, but with each element as ["weaponname"]=index#.

 

 

Okay, here is the basic bit I slopped together from what you basically handed to me:

I still need to add stuff to the list, the modData copy over, and the context menu code (which will be elsewhere)

I also think I misread the bottom most part of your scrip as I am not sure where the original item gets thrown into the BinarySearch...

 

Let me know if I got it pretty much right or not :-D

 

function BinarySearch(key, tab, imin, imax)

    local imid = math.floor((imax + imin)/2);

    if tab[imid] > key then

        return BinarySearch(key, tab, imin, imid-1);

    elseif tab[imid] < key then

        retun BinarySearch(key, tab, imid+1, imax);

    else

        return imid;

    end

end

local t = {    [benelliXM1014]=1,

            [benelliXM1014Sl]=2,

            [benelliXM1014SO]=3,

            [benelliXM1014SOSl]=4,

            [benelliXM1014PA]=5,

            [benelliXM1014PASl]=6,

            [benelliXM1014PASO]=7,

            [benelliXM1014PASOSl]=8,

            [spas12]=9,

            [spas12Sl]=10,

            [spas12PA]=11,

            [spas12PASl]=12,

            [ithaca37]=13,

            [ithaca37Sl]=14,

            [ithaca37SO]=15,

            [ithaca37SOSl]=16,

            

            };

local k=2;

function StartConvertfromUi(player, item)

    index = BinarySearch(k,t,0, TableMain(T)-1);

    player:AddItem(index);

end

Link to comment
Share on other sites

Clipped

It's at the bottom of the page, running the function with the min 0, and the max of table.maxn(tablename)-1 (array range is from 0 to the max value) is all you need to do. It's only really in with the function variables so it can be edited through the recursion without having to deal with global variables.

The min and max describe the table (kind of like a 2d array). Just make sure your table is formatted right, same as an array, but with each element as ["weaponname"]=index#.

Okay, here is the basic bit I slopped together from what you basically handed to me:

I still need to add stuff to the list, the modData copy over, and the context menu code (which will be elsewhere)

I also think I misread the bottom most part of your scrip as I am not sure where the original item gets thrown into the BinarySearch...

Let me know if I got it pretty much right or not :-D

function BinarySearch(key, tab, imin, imax)

local imid = math.floor((imax + imin)/2);

if tab[imid] > key then

return BinarySearch(key, tab, imin, imid-1);

elseif tab[imid] < key then

retun BinarySearch(key, tab, imid+1, imax);

else

return imid;

end

end

local t = { [benelliXM1014]=1,

[benelliXM1014Sl]=2,

[benelliXM1014SO]=3,

[benelliXM1014SOSl]=4,

[benelliXM1014PA]=5,

[benelliXM1014PASl]=6,

[benelliXM1014PASO]=7,

[benelliXM1014PASOSl]=8,

[spas12]=9,

[spas12Sl]=10,

[spas12PA]=11,

[spas12PASl]=12,

[ithaca37]=13,

[ithaca37Sl]=14,

[ithaca37SO]=15,

[ithaca37SOSl]=16,

};

local k=2;

function StartConvertfromUi(player, item)

index = BinarySearch(k,t,0, TableMain(T)-1);

player:AddItem(index);

end

You know... I just realized the entire search algorithm is useless in its current state. It needs to compare strings instead of numbers, hold on.

Just try to write the rest of the script using the simpler search I posted first for now.

Edit: Also, the table list needs quotes around the words and the TableMain thing in the function call should be "table.maxn(t)-1".

Edit2: Just use the simple one, arrays in Lua are foreign to me and trying to learn and teach how to use them on a smartphone is the least fun thing.

Two arrays, one with originals, one with conversions.

Search for the index of the original by passing in the string.

Use the resulting index to get the corresponding string from the conversion list.

Link to comment
Share on other sites

 

 

 

Clipped

It's at the bottom of the page, running the function with the min 0, and the max of table.maxn(tablename)-1 (array range is from 0 to the max value) is all you need to do. It's only really in with the function variables so it can be edited through the recursion without having to deal with global variables.

The min and max describe the table (kind of like a 2d array). Just make sure your table is formatted right, same as an array, but with each element as ["weaponname"]=index#.

Okay, here is the basic bit I slopped together from what you basically handed to me:

I still need to add stuff to the list, the modData copy over, and the context menu code (which will be elsewhere)

I also think I misread the bottom most part of your scrip as I am not sure where the original item gets thrown into the BinarySearch...

Let me know if I got it pretty much right or not :-D

function BinarySearch(key, tab, imin, imax)

local imid = math.floor((imax + imin)/2);

if tab[imid] > key then

return BinarySearch(key, tab, imin, imid-1);

elseif tab[imid] < key then

retun BinarySearch(key, tab, imid+1, imax);

else

return imid;

end

end

local t = { [benelliXM1014]=1,

[benelliXM1014Sl]=2,

[benelliXM1014SO]=3,

[benelliXM1014SOSl]=4,

[benelliXM1014PA]=5,

[benelliXM1014PASl]=6,

[benelliXM1014PASO]=7,

[benelliXM1014PASOSl]=8,

[spas12]=9,

[spas12Sl]=10,

[spas12PA]=11,

[spas12PASl]=12,

[ithaca37]=13,

[ithaca37Sl]=14,

[ithaca37SO]=15,

[ithaca37SOSl]=16,

};

local k=2;

function StartConvertfromUi(player, item)

index = BinarySearch(k,t,0, TableMain(T)-1);

player:AddItem(index);

end

You know... I just realized the entire search algorithm is useless in its current state. It needs to compare strings instead of numbers, hold on.

Just try to write the rest of the script using the simpler search I posted first for now.

Edit: also, the table list needs quotes around the words and the TableMain thing in the function call should be "table.maxn(t)-1".

 

 

I already fixed the list quotation thing after I posted, but I will fix the other bit now.

 

It'll take me a while to populate the entire list anyway..

 

Again I cannot stress where I'd be without you... It would take me months to figure something like this out...

Link to comment
Share on other sites

Clipped

It's at the bottom of the page, running the function with the min 0, and the max of table.maxn(tablename)-1 (array range is from 0 to the max value) is all you need to do. It's only really in with the function variables so it can be edited through the recursion without having to deal with global variables.

The min and max describe the table (kind of like a 2d array). Just make sure your table is formatted right, same as an array, but with each element as ["weaponname"]=index#.

Okay, here is the basic bit I slopped together from what you basically handed to me:

I still need to add stuff to the list, the modData copy over, and the context menu code (which will be elsewhere)

I also think I misread the bottom most part of your scrip as I am not sure where the original item gets thrown into the BinarySearch...

Let me know if I got it pretty much right or not :-D

function BinarySearch(key, tab, imin, imax)

local imid = math.floor((imax + imin)/2);

if tab[imid] > key then

return BinarySearch(key, tab, imin, imid-1);

elseif tab[imid] < key then

retun BinarySearch(key, tab, imid+1, imax);

else

return imid;

end

end

local t = { [benelliXM1014]=1,

[benelliXM1014Sl]=2,

[benelliXM1014SO]=3,

[benelliXM1014SOSl]=4,

[benelliXM1014PA]=5,

[benelliXM1014PASl]=6,

[benelliXM1014PASO]=7,

[benelliXM1014PASOSl]=8,

[spas12]=9,

[spas12Sl]=10,

[spas12PA]=11,

[spas12PASl]=12,

[ithaca37]=13,

[ithaca37Sl]=14,

[ithaca37SO]=15,

[ithaca37SOSl]=16,

};

local k=2;

function StartConvertfromUi(player, item)

index = BinarySearch(k,t,0, TableMain(T)-1);

player:AddItem(index);

end

You know... I just realized the entire search algorithm is useless in its current state. It needs to compare strings instead of numbers, hold on.

Just try to write the rest of the script using the simpler search I posted first for now.

Edit: also, the table list needs quotes around the words and the TableMain thing in the function call should be "table.maxn(t)-1".

I already fixed the list quotation thing after I posted, but I will fix the other bit now.

It'll take me a while to populate the entire list anyway..

Again I cannot stress where I'd be without you... It would take me months to figure something like this out...

Edit2 above

Link to comment
Share on other sites

 

 

 

 

 

Clipped

It's at the bottom of the page, running the function with the min 0, and the max of table.maxn(tablename)-1 (array range is from 0 to the max value) is all you need to do. It's only really in with the function variables so it can be edited through the recursion without having to deal with global variables.

The min and max describe the table (kind of like a 2d array). Just make sure your table is formatted right, same as an array, but with each element as ["weaponname"]=index#.

Okay, here is the basic bit I slopped together from what you basically handed to me:

I still need to add stuff to the list, the modData copy over, and the context menu code (which will be elsewhere)

I also think I misread the bottom most part of your scrip as I am not sure where the original item gets thrown into the BinarySearch...

Let me know if I got it pretty much right or not :-D

function BinarySearch(key, tab, imin, imax)

local imid = math.floor((imax + imin)/2);

if tab[imid] > key then

return BinarySearch(key, tab, imin, imid-1);

elseif tab[imid] < key then

retun BinarySearch(key, tab, imid+1, imax);

else

return imid;

end

end

local t = { [benelliXM1014]=1,

[benelliXM1014Sl]=2,

[benelliXM1014SO]=3,

[benelliXM1014SOSl]=4,

[benelliXM1014PA]=5,

[benelliXM1014PASl]=6,

[benelliXM1014PASO]=7,

[benelliXM1014PASOSl]=8,

[spas12]=9,

[spas12Sl]=10,

[spas12PA]=11,

[spas12PASl]=12,

[ithaca37]=13,

[ithaca37Sl]=14,

[ithaca37SO]=15,

[ithaca37SOSl]=16,

};

local k=2;

function StartConvertfromUi(player, item)

index = BinarySearch(k,t,0, TableMain(T)-1);

player:AddItem(index);

end

You know... I just realized the entire search algorithm is useless in its current state. It needs to compare strings instead of numbers, hold on.

Just try to write the rest of the script using the simpler search I posted first for now.

Edit: also, the table list needs quotes around the words and the TableMain thing in the function call should be "table.maxn(t)-1".

I already fixed the list quotation thing after I posted, but I will fix the other bit now.

It'll take me a while to populate the entire list anyway..

Again I cannot stress where I'd be without you... It would take me months to figure something like this out...

Edit2 above

 

 

Got it, I will use the simple one, I can't imagine it will be that slow...

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...