Signup Now
Results 1 to 8 of 8
  1. #1
    Free User
    Join Date
    May 2016
    Posts
    83
    Reputation
    26
    Rep Power
    16

    Help to add a COUNTER to this action

    Hello everyone,

    I'd like to ask help for you with this action. Its from one of the script I've created for the MWC Twisted Waters. In a nutshell, the script will collect items (dead creature corpses) from the ground and then throw it in a certain SQM (inside the lake). I've already managed to make the script work fine, but now I'd like to add a counter, so that we can know the exact ammount of corpses that have already been thrown into the lake. So let's go to the action:

    Code:
    init start
    
    local monsters = {"3994", "3995", "3996", "3998", "3999", "4000", "4188", "4189", "4190", "4378", "4992"}
    local corpsesbp = getlootingdestination("corpsesbp")
    
    init end
    
    auto(200)
    
    if $wptsection == "hunt" then
    
    collectitems(corpsesbp, table.unpack(monsters))
    
    end
    This is the action that makes the character collect the bodies from the floor. Then, when the backpack if full, or in case the character has no more cap, it will force the character to go to the location where it will throw the bodies in the lake.
    Then there will be an action somewhat like:

    moveitems (id, position)

    So how can I add a code to make it count everytime it drops a body in the lake? I've tried to put "While itemcount(id) do" but it didnt work.

    Thanks in advance

  2. #2
    Free User Donatello's Avatar
    Join Date
    Dec 2013
    Location
    Tuscany, Italy
    Posts
    398
    Reputation
    51
    Rep Power
    21
    Use this action to throw bodies away:
    init start
    local corpsesID = {"3994", "3995", "3996", "3998", "3999", "4000", "4188", "4189", "4190", "4378", "4992"}
    corpsesCount = corpsesCount or 0
    init end

    for _, v in ipairs(corpsesID) do
    while itemcount(v) > 0 do
    moveitems(v, ground($posx, $posy - 1, $posz)) -- This will throw corpses 1 SQM to north.
    corpsesCount = corpsesCount + 1
    end
    end


    Then you'll have a global var called: corpsesCount that will return how many corpses you have throw away already, with that you can do a simple check like:

    if corpsesCount > 100 then
    gotolabel("done")
    else
    gotolabel("start again")
    end

  3. #3
    Free User
    Join Date
    May 2016
    Posts
    83
    Reputation
    26
    Rep Power
    16
    Thanks,

    I'll check if that works as soons as I renew my subscription.

    Just one last doubt, how do I reset the corpsescount var? Does it reset to 0 everytime script is loaded or reloaded? Or can I simply add an action saying "Corpsescount = 0" at some point of the script?

    Rep+

  4. #4
    Wind Tester
    Join Date
    Dec 2013
    Location
    Warsaw, Poland
    Posts
    2,578
    Reputation
    149
    Rep Power
    27
    No it won't reset, since corpsesCount is global variable. You can 'reset it' (as you wrote) by
    corpsesCount = 0
    anywhere in bot.

  5. #5
    Free User
    Join Date
    May 2016
    Posts
    83
    Reputation
    26
    Rep Power
    16
    @Donatello

    Hello buddy, I tested it today, and it didnt work 100% as intented.

    The action that you sugested will only increase the count by 1 for each type of body that was moved and not the actual amount. Let me explain better:

    "3994", "3995", "3996" - different stages of body for rat
    "3998", "3999", "4000" - ids for cave rat
    "4188", "4189", "4190" - ids for snake
    "4378", "4992" - ids for butterfly

    So for example, lets say that the character collected 2 rats, 3 snakes, and 1 butterfly. The action will consider 3 different types of itens, so it will add 3 to the corpsesCount, but instead it should add 6, the total amount of bodies that were actualy thrown into the lake.


    I guess the problem is in the line:

    while itemcount(v) > 0 do

    I think there should be foreach here instead of while, but i'm not sure what var could be used with it.

    Thanks in advance for the support and let me know if you'd be interested in the script to maybe test or use it for yourself

  6. #6
    Wind Tester
    Join Date
    Dec 2013
    Location
    Warsaw, Poland
    Posts
    2,578
    Reputation
    149
    Rep Power
    27
    @fabiocastellan try this instead
    moveitems(v, ground($posx, $posy - 1, $posz), '0-15', 1) -- will move only one body at time, as it is adding only one to counter. You can move all, but then you have to count bodies before moving them and add amount of bodies to var
    wait(50, 100) -- you really should use waits after actions

  7. #7
    Free User
    Join Date
    May 2016
    Posts
    83
    Reputation
    26
    Rep Power
    16
    Quote Originally Posted by Imba View Post
    @fabiocastellan try this instead
    moveitems(v, ground($posx, $posy - 1, $posz), '0-15', 1) -- will move only one body at time, as it is adding only one to counter. You can move all, but then you have to count bodies before moving them and add amount of bodies to var
    wait(50, 100) -- you really should use waits after actions
    Bro, it worked, can I add 100000000 to your rep? <3

    Just curiosity, what this '0-15' means?

  8. #8
    Wind Tester
    Join Date
    Dec 2013
    Location
    Warsaw, Poland
    Posts
    2,578
    Reputation
    149
    Rep Power
    27
    it is locationfrom, so it will move items from containers with indexes 0-15 (all opened containers)

 

 

Posting Permissions

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