TheOnlyWRT
Member
So i am trying to code in my game the ability to pickup weapons when the enemy dies and drops their weapon. It worked great, and still does, but then i tried to add the ability of be able to drop your weapon whenever, and also drop your current weapon when you pickup a new one. And now whatever weapon is the first that i pickup, that is the weapon that all other dropped/picked up weapons are.
here is the code in the enemies to drop a weapon:
Here is the code for the player dropping a weapon:
and here is the code for the player picking up a weapon (in the collision with objectWeaponDrop event)
So basically its sets the picked up weapon (and ammo and magazines) to the last used weapons values.... and if i used a pistol, then picked up a machine gun, it is still a pistol.... so its a mess now.....
Thanks for your help!!!!
here is the code in the enemies to drop a weapon:
Code:
var shouldDrop = choose(3); //choose a number to see if the enemt should drop a weapon or not
if(shouldDrop == 3){
var setType = currentWeapon;
with instance_create_depth(x, y, 1, objectWeaponDrop){
type = setType; //set the type of the weapon being dropped
ammo = irandom_range(1, weapon[type, v_magazineCapacity]);
magazines = irandom_range(1, 3);
}
}
Code:
if(keyboard_check_pressed(ord("D"))){
if(currentWeapon != w_punch){
var weaponSet = currentWeapon;
var ammoSet = weapon[currentWeapon, v_ammo];
var magazineSet = weapon[currentWeapon, v_magazines];
with instance_create_depth(x, y, 1, objectWeaponDrop){
type = weaponSet;
ammo = ammoSet;
magaine = magazineSet;
}
currentWeapon = w_punch;
}
}
Code:
if(keyboard_check_pressed(ord("F"))){
if(currentWeapon == objectWeaponDrop.type){
currentWeapon = objectWeaponDrop.type;
weapon[currentWeapon, v_ammo] = weapon[currentWeapon, v_ammo] + objectWeaponDrop.ammo;
weapon[currentWeapon, v_magazines] = weapon[currentWeapon, v_magazines] + objectWeaponDrop.magazines;
} else {
if(currentWeapon != w_punch){
var weaponSet = currentWeapon;
var ammoSet = weapon[currentWeapon, v_ammo];
var magazineSet = weapon[currentWeapon, v_magazines];
with instance_create_depth(x, y, 1, objectWeaponDrop){
type = weaponSet;
ammo = ammoSet;
magaine = magazineSet;
}
}
currentWeapon = objectWeaponDrop.type;
weapon[currentWeapon, v_ammo] = objectWeaponDrop.ammo;
weapon[currentWeapon, v_magazines] = objectWeaponDrop.magazines;
}
}
Thanks for your help!!!!