your script got some flaws.
- bullet speed will change depending on the fps
- your bulets will miss 25+% of the time
- bullets that don’t hit a target with a health property will not be killed, and will be alive for the entire game duration, over time this will greatly slowdown or stall/crash the engine.
The dict usage is indeed a handy setup. but now you have preset damage numbers for basically any weapon you want to use for example a pisol or a rpg, so separating the game_difficulty from the weapon is the best action to take. a weapon should not hold the difficulty.
in the topic the TS linked in first post, i have an other script there, it uses a dict like this:
def grab_weapons(cont):
own = cont.owner
own['weapons'] = {
'pistol':{
'range' : 20,
'ammo' : 22,
'spare_ammo' : 66,
'max_ammo' : 132,
'clip_size' : 22,
'bullet' : 'plasma_bullet',
'bullet_damage' : 35,
'bullet_speed' : 25,
'bullet_drop' : 0.00001,
'bullet_spray_spread' : 0.015, #higher = bigger spray
'bullet_spray_reset' : 0.40, #higher = less accurate
'bullet_hole' : 'plasma_hole',
'arms_animation' : 'arms_pistol',
'weapon_animation' : 'pistol_firing',
'sound_firing' : 'gun-gunshot-02.wav',
'sound_reload' : 'clickclick.wav'
},
'baseballbat':{
'range' : 2,
'ammo' : 1,
'spare_ammo' : 0,
'max_ammo' : 1,
'clip_size' : 1,
'bullet' : 'plasma_bullet',
'bullet_damage' : 45,
'bullet_speed' : 25,
'bullet_drop' : 0.00001,
'bullet_spray_spread' : 0.05,
'bullet_spray_reset' : 0.20,
'bullet_hole' : 'plasma_hole',
'arms_animation' : 'arms_pistol',
'weapon_animation' : 'pistol_firing',
'sound_firing' : 'gun-gunshot-02.wav',
'sound_reload' : 'clickclick.wav'
},
'grenade':{
'range' : 2,
'ammo' : 1,
'spare_ammo' : 0,
'max_ammo' : 1,
'clip_size' : 1,
'bullet' : 'plasma_bullet',
'bullet_damage' : 45,
'bullet_speed' : 25,
'bullet_drop' : 0.00001,
'bullet_spray_spread' : 0.05,
'bullet_spray_reset' : 0.20,
'bullet_hole' : 'plasma_hole',
'arms_animation' : 'arms_pistol',
'weapon_animation' : 'pistol_firing',
'sound_firing' : 'gun-gunshot-02.wav',
'sound_reload' : 'clickclick.wav'
},
'axe':{
'range' : 2,
'ammo' : 1,
'spare_ammo' : 0,
'max_ammo' : 1,
'clip_size' : 1,
'bullet' : 'plasma_bullet',
'bullet_damage' : 45,
'bullet_speed' : 25,
'bullet_drop' : 0.00001,
'bullet_spray_spread' : 0.05,
'bullet_spray_reset' : 0.20,
'bullet_hole' : 'plasma_hole',
'arms_animation' : 'arms_pistol',
'weapon_animation' : 'pistol_firing',
'sound_firing' : 'gun-gunshot-02.wav',
'sound_reload' : 'clickclick.wav'
},
'pickaxe':{
'range' : 2,
'ammo' : 1,
'spare_ammo' : 0,
'max_ammo' : 1,
'clip_size' : 1,
'bullet' : 'plasma_bullet',
'bullet_damage' : 45,
'bullet_speed' : 25,
'bullet_drop' : 0.00001,
'bullet_spray_spread' : 0.05,
'bullet_spray_reset' : 0.20,
'bullet_hole' : 'plasma_hole',
'arms_animation' : 'arms_pistol',
'weapon_animation' : 'pistol_firing',
'sound_firing' : 'gun-gunshot-02.wav',
'sound_reload' : 'clickclick.wav'
},
'tnt':{
'range' : 2,
'ammo' : 1,
'spare_ammo' : 0,
'max_ammo' : 1,
'clip_size' : 1,
'bullet' : 'plasma_bullet',
'bullet_damage' : 45,
'bullet_speed' : 25,
'bullet_drop' : 0.00001,
'bullet_spray_spread' : 0.05,
'bullet_spray_reset' : 0.20,
'bullet_hole' : 'plasma_hole',
'arms_animation' : 'arms_pistol',
'weapon_animation' : 'pistol_firing',
'sound_firing' : 'gun-gunshot-02.wav',
'sound_reload' : 'clickclick.wav'
},
'sword':{
'range' : 2,
'ammo' : 1,
'spare_ammo' : 0,
'max_ammo' : 1,
'clip_size' : 1,
'bullet' : 'plasma_bullet',
'bullet_damage' : 45,
'bullet_speed' : 25,
'bullet_drop' : 0.00001,
'bullet_spray_spread' : 0.05,
'bullet_spray_reset' : 0.20,
'bullet_hole' : 'plasma_hole',
'arms_animation' : 'arms_pistol',
'weapon_animation' : 'pistol_firing',
'sound_firing' : 'gun-gunshot-02.wav',
'sound_reload' : 'clickclick.wav'
},
'sword_2h':{
'range' : 2,
'ammo' : 1,
'spare_ammo' : 0,
'max_ammo' : 1,
'clip_size' : 1,
'bullet' : 'plasma_bullet',
'bullet_damage' : 45,
'bullet_speed' : 25,
'bullet_drop' : 0.00001,
'bullet_spray_spread' : 0.05,
'bullet_spray_reset' : 0.20,
'bullet_hole' : 'plasma_hole',
'arms_animation' : 'arms_pistol',
'weapon_animation' : 'pistol_firing',
'sound_firing' : 'gun-gunshot-02.wav',
'sound_reload' : 'clickclick.wav'
}
}
As you can see it holds all the data per weapon, you can even add the difficulty damages to it, but why would you add all those things per weapon if you can do it with a simple difficulty property icw a tiny if statement. You can now even use that difficulty property to change the whole game(spawn more or tougher enemies, generate more or less loot, etc.). There is no need to go make a script/property for every single object ingame that needs to change when the difficulty changes.