Jump to content

Question

Posted

hi,

I have this code and try to verify the time has passed when case occurred

Example in l2pcinstance:
 

private int assasins = 0;

switch(assasins) {
  case 2:
    Announcements.getInstance().announceToAll("Player " + pk.getName() + " has killed two times" + pk.getTarget().getName());
    break;
  case 3:
    Announcements.getInstance().announceToAll("Player " + pk.getName() + " has killed three times" + pk.getTarget().getName());
  default:
}

 

i need verify if the next kill (case 3) ocurred  < 10 seconds. if the time passed make a different announcements..

 

i think how see the code with my idea...

private int assasins = 0;
switch(assasins) {
  case 2:
    	Announcements.getInstance().announceToAll("Player " + pk.getName() + " has killed two times" + pk.getTarget().getName());
		ThreadPoolManager.getInstance().schedule(assasins = 3 , 10 * 1000);
    break;
  case 3:
    Announcements.getInstance().announceToAll("Player " + pk.getName() + " has killed" + pk.getTarget().getName());
		ThreadPoolManager.getInstance().schedule(assasins = 4 , 10 * 1000);
    break;
  default:
}

 

sorry my bad english :3

Recommended Posts

  • 0
Posted (edited)

No no no. You have to create a new long variable, set the time using system current time + 10sec on kill, then on the switch compare the time if your variable > current time. 

Edited by SweeTs
  • Upvote 1
  • 0
Posted

thanks sweets i try this..

private int assasins = 0;
switch(assasins) {
	case 1:
	//Here obtain time when case 1 ocurred
	long firstkill = System.currentTimeMillis();
  case 2:
    	long checktime = System.currentTimeMillis() - firstkill;
		if(checktime < 10000) {
			Announcements.getInstance().announceToAll("Player " + pk.getName() + " has killed two times" + pk.getTarget().getName()); 
			} else {
				Announcements.getInstance().announceToAll("Player " + pk.getName() + " has killed" + pk.getTarget().getName());
		}
    break;
  case 3:
   .........
    break;
  default:
}

but i get an error, in case 2 "The local variable firstkill may not have been initialized"

How to fix this? i try the fix but not obtain solution hahaha thanks!

  • 0
Posted (edited)

Put the long out of the method. Like the assassins, under it. 

Edited by SweeTs
  • 0
Posted (edited)

i tested and not work.. every kill obtain first case only, never update or increment the variable "assasins", i try implement this code in fandc files like mobius.. anye help me?

 

private int assasins = 0;

protected void doPKPVPManage(Creature....
                             
                             long firstkill = System.currentTimeMillis() + 10 * 1000;
                             switch(assasins) {
                               case 1:
                               Announcements.getInstance().announceToAll("Test First Kill VAR:" + assasins);
                               break;
                               case 2:
                               if(System.currentTimeMillis() - firstkill > 10000) {
                                 Announcements.getInstance().announceToAll("Player " + pk.getName() + " has killed" + pk.getTarget().getName());
                               } else { 
                                 Announcements.getInstance().announceToAll("Player " + pk.getName() + " has killed two times in a row!" + pk.getTarget().getName()); 
                               }
                               break;
                               case 3:
                               if(System.currentTimeMillis() - firstkill > 20000) {
                                 Announcements.getInstance().announceToAll("Player " + pk.getName() + " has killed" + pk.getTarget().getName()); 
                               } else { 
                                 Announcements.getInstance().announceToAll("Player " + pk.getName() + " has killed three times in a row!" + pk.getTarget().getName()); 
                               }
                               break;
                               case 4: 
                               ...... 
                               break; 
                               default: 
                             }

 

Out Put only first case

Edited by StarSCreams
add
  • 0
Posted (edited)

this is happening because the variable firstkill is inside the kill method. Put it after assasins... 

generally follow this :

private long firstkill = 0L;

 

the firstkill variable must be used after the end of the switch.

switch(something)
{
	case 1:
		...
	brake;
	case 2:
		...
	break;
}

firstkill = System.currentTimeMillis() + (10*1000); //or instantly 10000 

the only thing you have to do is to check the the current time - firstkill  is > 10000 then 10 seconds  are passed

p.s Edited 

example in case 1:

 

switch(assasins)
{
  case 1:
    if (System.currentTimeMillis() - firstkill > 10000)
        10 seconds passed
    else
        not passed yet
  	break;
  cases X...
 	 ....
 	 ....
}

firstkill = System.currentTimeMillis() + (10 * 1000);

 

Edited by melron
  • 0
Posted (edited)

hey melron, thanks for you reply, you fix one of my problems (How to check if 10 seconds passed), but my other problem not fix..

 

i make the clean code to check it work, but never increment the variable..

Example:

private int assasins = 0;

protected void doPKPVPManage(Creature....

			.....
			//Line: @@ -4286,6 +4319,37 @@

			//Here my code check if pvpkill and update +1 kills to db
				pk.setPvpKills(pk.getPvpKills() + 1);
				
				assasins++;
				
				switch(assasins) {
					case 1:
						Announcements.getInstance().announceToAll("FIRST KILL VARIABLE: " + assasins);
					break;
					case 2:
						Announcements.getInstance().announceToAll("SECOND KILL VARIABLE: " + assasins);
					break;
					case 3:
						Announcements.getInstance().announceToAll("THIRD KILL VARIABLE: " + assasins);
					break;
					case 4:
						Announcements.getInstance().announceToAll("FOUR KILL VARIABLE: " + assasins);
					break;
					default:
							Announcements.getInstance().announceToAll("DEFAULT KILL++ VARIABLE: " + assasins);
					break;
				}

 

Ingame, i made more than 10 kills only show FIRST ANNOUNCEMENT u.u

 

Thanks for help me!

Edited by StarSCreams
  • 0
Posted (edited)

be sure that your variable assasins is a global variable. the code you posted seems running fine without problems

Edited by melron
  • 0
Posted (edited)
12 minutes ago, melron said:

be sure that your variable assasins is a global variable. the code you posted seems running fine without problems

how to check if my variable is global? i add to my variable static to make a global..

public static int assasins = 0;

 

but obtain same result, only show first kill

Edited by StarSCreams
  • 0
Posted (edited)

no you dont need it as static you need it instanceid ... just put the variable out of any method. if you still have problems add me in skype

Edited by melron
  • 0
Posted (edited)
25 minutes ago, melron said:

no you dont need it as static you need it instanceied ... just put the variable out of any method. if you still have problems add me in skype

thanks for you support, i found the problem.. i have put ondie character class:  assasins = 0;

but set 0 when any character dies not the killer for stop kills in a row.. i try find the fix now hahaha thanks!!!

Edited by StarSCreams
  • 0
Posted

hi, i try to fix my last problem but i can't...

 

i add assasins = 0; in protected void onDeath(Creature killer) .... to stop killingspree

and not increment assasins++; in protected void doPKPVPManage(Creature killer)

how to check if killer is dead? or how to fix? i upload my Player.java in paste bin if any can help me, search: //killingspree to see if my code is correct..

https://pastebin.com/hGXgnsUV

 

Thanks all!

  • 0
Posted

From the beginning, what's your whole idea? If time < 10s from previous kill send other message than default? Counting from first kill, or 2nd - > 3rd send other message as well? 

  • 0
Posted
7 hours ago, SweeTs said:

From the beginning, what's your whole idea? If time < 10s from previous kill send other message than default? Counting from first kill, or 2nd - > 3rd send other message as well? 

the messages and kills works, but when i add assassins = 0; in... protected void onDeath(Creature killer)..., don't work anymore. i add that to stop killing spree
to create this I followed this example: http://www.maxcheaters.com/topic/107756-sharefreya-killing-spree/

 

I hope you understand me i am from argentine and i do not know how to express myself very well in english u.u

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



  • Posts

    • 冬天是享受优惠、省钱的好时机。 首次下单时使用促销码 SOCNET 即可获得 15% 折扣 ,适用于全场商品! 前往商店(网站) 前往商店(Telegram 机器人)
    • Winter is the time to save with benefits. Activate the promo code SOCNET on your first order and get a 15% discount on the entire assortment! Go to the store (website) Go to the store (Telegram bot)
    • Winter is the time to save with benefits. Activate the promo code SOCNET on your first order and get a 15% discount on the entire assortment! Go to the store (website) Go to the store (Telegram bot)
    • L2 Kings    Stage 1 – The Awakening Dynasty and Moirai Level Cap: 83 Gear: Dynasty -Moirai & Weapons (Shop for Adena + Drop from mobs/instances ) Masterwork System: Available (Neolithics S required with neolithics u can do armor parts foundation aswell) Class Cloaks: Level 1 - Masterwork sets such us moirai/dynasty stats are boosted also vesper(stage 2) Olf T-Shirt: +6 (fails don’t reset) safe is +2 Dolls: Level 1 Belts: Low & Medium Enchant: Safe +3 / Max +8 / Attribution Easy in Moirai-Dynasty . Main Zones: Varka Outpost: Easy farm, Adena, EXP for new players = > 80- 100kk hour Dragon Valley: Main farm zone — , 100–120kk/hour Weapon Weakness System active (all classes can farm efficiently) Archers get vampiric auto-hits vs mobs Dragon Valley Center: Main Party Zone — boosted drops (Blessed enchants, Neolithics chance) => farm like 150-200kk per hour. Dragon Valley North: Spoil Zone (Asofe + crafting materials for MW) Primeval Isle: Safe autofarm zone (low adena for casual players) ==> 50kk per hour Forge of the Gods & Imperial Tomb: Available from Stage 1 (lower Adena reward in compare with Dragon Valley) Hellbound also avaliable from stage 1 In few words all zones opened but MAIN farm zone with boosted adena and drops is Dragon valley also has more mobs Instances: Zaken (24h Reuse) → Instead of Vespers drop Moirai , 100% chance to drop 1 of 9 dolls lvl 1, Zaken 7-Day Jewelry Raid Bosses (7 RBs): Drop Moirai Parts + Neolithic S grade instead of Vespers parts that has 7 Rb Quest give Icarus Weapons Special Feature 7rb bosses level up soul crystals aswell. Closed Areas : Monaster of SIlence, LOA, ( It wont have mobs) / Mahum Quest/Lizardmen off) Grand Epics: Unlocked on Day 4 of Stage 1 → Antharas, Valakas, Baium, AQ, etc ================================================================================= Stage 2 – Rise of Vespers Level Cap: 85 Gear: Moirai Armors (Adena GM SHOP / Craft/ Drop) Weapons: Icarus Cloaks: Level 2 Olf: +8 Dolls: Level 2 Belts: High & Top Enchant: Safe +3 / Max +8 Masterwork can be with Neolithics S84 aswell but higher so craft will be usefull aswell. 7 Raid Boss Quest Updated: Now works retail give vesper weapons 7rb Bosses Drops : Vespers Instances: Zaken : Drops to retail vespers + the dolls and the extra items that we added on stage 1 New Freya Instance: Added — drops vespers and instead of mid s84 weapons will drop vespers . Extra drops Blessed Bottle of Freya - drops 100% chance 1 of 9 dolls. Farm Areas Dragon Valley remains main farm New Zone : Lair of Antharas (mobs nerfed and added drop Noble stone so solo players can farm too) New Party Zone : LOA Circle   ============================================================================   Stage 3 – The Vorpal ERA Gear: Vorpal Unclock Cloaks: Level 3 Olf: +10 (max cap) Dolls: Level 3 Enchant: Safe +3 / Max +12 Farm Zones : Dragon Valley Center Scorpions becomes a normal solo zone (no longer party zone) Drops:   LOA & Knorik → Mid Weapons avaliable in drop New Party Zone Kariks Instances: Easy Freya Drops Mid Weapons Frintezza Release =================================================================================     Stage 4 – Elegia Era (Final Stage) Elegia Unlock Gear: Elegia Weapons: Elegia TOP s84 ( farmed via H-Freya/ Drops ) Cloaks: Level 5 Dolls: Level 3 (final bonuses) Enchant: Safe +6 / Max +16 Instances: Hard Freya → Drops Elegia Weapons + => The Instance will drop 2-3 parts for sure and also will be able to Join with 7 people . Party Zone will have also drop chances for elegia armor parts and weapons but small   Events (Hourly): Win: 50 Event Medals + 3 GCM + morewards Lose: 25 Medals + 1 GCM + more rewards Tie: 30 Medals + 2 GCM + more rewards   ================================================================================ Epic Fragments Currency Participating in Daily Bosses mass rewarding all players Participating in Instances (zaken freya frintezza etc) all players get reward ================================================================================ Adena - Main server currency (all items in gm shop require adena ) Event Medals (Festival Adena) - Event shop currency Donation coins you can buy with them dressme,cosmetics and premium account Epic Fragments you can buy with them fake epic jewels Olympiad Tokens you can buy many items from olympiad shop (Hero Coin even items that are on next stages) Olympiad Win = 1000 Tokens / Lose = 500 Tokens ================================================================================= Offline Autofarm Allows limited Offline farming requires offline autofarm ticket that you get by voting etc ================================================================================= Grand Epics have Specific Custom NPC that can spawn Epics EU/LATIN TIME ZONE ================================================================================= First Olympiad Day 19 December First Heroes 22 December ( 21 December Last day of 1st Period) After that olympiad will be weekly. ================================================================================= Item price and economy Since adena is main coin of server and NOT donation coins we will always add new items in gm shop with adena in order to burn the adena of server and not be inflation . =================================================================================        
  • Topics

×
×
  • Create New...

AdBlock Extension Detected!

Our website is made possible by displaying online advertisements to our members.

Please disable AdBlock browser extension first, to be able to use our community.

I've Disabled AdBlock