PDA

View Full Version : Simulated AE Rampage code.


Kayen
04-11-2009, 02:40 PM
This code can be applied to any mob to simulate an AE Rampage effect that will look like like real rampage to the players. AE Rampage hits any melee's with "Rampage" within a certain radius of the mob. This code will work stand alone but can be modified to whatever you wish.

This works under sub EVENT_TIMER

How I set it up.

When mob is attacked, timer begins to set off the rampage code. Stores the mobs name, stores its max damage, then calculates what that damage would be with max shielding(can adjust this), then stores what half the max damage would be, and sets this as the min. rampage damage. Finally it finds the difference between the max and the min. More detailed bellow.

if ($timer eq "getclientsRAMPAGE") {
$cmname = $npc->GetCleanName(); #Defines the mobs name
my $MaxDam = $npc->GetMaxDMG(); #Gets the mobs max damage
my $ShieldMaxDam = ($MaxDam * .65); #Adjust this to take account of whatever % of shielding you desire. On our server most melee are maxed so I set to 35% by default.
my $ShieldMinDam = $ShieldMaxDam / 2; #Half of max shield will be the min that can rampage can hit for
my $DamageVar = ($ShieldMaxDam - $ShieldMinDam); #Finds the difference between max and min to be used to calc. the actual rampage value.
$entity_list->MessageClose($npc, 1, 200, 13, "$cmname goes on a RAMPAGE"); #Displays exactly like a regular rampage message displays


Next we search the entity list for all clients in the zone, and it will run this loop for every client in zone. It will check the clients distance from the mob, if the distance is < then the defined value (here I choose 31), AND the player is not the mobs target they will get hit with rampage damage. Rampage damage is a random number between the max and min hit defined above. Therefore each player that is in the radius will get hit with a random amount of damage in the set range, and receive you have been rampaged message for that amount of damage.

my $list_check = 0;

for ($list_check = 0; $list_check < 2000; $list_check++) {

$client_search = $entity_list->GetClientByID($list_check);
#Above searches for every client in zone

if ($client_search) {
my $distanceCHK = $client_search->CalculateDistance($x, $y, $z);
#Calculates distance between client and mob
my $PLTarget = $npc->GetTarget();
#Finds the NPC's targets ID
my $TargID = $PLTarget->GetID();
#Finds the ID of the NPC target
my $ClID = $client_search->GetID();
#Finds the clients ID
my $RampDamageVar = (int(rand($DamageVar ))) + $ShieldMinDam;
#Calculates Rampage Damage.

if (($distanceCHK <= 31) && ($TargID != $ClID)) {
#Makes sure distance is within range and player is not target
$client_search->Damage($npc, $RampDamageVar, 7477, 1, true, -1, false);
$client_search->Message(13, "$cmname hits YOU for $RampDamageVar points of damage" );
#Damages target and displays rampage message


So for example. If mobs max hit is 6000. This code would find a random number between 3000-6000 for each client in range and damage them with it.

Code:



sub EVENT_ATTACK {
quest::settimer(getclientsRAMPAGE, 8);
}

sub EVENT_TIMER {

#####################################
##########AE RAMPAGE##################
#####################################
if ($timer eq "getclientsRAMPAGE") {
$cmname = $npc->GetCleanName();
my $MaxDam = $npc->GetMaxDMG();
my $ShieldMaxDam = ($MaxDam * .65);
my $ShieldMinDam = $ShieldMaxDam / 2;
my $DamageVar = ($ShieldMaxDam - $ShieldMinDam);

$entity_list->MessageClose($npc, 1, 200, 13, "$cmname goes on a RAMPAGE");

my $list_check = 0;

for ($list_check = 0; $list_check < 2000; $list_check++) {

$client_search = $entity_list->GetClientByID($list_check);

if ($client_search) {
my $distanceCHK = $client_search->CalculateDistance($x, $y, $z);
my $PLTarget = $npc->GetTarget();
my $TargID = $PLTarget->GetID();
my $ClID = $client_search->GetID();
my $RampDamageVar = (int(rand($DamageVar ))) + (int($ShieldMinDam));

if (($distanceCHK <= 31) && ($TargID != $ClID)) {
$client_search->Damage($npc, $RampDamageVar, 7477, 1, true, -1, false);
$client_search->Message(13, "$cmname hits YOU for $RampDamageVar points of damage" );
}

}
}
}
}


Enjoy.

Kayen
GM Storm Haven

RichardoX
04-12-2009, 08:09 PM
Very cool stuff. :)

Dibalamin
04-14-2009, 03:37 PM
Thanks for the step by step explaination, that rocked!

One question though:

How would you mod this code to select a single random target(s) from the zone & then cast on them?

It's there, I'm just not good enough yet to see it.

Kayen
04-14-2009, 07:02 PM
It is actual not that simple.

Here is away to use this code to choose semi-random targets. It isn't truly random b/c the list always cycles in the same order so the players at top have a better chance of getting hit, however they will really never notice. It's not perfect but its functional.

The code basically searches the clients, and then for each client does a random 1-20(This can be changed to whatever you want, I'd recommend however many players are at the event). If the number is 18 the effect essentially goes off on that player and the cycle ends, if 20 is saves the players ID, then starts a 3 sec timer, then from that timer it casts a spell on that player. If you don't roll a 29, nothing happens. Here is the commented code.


if ($timer eq "getclients") {
my $Stop = 0; #This decides if the script is on or off

my $list_check = 0;

for ($list_check = 0; $list_check < 2000; $list_check++) {

$client_search = $entity_list->GetClientByID($list_check);

if ($client_search) {
my $distanceCHK = $client_search->CalculateDistance($x, $y, $z);
if ($distanceCHK <= 300) { #Checks all players w/in 300 range
my $ChooseClient = quest::ChooseRandom(1,2,3,4,5,6,7,8,9,10,11,12,13, 14,15,16,17,18,19,20);
if (($ChooseClient == 20) && ($Stop == 0) ) { #So 1/20 chance to get spell cast on them, the $Stop == 0, turns this off once a player is choosen
$RandomSpellID = $client_search->GetID(); #Saves the Player's ID who was choose so the spell can target them
quest::stoptimer("getclients"); #Stops the loop, otherwise it cycles again till a client is selected
#$client_search->Message(13, "You were choosen at random $RandomSpellID" ); #Sends message to client they were selected
quest::settimer("CastRandomWither", 3); #Sets timer for spell cast
my $Stop = 1;
}
if ($ChooseClient <= 17) {
#$client_search->Message(13, "You were NOT choosen at random $ChooseClient" ); #Client is not choose (You don't need even really need this)
}
}

}
}
}

if ($timer eq "CastRandomWither") {
quest::stoptimer("CastRandomWither");
$npc->CastSpell(5120, $RandomSpellID); #Cast spell 5120, on client who was choose.
}

}



sub EVENT_TIMER {


#####################################
##########Random Cast##################
#####################################
if ($timer eq "getclients") {
my $Stop = 0;

my $list_check = 0;

for ($list_check = 0; $list_check < 2000; $list_check++) {

$client_search = $entity_list->GetClientByID($list_check);

if ($client_search) {
my $distanceCHK = $client_search->CalculateDistance($x, $y, $z);
if ($distanceCHK <= 300) {
my $ChooseClient = quest::ChooseRandom(1,2,3,4,5,6,7,8,9,10,11,12,13, 14,15,16,17,18);
if (($ChooseClient == 18) && ($Stop == 0) ) {
$RandomSpellID = $client_search->GetID();
quest::stoptimer("getclients");
#$client_search->Message(13, "You were choosen at random $RandomSpellID" );
quest::settimer("CastRandomWither", 3);
my $Stop = 1;
}
if ($ChooseClient <= 17) {
#$client_search->Message(13, "You were NOT choosen at random $ChooseClient" );
}
}

}
}
}

if ($timer eq "CastRandomWither") {
quest::stoptimer("CastRandomWither");
$npc->CastSpell(5120, $RandomSpellID);
}

}

Dibalamin
04-14-2009, 09:11 PM
Perfect, thanks for the code man & for taking the time to respond!

KingMort
04-29-2009, 09:37 PM
Been playing with this a bit on my server.. Can't seem to get the mob to do any actual Damage with the rampage...

I'm not that great with Perl.. Can you look this thing over and fix it for us ? Would rock !! NICE work btw on this... Have always wanted to have mobs AE Ramp..

King

covou
05-01-2009, 07:01 AM
Just thought i would point out for those using this coode that it is missing a paranthesis (sp?)...

sub EVENT_TIMER

#####################################
##########AE RAMPAGE##################
#####################################
if ($timer eq "getclientsRAMPAGE") {

should be

sub EVENT_TIMER {

#####################################
##########AE RAMPAGE##################
#####################################
if ($timer eq "getclientsRAMPAGE") {

trevius
05-01-2009, 07:30 AM
Thanks for pointing that out. I made the correction in the original post.

Kayen
05-01-2009, 02:35 PM
Maybe the syntax error was the problem Mort.

Let me know if your still having trouble.

I know it works, have it in place on SH a various mobs.

KingMort
05-01-2009, 07:23 PM
Well can see the Message that it's rampaging but no one gets any damage .. I was invul tanking but those around were taking no damage at all...

Kayen
05-01-2009, 11:10 PM
Mort,

Are you using a very large mob? The larger the mob the larger you need to make the rampage distance. Post the code your using I'll take a look, unless its exactly the same.

Here is a direct copy and paste of just a trash mob I have using it. Feel free to just use that and let me know.

sub EVENT_COMBAT {

if ($combat_state == 1) {
quest::settimer("Rampage", 8);
}

if ($combat_state == 0) {
$npc->WipeHateList();
quest::stoptimer("Rampage");
quest::stoptimer("getclients");
#$npc->SetHP($npc->GetMaxHP() * 1);
}
}

sub EVENT_TIMER {
if ($timer eq "Rampage") {
quest::stoptimer("Rampage");
my $TimeRA = quest::ChooseRandom(8);
quest::settimer("getclientsRAMPAGE", $TimeRA);
}

####################################
##########AE RAMPAGE##################
#####################################
if ($timer eq "getclientsRAMPAGE") {
$cmname = $npc->GetCleanName();
my $MaxDam = $npc->GetMaxDMG();
my $ShieldMaxDam = ($MaxDam * .65);
my $ShieldMinDam = $ShieldMaxDam / 2;
my $DamageVar = ($ShieldMaxDam - $ShieldMinDam);

$entity_list->MessageClose($npc, 1, 200, 13, "$cmname goes on a RAMPAGE");

my $list_check = 0;

for ($list_check = 0; $list_check < 2000; $list_check++) {

$client_search = $entity_list->GetClientByID($list_check);

if ($client_search) {
my $distanceCHK = $client_search->CalculateDistance($x, $y, $z);
my $PLTarget = $npc->GetTarget();
my $TargID = $PLTarget->GetID();
my $ClID = $client_search->GetID();
my $RampDamageVar = (int(rand($DamageVar ))) + $ShieldMinDam;

if (($distanceCHK <= 31) && ($TargID != $ClID)) {
$client_search->Damage($npc, $RampDamageVar, 7477, 1, true, -1, false);
$client_search->Message(13, "$cmname hits YOU for $RampDamageVar points of damage" );
}

}
}
}
################################################## ##########
################################################## ##########
################################################## ##########
}

KingMort
05-02-2009, 04:53 PM
Alright well it is working but when it hits the player looks like this

NPC hits you for 21018.95 points damage

I imagine thats 21,018.95 damage but it sure does look weird.. any way to lose the damage after the decimal so it's just 21,019 (maybe rounding it up or something)

King

Kayen
05-03-2009, 01:20 AM
Yeah, good catch actually here is what you need to change

old
my $RampDamageVar = (int(rand($DamageVar ))) + $ShieldMinDam;

New
my $RampDamageVar = (int(rand($DamageVar ))) + (int($ShieldMinDam));

Using int will remove decimals.

I'll apply this to my code too, I didn't catch it when I was testing cause prob was using easily divisable numbers

trevius
05-04-2009, 07:05 AM
I edited those changes into the code in the first post so people using this will get the finished code without having to do any edits.

KingMort
05-04-2009, 09:39 AM
Thanks again !

trevius
05-04-2009, 05:19 PM
Thanks to KLS, this script should now be obsolete:

http://code.google.com/p/projecteqemu/source/browse/trunk/EQEmuServer/changelog.txt?spec=svn465&r=465

:)

KLS
05-05-2009, 12:15 AM
Inspired by this thread btw, in case anyone was wondering.

trevius
05-05-2009, 03:39 AM
With the frequency that we use that client search quest code, I think it would make a good addition to the source if we could figure out the best way to handle it in the code for quests. I was thinking of making a new sub event similar to timers, and you would call it in a similar way. Then, it would just do a for loop on anything matching that client search name.


sub EVENT_SPAWN {
quest::clientsearch("nearby");
}

sub EVENT_CLIENT_SEARCH {

if ($clientsearch eq "nearby");
// Do some distance checks and do something else to them
}

}

Something like that.

Or, maybe just add a way to easily make a list of all clients or all NPCs in a zone. Maybe something that would look through the entity list and make a new list of whatever you are looking for. I think that would cut down the overhead of doing a FOR loop to 2000 every time. Then, it would also be nice to have a way to pull the top entity ID from the zone so instead of setting it to 2000, it could be set to whatever the actual top ID number is.

Getting a bit off topic here though. Thinking about making a new post in the features requests about it. It would be very useful if we could come up with a way to handle this easily. There are just too many uses for being able to find any client in a zone at random, or by distance, or whatever you specify. I just don't know the best way to handle it yet to start coding it.

KingMort
05-05-2009, 01:24 PM
Not trying to Hijack but KLS while your on that subject could you also add functions in NPCSPECIALATTK so that mobs can be Un-Lullable, and Un-Pacifyable please ??

Thanks in advance

King
www.raidaddicts.org

KLS
05-05-2009, 09:09 PM
I can but might wanna post it in features requests incase I forget.