OK Zaxtaj,
There are two basic ways to execute script from a item. and probly many more.
Way 1)
//::///////////////////////////////////////////////
//:: Title : MODULE, onUseItem Event
//:: Author:
//:: Module:
//:: Date :
//:: Vers : 1.0
//:://////////////////////////////////////////////
void main() {
location lLoc = GetItemActivatedTargetLocation();
object oItem = GetItemActivated();
object oCaster = GetItemActivator();
object oTarget = GetItemActivatedTarget();
string oCasterName = GetName(oCaster);
string oTargetName = GetName(oTarget);
//=======================================================================
// Add Special Activate Script Here
//=======================================================================
// this would be your script from the forums
}
Way 2)
//:://////////////////////////////////////////////////////////////
//:: Title : mod_on_act
//:: Author: Greyfort
//:: Module: any who need
//:: Date : Aug 18, 2010
//:: Vers : 1.0
//:://////////////////////////////////////////////////////////////
//::///////////////////////////////////////////////
//:: Example XP2 OnActivate Script Script
//:: x2_mod_def_act
//:: © 2003 Bioware Corp.
//:://////////////////////////////////////////////
/*
Put into: OnItemActivate Event
*/
//:://////////////////////////////////////////////
//:: Created By: Georg Zoeller
//:: Created On: 2003-07-16
//:://////////////////////////////////////////////
#include "x2_inc_switches"
void main()
{
object oItem = GetItemActivated();
// * Generic Item Script Execution Code
// * If MODULE_SWITCH_EXECUTE_TAGBASED_SCRIPTS is set to TRUE on the module,
// * it will execute a script that has the same name as the item's tag
// * inside this script you can manage scripts for all events by checking against
// * GetUserDefinedItemEventNumber(). See x2_it_example.nss
if (GetModuleSwitchValue(MODULE_SWITCH_ENABLE_TAGBASED_SCRIPTS) == TRUE)
{
SetUserDefinedItemEventNumber(X2_ITEM_EVENT_ACTIVATE);
int nRet = ExecuteScriptAndReturnInt(GetUserDefinedItemEventScriptName(oItem),OBJECT_SELF);
if (nRet == X2_EXECUTE_SCRIPT_END)
{
return;
}
}
}
put this in your module event Activate Item
Open a new script pasete this in..
#include "x2_inc_switches"
void main()
{
int nEvent =GetUserDefinedItemEventNumber();
switch (nEvent)
{
case X2_ITEM_EVENT_ACTIVATE:
ExecuteScript("ac_"+GetTag(GetItemActivated()),
OBJECT_SELF); break;
case X2_ITEM_EVENT_EQUIP:
ExecuteScript("eq_"+GetTag(GetPCItemLastEquipped()),
OBJECT_SELF); break;
case X2_ITEM_EVENT_UNEQUIP:
ExecuteScript("ue_"+GetTag(GetPCItemLastUnequipped()),
OBJECT_SELF); break;
case X2_ITEM_EVENT_ACQUIRE:
ExecuteScript("aq_"+GetTag(GetModuleItemAcquired()),
OBJECT_SELF); break;
case X2_ITEM_EVENT_UNACQUIRE:
ExecuteScript("ua_"+GetTag(GetModuleItemLost()),
OBJECT_SELF); break;
case X2_ITEM_EVENT_SPELLCAST_AT:
ExecuteScript("sp_"+GetTag(GetModuleItemLost()),
OBJECT_SELF); break;
case X2_ITEM_EVENT_ONHITCAST:
ExecuteScript("on_"+GetTag(GetSpellCastItem()),
OBJECT_SELF); break;
}
}
save script the name of your item “itemtagâ€
Now open a new script, paste code from forums in
#include "x2_inc_switches"
void Actions()
{
// The actions the clones carry out once created.
// Attack nearest enemy
ASSOCIATE_COMMAND_ATTACKNEAREST;
// if there is no master destroy the clone
if (GetMaster(OBJECT_SELF) == OBJECT_INVALID)
{
SetPCLike(GetMaster(OBJECT_SELF), OBJECT_SELF);
ChangeToStandardFaction(OBJECT_SELF, STANDARD_FACTION_COMMONER);
ApplyEffectAtLocation(DURATION_TYPE_TEMPORARY, EffectVisualEffect(VFX_FNF_SUMMON_MONSTER_1), GetLocation(OBJECT_SELF));
DestroyObject(OBJECT_SELF, 0.0);
}
// if the clone dies (so you can't loot it's items) revive then destroy it.
if (GetIsDead(OBJECT_SELF) == TRUE)
{
SetIsDestroyable(FALSE,TRUE,FALSE);
ApplyEffectAtLocation(DURATION_TYPE_TEMPORARY, EffectVisualEffect(VFX_FNF_SUMMON_MONSTER_1), GetLocation(OBJECT_SELF));
int nHealed = GetMaxHitPoints(OBJECT_SELF);
effect eRaise = EffectResurrection();
effect eHeal = EffectHeal(nHealed + 10);
ApplyEffectToObject(DURATION_TYPE_INSTANT, eRaise, OBJECT_SELF);
ApplyEffectToObject(DURATION_TYPE_INSTANT, eHeal, OBJECT_SELF);
SetIsDestroyable(TRUE,FALSE,FALSE);
DestroyObject(OBJECT_SELF, 0.0);
}
// follow the master if there are no enemys, or if not dieing
ASSOCIATE_COMMAND_FOLLOWMASTER;
// repeat checks.
AssignCommand(OBJECT_SELF, Actions());
}
void main()
{// checking if you have any dominated people in your party if you do no clones will be summoned.
if(GetUserDefinedItemEventNumber() != X2_ITEM_EVENT_ACTIVATE) return;
object oPC = GetItemActivator();
object oClone;
int oCloneHandle;
if (GetAssociate(ASSOCIATE_TYPE_DOMINATED, oPC, 1) == OBJECT_INVALID)
{
oCloneHandle = 0;
}
else
{// set clones to summon equal to the casters level
oCloneHandle = GetCasterLevel(oPC);
}
for (;oCloneHandle
{// this is the clone creation process
oClone = CopyObject(oPC, GetLocation(oPC), OBJECT_INVALID, "Clone of "+GetName(oPC));
SetLootable(oClone, FALSE);
SetLocalObject(oClone, "Player", oPC);
ChangeToStandardFaction(oClone, AI_LEVEL_VERY_HIGH);
AssignCommand(oPC, ApplyEffectToObject(DURATION_TYPE_INSTANT, EffectCutsceneDominated(), oClone));
ApplyEffectAtLocation(DURATION_TYPE_TEMPORARY, EffectVisualEffect(VFX_FNF_SUMMON_MONSTER_1), GetLocation(oClone));
ApplyEffectToObject(DURATION_TYPE_TEMPORARY, EffectVisualEffect(VFX_DUR_IOUNSTONE_BLUE), oPC, 5.0);
AssignCommand(oPC, AddToParty(oPC, oClone));
// tell clone to do it's checks
AssignCommand(oClone, Actions());
}
}
save script as “ac_tag of itemâ€
be sure item as property unique power self , or unique power and nuber of time to unlimeted just for your testing yu can change that at any time
build mod checking script only, no need to build anything else and test. I prefer the 2nd way because you mod event act item can get rather large with way1). If i missed any thing let me know.
I almost forgot for way2) you need to gointo you module on load and make sure it looks like this:
// * Item Event Scripts: The game's default event scripts allow routing of all item related events
// * into a single file, based on the tag of that item. If an item's tag is "test", it will fire a
// * script called "test" when an item based event (equip, unequip, acquire, unacquire, activate,...)
// * is triggered. Check "x2_it_example.nss" for an example.
// * This feature is disabled by default.
SetModuleSwitch (MODULE_SWITCH_ENABLE_TAGBASED_SCRIPTS, TRUE);
if (GetModuleSwitchValue (MODULE_SWITCH_ENABLE_TAGBASED_SCRIPTS) == TRUE)
{
// * If Tagbased scripts are enabled, and you are running a Local Vault Server
// * you should use the line below to add a layer of security to your server, preventing
// * people to execute script you don't want them to. If you use the feature below,
// * all called item scrips will be the prefix + the Tag of the item you want to execute, up to a
// * maximum of 16 chars, instead of the pure tag of the object.
// * i.e. without the line below a user activating an item with the tag "test",
// * will result in the execution of a script called "test". If you uncomment the line below
// * the script called will be "1_test.nss"
// SetUserDefinedItemEventPrefix("1_");
}
Greyfort
Modifié par Greyfort, 09 décembre 2010 - 10:36 .