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)

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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.




×
×
  • Create New...