-
Frage zur Anwendung von LeGo-Funktionen RemoveFrom- und PutInslot
Ich nehm das am besten mal aus dem Scriptbin-Topic raus.
Also es geht um diese beiden in der EngineAdr_G1 definierten funktionen:
Code:
//========================================
// Vob an Npc hängen
//========================================
func int oCNpc_PutInSlot(var c_npc slf, var string SlotName, var int oCVobPtr, var int SlotID) {
CALL_IntParam(SlotID);
CALL_PtrParam(oCVobPtr);
CALL_zStringPtrParam(SlotName);
CALL__thiscall(MEM_InstToPtr(slf), oCNpc__PutInSlot);
return CALL_RetValAsInt();
};
//========================================
// Vob von Npc entfernen
//========================================
func void oCNpc_RemoveFromSlot(var c_npc slf, var string SlotName, var int retVal, var int SlotID) {
CALL_IntParam(SlotID);
CALL_PutRetValTo(_@(retVal));
CALL_zStringPtrParam(SlotName);
CALL__thiscall(MEM_InstToPtr(slf), oCNpc__RemoveFromSlot);
};
Ich bin mir unsicher, was in das Feld SlotID eingetragen werden soll. bzw wie ich die ID des Slots rauskriege.
Auch weiß ich nicht mit Sicherheit, wie ich z.B. ein Item in eine Ptr umwandle. Bei Vobs ist das kein Thema, aber hier...
Und was ist retVal? Return Value? Also ob ich was zurückhaben möchte? Was bringt mir das? Oder wird der Wert gebraucht um in der anderen Funktion das Event anzusprechen?
Aktuell würde ich das ja so versuchen:
Code:
var C_NPC her;
var int PtrCatcher;
her=Hlp_getNpc(hero);
PtrCatcher=oCNpc_PutInSlot(her, "ZS_RIGHTHAND", MEM_InstToPtr(itmwpickaxe), 1);
oCNpc_RemoveFromSlot(her, "ZS_RIGHTHAND", PtrCatcher, 1);
Vielleicht weiß ja jemand wie man das gut erklärt
"Das erinnert doch sehr erfreulich an das, was man sich als Gothicfan wünscht!"
-Korallenkette
Geändert von Bisasam (08.01.2021 um 03:10 Uhr)
-
Da es in beiden Funktionen um das Einsetzen von Dingen in Slots geht, pack ich das hier mal rein.
Die Funktion HandleDynamicWeaponVisual von Sektenspinner scheint unter G1 nicht zu laufen.
Die Konstanten-Definition aus dem Original habe ich rausgenommen, da diese in den EngineAdr vorhanden sind.
Ich habe die aktuelle EngineAdr_G1, die auch geparst wird.
Da CreateInvItem in G1 nicht die globale Variable item befüllt, habe ich die Zeile Npc_GetInvItem hinzugefügt.
Diese hat in früheren Tests zuverlässig funktioniert.
Der Code nun:
Code:
func void HandleDynamicWeaponVisual(var int itemEquipped, var int itemReadied) {
var oCItem weap;
if (Npc_HasReadiedMeleeWeapon(hero) || Npc_HasReadiedRangedWeapon(hero)) {
weap = Npc_GetReadiedWeapon(hero);
if (Hlp_GetInstanceID(weap) == itemEquipped) {
//remove from slot
CALL_IntParam(true); //kill effect
CALL_IntParam(false); //dont drop
CALL_zStringPtrParam("ZS_RIGHTHAND");
CALL__thiscall(MEM_InstToPtr(hero), oCNpc__RemoveFromSlot);
//exchange items
Npc_RemoveInvItem(hero, itemEquipped);
CreateInvItem(hero, itemReadied);
Npc_GetInvItem(hero,itemReadied);
//put in Slot
CALL_IntParam(true); //is in inventory
CALL_PtrParam(MEM_InstToPtr(item));
if (weap.flags & ITEM_BOW) {
CALL_zStringPtrParam("ZS_LEFTHAND"); //bogen links!
} else {
CALL_zStringPtrParam("ZS_RIGHTHAND");
};
CALL__thiscall(MEM_InstToPtr(hero), oCNpc__PutInSlot);
};
} else {
var int doIt; doIt = false;
weap = Npc_GetEquippedMeleeWeapon(hero);
if (Hlp_GetInstanceID(weap) == itemReadied) { doIt = true; };
weap = Npc_GetEquippedRangedWeapon(hero);
if (Hlp_GetInstanceID(weap) == itemReadied) { doIt = true; };
if (doIt) {
CreateInvItem(hero, itemEquipped);
EquipWeapon(hero, itemEquipped);
Npc_RemoveInvItem(hero, itemReadied);
};
};
};
Ich rufe ihn in einer Frame-Schleife auf:
Code:
HandleDynamicWeaponVisual(ItMw_1H_Club_01, ItMw_1H_Poker_01);
Beide Items existieren. In G2 gehts auch, aber hier läuft irgendwas falsch.
Ich weiß, dass es in G1 keine Items mit Effekten gibt. Daher habe ich mal testweise den Call fürs Löschen des Effektes rausgenommen. Aber es passiert das gleiche.
Meldung des zSpy:
Code:
00:58 Info: 5 C: Creating Sound DrawSound_WO.wav (single) .... <zSndMSS.cpp,#1037>
00:58 Fault: 0 Q: [start of stacktrace]
00:58 Fault: 0 Q: ASMINT_CALLMYEXTERNAL() + 5 bytes
00:58 Fault: 0 Q: ASM_RUNONCE() + 77 bytes
00:58 Fault: 0 Q: CALLINT_MAKECALL(6971008, 0) + 263 bytes
00:58 Fault: 0 Q: CALL__STDCALL(6971008) + 21 bytes
00:58 Fault: 0 Q: CALL__THISCALL(233545128, 6971008) + 73 bytes
00:58 Fault: 0 Q: HANDLEDYNAMICWEAPONVISUAL(14969, 14970) + 105 bytes
00:58 Fault: 0 Q: RAGSCHLEIFE() + 45 bytes
00:58 Fault: 0 Q: [end of stacktrace]
00:58 Fault: 0 Q: Exception handler was invoked. Ikarus tried to print a Daedalus-Stacktrace to zSpy. Gothic will now crash and probably give you a stacktrace of its own.
"Das erinnert doch sehr erfreulich an das, was man sich als Gothicfan wünscht!"
-Korallenkette
-
Hello Bisasam,
There is a small difference between G1 and G2A versions of function oCNpc_RemoveFromSlot. G1 version has only 1 parameter. G1 version (available in LeGo):
Code:
func void oCNpc_RemoveFromSlot(var c_npc slf, var string SlotName, var int retVal, var int SlotID) {
CALL_IntParam(SlotID);
CALL_PutRetValTo(_@(retVal));
CALL_zStringPtrParam(SlotName);
CALL__thiscall(MEM_InstToPtr(slf), oCNpc__RemoveFromSlot);
};
In this function however HandleDynamicWeaponVisual G2A version is used - which has 2 parameters:
Code:
func void HandleDynamicWeaponVisual(var int itemEquipped, var int itemReadied) {
...
CALL_IntParam(true); //kill effect
CALL_IntParam(false); //dont drop
CALL_zStringPtrParam("ZS_RIGHTHAND");
CALL__thiscall(MEM_InstToPtr(hero), oCNpc__RemoveFromSlot);
...
};
Maybe you can comment out original code and use instead predefined functions from LeGo:
Code:
func void HandleDynamicWeaponVisual(var int itemEquipped, var int itemReadied) {
var oCItem weap;
if (Npc_HasReadiedMeleeWeapon(hero) || Npc_HasReadiedRangedWeapon(hero)) {
weap = Npc_GetReadiedWeapon(hero);
if (Hlp_GetInstanceID(weap) == itemEquipped) {
//remove from slot
//CALL_IntParam(true); //kill effect
//CALL_IntParam(false); //dont drop
//CALL_zStringPtrParam("ZS_RIGHTHAND");
//CALL__thiscall(MEM_InstToPtr(hero), oCNpc__RemoveFromSlot);
var int retVal;
oCNpc_RemoveFromSlot (hero, "ZS_RIGHTHAND", retVal, 0);
//exchange items
Npc_RemoveInvItem(hero, itemEquipped);
CreateInvItem(hero, itemReadied);
Npc_GetInvItem (hero,itemReadied);
//put in Slot
//CALL_IntParam(true); //is in inventory
//CALL_PtrParam(MEM_InstToPtr(item));
//if (weap.flags & ITEM_BOW) {
// CALL_zStringPtrParam("ZS_LEFTHAND"); //bogen links!
//} else {
// CALL_zStringPtrParam("ZS_RIGHTHAND");
//};
//CALL__thiscall(MEM_InstToPtr(hero), oCNpc__PutInSlot);
if (weap.flags & ITEM_BOW) {
oCNPC_PutInSlot (hero, "ZS_LEFTHAND", _@ (item), 1);
} else {
oCNPC_PutInSlot (hero, "ZS_RIGHTHAND", _@ (item), 1);
};
};
} else {
var int doIt; doIt = false;
weap = Npc_GetEquippedMeleeWeapon(hero);
if (Hlp_GetInstanceID(weap) == itemReadied) { doIt = true; };
weap = Npc_GetEquippedRangedWeapon(hero);
if (Hlp_GetInstanceID(weap) == itemReadied) { doIt = true; };
if (doIt) {
CreateInvItem(hero, itemEquipped);
EquipWeapon(hero, itemEquipped);
Npc_RemoveInvItem(hero, itemReadied);
};
};
};
In case of oCNpc_RemoveFromSlot I am not sure what retVal is, it returns for me 0 value.
-
Thanks, Fawkes. Youre always a great help.
This Code here works 100%. Tested it multiple times:
Code:
func void HandleDynamicWeaponVisual(var int itemEquipped, var int itemReadied) {
var oCItem weap;
var int ReturnWert;
if (Npc_HasReadiedMeleeWeapon(hero) || Npc_HasReadiedRangedWeapon(hero)) {
weap = Npc_GetReadiedWeapon(hero);
if (Hlp_GetInstanceID(weap) == itemEquipped) {
//remove from slot
oCNpc_RemoveFromSlot(hero, "ZS_RIGHTHAND", ReturnWert, 0);
//exchange items
Npc_RemoveInvItem(hero, itemEquipped);
CreateInvItem(hero, itemReadied);
Npc_GetInvItem(hero,itemReadied); //Befüllt globale var item
//put in Slot
if (weap.flags & ITEM_BOW) {
ReturnWert=oCNpc_PutInSlot(hero, "ZS_LEFTHAND", _@(item), 1);
} else {
ReturnWert=oCNpc_PutInSlot(hero, "ZS_RIGHTHAND", _@(item), 1);
};
};
} else {
var int doIt; doIt = false;
weap = Npc_GetEquippedMeleeWeapon(hero);
if (Hlp_GetInstanceID(weap) == itemReadied) { doIt = true; };
weap = Npc_GetEquippedRangedWeapon(hero);
if (Hlp_GetInstanceID(weap) == itemReadied) { doIt = true; };
if (doIt) {
CreateInvItem(hero, itemEquipped);
EquipWeapon(hero, itemEquipped);
Npc_RemoveInvItem(hero, itemReadied);
};
};
};
Ill update the part in the ScriptBin.
But if Lehona or Gottfried could explain what the heck the ReturnValue does, Id be grateful
"Das erinnert doch sehr erfreulich an das, was man sich als Gothicfan wünscht!"
-Korallenkette
Berechtigungen
- Neue Themen erstellen: Nein
- Themen beantworten: Nein
- Anhänge hochladen: Nein
- Beiträge bearbeiten: Nein
|