View Single Post
  #4  
Old 04-14-2009, 07:02 PM
Kayen
Developer
 
Join Date: Mar 2009
Location: -
Posts: 228
Default Choosing a random player and casting on them.

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.


Quote:
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.
}

}


Code:
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);
}

}

Last edited by trevius; 05-01-2009 at 03:29 PM..
Reply With Quote