Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   Code Gallery (https://forums.graalonline.com/forums/forumdisplay.php?f=179)
-   -   Boomerang (https://forums.graalonline.com/forums/showthread.php?t=134260135)

fowlplay4 08-09-2010 10:33 PM

Boomerang
 
1 Attachment(s)
This is the boomerang script, I made for Classic iPhone a month or two ago. Basic collision detection for hitting players is in the script, but will require modification for things like throwing it diagonally initially.

PHP Code:

//#CLIENTSIDE

function onWeaponFired() {
  
// Check if boomerang is out
  
if (this.active) return;
  
// Player animation
  
setani("grab""");
  
freezeplayer(0.1);
  
// Throw boomerang
  
beginBoomerang();
}

function 
beginBoomerang() {
  
// Initialize Boomerang
  
this.boomerang_x player.vecx(player.dir);
  
this.boomerang_y player.1.5 vecy(player.dir);
  
this.boomerang_dir player.dir;
  
this.boomerang_ang 0;
  
// Activate
  
this.active true;
  
// Draw boomerang
  
drawBoomerang();
  
// Loop
  
setTimer(0.05);
}

function 
onTimeout() {
  
// Check if deactivating
  
if (!this.active) {
    
hideBoomerang();
    return;
  }
  
// Move boomerang
  
if (this.boomerang_ang < (pi 2)) {
    
this.boomerang_x += vecx(this.boomerang_dir) * cos(this.boomerang_ang) * 2;
    
this.boomerang_y += vecy(this.boomerang_dir) * cos(this.boomerang_ang) * 2;
    
this.boomerang_ang += (pi 16);
  } else {
    
temp.newangle getangle(this.boomerang_x player.1.5this.boomerang_y player.1.5);
    
this.boomerang_x += cos(temp.newangle) * cos(this.boomerang_ang) * 1.5;
    
this.boomerang_y -= sin(temp.newangle) * cos(this.boomerang_ang) * 1.5;
    if (
this.boomerang_ang pi) {
      
this.boomerang_ang += (pi 16);
    }
    if (
this.boomerang_x in |player.xplayer.3| && this.boomerang_y in |player.yplayer.3|) {
      
this.active false;
    }
  }
  
// Draw boomerang
  
updateBoomerang();
  
// Hit Objects
  
temp.plyr testplayer(this.boomerang_x 0.5this.boomerang_y 0.5);
  if (
temp.plyr 0) {
    if (
this.lasthit == 0) {
      
this.lasthit 5;
      
// Hit Player
      
temp.obj players[temp.plyr];
    } else {
      
this.lasthit--;
    }
  }
  
// Loop
  
setTimer(0.05);
}

function 
drawBoomerang() {
  
with (findimg(1)) {  
    
thiso.boomerang_x;
    
thiso.boomerang_y;
    
ani "classic_boomerang";
    
layer 1;
  }
}

function 
hideBoomerang() {
  
hideimg(1);
}

function 
updateBoomerang() {
  
with (findimg(1)) {  
    
thiso.boomerang_x;
    
thiso.boomerang_y;
  }


Included the gani that it uses as well, it uses the default sprites.

12171217 08-09-2010 10:46 PM

Isn't it generally undesirable to use "global" showimgs, those with an index below 200, as they only seem to be updated every other frame (From what I saw the other day) and there's more efficient ways to do it (In terms of network usage) that also have the advantage of letting you control it on each individual client, allowing you to interpolate or extrapolate it in order to smooth it?

fowlplay4 08-11-2010 02:00 AM

Quote:

Originally Posted by 12171217 (Post 1592465)
Isn't it generally undesirable to use "global" showimgs, those with an index below 200, as they only seem to be updated every other frame (From what I saw the other day) and there's more efficient ways to do it (In terms of network usage) that also have the advantage of letting you control it on each individual client, allowing you to interpolate or extrapolate it in order to smooth it?

I've never had complaints about using the global indexes with animations before, and the 'efficiency' gains don't really seem worth it to me.

Feel free to script your version and post it.

napo_p2p 08-11-2010 02:16 AM

Quote:

Originally Posted by fowlplay4 (Post 1592714)
I've never had complaints about using the global indexes with animations before, and the 'efficiency' gains don't really seem worth it to me.

Feel free to script your version and post it.

Same here. Most of the time it is "good enough". Plus, clientside interpolation could potentially go out of control if you have 100 people using boomerangs like mad (especially if on an iPhone).

Crow 08-11-2010 09:32 AM

Quote:

Originally Posted by napo_p2p (Post 1592717)
(especially if on an iPhone)

Don't worry about that. The iPhone client seems to run better than the PC one :\

LordOfPi13 09-14-2010 02:28 AM

Quote:

Originally Posted by napo_p2p (Post 1592717)
Same here. Most of the time it is "good enough". Plus, clientside interpolation could potentially go out of control if you have 100 people using boomerangs like mad (especially if on an iPhone).

Some people still have the first generation iPod Touch... sooooooooooo....

sssssssssss 09-14-2010 10:58 PM

Cool. First post for a gs2 boomerang I've ever seen. :x GJ.

irock1 09-15-2011 01:19 PM

Setlevel2 dosent work on it to warp players

iBeatz 09-15-2011 05:30 PM

Quote:

Originally Posted by irock1 (Post 1668200)
Setlevel2 dosent work on it to warp players

You probably have used setLevel2 clientside. setLevel2 only works serverside. To use setLevel2 in a weapon such as this, I'd recommend using the triggerServer function to send the player object to the server, and then setting that player's level there.

Ie.
Clientside:
PHP Code:

triggerServer("gui"name"SetLevel"player object here); 

Serverside:
PHP Code:

function onActionServerSide() {
  if(
params[0] == "SetLevel"){
    
// your setlevel stuff here
  
}



cbk1994 09-15-2011 09:50 PM

Quote:

Originally Posted by iBeatz (Post 1668226)
Clientside:
PHP Code:

triggerServer("gui"name"SetLevel"player object here); 


There's never any reason to send the player's account in a trigger.

irock1 09-30-2011 10:47 AM

No, I want to make it warp players on touch..

Gunderak 10-07-2011 01:50 PM

post your problems in npc scripting, not on threads.
also BUMP!


All times are GMT +2. The time now is 01:28 AM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.