Adding the 'Far Shot' Feat
This is another of my 30-second tutorials, where-in I am going to quickly explain something new (its new to me and I don't think anyone else had tried this specific thing before so it will be new to people).
The new thing is the use of a weapon's internal flags - thats the specific weapon flags, not just generic object flags. Note that I use one of these too. Hang on, here is the script so everyone can see before I go further:
def san_insert_item( attachee, triggerer ):
________done = attachee.obj_get_int( obj_f_weapon_pad_i_1 )
________if triggerer.has_feat(feat_far_shot):
________________if done == 1:
________________________return RUN_DEFAULT
________________else:
________________________curr = attachee.obj_get_int( obj_f_weapon_range )
________________________curr = curr * 1.5
________________________attachee.obj_set_int( obj_f_weapon_range, curr )
________________________attachee.obj_set_int( obj_f_weapon_pad_i_1, 1 )
________________________game.sound(3013,1)
________else:
________________if done == 1:
________________________curr = attachee.obj_get_int( obj_f_weapon_range )
________________________curr = curr * 2/3
________________________attachee.obj_set_int( obj_f_weapon_range, curr )
________________________attachee.obj_set_int( obj_f_weapon_pad_i_1, 0 )
________________________game.sound(3013,1)
________return RUN_DEFAULT
The first thing we encounter is the aforementioned use of one of the weapon's generic object flags, the integer flag pad_i_1 (I refer to it as a 'generic object flag' not because that is a precise description but because every type of object has these sorts of things). I just used this flag to keep an eye on whether the weapon has had its range adjusted. But I am gettting ahead of myself again: lets start over.
'Far Shot' has been implemented not by adding anything to the PCs (or NPCs) but rather by adding an 'insert item' script to every ranged weapon in the game - not as much effort as it sounds really, there are only two possible scripts and a quick copy-paste into the san_insert_item column of Protos.tab of each weapon. Each time the weapon is inserted, it checks whether the user has 'Far Shot' or not: if he does, the script automatically changes the range on the weapon if this has not already happened.
Back to the obj flag - this sets if the weapon is adjusted, so we don't double the range of the weapon each time. It has the secondary function that if the range is doubled and the weapon is handed off to someone who DOESN'T have the Far Shot feat (I can't see more than one person in any party having it, if that, unless you want a party of long-distance killers) then the weapon will reset. I say 'doubled' but of course its 150% for projectile weapons, 200% for ranged.
On to the money flag: obj_f_weapon_range. This stores the range of the weapon, of course. And we can access it and change it as necessary like any of the other flags we have seen so far (though this is not true for all flags - some of you may remember I couldn't read the faction flag. Some are integers, some are floating point, and some just crash the game when you read them).
Last thing - a sound so you know each time it changes range. Should only fire the first time you get the feat, and if you hand it off to someone who doesn't have it. In time I will remove this.
And thats it! So easy :-) Plus it has the added bonus that every ranged weapon now has a script, so if I can think of a way to implement something else like Improved Precise Shot by script, the script attachment is already there :-) And now I have a second look through the obj flags, I can already see a way to do the 'flat +2 bonus' workaround.
0 Comments:
Post a Comment
<< Home