Senior Member
|
07-17-2023
, 16:40
Re: file in .ini mode
|
#6
|
Quote:
Originally Posted by lexzor
using the file format that fysiks used
PHP Code:
#include <amxmodx>
#include <amxconst>
new g_DispActive[128]
new g_DispSndFail[128]
new g_DispSndDestroy[128]
new g_DispSndIdle[128]
new g_DispModelPrint[128]
new g_DispModel[128]
new g_DispModelVip[128]
new g_DispModelGibsR[128]
new g_DispModelGibsB[128]
new g_DispSprSmoke[128]
new g_DispSprHealLifeB[128]
new g_DispSprHealLifeR[128]
public plugin_precache()
{
new iFile = fopen("path/to/file.ini", "r")
if(!iFile)
{
// file failed to be opened: doesn't exist or another cause
return
}
new szLine[256], szVariableIndentifier[128], szModelPath[128]
while(fgets(iFile, szLine, charsmax(szLine))) //while can read
{
//check if: line is empty || line is commented
if(szLine[0] == EOS || szLine[0] == ';')
{
continue; // continue reading, don't parse this line
}
parse(szLine, szVariableIndentifier, charsmax(szVariableIndentifier), szModelPath, charsmax(szModelPath)) // parse line looking like: "variable_name" "path_to_model"
if(equal(szVariableIndentifier, "g_DispActive")) // checking if the variable name from the file correspond with one of the variables
{
if(file_exists(szModelPath)) // check if model exists
{
precache_model(szModelPath)// precache it
copy(g_DispActive, charsmax(g_DispActive), szModelPath) //copy the model to the variable so you can use it later in the plugin
}
else
{
log_error(AMX_ERR_NOTFOUND, "File %s does not exists", szModelPath) // log an error if model path is incorrect or file doesn't exists
}
}
else if(equal(szVariableIndentifier, "g_DispSndFail"))
{
if(file_exists(szModelPath))
{
precache_model(szModelPath)
copy(g_DispSndFail, charsmax(g_DispSndFail), szModelPath)
}
else
{
log_error(AMX_ERR_NOTFOUND, "File %s does not exists", szModelPath)
}
}
else if()///do this for every variable
{
//...
}
else //add this in case the a variable name doesn't correspond with existing one
{
log_error(AMX_ERR_NOTFOUND, "Varibale name %s does not exists", szVariableIndentifier)
}
}
}
|
I'm studying everything but I got lost in some things
My precache was like this but I have a doubt what to do with g_DamageSounds, xBulletsSounds
PHP Code:
public plugin_precache()
{
new iFile = fopen("amxmodx/config/dispenser.ini", "r")
if(!iFile)
{
return
}
new szLine[256], szVariableIndentifier[128], szModelPath[128]
while(fgets(iFile, szLine, charsmax(szLine))) //while can read
{
//check if: line is empty || line is commented
if(szLine[0] == EOS || szLine[0] == ';')
{
continue; // continue reading, don't parse this line
}
parse(szLine, szVariableIndentifier, charsmax(szVariableIndentifier), szModelPath, charsmax(szModelPath)) // parse line looking like: "variable_name" "path_to_model"
if(equal(szVariableIndentifier, "g_DispActive")) // checking if the variable name from the file correspond with one of the variables
{
if(file_exists(szModelPath)) // check if model exists
{
precache_model(szModelPath)// precache it
copy(g_DispActive, charsmax(g_DispActive), szModelPath) //copy the model to the variable so you can use it later in the plugin
}
else
{
log_error(AMX_ERR_NOTFOUND, "File %s does not exists", szModelPath) // log an error if model path is incorrect or file doesn't exists
}
}
else if(equal(szVariableIndentifier, "g_DispSndFail"))
{
if(file_exists(szModelPath))
{
precache_model(szModelPath)
copy(g_DispSndFail, charsmax(g_DispSndFail), szModelPath)
}
else
{
log_error(AMX_ERR_NOTFOUND, "File %s does not exists", szModelPath)
}
}
else if(equal(szVariableIndentifier, "g_DispSndDestroy"))
{
if(file_exists(szModelPath))
{
precache_model(szModelPath)
copy(g_DispSndDestroy, charsmax(g_DispSndDestroy), szModelPath)
}
else
{
log_error(AMX_ERR_NOTFOUND, "File %s does not exists", szModelPath)
}
}
else if(equal(szVariableIndentifier, "g_DispSndIdle"))
{
if(file_exists(szModelPath))
{
precache_model(szModelPath)
copy(g_DispSndIdle, charsmax(g_DispSndIdle), szModelPath)
}
else
{
log_error(AMX_ERR_NOTFOUND, "File %s does not exists", szModelPath)
}
}
else if(equal(szVariableIndentifier, "g_DispModelPrint"))
{
if(file_exists(szModelPath))
{
precache_model(szModelPath)
copy(g_DispModelPrint, charsmax(g_DispModelPrint), szModelPath)
}
else
{
log_error(AMX_ERR_NOTFOUND, "File %s does not exists", szModelPath)
}
}
else if(equal(szVariableIndentifier, "g_DispModel"))
{
if(file_exists(szModelPath))
{
precache_model(szModelPath)
copy(g_DispModel, charsmax(g_DispModel), szModelPath)
}
else
{
log_error(AMX_ERR_NOTFOUND, "File %s does not exists", szModelPath)
}
}
else if(equal(szVariableIndentifier, "g_DispModelVip"))
{
if(file_exists(szModelPath))
{
precache_model(szModelPath)
copy(g_DispModelVip, charsmax(g_DispModelVip), szModelPath)
}
else
{
log_error(AMX_ERR_NOTFOUND, "File %s does not exists", szModelPath)
}
}
else if(equal(szVariableIndentifier, "g_DispModelGibsR"))
{
if(file_exists(szModelPath))
{
precache_model(szModelPath)
copy(g_DispModelGibsR, charsmax(g_DispModelGibsR), szModelPath)
}
else
{
log_error(AMX_ERR_NOTFOUND, "File %s does not exists", szModelPath)
}
}
else if(equal(szVariableIndentifier, "g_DispModelGibsR"))
{
if(file_exists(szModelPath))
{
precache_model(szModelPath)
copy(g_DispModelGibsR, charsmax(g_DispModelGibsR), szModelPath)
}
else
{
log_error(AMX_ERR_NOTFOUND, "File %s does not exists", szModelPath)
}
}
else if(equal(szVariableIndentifier, "g_DispModelGibsB"))
{
if(file_exists(szModelPath))
{
precache_model(szModelPath)
copy(g_DispModelGibsB, charsmax(g_DispModelGibsB), szModelPath)
}
else
{
log_error(AMX_ERR_NOTFOUND, "File %s does not exists", szModelPath)
}
}
else if(equal(szVariableIndentifier, "g_DispModelGibsB"))
{
if(file_exists(szModelPath))
{
precache_model(szModelPath)
copy(g_DispModelGibsB, charsmax(g_DispModelGibsB), szModelPath)
}
else
{
log_error(AMX_ERR_NOTFOUND, "File %s does not exists", szModelPath)
}
}
else if(equal(szVariableIndentifier, "g_DispSprSmoke"))
{
if(file_exists(szModelPath))
{
precache_model(szModelPath)
copy(g_DispSprSmoke, charsmax(g_DispSprSmoke), szModelPath)
}
else
{
log_error(AMX_ERR_NOTFOUND, "File %s does not exists", szModelPath)
}
}
else if(equal(szVariableIndentifier, "g_DispSprHealLifeB"))
{
if(file_exists(szModelPath))
{
precache_model(szModelPath)
copy(g_DispSprHealLifeB, charsmax(g_DispSprHealLifeB), szModelPath)
}
else
{
log_error(AMX_ERR_NOTFOUND, "File %s does not exists", szModelPath)
}
}
else if(equal(szVariableIndentifier, "g_DispSprHealLifeR"))
{
if(file_exists(szModelPath))
{
precache_model(szModelPath)
copy(g_DispSprHealLifeR, charsmax(g_DispSprHealLifeR), szModelPath)
}
else
{
log_error(AMX_ERR_NOTFOUND, "File %s does not exists", szModelPath)
}
}
else //add this in case the a variable name doesn't correspond with existing one
{
log_error(AMX_ERR_NOTFOUND, "Varibale name %s does not exists", szVariableIndentifier)
}
}
g_PrecSprFlare3 = precache_model("sprites/flare3.spr")
g_PrecSprLife = precache_model("sprites/teste/dispenser1.spr")
/*g_PrecSprSmoke = precache_model(g_DispSprSmoke)
g_PrecSprHealLifeB = precache_model(g_DispSprHealLifeB)
g_PrecSprHealLifeR = precache_model(g_DispSprHealLifeR)
g_PrecDispModelGibsR = precache_model(g_DispModelGibsR)
g_PrecDispModelGibsB = precache_model(g_DispModelGibsB)
xModelIndex[0] = precache_model(g_DispModelVip)
xModelIndex[1] = precache_model(g_DispModel)
precache_model(g_DispModelPrint)
precache_model(g_DispModel)
precache_model(g_DispModelVip)
precache_sound(g_DispActive)
precache_sound(g_DispSndFail)
precache_sound(g_DispSndDestroy)
precache_sound(g_DispSndIdle)*/
static i
for(i = 0; i < sizeof(g_DamageSounds);i++)
engfunc(EngFunc_PrecacheSound, g_DamageSounds[i])
for(i = 0; i < sizeof(xBulletsSounds);i++)
engfunc(EngFunc_PrecacheSound, xBulletsSounds[i])
}
PHP Code:
write_short(g_PrecSprSmoke)
New
PHP Code:
write_short(szModelPath)
?
|
|