Results 1 to 5 of 5

Thread: Whats wrong with this action?

  1. #1
    Normal User jesusz0r's Avatar
    Join Date
    Jun 2012
    Posts
    221
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quoted
    0 Post(s)
    Reputation
    17
    Rep Power
    5

    Whats wrong with this action?

    PHP Code:
    local players getcreatures("pfs")
    local random math.random(1,3)

    for 
    i=0#players do
        
    if (target.hppc <= 30 and target.id ~= 0then
            
    if (players[i].posx == posx-1) and players[i].count 0 then
                
    if random == 1 then turn('w')
                elseif 
    random == 2 then turn('s')
                elseif 
    random == 3 then turn('n'end
            
    elseif (players[i].posx == posx+1) and players[i].count 0 then
                
    if random == 1 then turn('e')
                elseif 
    random == 2 then turn('s')
                elseif 
    random == 3 then turn('n'end
            
    elseif (players[i].posy == posy-1) and players[i].count 0 then
                
    if random == 1 then turn('w')
                elseif 
    random == 2 then turn('e')
                elseif 
    random == 3 then turn('n'end
            
    elseif (players[i].posy == posy+1) and players[i].count 0 then
                
    if random == 1 then turn('w')
                elseif 
    random == 2 then turn('s')
                elseif 
    random == 3 then turn('e'end
            end
        end
    end 
    It's suppose to turn to a different direction if someoen is in front of you while your target is 30% hp or less!

  2. #2
    Normal User sirmate's Avatar
    Join Date
    Mar 2012
    Location
    Poland
    Posts
    176
    Mentioned
    2 Post(s)
    Tagged
    3 Thread(s)
    Quoted
    2 Post(s)
    Reputation
    105
    Rep Power
    6
    I've made it in abit other way.

    Code:
    local function isPlayerOnTile(POSITION_X, POSITION_Y, POSITION_Z)
        local TILE_DATA = gettile(POSITION_X, POSITION_Y, POSITION_Z)
        
        for CURRENT_INDEX = 0, TILE_DATA.count - 1 do
            if (TILE_DATA.items[CURRENT_INDEX].id == 99 and TILE_DATA.items[CURRENT_INDEX].count <= 0x40000000) then
                return true
            end
        end
        
        return false
    end
    
    
    if (30 >= target.hppc and target.id > 0 and paround(4) > 0) then
        local POSITIONS, FREE_DIRECTIONS = {{X = 0, Y = -1, DIR = [[n]]}, {X = 1, Y = 0, DIR = [[e]]}, {X = 0, Y = 1, DIR = [[s]]}, {X = -1, Y = 0, DIR = [[w]]}}, {}
            
        if (isPlayerOnTile(posx + POSITIONS[getcreature(id).direction + 1].X, posy + POSITIONS[getcreature(id).direction + 1].Y, posz)) then
            for _, POSITION in ipairs(POSITIONS) do
                if (not isPlayerOnTile(posx + POSITION.X, posy + POSITION.Y, posz)) then
                    table.insert(FREE_DIRECTIONS, POSITION.DIR)
                end
            end
            
            if(#FREE_DIRECTIONS > 0) then
                local TURN_DIRECTION = FREE_DIRECTIONS[math.random(#FREE_DIRECTIONS)]
    
    
                while ((({[[n]], [[e]], [[s]], [[w]]})[getcreature(id).direction + 1]) ~= TURN_DIRECTION) do
                    turn(TURN_DIRECTION) wait(25, 75)
                end
            end
        end
    end
    Last edited by sirmate; 08-24-2012 at 12:33 PM.
    (๏̯͡๏ )

  3. #3
    Normal User jesusz0r's Avatar
    Join Date
    Jun 2012
    Posts
    221
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quoted
    0 Post(s)
    Reputation
    17
    Rep Power
    5
    You took it to another level, thank you bro!

  4. #4
    Normal User sirmate's Avatar
    Join Date
    Mar 2012
    Location
    Poland
    Posts
    176
    Mentioned
    2 Post(s)
    Tagged
    3 Thread(s)
    Quoted
    2 Post(s)
    Reputation
    105
    Rep Power
    6
    No problem, you'r welcome
    (๏̯͡๏ )

  5. #5
    iScripter Eli's Avatar
    Join Date
    Mar 2012
    Posts
    3,764
    Mentioned
    492 Post(s)
    Tagged
    2 Thread(s)
    Quoted
    956 Post(s)
    Reputation
    586
    Rep Power
    10
    That's sick!

Posting Permissions

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