I'd assume that the OP is trying to make this script as generic as possible so that it can be used on any lever to unlock any door without needing to edit the script. If that's the case, then
object oTarget = GetObjectByTag(GetLocalString(OBJECT_SELF, "SCDoor_001"));
is the logical choice. It will get the tag of the door from the local variable SCDoor_001 on the lever so that the script does not need to be changed.
If that's so then I'd assume the OP also meant to allow different text to be displayed for each door/lever combo and different time delays to be set before the door is closed and locked.
I don't think the "action" commands are appropriate here since they are intended to be used on mobile creatures which can then move to the object before performing the action.
Also, this script has a potential module-breaker if a player keeps on using the lever over and over. More and more delayed commands will be queued which could cause unacceptable lag. At the least, as time runs out the door will play the "close" animation over and over.
I think this will work:
void main()
{
object oPC = GetLastUsedBy();
ExecuteScript("x2_plc_used_act", OBJECT_SELF);//<-- do lever animation
if (!GetIsPC(oPC) && !GetLocalInt(OBJECT_SELF,"NW_DO_ONCE")) return;
SetLocalInt(OBJECT_SELF,"NW_DO_ONCE",TRUE);//<-- stops this script from executing again
object oTarget = GetObjectByTag(GetLocalString(OBJECT_SELF, "SCDoor_001"));
if(!GetIsObjectValid(oTarget)) return;
FloatingTextStringOnCreature(GetLocalString(OBJECT_SELF, "SCDoor_002"), oPC);
SetLocked(oTarget,FALSE);
AssignCommand(oTarget, PlayAnimation(ANIMATION_DOOR_OPEN1);
float fDelay = GetLocalFloat(OBJECT_SELF, "SCDoor_003");
DelayCommand(fDelay, AssignCommand(oTarget, PlayAnimation(ANIMATION_DOOR_CLOSE));
DelayCommand(fDelay, SetLocked(oTarget,TRUE));
DelayCommand(fDelay, DeleteLocalInt(OBJECT_SELF,"NW_DO_ONCE"));//<-- allows this script to execute again after the delay
}
In the toolset, on the lever set the string variable SCDoor_001 equal to the tag of the door which the lever must open, the value of the string variable SCDoor_002 to the text to be displayed when the lever is operated and the value of the floating-point variable SCDoor_003 to 300.0.
eg:
string SCDoor_001 = SCDoor_001
(Yes, you can have a variable and an object tag exactly the same. The game won't get confused, although you might.) ;-)
string SCDoor_002 = Something creaks in the distance
float SCDoor_003 = 300.0
I hope this does what you want.
Modifié par Melkior_King, 15 août 2011 - 01:41 .