1. Post #3281
    Shit
    On
    Shit
    code_gs's Avatar
    March 2013
    18,650 Posts
    And second question... I don't want to use autorun scripts, or my own gamemode, to scale the damage my SWEP does to its owner. Is it an ok idea to hook GM:ScalePlayerDamage or GM:EntityTakeDamage in a SWEP?
    Yes

  2. Post #3282
    Gold Member
    pilot's Avatar
    January 2012
    824 Posts
    Lua logic question:
    Trying to find a matching value from a table to a string and print that result.

    So far I have:

    Code:
    local RankList = {}
    RankList[1] = "Recruit"
    RankList[2] = "Private"
    RankList[3] = "Corporal"
    RankList[4] = "Sergeant"
    RankList[5] = "Lieutenant"
    RankList[6] = "Captain"
    RankList[7] = "Commander"
    
    local targetName = ply:Name() --Let's pretend this returns "Recruit Bob"
    
    for k, v in ipairs(RankList) do
    	local getRank = string.match(targetName, v, 1)
    	print(getRank)
    end
    This prints:
    Code:
    Recruit
    nil
    nil
    nil
    nil
    nil
    nil
    I just want it to print "Recruit" without the nil's. Anyone know how to do that?

  3. Post #3283
    bigdogmat's Avatar
    May 2014
    890 Posts
    Lua logic question:
    Trying to find a matching value from a table to a string and print that result.

    So far I have:


    I just want it to print "Recruit" without the nil's. Anyone know how to do that?
    Code:
    for k, v in ipairs(RankList) do
      if string.match(targetName, v) then
        print(v)
        break
      end
    end
    Edit: To explain, string.match returns the match it found or nil if it couldn't find one. Because we're using a straight string search it'll return `v` as that's what we're searching for. Also string.find is probably better suited for this case as you're not searching for a pattern.

  4. Post #3284
    DarkDragonLov's Avatar
    April 2017
    19 Posts
    I guess cus new page I'll ask again, rephrased.

    I want a list or table of entities that are harmed by a util.BlastDamageInfo
    Is there a way to get this? Is there a way to get how much damage each of those entities took?

  5. Post #3285
    Shit
    On
    Shit
    code_gs's Avatar
    March 2013
    18,650 Posts
    I guess cus new page I'll ask again, rephrased.

    I want a list or table of entities that are harmed by a util.BlastDamageInfo
    Is there a way to get this? Is there a way to get how much damage each of those entities took?
    I don't think so, you would just have to add them all through various hook calls.

  6. Post #3286
    Fantym420's Avatar
    October 2010
    989 Posts
    I guess cus new page I'll ask again, rephrased.

    I want a list or table of entities that are harmed by a util.BlastDamageInfo
    Is there a way to get this? Is there a way to get how much damage each of those entities took?
    here's how i'd approach this:

    1. Generate a unique id for your blast, math.random() or something.

    2. Before you create the blast use ents.FindInSphere with the same position and radius as your explosion, this is the entities that may be hit. Store the table someplace you can access it, probably a global table of blasts... Then run through the ents in the table from ents.FindInSphere and add the values .blastID and .blastTime to each entity. Set .blastID to the unique id, and set .blastTime to CurTime()

    3. Do the util.BlastDamageInfo

    4. Then in the hook GM:EntityTakeDamage you'll check each incoming target for a blastID and check if that blast table exists, if it does then make sure the blast isn't too old, if CurTime() > .blastTime + 1( or whatever number/fraction of seconds) then it's too old. If all is well then check the damageType, CTakeDamageInfo:IsDamageType to check if it's a blast damageInfo:IsDamageType(DMG_BLAST ). If it is then add it to another table table, delete it from the global blast table, add up all blast damage (for that blastID), or do whatever with it now that it's been identified as an entity in that blast, all damage info is on the damageInfo, object, damage, pos, type, inflictor, attacker, etc.

    I don't know if this is the best way, It's just how I'd approach it.

    Hope this helps.
    Reply With Quote Edit / Delete Reply Windows 7 Chrome Show Events Disagree Disagree x 3 (list)

  7. Post #3287
    i am resally durnbk
    YourStalker's Avatar
    December 2012
    3,151 Posts
    maybe should refresh the page before replying to day old posts.