Sun
Knowledge is power - France is bacon
- Joined
- Jan 26, 2015
- Messages
- 334
- Solutions
- 22
- Reaction score
- 249
TFS 0.4 r3884
Hello. For a couple of days now I've been trying to make edits in my movement.cpp to load both event="function" value="onEquipItem" and script="xxx.lua" together in the same line.(only one can be loaded at a time by default as they cancel eachother out in c++)
I'm a total noob in c++ and these sources are confusing af to someone like me, so I made notes from myself of everything I figured out to make it less confusing, which you can find in the spoiler tag below.
and
are loaded in movements.xml by event="function" value="onEquipItem" and event="funtion" value="onDeEquipItem",
while in the sources the "onEquipItem & onDeEquipItem Functions" are loaded by:
the thing to notice here is "equipFunction = EquipItem;" and "equipFunction = DeEquipItem;"
as those 2 lines are what's actually making value="oneEquipItem" and value="onDeEquipItem" load the c++ EquipItem function.
The problem here is that:
is what loads the luascript function to make it read & load the luascript.
Unless you noticed,
is not only loading the luascript function
but also blocking (equipFunction = EquipItem; )
I think the best solution would be to create another "equipFunction" but with a different name and make another xml function name.
Something like ("equipBoth = EquipItem; ) in c++ and (both="equip") in xml this way we could load both the c++ function "EquipItem" and
the exhaust luascript without having it interfere with other xml lines which we don't want it to affect.
I'm not even sure how or if it can be done the way I'm thinking. Perhaps my "solution" isn't even the best.
I tried just copying & pasting all the lines with equipFunction in both movement.cpp & movement.h & renaming the lines
and put something like:
in movements.cpp inside of
just beneath:
But it seems as though it's not as simple as that.
movement.cpphttp://movement.cpp
movement.h
Any help is very appreciated.
If I happen to figure out a soultion I'll post it in case any1 else is looking for the same thing
Hello. For a couple of days now I've been trying to make edits in my movement.cpp to load both event="function" value="onEquipItem" and script="xxx.lua" together in the same line.(only one can be loaded at a time by default as they cancel eachother out in c++)
I'm a total noob in c++ and these sources are confusing af to someone like me, so I made notes from myself of everything I figured out to make it less confusing, which you can find in the spoiler tag below.
Code:
bool MoveEvent::EquipItem(MoveEvent* moveEvent, Player* player, Item* item, slots_t slot, bool isCheck)
and
Code:
bool MoveEvent::DeEquipItem(MoveEvent*, Player* player, Item* item, slots_t slot, bool isRemoval)
are loaded in movements.xml by event="function" value="onEquipItem" and event="funtion" value="onDeEquipItem",
while in the sources the "onEquipItem & onDeEquipItem Functions" are loaded by:
Code:
bool MoveEvent::loadFunction(const std::string& functionName)
{
std::string tmpFunctionName = asLowerCaseString(functionName);
if(tmpFunctionName == "onstepinfield")
stepFunction = StepInField;
else if(tmpFunctionName == "onaddfield")
moveFunction = AddItemField;
else if(tmpFunctionName == "onequipitem")
equipFunction = EquipItem;
else if(tmpFunctionName == "ondeequipitem")
equipFunction = DeEquipItem;
else
{
std::clog << "[Warning - MoveEvent::loadFunction] Function \"" << functionName << "\" does not exist." << std::endl;
return false;
}
m_scripted = EVENT_SCRIPT_FALSE;
return true;
}
the thing to notice here is "equipFunction = EquipItem;" and "equipFunction = DeEquipItem;"
as those 2 lines are what's actually making value="oneEquipItem" and value="onDeEquipItem" load the c++ EquipItem function.
The problem here is that:
Code:
bool MoveEvent::fireEquip(Player* player, Item* item, slots_t slot, bool boolean)
{
if(isScripted())
return executeEquip(player, item, slot, boolean);
return equipFunction(this, player, item, slot, boolean);
}
is what loads the luascript function to make it read & load the luascript.
Unless you noticed,
Code:
return equipFunction(this, player, item, slot, boolean);
but also blocking (equipFunction = EquipItem; )
I think the best solution would be to create another "equipFunction" but with a different name and make another xml function name.
Something like ("equipBoth = EquipItem; ) in c++ and (both="equip") in xml this way we could load both the c++ function "EquipItem" and
the exhaust luascript without having it interfere with other xml lines which we don't want it to affect.
I'm not even sure how or if it can be done the way I'm thinking. Perhaps my "solution" isn't even the best.
I tried just copying & pasting all the lines with equipFunction in both movement.cpp & movement.h & renaming the lines
and put something like:
Code:
if(readXMLString(p, "both", strValue))
{
if(tmpStrValue == "equip")
equipFunction = EquipItem;
else if(tmpStrValue == "deequip")
equipFunction = DeEquipItem;
else
std::clog << "[Warning - MoveEvent::configureMoveEvent] Unknown exhaust type \"" << strValue << "\"" << std::endl;
}
Code:
bool MoveEvent::configureEvent(xmlNodePtr p)
Code:
if(readXMLString(p, "slot", strValue))
{
std::string tmpStrValue = asLowerCaseString(strValue);
if(tmpStrValue == "head")
slot = SLOTP_HEAD;
else if(tmpStrValue == "necklace")
slot = SLOTP_NECKLACE;
else if(tmpStrValue == "backpack")
slot = SLOTP_BACKPACK;
else if(tmpStrValue == "armor")
slot = SLOTP_ARMOR;
else if(tmpStrValue == "left-hand")
slot = SLOTP_LEFT;
else if(tmpStrValue == "right-hand")
slot = SLOTP_RIGHT;
else if(tmpStrValue == "hands" || tmpStrValue == "two-handed")
slot = SLOTP_TWO_HAND;
else if(tmpStrValue == "hand" || tmpStrValue == "shield")
slot = SLOTP_RIGHT | SLOTP_LEFT;
else if(tmpStrValue == "legs")
slot = SLOTP_LEGS;
else if(tmpStrValue == "feet")
slot = SLOTP_FEET;
else if(tmpStrValue == "ring")
slot = SLOTP_RING;
else if(tmpStrValue == "ammo" || tmpStrValue == "ammunition")
slot = SLOTP_AMMO;
else if(tmpStrValue == "pickupable")
slot = SLOTP_RIGHT | SLOTP_LEFT | SLOTP_AMMO;
else if(tmpStrValue == "wherever" || tmpStrValue == "any")
slot = SLOTP_WHEREEVER;
else
std::clog << "[Warning - MoveEvent::configureMoveEvent] Unknown slot type \"" << strValue << "\"" << std::endl;
}
movement.cpphttp://movement.cpp
movement.h
Any help is very appreciated.
If I happen to figure out a soultion I'll post it in case any1 else is looking for the same thing