EQEmulator Forums

EQEmulator Forums (https://www.eqemulator.org/forums/index.php)
-   Quests::Custom (https://www.eqemulator.org/forums/forumdisplay.php?f=671)
-   -   Script Check (https://www.eqemulator.org/forums/showthread.php?t=44138)

ccyre3 08-02-2024 10:34 PM

Script Check
 
This script works as its supposed to, but i get line 7 errors about setnexthpevent. Yes, I'm new, and yes, i used gpt to help me haha. anyway, any ideas why the error?

Code:

sub EVENT_SPAWN {
    # Variables to set hp and get flag to set hp
    my $hp_key = $npc->GetNPCTypeID() . "-60-hp";
   
    # Check if the 60% key exists; if it doesn't, set it to 60% hp event
    if (quest::get_data($hp_key) == 1) {
        quest::setnexthpevent(30);
        # Adjust HP if spawned with reduced health
        my $new_hp = $npc->GetMaxHP() * 0.60;
        $npc->SetHP($new_hp);
    } else {
        quest::setnexthpevent(60);
    }
}

sub EVENT_HP {
    # First HP check at 60%
    if ($hpevent == 60) {
        my $hp_key = $npc->GetNPCTypeID() . "-60-hp";
        quest::set_data($hp_key, 1);

        # Get current HP percentage
        my $current_hp = $npc->GetHP();
        my $max_hp = $npc->GetMaxHP();
        my $hp_percentage = $current_hp / $max_hp;

        # Depop current NPC and spawn at new location with the same HP percentage
        quest::depop();
        my $x = 239.61;
        my $y = -9.02;
        my $z = -5.50;
        my $h = 492.75;
        my $boss_id = 1228;
        my $new_npc = quest::spawn2($boss_id, 0, 0, $x, $y, $z, $h);
        my $new_npc_entity = $entity_list->GetNPCByID($new_npc);
        if ($new_npc_entity) {
            my $new_hp = $new_npc_entity->GetMaxHP() * $hp_percentage;
            $new_npc_entity->SetHP($new_hp);
            $new_npc_entity->SetNextHPEvent(30); # Ensure the new NPC continues the HP event
        }
    }
    # Second HP check at 30%
    elsif ($hpevent == 30) {
        # Make the NPC immune to all attacks for 10 seconds
        $npc->SetInvul(1);  # Make NPC invulnerable

        # Schedule an event to remove invulnerability after 10 seconds
        quest::settimer("remove_invul", 10);
    }
}

sub EVENT_TIMER {
    if ($timer eq "remove_invul") {
        quest::stoptimer("remove_invul");
        $npc->SetInvul(0);  # Remove invulnerability
    }
}

sub EVENT_DEATH_COMPLETE {
    # Deletes the key on death
    my $hp_key = $npc->GetNPCTypeID() . "-60-hp";
    quest::delete_data($hp_key);
    quest::signalwith(77027, 2, 2); # Notify NPC with ID 77027 with a 2-second delay when NPC 1228 dies
   
    # Shout message on death
    quest::shout("In the end... yyyXXxxxyronnnn iwwwiiiilll rrooDeSStttrrooYyYy YuooYouuu");
}


joligario 08-03-2024 04:46 AM

Not seeing any issues with that call, but you should check that the key exists before checking its value


All times are GMT -4. The time now is 01:50 PM.

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