Setting plot flag when an item is in Inventory
#1
Posté 29 juin 2010 - 03:38
Any help would be greatly appreciated.
#2
Posté 29 juin 2010 - 06:40
Option 1.- Override player_core.nss. It is located in _Core scripts, but it seems the worst option because it can do your module incompatible with other modules.
Option 2.- Take a look here http://social.biowar...1/index/1736512, but it may be a little messy if you are a newbie.
Option 3.- Since I don't know if the item is given by somebody or removed from a placeable, I think this is the best option. I am gonna suppose that the item that will set the plot flag is an item that you have created. Then set the ITEM_SEND_ACQUIRED_EVENT to 1 in the local variables of that item.
This way when the item is acquired (whatever it means, I hope "added to inventory" is considered "acquired"), it will send an EVENT_TYPE_CAMPAIGN_ITEM_ACQUIRED event to you module core script.
So, here is an example.
I have created this resources:
my_plot.plo (this is the plot that contains the flag, for example MY_ITEM_ACQUIRED, that I want to set when my_item is picked up)
my_item.uti (remember to set the ITEM_SEND_ACQUIRED_EVENT variable)
The module core script shoudl look like this (warning, code not tested):
#include "events_h"
#include "global_objects_h"
#include "wrappers_h"
#include "utility_h"
#include "plt_my_plot"
void main()
{
int bEventHandled = FALSE;
event ev = GetCurrentEvent();
int nEvent = GetEventType(ev);
switch (nEvent)
{
case EVENT_TYPE_CAMPAIGN_ITEM_ACQUIRED:
{
object oAcquirer = GetEventCreator(ev); // item acquierer
// the item that's been acquired
object oItemAcquired = GetEventObject(ev, 0);
if (GetTag(oItemAcquired) == "my_item")
{
WR_SetPlotFlag(PLT_MY_PLOT, MY_ITEM_ACQUIRED, TRUE);
}
break;
}
}
if (!bEventHandled)
{
HandleEvent(ev, RESOURCE_SCRIPT_MODULE_CORE);
}
}
Modifié par _L_o_B_o_, 29 juin 2010 - 06:44 .
#3
Posté 29 juin 2010 - 07:28
There are a couple of main ways to do this safely:ITSSEXYTIME wrote...
Alright so I'm trying to write a script that causes a plot flag to be set when an item is picked up. However, I have no idea on how to do this. I'm assuming I have to have a script check to see if the item is picked up and then if it is found change the plot flag with WR_SetPlotFlag but I've no idea how to format this to accomplish this. (Newbie at scripting).
- Option 1: Plot Item + ITEM_SEND_ACQUIRED_EVENT + Main Flag
- Option 2: Normal Item + Defined Flag
Option 1
You can use this option where you want the player to find or receive an item which they can't voluntarily dispose of. Once you have created the item set the Plot Item property to True. This prevents the player using it, selling it or other wise doing anything other than carry it around.
Then open the item's Variable pop-up and set the ITEM_SEND_ACQUIRED_EVENT to 1. This tells the scripting to fire an event when this item is picked up by or given to the player.
Next create a plot with a Main Flag to indicate when the player has acquired the item. For example I might have a plot for collecting plants named sj_gathering and in that a plot flag named SJ_GATHERING_SPECIMEN_ACQUIRED.
Finally we need to script it so that when the item is acquired and fires the event our plot flag is updated. The event fired is the EVENT_TYPE_CAMPAIGN_ITEM_ACQUIRED event and it is sent to the module. So in your module script you have to include the plot (#include "plt_sj_gathering" in my example) and add something like this to the module's event switch block:
case EVENT_TYPE_CAMPAIGN_ITEM_ACQUIRED:
{
// the acquired item is the first entry in the event's object list
string sItemTag = GetTag(GetEventObject(evCurrent, 0));
if(sItemTag == "sj_gathering_specimen")
{
// flag plant a as collected
WR_SetPlotFlag(PLT_SJ_GATHERING, SJ_GATHERING_SPECIMEN_ACQUIRED, TRUE);
bEventHandled = TRUE;
}
break;
}
Option 2
You can use this option where you just want to know if the Player has the item at a certain point but want the Player to be free to use, sell, give away, drop, destroy and otherwise abuse the item.
Once you have created the item you don't have to do anything to it. So no setting Plot Item status or a local variable.
Next create a plot with a Defined Flag to check if the currently has acquired the item. For example I might have a plot for collecting plants named sj_gathering and in that a plot flag named SJ_GATHERING_HAS_SPECIMEN.
Finally we need to script it so that the Defined Flag will tell us if the Player currently has the item in their possession. This script is attached to the plot's Script property and might look something like:
#include "plot_h"
#include "utility_h"
#include "wrappers_h"
#include "plt_sj_gathering"
int StartingConditional()
{
int bResult;
// deconstruct event
event evCurrent = GetCurrentEvent();
int nEventType = GetEventType(evCurrent);
int nPlotFlag = GetEventInteger(evCurrent, 1);
// common variables
object oHero = GetHero();
switch(nEventType)
{
case EVENT_TYPE_SET_PLOT:
{
int nNewValue = GetEventInteger(evCurrent, 2); // value to be assigned
int nOldValue = GetEventInteger(evCurrent, 3); // value currently assigned
switch(nPlotFlag)
{
// NOTE: no Main Flags
}
break;
}
case EVENT_TYPE_GET_PLOT:
{
switch(nPlotFlag)
{
case SJ_GATHERING_HAS_SPECIMEN:
{
bResult = IsObjectValid(GetItemPossessedBy(oHero, "sj_gathering_specimen"));
break;
}
}
break;
}
}
return bResult;
}
Modifié par Sunjammer, 29 juin 2010 - 07:37 .
#4
Posté 29 juin 2010 - 07:43
- Joe Versus the Brecilian is a (slightly more involved) example of Option 1
- Deep Road Courier is an example of Option2
#5
Posté 29 juin 2010 - 09:20
#6
Posté 30 juin 2010 - 04:24
Nevermind got it to compile. Thanks again for all the help guys.
Modifié par ITSSEXYTIME, 30 juin 2010 - 04:47 .





Retour en haut






