Problem with a Script

Post » Wed Aug 18, 2010 4:45 am

I recently made a script to make it impossible to obtain an item from pickpocketing it from the NPC that carries it. I first tested it out by putting the item on the ground then picking it up, the script worked perfectly and removed it from my inventory, but when i put it in the NPC's inventory and tried to take it from his inventory, the game crashed, it does this every time i do it. It wasn;t a random occurance

This is the script:

scn CantRemoveScript


short itemcount



begin GameMode


set itemcount to Player.GetItemCount MySword
if itemcount >= 1
MessageBox "You can't take this"

Player.RemoveItem MySword 1
MyDude.AddItem MySword 1
endif
end


This is script for the object and i was wondering if any advanced scripters could help me out on this one, help would be very appreciated.
User avatar
sharon
 
Posts: 3449
Joined: Wed Nov 22, 2006 4:59 am

Post » Tue Aug 17, 2010 6:17 pm

Perhaps something like this?

scn CantRemoveScriptbegin OnAdd	MessageBox "You can't take this" 	Player.RemoveItem MySword 1	MyDude.AddItem MySword 1end

User avatar
Petr Jordy Zugar
 
Posts: 3497
Joined: Tue Jul 03, 2007 10:10 pm

Post » Tue Aug 17, 2010 5:54 pm

Perhaps something like this?

scn CantRemoveScriptbegin OnAdd	MessageBox "You can't take this" 	Player.RemoveItem MySword 1	MyDude.AddItem MySword 1end



i actually tried that for my first script and i encountered the same problem, i thought that since it was trying to add and remove at the same time while the inventories were open that that was the problem, so i made it start on GameMode hoping that since it will only start while not in the inventories it would solve the problem, but it didn't.
User avatar
MARLON JOHNSON
 
Posts: 3377
Joined: Sun May 20, 2007 7:12 pm

Post » Wed Aug 18, 2010 7:16 am

IIRC, the Player can't pickpocket an item that is currently equipped by an NPC. So, if you can get your NPC to keep the sword equipped, pickpocketing it will not be an issue.
User avatar
zoe
 
Posts: 3298
Joined: Sun Nov 12, 2006 1:09 pm

Post » Tue Aug 17, 2010 8:25 pm

If you want them to have it equipped, then you can't pickpocket it. If you want the player to have to kill them to get it, use a OnDeath script on the actor to add it to them.
User avatar
ezra
 
Posts: 3510
Joined: Sun Aug 12, 2007 6:40 pm


Return to IV - Oblivion