ForumsProgramming Forum[Need Help] Attaching movie clips (my weapons).. etc

115 37134
Voidcrystal
offline
Voidcrystal
138 posts
Nomad

Hello!

1.I need help with some scripting that i can't really do, i need to attach my weapon to the character, i have made the weapon and i can rotate it and here is the script:

onClipEvent (enterFrame) {

_rotation = ((Math.atan2(_root._ymouse-_y,_root._xmouse-_x)/(Math.PI/180))+90)
}

2.I would also like to make the buttons 1, 2, 3, 4, 5 as weapon buttons, as an example: 1: glock, 2: uzi, 3: mp5, 4: Sniper, 5. bazooka. But i don't want the people to have them all at the beginning, i want them to buy them for kills at the end of the level.

3. How do i make my enemies have more hp or less hp? And how to make the the weapons shoot faster and slower, more dmg and lesser dmg.

I know this is kinda much but this is all the things i don't really understand atm, thanks for reading and if you can help, please do.

  • 115 Replies
AbnormalIdiot
offline
AbnormalIdiot
110 posts
Nomad

1.You could drag the weapon you want to part of the character movieclip, and when you choose weapons, make the one you choose visible, and the others invisible.

2.You could make a variable for each weapon unlocked, then if the weapon is available make it visible, and the others invisible. So, for example make a var glockAvailable, and in the onLoad function: glockAvailable = true; In the enterFrame function add something like:
if(Key.isDown(49) && glockAvailable == true)
{
_root.character.glock._visible = true;
_root.character.uzi._visible = false;
_root.character.mp5._visible = false;
_root.character.sniper._visible = false;
_root.character.bazooka._visible = false;
}

3. If you want their hp to be a random number then in the enemy's onLoad function: hp = Math.round(Math.random()*50 + 50); - that would make the hp somewhere between 50 and 100.
To make the gun shoot slower or faster, make to variables: shotDelay and maxShotDelay. Make maxShotDelay whatever number you want when you change to a certain weapon. Then make shotDelay decrease by one each frame, then when you click the mouse, only shoot if shotDelay is less than 0, then when you shoot the bullet set shotDelay to maxShotDelay.

Voidcrystal
offline
Voidcrystal
138 posts
Nomad

Tested: "2." and it didn't work, i'll send the script. Btw i have AS2

Frame:

if(Key.isDown(1)&& glockAvailable == true)
_root.mcMain.glock._visible = true

Mc (my character)

onClipEvent (load) {

var glockAvailable = true;

AbnormalIdiot
offline
AbnormalIdiot
110 posts
Nomad

Don't use 1 for the button 1. Use 49. here is a link of all symbols/letters and the number corresponding to them in flash (the rightmost number). So 1 is 49, 2 is 50, etc. Btw, if you want to use letters (like WASD to move) use the uppercase letter, so W is 87, etc.

Voidcrystal
offline
Voidcrystal
138 posts
Nomad

still doesn't work

AbnormalIdiot
offline
AbnormalIdiot
110 posts
Nomad

Try putting var glockAvailable; At the very beginning of your class (but after class mcMain extends MovieClip) and glockAvailable = true; in the onload function

Voidcrystal
offline
Voidcrystal
138 posts
Nomad

Still :S. Ok for more information i'm going to send all script that has to do with this:

On the gun (glock)

onClipEvent (enterFrame) {

_rotation = ((Math.atan2(_root._ymouse-_y,_root._xmouse-_x)/(Math.PI/180))+90)
}


on the boll<mcMain> (my char)

onClipEvent (load) {
var glockAvailable;


The Frame

mcMain.onEnterFrame = function (){
var glockAvailable;
_root.mcMain.glock._visible = true


See anything wrong :S?

AbnormalIdiot
offline
AbnormalIdiot
110 posts
Nomad

Actually, since you're doing this in a movieclip, try taking out

var glockAvailable;

In both places, and add

glockAvailable = true;

in your main character.

Voidcrystal
offline
Voidcrystal
138 posts
Nomad

Does not work :/ actually i am just trying to attach the weapon to the mcMain if that is what you mean? In your last post you didn't mention _root.mcMain.glock

We can try to just attach it first? That would maybe fix it ^^

AbnormalIdiot
offline
AbnormalIdiot
110 posts
Nomad

Wasn't attaching the weapon to mcMain the first step? Without that none of this will work.

Voidcrystal
offline
Voidcrystal
138 posts
Nomad

Yeah but that is what i mean, it doesn't work . So if you know how, please

AbnormalIdiot
offline
AbnormalIdiot
110 posts
Nomad

Oh, double click on mcMain then drag each of the guns out of the library and put them where you would want them to be on your character. Give each weapon the instance name of what type of gun it is. For example, give the glock the instance name glock. Give your main character the instance name mcMain. Then you can refer to the character as _root.mcMain and the guns as _root.mcMain.[gun name] Now the code should work (:

Voidcrystal
offline
Voidcrystal
138 posts
Nomad

Cool i'll try

Voidcrystal
offline
Voidcrystal
138 posts
Nomad

The Weapon Dir code didn't work as it should when i did that
, any code to attach it?

Voidcrystal
offline
Voidcrystal
138 posts
Nomad

Haha ;D it works now, i moved some scripts ^^! And also the other script, Thanks alot! I will maybe post here again if i need help with the Hp thing or something else so remember to check this out ok :P?

AbnormalIdiot
offline
AbnormalIdiot
110 posts
Nomad

Alright, glad I could help!

Showing 1-15 of 115