Jump to content

Photo

A projectile destroying weapon

lweapon

  • Please log in to reply
3 replies to this topic

#1 SparksTheUnicorn

SparksTheUnicorn

    Lonk, Hero of Lime

  • Members

Posted 10 June 2020 - 09:21 PM

Basically what I am looking for is an lweapon script that makes it so that when the items projectile hits an enemy projectile (like fire trails, rocks, arrows, wind, magic and so on), it will completely destroy that projectile. Thanks :)



#2 Mani Kanina

Mani Kanina

    Rabbits!

  • Members

Posted 11 June 2020 - 12:04 AM

just cycle through all the screen's eweapons and compare their position with your lweapon to see if they collide, and if they do, remove them. It's not super complicated, see Screen->NumEWeapons() and Screen->LoadEWeapon(int num)
 
lweapon TargetLWeapon;
eweapon TargetEWeapon;

for(int i = 0; i <= Screen->NumEWeapons(); i++){

TargetEWeapon = Screen->LoadEWeapon(i);

if(TargetEWeapon->X == TargetLWeapon->X && TargetEWeapon->Y == TargetLWeapon->Y){
TargetEWeapon->X = -64;
TargetEWeapon->Y = -64;
}
}
Some shitty example code, the collision detection here is pixel perfect because I'm too lazy, but you should get the point.

Edited by Mani Kanina, 11 June 2020 - 12:11 AM.

  • Anthus and SparksTheUnicorn like this

#3 Emily

Emily

    Scripter / Dev

  • ZC Developers

Posted 11 June 2020 - 02:56 AM

just cycle through all the screen's eweapons and compare their position with your lweapon to see if they collide, and if they do, remove them. It's not super complicated, see Screen->NumEWeapons() and Screen->LoadEWeapon(int num)
 

lweapon TargetLWeapon;
eweapon TargetEWeapon;

for(int i = 0; i <= Screen->NumEWeapons(); i++){

TargetEWeapon = Screen->LoadEWeapon(i);

if(TargetEWeapon->X == TargetLWeapon->X && TargetEWeapon->Y == TargetLWeapon->Y){
TargetEWeapon->X = -64;
TargetEWeapon->Y = -64;
}
}
Some shitty example code, the collision detection here is pixel perfect because I'm too lazy, but you should get the point.

 

lweapon TargetLWeapon;
eweapon TargetEWeapon;

for(int i = 0; i <= Screen->NumEWeapons(); i++){

TargetEWeapon = Screen->LoadEWeapon(i);

if(Collision(TargetLWeapon, TargetEWeapon)){
Remove(TargetEWeapon);
}
}

Proper collision, and destruction, using std.zh functions. Even simpler.


  • ShadowTiger, Mani Kanina, Jared and 1 other like this

#4 Moosh

Moosh

    Tiny Little Questmaker

  • ZC Developers

Posted 11 June 2020 - 03:42 AM

Since this is in script requests I'm assuming you were looking for a working script and since you specified lweapon script, I'm assuming you're using 2.55.

lweapon script EWeaponDestroyer{ 
	void run(int sfx, int breakOnHit){
		int i;
		eweapon e;
		while(true){
			for(i=Screen->NumEWeapons(); i>=1; --i){
				e = Screen->LoadEWeapon(i);
				if(e->CollDetection&&e->DeadState==WDS_ALIVE){
					if(Collision(this, e)){
						if(sfx)
							Game->PlaySound(sfx);
						e->DeadState = 0;
						if(breakOnHit){
							this->DeadState = 0;
							Quit();
						}
					}
				}
			}
			Waitframe();
		}
	}
}

Here you go. D0 is a sound to play when the weapon collides with another. If D1 is 1, the weapon dies on the first collision. I'd avoid doing anything too bullet hellish since this kind of thing will always result in a lot of iterations. But with just Link's weapons it should be fine.


Edited by Moosh, 11 June 2020 - 03:43 AM.

  • ShadowTiger, Anthus, Mani Kanina and 2 others like this



Also tagged with one or more of these keywords: lweapon

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users