@@ -150,14 +150,26 @@ int CFunctions::amxLoad(lua_State *luaVM) {
150
150
return 1 ;
151
151
}
152
152
153
- char buff[256 ];
154
- snprintf (buff, sizeof (buff), " %s/mods/deathmatch/resources/[gamemodes]/[amx]/%s/%s" , fs::current_path ().string ().c_str (), resName, amxName);
155
- fs::path amxPath = buff;
156
- amxPath = fs::canonical (amxPath);
153
+ lua_State* theirLuaVM = pModuleManager->GetResourceFromName (resName);
154
+ if (theirLuaVM == nullptr ) {
155
+ using namespace std ::string_literals;
156
+ std::string errMsg = " resource " s + resName + " does not exist!" ;
157
+ lua_pushboolean (luaVM, false );
158
+ lua_pushstring (luaVM, errMsg.c_str ());
159
+ return 2 ;
160
+ }
161
+
162
+ char amxPath[256 ];
163
+ if (!pModuleManager->GetResourceFilePath (theirLuaVM, amxName, amxPath, 256 ))
164
+ {
165
+ lua_pushboolean (luaVM, false );
166
+ lua_pushstring (luaVM, " file not found" );
167
+ return 2 ;
168
+ }
157
169
158
170
// Load .amx
159
171
AMX *amx = new AMX;
160
- int err = aux_LoadProgram (amx, buff , NULL );
172
+ int err = aux_LoadProgram (amx, amxPath , NULL );
161
173
if (err != AMX_ERR_NONE) {
162
174
delete amx;
163
175
lua_pushboolean (luaVM, 0 );
@@ -196,17 +208,17 @@ int CFunctions::amxLoad(lua_State *luaVM) {
196
208
197
209
// Save info about the amx
198
210
AMXPROPS props;
199
- props.filePath = amxPath. string () ;
211
+ props.filePath = amxPath;
200
212
props.resourceName = resName;
201
- props.resourceVM = pModuleManager-> GetResourceFromName (resName) ;
213
+ props.resourceVM = theirLuaVM ;
202
214
203
215
lua_register (props.resourceVM , " pawn" , CFunctions::pawn);
204
216
loadedAMXs[amx] = props;
205
217
206
218
lua_getfield (luaVM, LUA_REGISTRYINDEX, " amx" );
207
219
lua_getfield (luaVM, -1 , resName);
208
220
if (lua_isnil (luaVM, -1 )) {
209
- lua_newtable (luaVM);
221
+ lua_newtable (luaVM);
210
222
lua_setfield (luaVM, -3 , resName);
211
223
}
212
224
0 commit comments