@@ -150,14 +150,26 @@ int CFunctions::amxLoad(lua_State *luaVM) {
150150 return 1 ;
151151 }
152152
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+ }
157169
158170 // Load .amx
159171 AMX *amx = new AMX;
160- int err = aux_LoadProgram (amx, buff , NULL );
172+ int err = aux_LoadProgram (amx, amxPath , NULL );
161173 if (err != AMX_ERR_NONE) {
162174 delete amx;
163175 lua_pushboolean (luaVM, 0 );
@@ -196,17 +208,17 @@ int CFunctions::amxLoad(lua_State *luaVM) {
196208
197209 // Save info about the amx
198210 AMXPROPS props;
199- props.filePath = amxPath. string () ;
211+ props.filePath = amxPath;
200212 props.resourceName = resName;
201- props.resourceVM = pModuleManager-> GetResourceFromName (resName) ;
213+ props.resourceVM = theirLuaVM ;
202214
203215 lua_register (props.resourceVM , " pawn" , CFunctions::pawn);
204216 loadedAMXs[amx] = props;
205217
206218 lua_getfield (luaVM, LUA_REGISTRYINDEX, " amx" );
207219 lua_getfield (luaVM, -1 , resName);
208220 if (lua_isnil (luaVM, -1 )) {
209- lua_newtable (luaVM);
221+ lua_newtable (luaVM);
210222 lua_setfield (luaVM, -3 , resName);
211223 }
212224
0 commit comments