• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Swapping Weapons and changing their damage

M

Max Doerwaldt

Guest
So I have a system to swap weapons and it works, the problem I have is that I can't seem to change the amount of damage they do. They all deal the same amount.
weapon swap code:
var new_weapon = argument0;
var temp = weapon_sprite;
weapon_sprite = new_weapon.sprite_index;
new_weapon.sprite_index = temp;
if (swap_key) {
var nearest_weapon = instance_nearest(x, y, obj_weapon_item);
if (place_meeting(x, y+4, nearest_weapon)) {
scr_swap_weapons(nearest_weapon);
}
}
if (swap_key) {
var nearest_weapon = instance_nearest(x, y, obj_weapon_sword);
if (place_meeting(x, y+4, nearest_weapon)) {
scr_swap_weapons(nearest_weapon);
}
}
and I attempted to change the damage like this:
if (weapon_sprite == stick) {
attack = 1;
}
if (weapon_sprite == sword) {
attack = 3;
}
 
P

PandaPenguin

Guest
this code is a mess...what exactly are you trying to do here??

var temp = weapon_sprite;
where does this "weapon_sprite" come from? is it from the weapon object you start this script?
what you do is overly complex and very very prone to failure and error.

take a look at this tutorial (it has 2 parts) where a better methode of switching weapons is shown
especially part 2 is what I strongly suggest you use for this ;)
 
M

Max Doerwaldt

Guest
this code is a mess...what exactly are you trying to do here??


where does this "weapon_sprite" come from? is it from the weapon object you start this script?
what you do is overly complex and very very prone to failure and error.

take a look at this tutorial (it has 2 parts) where a better methode of switching weapons is shown
especially part 2 is what I strongly suggest you use for this ;)
I got this code from a tutorial, and I saw that video there, but it looked like inventory switching like the player already has the weapon, I wanted switching with weapons on the ground. weapon_sprite was a variable I used for this, the script here made it look like the player was switching the weapons on the ground but really just switching the sprites.
 
Top