Ranged NPC problems. menu

User Tag List

Results 1 to 10 of 10
  1. #1
    bendaferi's Avatar Active Member
    Reputation
    34
    Join Date
    Jun 2008
    Posts
    111
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Ranged NPC problems.

    Hello there!

    I tryed to make tree look like npc which gets rooted upon spawning. The idea was to make him ranged casting Boulder Toss ranged attacks every 2 seconds

    My first thought was it doesn't need to make a lua script since it can be edited in the creature_proto. So I set CanRanged to 1 set up speed and dmg finally changed spell1 to 50086.
    Did not work. The tree was hitting me like before.

    Then I searched for a command that would make my tree toss those boulders. I found DealDamage().

    Code:
    ...
    target = Unit:GetRandomPlayer(0)
    Unit:DealDamage(target, 52, 50086)
    ...
    Still no flying rocks.

    If anyone has a tip how to solve this little problem please share with me.

    P.S.: Bonus Question

    Is it possible to tell this "tree" to attack every hostile mob and players who enter its combat range? I mean not everyone at the same time, just one by one, since I did find a command for units and players bot not for both. ( :GetRandomEnemy() and :GetRandomPlayer() )
    Is it enough to start with looking for hostile units and if that's a nil value then look for an enemy player?
    Since this "tree" has an alliance faction I want him to attack every horde faction beings. Including mobs and players.

    Thank you for the help!
    bendaferi

    Ranged NPC problems.
  2. #2
    stoneharry's Avatar Moderator Harry

    Authenticator enabled
    Reputation
    1613
    Join Date
    Sep 2007
    Posts
    4,554
    Thanks G/R
    151/146
    Trade Feedback
    0 (0%)
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Something like this:
    Code:
    function CastSpellOnRandomTarget(pUnit)
       local found = false
       for _,unit in pairs(pUnit:GetInRangeUnits()) do -- return creatures
          if unit:IsHotile() and unit:GetDistanceYards(pUnit) < 30 then
             pUnit:FullCastSpellOnTarget(50086, unit)
             found = true 
             break
           end
        end
        if not found then
           for _,plr in pairs(pUnit:GetInRangePlayers()) do
               if plr:IsHostile() and plr:GetDistanceYards(pUnit) < 30 then
                   pUnit:FullCastSpellOnTarget(50086, plr)
                   break
                end
            end
    end

  3. #3
    bendaferi's Avatar Active Member
    Reputation
    34
    Join Date
    Jun 2008
    Posts
    111
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you for your help. A few things are a bit cleaner now and I surely can manage it on my own but to be honest I was hoping there is a way make my NPC not to cast the boulder toss, just do a defined ( for example 54-62 ) damage while using the boulder toss visual. That's why I was trying to figure out the DealDamage() command but seems that won't work anyway.

    Thank you again.

  4. #4
    stoneharry's Avatar Moderator Harry

    Authenticator enabled
    Reputation
    1613
    Join Date
    Sep 2007
    Posts
    4,554
    Thanks G/R
    151/146
    Trade Feedback
    0 (0%)
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    You can use Strike to deal damage, but I don't know how you would just play the visual.

  5. #5
    bendaferi's Avatar Active Member
    Reputation
    34
    Join Date
    Jun 2008
    Posts
    111
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Managed to do it with some dbc edit finally. But I just can't figure out what the '_' sign means in your script for example:

    Code:
    for _,unit in pairs(pUnit:GetInRangeUnits()) do
    I read about the "numeric and generic for" in lua but still i don't get it.

    Isn't the _ supposed to be the key or index and the unit the value?

    Sorry I'm trying to figure it out by myself but so far my best bet is that the _ returns the first unit in the row.

    Thank you,
    bendaferi

  6. #6
    stoneharry's Avatar Moderator Harry

    Authenticator enabled
    Reputation
    1613
    Join Date
    Sep 2007
    Posts
    4,554
    Thanks G/R
    151/146
    Trade Feedback
    0 (0%)
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Code:
    for k,v in pairs(pUnit:GetInRangeUnits()) do
    -- k and v is usually what these are represented as.
    -- k = position in the table, v = the value.
    -- since we are getting units, v will be the value of the creature.
    print(k)
    if v:GetEntry() == 1019 then -- if entry = 1019
    print("Found the npc! Stopping search at: "..k)
    end
    end
    When we are not going to use that variable within the for loop, we just give it a _.

  7. #7
    bendaferi's Avatar Active Member
    Reputation
    34
    Join Date
    Jun 2008
    Posts
    111
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you stoneharry. Funny that now I understood how your first example script works I put it into my script and it won't work. Well I found 2 little missings that I edited immediatelly (missing 's' in :IsHostile() and a missing 'end' at the end) but other than that I don't see any mistakes and the whole scipt seems to be ok for me. No errors on the console window. For some reason my creature won't react to his OnCombat event.

    Code:
    function ne_torony_combat(pUnit, event, player) 
    pUnit:RegisterEvent("basszadneki", 2000, 0)
    pUnit:SendChatMessage(12, 0, "I'm in combat. Or not?!") -- yet, seems not :/
    end
    function basszadneki(pUnit)
    	pUnit:SendChatMessage(12, 0, "Heyheyhey") -- just a check if he won't cast spell at least is he doing the 'basszadneki' event.
       local found = false
       for _,unit in pairs(pUnit:GetInRangeUnits()) do -- return creatures
          if unit:IsHostile() and unit:GetDistanceYards(pUnit) < 30 then
             pUnit:FullCastSpellOnTarget(50086, unit)
             found = true 
             break
           end
        end
        if not found then
           for _,plr in pairs(pUnit:GetInRangePlayers()) do
               if plr:IsHostile() and plr:GetDistanceYards(pUnit) < 30 then
                   pUnit:FullCastSpellOnTarget(50086, plr)
                   break
                end
            end
    	end
    end
    RegisterUnitEvent(50008, 1, "ne_torony_combat")
    The red part should be the attacker.
    "(pCreature, event, pAttacker)"
    Is that the problem? If so what should I name it instead?

    For now the whole script seems to be not working. Advices are welcome

  8. #8
    stoneharry's Avatar Moderator Harry

    Authenticator enabled
    Reputation
    1613
    Join Date
    Sep 2007
    Posts
    4,554
    Thanks G/R
    151/146
    Trade Feedback
    0 (0%)
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Try this:

    Code:
    function ne_tourny_onspawn(pUnit, event) 
    	pUnit:RegisterEvent("basszadnekicheckspell", 2000, 0)
    	pUnit:SendChatMessage(12, 0, "I'm in combat. Or not?!")
    end
    
    function basszadnekicheckspell(pUnit)
    	pUnit:SendChatMessage(12, 0, "Heyheyhey") -- just a check if he won't cast spell at least is he doing the 'basszadneki' event.
    	local found = false
    	for _,unit in pairs(pUnit:GetInRangeUnits()) do -- return creatures
    		if unit:IsHostile() and unit:GetDistanceYards(pUnit) < 30 then
    			pUnit:FullCastSpellOnTarget(50086, unit)
    			pUnit:SendChatMessage(12,0,"Casting spell on: "..unit:GetName())
    			found = true 
    			break
    		end
    	end
    	if not found then
    		for _,plr in pairs(pUnit:GetInRangePlayers()) do
    			if plr:IsHostile() and plr:GetDistanceYards(pUnit) < 30 then
    				pUnit:FullCastSpellOnTarget(50086, plr)
    				pUnit:SendChatMessage(12,0,"Casting spell on: "..plr:GetName())
    				break
    			end
    		end
    	end
    end
    
    RegisterUnitEvent(50008, 18, "ne_tourny_onspawn")

  9. #9
    bendaferi's Avatar Active Member
    Reputation
    34
    Join Date
    Jun 2008
    Posts
    111
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    So: thank you but the last script didn't work.
    I wrote mine but there are many missings and bugs.

    Code:
    local jatekos
    local mob
    
    function ne_torony_OnCombat(pUnit, event, pMisc)
    if (pMisc:IsAlive() == false) then
    pUnit:DisableCombat()
    else
    if pMisc:IsPlayer() then
    jatekos = pMisc
    pUnit:FullCastSpellOnTarget(50086, jatekos)
    pUnit:RegisterEvent("jatekosra", 2000, 0)
    else if pMisc:IsCreature() then
    mob = pMisc
    pUnit:FullCastSpellOnTarget(50086, mob)
    pUnit:RegisterEvent("mobra", 2000, 0)
    end
    end
    end
    end
    RegisterUnitEvent(50008, 1, ne_torony_OnCombat)
    My little tree will finally recognize enemy units (NPCs and Players) and it's indeed throwing those boulders on them.
    The highlighted part (red) seems to be not working. The reason I wrote that is the tree was attacking even my corpse. He still does.
    So I couldn't test if he switches target upon killing or not. Not sure if that would work and how...

    advices are welcome.
    Last edited by bendaferi; 03-14-2012 at 07:02 PM.

  10. #10
    bendaferi's Avatar Active Member
    Reputation
    34
    Join Date
    Jun 2008
    Posts
    111
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I see there is nothing new what would solve my problem. Nevermind, I got a new one (didn't want to start a new thread for this):

    :SetUnitToFollow() does not work. Now i'm running a freshly compiled arcemu server without any problem so far. I was testing some lua functions including server hooks.

    Code:
    local bot
    local jatekos
    local van = false
    
    function gyere_OnChat(event, plr, message, _type, language)
    	if (message == "gyere") then
    	jatekos = plr
    	if not van then
    		jatekos:SpawnCreature(50000, jatekos:GetX(), jatekos:GetY(), jatekos:GetZ(), jatekos:GetO(), jatekos:GetFaction(), 0)
    		van = true
    	else
    		bot:SendChatMessage(12, 0, "Itt vagyok mar...")
    		end
    	end
    	if (message == "takarodj") then
    		bot:Despawn(1000, 0)
    		van = false
    	end
    end
    RegisterServerHook(16, "gyere_OnChat")
    
    function bot_OnSpawn(unit, event, plr)
    bot = unit
    bot:SendChatMessage(12, 0, "Hello")
    bot:RegisterEvent("kovet_kezd", 1000, 1)
    end
    function kovet_kezd(unit, event, plr)
    bot:SendChatMessage(12, 0, "Csa " ..jatekos:GetName())
    bot:SetUnitToFollow(jatekos, 2, 1)
    end
    RegisterUnitEvent(50000, 18, "bot_OnSpawn")
    So my npc spawns when I say "gyere" and despawns when I say "takarodj". Okay he also won't spawn if he already exists. Everything is just working fine expect the SetUnitToFollow.
    Somewhere I read the 'angle' is not the angle so I wrote '1' there. Sill not working.

    The red part is just a debug. He knows who "jatekos" (player) is, spamming the message with his name, but he won't follow the player.

    Just wanted to know what I'm doing wrong

    thank you!

    EDIT:

    I didn't find any error in the script so downloaded Stoneharry's Kronos repack. The same script worked without any error there. The unit was following me without any problems. Weird. The new arcemu does not support this lua function any more or what?
    Last edited by bendaferi; 03-16-2012 at 06:27 AM.

Similar Threads

  1. [Lua Script] Ranged npc (normal fire) problem.
    By BurnDownTheSystem in forum WoW EMU Questions & Requests
    Replies: 2
    Last Post: 06-27-2012, 04:54 AM
  2. Quest NPC problem.
    By Timmy420 in forum WoW EMU Questions & Requests
    Replies: 0
    Last Post: 04-27-2009, 11:03 PM
  3. NPC Problem
    By Madara Uchiha in forum World of Warcraft Emulator Servers
    Replies: 2
    Last Post: 05-21-2008, 07:04 PM
  4. How do you make a ranged npc?
    By justsum1 in forum World of Warcraft Emulator Servers
    Replies: 2
    Last Post: 01-28-2008, 08:37 PM
  5. BIG NPC problem
    By logicd22 in forum World of Warcraft Emulator Servers
    Replies: 5
    Last Post: 01-26-2008, 05:46 PM
All times are GMT -5. The time now is 01:59 PM. Powered by vBulletin® Version 4.2.3
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved. User Alert System provided by Advanced User Tagging (Pro) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
Digital Point modules: Sphinx-based search