LUA, How Can i check for a nil value? menu

Shout-Out

User Tag List

Results 1 to 5 of 5
  1. #1
    controlsx2's Avatar Member
    Reputation
    16
    Join Date
    Jun 2007
    Posts
    223
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    LUA, How Can i check for a nil value?

    Ive got a Horde and Alliance Only Area on my Server. To keep the oposite faction out im using the following script.

    Code:
    RegisterUnitEvent(70000, 18, "Announcer")
    RegisterUnitEvent(70000, 4, "Announcer_Died")
    
    function Announcer_Died(Unit, event, player)
    Unit:RemoveEvents()
    end
    
    function Announcer(Unit, event, player)
    Unit:RegisterEvent("Announcer_Say",100, 0)
    end
    
    function Announcer_Say(Unit, event, player)
    local plr=Unit:GetRandomPlayer(2)
    local race=plr:GetPlayerRace()
    if race==1 or race==3 or race==4 or race==7 or race==11 then
    else
    Unit:CastSpellOnTarget(54028,plr)
    plr:Teleport(1, -2725.112, -4990.3989, 27.738)
    plr:SendAreaTriggerMessage("You Have Tried to Enter the Area of Your Enemy")
    end
    end
    Thats an Example of the Anti-Horde Script it works perfectly the problem is my world.exe is being spammed with

    Code:
    attempt to index local 'plr' (a nil value)
    Im guessing this is when there isnt any players close to the NPC. I tried adding an if so it went like this

    Code:
    RegisterUnitEvent(70000, 18, "Announcer")
    RegisterUnitEvent(70000, 4, "Announcer_Died")
    
    function Announcer_Died(Unit, event, player)
    Unit:RemoveEvents()
    end
    
    function Announcer(Unit, event, player)
    Unit:RegisterEvent("Announcer_Say",100, 0)
    end
    
    function Announcer_Say(Unit, event, player)
    local plr=Unit:GetRandomPlayer(2)
    local race=plr:GetPlayerRace()
    if (plr==nil) then
    else
    if race==1 or race==3 or race==4 or race==7 or race==11 then
    else
    Unit:CastSpellOnTarget(54028,plr)
    plr:Teleport(1, -2725.112, -4990.3989, 27.738)
    plr:SendAreaTriggerMessage("You Have Tried to Enter the Area of Your Enemy, Alenya Has Saved you!")
    end
    end
    end
    And the script still runs but im still getting spammed. What could be the issue?
    Also the spell isnt getting cast on the player its being cast on the NPC, its no big deal as it works without it but would be a nice touch
    Last edited by controlsx2; 06-20-2009 at 09:45 AM.

    LUA, How Can i check for a nil value?
  2. #2
    AngelSandy's Avatar Member
    Reputation
    19
    Join Date
    Jan 2009
    Posts
    330
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well.
    First of all I suppose the target is Friendly to some and Unfriendly to others. Just make it do a kill command whenever it gets into combat.


    Code:
    
    function Kill_Plr(pUnit,event)
    local Plr = pUnit:GetRandomPlayer(0)
    if plr ~= nil then
         Plr:Kill()
    end
    end
    
    pUnit:RegisterEvent(ENTRY ID,1,"Kill_Plr")
    

    Easy as that?

  3. #3
    Jotox's Avatar Contributor
    Reputation
    250
    Join Date
    Mar 2008
    Posts
    282
    Thanks G/R
    0/4
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    if (plr) then
    ...
    end
    the code (...) will only execute if plr exists.

  4. #4
    AngelSandy's Avatar Member
    Reputation
    19
    Join Date
    Jan 2009
    Posts
    330
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Isn't that what he wants?

  5. #5
    controlsx2's Avatar Member
    Reputation
    16
    Join Date
    Jun 2007
    Posts
    223
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ive figured out that its the

    local plr=Unit:GetRandomPlayer(2)

    thats causing problems, its writing to console whnever the value is Nil, i guess ill live with it. The only way im going to get around it is to make the NPC hostile and put my code within the OnCombat
    Last edited by controlsx2; 06-21-2009 at 08:36 PM.

Similar Threads

  1. [How-To] How can I check if I was detected as a Cheater?
    By Anxious in forum Pokemon GO Hacks|Cheats
    Replies: 5
    Last Post: 08-08-2016, 07:09 AM
  2. how can make luancher for 5.0.5 ?
    By alleriia in forum World of Warcraft General
    Replies: 0
    Last Post: 01-24-2013, 01:06 AM
  3. how can i check if the bot DC with autoit?
    By burningman222 in forum Diablo 3 Bots Questions & Requests
    Replies: 1
    Last Post: 11-06-2012, 11:54 PM
All times are GMT -5. The time now is 03:53 PM. Powered by vBulletin® Version 4.2.3
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved. User Alert System provided by Advanced User Tagging (Pro) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
Google Authenticator verification provided by Two-Factor Authentication (Free) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
Digital Point modules: Sphinx-based search