View difference between Paste ID: RPLJvXfH and q4FUaR1i
SHOW: | | - or go back to the newest paste.
1
211,6 → 211,8
2
        _type = CREATURE_EVENT_DEATH;
3
    else if(type == "preparedeath")
4
        _type = CREATURE_EVENT_PREPAREDEATH;
5
+    else if(type == "extendedopcode")
6
+        _type = CREATURE_EVENT_EXTENDED_OPCODE;
7
 
8
    return _type;
9
}
10
330,6 → 332,8
11
        return "onDeath";
12
    case CREATURE_EVENT_PREPAREDEATH:
13
        return "onPrepareDeath";
14
+    case CREATURE_EVENT_EXTENDED_OPCODE:
15
+        return "onExtendedOpcode";
16
    case CREATURE_EVENT_NONE:
17
    default:
18
        break;
19
401,6 → 405,8
20
        return "cid, corpse, deathList";
21
    case CREATURE_EVENT_PREPAREDEATH:
22
        return "cid, deathList";
23
+    case CREATURE_EVENT_EXTENDED_OPCODE:
24
+        return "cid, opcode, buffer";
25
    case CREATURE_EVENT_NONE:
26
    default:
27
        break;
28
2145,3 → 2145,57
29
        return 0;
30
    }
31
}
32
+ 
33
+uint32_t CreatureEvent::executeExtendedOpcode(Creature* creature, uint8_t opcode, const std::string& buffer)
34
+{
35
+    //onExtendedOpcode(cid, opcode, buffer)
36
+    if(m_interface->reserveEnv())
37
+    {
38
+        ScriptEnviroment* env = m_interface->getEnv();
39
+        if(m_scripted == EVENT_SCRIPT_BUFFER)
40
+        {
41
+            env->setRealPos(creature->getPosition());
42
+            std::stringstream scriptstream;
43
+            scriptstream << "local cid = " << env->addThing(creature) << std::endl;
44
+            scriptstream << "local opcode = " << (int)opcode << std::endl;
45
+            scriptstream << "local buffer = " << buffer.c_str() << std::endl;
46
+ 
47
+            scriptstream << m_scriptData;
48
+            bool result = true;
49
+            if(m_interface->loadBuffer(scriptstream.str()))
50
+            {
51
+                lua_State* L = m_interface->getState();
52
+                result = m_interface->getGlobalBool(L, "_result", true);
53
+            }
54
+ 
55
+            m_interface->releaseEnv();
56
+            return result;
57
+        }
58
+        else
59
+        {
60
+            #ifdef __DEBUG_LUASCRIPTS__
61
+            char desc[35];
62
+            sprintf(desc, "%s", player->getName().c_str());
63
+            env->setEvent(desc);
64
+            #endif
65
+ 
66
+            env->setScriptId(m_scriptId, m_interface);
67
+            env->setRealPos(creature->getPosition());
68
+     
69
+            lua_State* L = m_interface->getState();
70
+            m_interface->pushFunction(m_scriptId);
71
+            lua_pushnumber(L, env->addThing(creature));
72
+            lua_pushnumber(L, opcode);
73
+            lua_pushlstring(L, buffer.c_str(), buffer.length());
74
+ 
75
+            bool result = m_interface->callFunction(3);
76
+            m_interface->releaseEnv();
77
+            return result;
78
+        }
79
+    }
80
+    else
81
+    {
82
+        std::cout << "[Error - CreatureEvent::executeRemoved] Call stack overflow." << std::endl;
83
+    return 0;
84
+    }
85
+}