NOTE: Not really good in how to explain things clearly Lolz;D!
If the "weapon[current_weapon, gun_eqp] = true" that means I can use this weapon. If "false" then I can't use the weapon.
Now I want is this...as soon as the player pressed "Space Bar" while he is right on top of the weapon on the ground will replace my current weapon with the weapon that's on the floor,my previous weapon is now on the floor, if the two weapons are similar,the current weapon that I'm holding is the same as the weapon on the floor,nothing will happen as soon as I press the "Space Bar" but I can't get it to work,because I'm still new with GML.
Player Code...
Create Event: execute code: globalvar shoottime, weapon_num, weapon, current_weapon; shoottime = 0; //If the player needs to wait before he can shoot again //Melee Attack Seperated from weapon list weapon[melee, bul_spr] = spr_melee; weapon[melee, bul_spe] = 0; weapon[melee, bul_acc] = 0; weapon[melee, bul_num] = 1; weapon[melee, bul_dam] = 50; weapon[melee, bul_dly] = 15; weapon[melee, bul_amo] = 1; weapon[melee, gun_eqp] = true //Weapon List weapon_num = 0; weapon[flamethrower, bul_spr] = spr_fire; weapon[flamethrower, bul_spe] = 7; weapon[flamethrower, bul_acc] = 10; weapon[flamethrower, bul_num] = 8; weapon[flamethrower, bul_dam] = 1; weapon[flamethrower, bul_dly] = 0; weapon[flamethrower, bul_amo] = 500; weapon[flamethrower, gun_eqp] = true weapon_num += 1; weapon[grenade_launcher, bul_spr] = spr_Glauncher; weapon[grenade_launcher, bul_spe] = 9.5; weapon[grenade_launcher, bul_acc] = 2; weapon[grenade_launcher, bul_num] = 1; weapon[grenade_launcher, bul_dam] = 9; weapon[grenade_launcher, bul_dly] = 25; weapon[grenade_launcher, bul_amo] = 20; weapon[grenade_launcher, gun_eqp] = true weapon_num += 1; weapon[shotgun, bul_spr] = spr_shotshell; weapon[shotgun, bul_spe] = 10; weapon[shotgun, bul_acc] = 20; weapon[shotgun, bul_num] = 5; weapon[shotgun, bul_dam] = 25; weapon[shotgun, bul_dly] = 20; weapon[shotgun, bul_amo] = 50; weapon[shotgun, gun_eqp] = true weapon_num += 1; weapon[rifle, bul_spr] = spr_Lbullet; weapon[rifle, bul_spe] = 20; weapon[rifle, bul_acc] = 1; weapon[rifle, bul_num] = 1; weapon[rifle, bul_dam] = 40; weapon[rifle, bul_dly] = 12; weapon[rifle, bul_amo] = 80; weapon[rifle, gun_eqp] = false weapon_num += 1; weapon[pistol, bul_spr] = spr_bullet; weapon[pistol, bul_spe] = 10; weapon[pistol, bul_acc] = 5; weapon[pistol, bul_num] = 1; weapon[pistol, bul_dam] = 10; weapon[pistol, bul_dly] = 10; weapon[pistol, bul_amo] = 100; weapon[pistol, gun_eqp] = false weapon_num += 1; weapon[machine_gun, bul_spr] = spr_bullet; weapon[machine_gun, bul_spe] = 12; weapon[machine_gun, bul_acc] = 8; weapon[machine_gun, bul_num] = 1; weapon[machine_gun, bul_dam] = 5; weapon[machine_gun, bul_dly] = 1; weapon[machine_gun, bul_amo] = 300; weapon[machine_gun, gun_eqp] = true weapon_num += 1; current_weapon = flamethrower; //weapon to start on
This is how the player swaps to different weapons,if the weapons are available.
Key Press Event for E-key Key:
execute code:
//toggle through guns forwards
current_weapon = (current_weapon+1) mod weapon_num;
if(keyboard_check_pressed(ord('E')))
{
while(weapon[current_weapon,gun_eqp]==false)current_weapon=(current_weapon+1) mod weapon_num;
};
Key Press Event for Q-key Key:
execute code:
//toggle through guns backwards
current_weapon = ((current_weapon-1) mod weapon_num + weapon_num) mod weapon_num;
if(keyboard_check_pressed(ord('Q')))
{
while(weapon[current_weapon,gun_eqp]==false)current_weapon =((current_weapon-1) mod weapon_num + weapon_num) mod weapon_num;
};the "wpn_drop" checks what weapon i'm holding so as soon as the player's current weapon has been replaced the "wpn_drop" now tells the "wpn_pickup" what weapon it should be next,wpn_drop(weapon drop: the weapon that was once held by the player) wpn_pickup(weapon pickup: the weapon that will soon be used by the player)
it also changes the "weapon[current_weapon,gun_eqp]=true" to "weapon[current_weapon,gun_eqp]=false" so that I won't be able to use it,because I don't have that weapon.
Weapon On the ground...
Create Event:
execute code:
wpn_pickup=random(6)
image_angle = random(360)
image_index = wpn_pickup
image_speed = 0
Collision Event with object obj_player_soldier:
execute code:
var wpn_drop;
if(keyboard_check_pressed(vk_space))
{
if wpn_pickup != current_weapon
{
image_angle = random(360);
wpn_drop = current_weapon
weapon[current_weapon,gun_eqp]=false;
current_weapon = wpn_pickup
weapon[current_weapon,gun_eqp]=true;
wpn_pickup=wpn_drop;
image_index = wpn_pickup;
}
};
Edited by 8feet, 04 February 2010 - 10:00 AM.











