EQEmulator Forums

EQEmulator Forums (https://www.eqemulator.org/forums/index.php)
-   Support::Windows Servers (https://www.eqemulator.org/forums/forumdisplay.php?f=587)
-   -   Prespawn this a good idea or no? (https://www.eqemulator.org/forums/showthread.php?t=37444)

NatedogEZ 10-29-2013 08:02 AM

Prespawn this a good idea or no?
 
Before NPCs spawn I want to set entity variables to them if they have certain special attacks.. that way I can just use the entity variables to dictate what special attacks I want to add to them if any...

My Perl script works well with this so far as in it skips mobs that already have Special attacks set in the database and adds special attacks to the mobs that do not have any (usually trash mobs).

The second loop is only to check if they have ANY of them so that my scaling script will skip them in the process of adding special attacks to NPCs.

My question is... would this bog down the server at all adding that many entity variables to an NPC? Mainly the first loop that adds the specific entity variables based on the type they have.



Code:


void NPC::mod_prespawn(Spawn2 *sp)
{

        for( int i = 1; i < 36; i++ )
        {
                if(GetSpecialAbility(i))
                {
                        const char* HasAbility = "1";
                        const char* SpecialList[] = {"SPECATK_SUMMON", "SPECATK_ENRAGE", "SPECATK_RAMPAGE", "SPECATK_AREA_RAMPAGE", "SPECATK_FLURRY", "SPECATK_TRIPLE", "SPECATK_QUAD", "SPECATK_INNATE_DW", "SPECATK_BANE", "SPECATK_MAGICAL", "SPECATK_RANGED_ATK", "UNSLOWABLE", "UNMEZABLE", "UNCHARMABLE", "UNSTUNABLE", "UNSNAREABLE", "UNFEARABLE", "UNDISPELLABLE", "IMMUNE_MELEE", "IMMUNE_MAGIC", "IMMUNE_FLEEING", "IMMUNE_MELEE_EXCEPT_BANE", "IMMUNE_MELEE_NONMAGICAL", "IMMUNE_AGGRO", "IMMUNE_AGGRO_ON", "IMMUNE_CASTING_FROM_RANGE", "IMMUNE_FEIGN_DEATH", "IMMUNE_TAUNT", "NPC_TUNNELVISION", "NPC_NO_BUFFHEAL_FRIENDS", "IMMUNE_PACIFY", "LEASH", "TETHER", "DESTRUCTIBLE_OBJECT", "NO_HARM_FROM_CLIENT"};
                        SetEntityVariable(SpecialList[i-1], HasAbility);
                }
        }

        for( int i = 1; i < 36; i++ )
        {
                if(GetSpecialAbility(i))
                {
                        const char* HasAbility = "1";
                        const char* Stuff = "HasSpecial";
                        SetEntityVariable(Stuff, HasAbility);
                        break;
                }
        }
}


Tabasco 10-29-2013 12:26 PM

I suppose it depends on how many NPC's have special attacks and how much memory you have. In any case I wouldn't expect it to increase your memory usage per NPC in a really significant way and I don't think the processing overhead would be noticeable unless you were repopping a large zone.

I don't have the big picture here, but what you're storing appears to be redundant. There are quest functions for getting and setting special attacks already. Is there a particular reason you want it stored that way?

NatedogEZ 10-29-2013 04:53 PM

I don't see anything for getting NPC special attacks in perl... or am I missing it?


nvm... I was missing it by a mile..

HasNPCSpecialAtk("Z")


Found it lol thank you! :) (I didn't think there was a function for this.. now I know!)


I still need the second part though so I know if NPCs have ANY special attack that way I dont overwrite them when I scale the zone.

Tabasco 10-29-2013 05:05 PM

I kept looking for it under a different name, but it's there.

$mob->HasNPCSpecialAtk("<flags>")

Akkadius 10-29-2013 06:07 PM

Natedog, this is a bad idea

NatedogEZ 10-29-2013 06:14 PM

Second part a bad idea? May I ask why? :p


(just this part.. I want to know if they have special abilities before I start messing with them in perl)

Code:

void NPC::mod_prespawn(Spawn2 *sp)
{
        for( int i = 1; i < 36; i++ )
        {
                if(GetSpecialAbility(i))
                {
                        const char* HasAbility = "1";
                        const char* Stuff = "HasSpecial";
                        SetEntityVariable(Stuff, HasAbility);
                        break;
                }
        }
}


Akkadius 10-30-2013 01:15 AM

I was being a smart ass by not offering any help or suggestion.

If I were to get special attacks in the zone I would do it via DBI this way.

It really doesn't make a whole lot of sense to try and push entity variables into memory when you can do it simply via another means.

Query the zone NPC types data and push it into a 3D hash that you can quickly reference.

Assuming you have some sort of controller NPC that is handling scaling you can do something like:

Code:

sub LoadMysql{       
        use DBI;
        use DBD::mysql;
        # CONFIG VARIABLES
        my $confile = "eqemu_config.xml"; #default
        open(F, "<$confile") or die "Unable to open config: $confile\n";
        my $indb = 0;

        while(<F>) {
                s/\r//g;
                if(/<database>/i) { $indb = 1; }
                next unless($indb == 1);
                if(/<\/database>/i) { $indb = 0; last; }
                if(/<host>(.*)<\/host>/i) { $host = $1; }
                elsif(/<username>(.*)<\/username>/i) { $user = $1; }
                elsif(/<password>(.*)<\/password>/i) { $pass = $1; }
                elsif(/<db>(.*)<\/db>/i) { $db = $1; }
        }
        # DATA SOURCE NAME
        $dsn = "dbi:mysql:$db:localhost:3306";
        # PERL DBI CONNECT
        $connect = DBI->connect($dsn, $user, $pass);
}


sub LoadStaticZoneScaling{
        ### Load Static Zone Scaling Data ###
        $connect = plugin::LoadMysql();
        $query = "SELECT
                spawnentry.npcID,
                npc_types.npcspecialattks,
                npc_types.name,
                spawn2.zone,
                spawn2.`version`,
                spawn2.respawntime,
                spawn2.spawngroupID
                FROM
                spawnentry
                Inner Join spawn2 ON spawnentry.spawngroupID = spawn2.spawngroupID
                Inner Join npc_types ON spawnentry.npcID = npc_types.id
                where spawn2.zone = '" . $zonesn . "' and spawnentry.npcID > 0 and spawn2.version = " . $instanceversion . "
                GROUP by npc_types.name";
        $query_handle = $connect->prepare($query); $query_handle->execute();
        ### Let's put the cache data into memory...
        while (@row = $query_handle->fetchrow_array()){  $ScalingData[$row[0]] = [@row];  }
}

Then, when you spawn or want to do a sanity check to make sure that $ScalingData has actually been loaded, you can do a bool after the while so that if you've already done the query, you don't need to hit the DB with another inner join - this will stay persistent through a zones lifespan. This is similar to how I perform scaling but I involve several tables of data.

When you want to reference it in script you can then set entity variables during the load, after the load or however.

For example, let's say I already did sub LoadStaticZoneScaling in my EVENT_SPAWN

I can do:

Code:

my @NLIST = $entity_list->GetNPCList();
foreach my $NPC (@NLIST){
        $NPC->SetEntityVariable("SpecialAttacks", $ScalingData[$NPC->GetNPCTypeID()][1]);
}

This would set all entities in the zone with their special attacks.

With this you run into the issue of NPC's spawning and needing that data again. You will need to do something in global_npc.pl to trigger a fetch for the data again - you can toss it around a few different ways.

Hopefully that helps and gives you an idea - that will help you prevent overwriting an NPC's special attacks if they have them already.

NatedogEZ 10-30-2013 01:35 AM

Ah thanks Akkadius that actually seems like a better idea :)

Akkadius 10-30-2013 01:41 AM

Quote:

Originally Posted by NatedogEZ (Post 225443)
Ah thanks Akkadius that actually seems like a better idea :)

I do believe you got the idea but I edited my script after I looked at it quick I noticed I wasn't executing the script:

$query_handle = $connect->prepare($query); $query_handle->execute();

Otherwise most of it should be fairly accurate.

Hopefully it helps


All times are GMT -4. The time now is 11:00 PM.

Powered by vBulletin®, Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.