Do we have a simple script...

Discussion in 'General Modification' started by Shiningted, May 28, 2006.

Remove all ads!
  1. darmagon

    darmagon stumbler in the dark

    Joined:
    Mar 22, 2005
    Messages:
    295
    Likes Received:
    0
    Yeah like I said it is far from simple. The post was mostly written to get my head around the whole thing before I started actually writing the code. The concept is fairly simple, tho. Just create an object that responds to all the tests a player can throw at it as if it were the original weapon but that will not auto-equip because it is not a weapon according to the gama object system. Then we set it up so that it becomes the original weapon when we need it to.

    Anyway I am getting started on the code now. Wish me luck...

    Darmagon
     
  2. Shiningted

    Shiningted I want my goat back Global Moderator

    Joined:
    Oct 23, 2004
    Messages:
    11,746
    Likes Received:
    29
    LUCK!

    But I am mainly interested in stuff that is in NPCs' inventory... so the players never get near it. If they get into combat / killed / charmed / knocked unconscious, well then we run the script to replace ur psuedo-weapons with the real thing to be looted (if they appear to draw their weapons just as they get knocked unconscious / killed without entering combat by a massive blast, well, that will look even cooler).

    Should make things easier, no? And if it means not using it on recruitable NPCs, small price to pay, they are all martial types anyway. I will settle for unarmed shopkeepers and clerics.
     
  3. Allyx

    Allyx Master Crafter Global Moderator Supporter

    Joined:
    Dec 2, 2004
    Messages:
    4,589
    Likes Received:
    115
    I don't understand the need to overcomplicate things like you guy's have (perhaps I'm missing some important point but), why not create the real weapons in the san_start_combat script itself? (or in san_dying if they never got the chance to react) and destroy them in san_end_combat? Is it just in case PC's want to pick the NPC's pocket? IIRC Pick pocket usually only takes coins from the victim.
     
  4. Lord_Spike

    Lord_Spike Senior Member Veteran

    Joined:
    Mar 25, 2005
    Messages:
    3,151
    Likes Received:
    0
    That's one impressive pocket if you can keep your mace/axe/sword in it...
     
  5. krunch

    krunch moving on in life

    Joined:
    Aug 9, 2005
    Messages:
    3,280
    Likes Received:
    0
    If you think about it, it kind of makes some cents. (pun intended)

    It is, after all, called "pick pockets" for a reason.
     
  6. Shiningted

    Shiningted I want my goat back Global Moderator

    Joined:
    Oct 23, 2004
    Messages:
    11,746
    Likes Received:
    29
    There are a few reasons - pickpocketing, getting suddenly killed / slept / held / knocked out by massive or collateral damage without firing the enter combat script (if that can happen, wouldn't surprise me), charming, suggesting etc - which, while unlikely, have to b taken into account if we are to create a really immersive experience. After all the Keep is a place of strict rules and many guards, much of the fun for non-good parties is going to be how you can get away with things without giving yourself away by murdering everyone.

    Its not that different to all the san_resurrection scripts that go with the san_dying ones - who seriously EVER resurrected the Temple priests or any other non-follower NPC? But if you have made a stuff-up in a quest and realise you shouldn't have butchered everyone in sight, well, you can fix it :)
     
  7. darmagon

    darmagon stumbler in the dark

    Joined:
    Mar 22, 2005
    Messages:
    295
    Likes Received:
    0
    Yeah what he said and just maybe because knowing how to do something like this could have other uses. Research is never wasted. You always learn new things (ie. like the auto-equipping behaviour of NPC we learned about at the beginning of this thread.)

    Anyway here is what I have so far:
    Code:
    def unequip_npc_slot_item_no_autoequip( slot, npc, callback_scr_nums=[], callback_file_nums =[]):
    	item = npc.item_worn_at(slot)
    	if item != OBJ_HANDLE_NULL:
    		rep = game.obj_create(12055, npc.location)
    		s = rep.obj_set_int
    		g = item.obj_get_int
    		s(obj_f_item_inv_aid, g(obj_f_item_inv_aid))
    		if g(obj_f_item_description_unknown) != 0:
    			s(obj_f_item_description_unknown, g(obj_f_item_description_unknown))
    		else:
    			s(obj_f_item_description_unknown, item.name)
    		s(obj_f_item_weight,g(obj_f_item_weight))
    		s(obj_f_pad_i_7, item.name)
    		i = 0
    		for csn in callback_scr_nums:
    			if len(callback_file_nums) > 0:
    				rep.scripts[csn] = callback_file_nums[i]
    				if  i < len(call_back_file_nums):
    					i = i + 1
    		item.destroy()
    		npc.item_get(rep)
    Where slot is the item slot you want to unequip. npc is (duh!) the npc, callback_scr_nums is a list of script attachment point numbers you want to define on the object, and callback_file_nums is a list of the file numbers that hold the definitions of your script attachment point functions.. The script attachment point numbers can be gotten from the protos. san_examine is 0. If you count upwards from there as they are listed in world builder of proto ed you get the number you need. The file numbers are just the numbers in the py script file names with any leading zeroes stripped

    Just to be concrete I am going to use Jaroo's file here, which is number 12. The relevant script that we want to define to accomplish teds goal is 21 (san_insert_item) which fires whenever an item is inserted into an inventory. So to use this function we would first define san_nsert_item like this:
    Code:
    def san_insert_item(attachee, triggerer):
        name = attachee.obj_get_int(obj_f_item_pad_i_7)
        if name != 0:
            item = game.obj_create(name, triggerer.location)
            attachee.destroy()
            triggerer.item_get(item)
            return SKIP_DEFAULT
        return RUN_DEFAULT
    
    in our chosen py script file. IN this case that is Jaroo's file which is script file number 12.

    Now we have the script set up we can call the unequip function on the npc:
    Code:
    unequip_npc_slot_item_no_autoequip(3, npc,[21],[12])
    
    This should take care of most of what we need. Pocket picking, looting a dead body, disintegration etc.

    All that remains to be done is the combat thing so that the npc can equip the weapon. For this I would suggest not destroying the new object but just creating the weapon on the start of combat and destroying it at the end. We can get the id of the weapon we need to create this way:
    Code:
    item=npc.item_find_by_proto(12055)
    name = item.obj_get_int(obj_f_item_pad_i_7)
    weapon = game.obj_create(name, npc.location)
    npc.item_get(weapon)
    
    A bit more needs to be done but this should take care of most of it.

    Darmagon
     
    Last edited: Jun 1, 2006
  8. rufnredde

    rufnredde Established Member Veteran

    Joined:
    Apr 8, 2006
    Messages:
    266
    Likes Received:
    1
    Well I can honestly say the the title of this thread may need to be changed. Immediately followed by that is elegant Darmagon, it opens up loads of possiblities. Thanks for sharing! I did not realize you could do that with the script attachment points. Looking forward to your future posts in your Game Secrets Thread.
     
  9. Cerulean the Blue

    Cerulean the Blue Blue Meanie Veteran

    Joined:
    Apr 23, 2005
    Messages:
    1,962
    Likes Received:
    0
    Great work Darmagon. I have one question though.

    Is the attachee in the san_insert script the NPC doing the equipping? If so, you may have a problem. IIRC you cant access an obj_f_item_pad_i on an NPC. I tried using that when working with the familiars. I could access it for the in-inventory familiar (since it is really an item) but not for the summoned familiar (since it is an NPC). Of course, if you've tested this and it works, then I must be wrong.
     
  10. darmagon

    darmagon stumbler in the dark

    Joined:
    Mar 22, 2005
    Messages:
    295
    Likes Received:
    0
    No the attachee is the item, the triggerer is the owner of the inventory the item is inserted into. That is tested. I had i little bit of fun passing the item around my test party. You see I had the script set to:triggerer.critter_kill_by_effect().... Okay a little morbid but it was the best way to make certain the script was working properly that I could think of.

    Darmagon
     
  11. Gaear

    Gaear Bastard Maestro Administrator

    Joined:
    Apr 27, 2004
    Messages:
    10,996
    Likes Received:
    23
    Hello 2006 ...

    Ted, I suppose you're the only player from this old thread who might still read this, but I think I can confirm that Darmagon's original script does indeed fail when it encounters a slot wherin a PC doesn't have an item equipped. I assume you got around this somehow for KotB's unequipping routine in the Keep ...

    The last script D-gon turned in looks like utter gibberish to me, lol ... the golden age of the brainiacs. ;)
     
  12. marc1967

    marc1967 Established Member

    Joined:
    Jan 19, 2014
    Messages:
    546
    Likes Received:
    19
    Hello 2011 ...

    Found a semi-fringe case in the uneqip() function where the weapon in-hand that gets unequipped can be permanently lost if everyone's inventory is full. Right now, if the Enlarged player's inventory is completely full, the function unequip() will attempt to put the item into another player's inventory. But if everyone's inventory is also full then the weapon goes poof forever.

    The solution I am using is just to leave the temporary holding chest there if no inventory slot is available. I think the oddness of having a chest mysteriously appear is better than losing your +5 Holy Flaming Frost Keen Glaive of Retribution to the nether world.

    Other solutions would be to just leave the weapon in hand, or delete the least valuable item from the inventory, or some other clever idea. But this seems to get the job done, and it's a simple one-line fix at the very end of the function unequip() in Co8.py.

    Code:
    if tempp != 0:
        holder.destroy()
    
     
Our Host!