Because the cashmod include already have this.
PHP Code:
#include <amxmodx>
#include <amxmisc>
#include <engine>
#include <fakemeta>
#include <cashmod>
#pragma semicolon 1
new const gszModel_Present[] = "models/present/w_present2.mdl";
new const gszClass_Present[] = "cashmod_present";
new Float:fMaxs[3] =
{
2.0,
2.0,
4.0
};
new Float:fMins[3] =
{
-2.0,
-2.0,
-4.0
};
new const VERSION[] = "1.0.6";
public plugin_init()
{
register_plugin("HNS MoneyMod Present", VERSION, "dinnk. [Idea from FakeNick");
register_clcmd("say /padd", "spawn_present");
register_clcmd("say /pdelete", "remove_present");
register_clcmd("say /pdeleteall", "remove_all");
register_clcmd("say /psave", "save");
register_clcmd("say /pload", "load_all");
register_forward(FM_Touch, "fwTouch");
register_event("HLTV", "eventNewRound", "a", "1=0", "2=0");
}
public plugin_precache()
{
precache_model(gszModel_Present);
}
public eventNewRound()
{
new iEnt;
while( (iEnt = engfunc(EngFunc_FindEntityByString, iEnt, "classname", gszClass_Present)) )
{
remove_entity(iEnt);
}
new szDir[64], szFile[128], szLine[256], fOrigin_File[3][32], szTemp[128], szTemp2[128];
new iLen, iLine;
new Float:fOrigin[3];
get_configsdir(szDir, charsmax(szDir));
new szMap[32];
get_mapname(szMap, charsmax(szMap));
formatex(szFile, charsmax(szFile), "%s/presents/%s_origins.cfg", szDir, szMap);
if( !file_exists(szFile) )
{
server_print("No presents added @ %s", szMap);
return PLUGIN_HANDLED;
}
iLine = read_file(szFile, random_num(0, file_size(szFile, 1)), szLine, charsmax(szLine), iLen);
if( iLine )
{
strtok(szLine, szTemp, charsmax(szTemp), szTemp2, charsmax(szTemp2), '|', 0);
parse(szTemp, fOrigin_File[0], charsmax(fOrigin_File[]), fOrigin_File[1], charsmax(fOrigin_File[]), fOrigin_File[2], charsmax(fOrigin_File[]));
fOrigin[0] = str_to_float(fOrigin_File[0]);
fOrigin[1] = str_to_float(fOrigin_File[1]);
fOrigin[2] = str_to_float(fOrigin_File[2]);
func_spawn(fOrigin);
}
return PLUGIN_CONTINUE;
}
public load_all(id)
{
if( !access(id, ADMIN_KICK) )
{
console_print(id, "You don't have access to this command!");
return PLUGIN_HANDLED;
}
new iEnt;
while( (iEnt = engfunc(EngFunc_FindEntityByString, iEnt, "classname", gszClass_Present)) )
{
remove_entity(iEnt);
}
new szDir[64], szFile[128];
get_configsdir(szDir, charsmax(szDir));
new szMap[32];
get_mapname(szMap, charsmax(szMap));
formatex(szFile, charsmax(szFile), "%s/presents/%s_origins.cfg", szDir, szMap);
new sFileOrigin[3][32], iLine = 0, iLength, szText[256];
new Float:fOrigin[3];
while( read_file(szFile, iLine++, szText, charsmax(szText), iLength) )
{
parse(szText, sFileOrigin[0], charsmax(sFileOrigin[]), sFileOrigin[1], charsmax(sFileOrigin[]), sFileOrigin[2], charsmax(sFileOrigin[]));
fOrigin[0] = str_to_float(sFileOrigin[0]);
fOrigin[1] = str_to_float(sFileOrigin[1]);
fOrigin[2] = str_to_float(sFileOrigin[2]);
func_spawn(fOrigin);
}
Print(id, "Loaded %i presents!", iLine);
return PLUGIN_HANDLED;
}
public spawn_present(id)
{
if( !access(id,ADMIN_KICK) )
{
return;
}
new Float:fOrigin[3], iOrigin[3];
get_user_origin(id, iOrigin, 3);
IVecFVec(iOrigin, fOrigin);
if( (engfunc(EngFunc_PointContents, fOrigin) != CONTENTS_SKY) && (engfunc(EngFunc_PointContents, fOrigin) != CONTENTS_SOLID) )
{
func_spawn(fOrigin);
Print(id, "Successfully created present at origins: [^x04 %d^x03 ], [^x04 %d^x03 ], [^x04 %d^x03 ]!", iOrigin[0], iOrigin[1], iOrigin[2]);
Print(id, "Now save the origins with command^x04 !psave^x03 !");
}
else
{
Print(id, "Sorry, that location isn't available!");
}
}
public remove_present(id)
{
if( !access(id,ADMIN_KICK) )
{
return;
}
new iEnt, iBody;
get_user_aiming(id, iEnt, iBody);
if( pev_valid(iEnt) )
{
if( IsPresent(iEnt) )
{
remove_entity(iEnt);
Print(id, "Present successfully removed. Now refresh the save file with the command^x04 !psave^x03 !");
}
else
{
Print(id, "Sorry, you must aim at a present!");
}
}
}
public remove_all(id)
{
if( !access(id, ADMIN_KICK) )
{
return;
}
new iEnt = -1, iCount;
iCount = 0;
while( (iEnt = engfunc(EngFunc_FindEntityByString, iEnt, "classname", gszClass_Present)) )
{
iCount++;
remove_entity(iEnt);
}
Print(id, "All presents removed!^x04 [^x03 Presents: %i^x04 ]", iCount);
Print(id, "Now save the origins with the command^x04 !psave^x03 !");
}
public save(id)
{
if( !access(id, ADMIN_KICK) )
{
return;
}
new szDir[64], szFile[128], szBuffer[256], iEnt = -1, iCount;
new Float:fEntOrigin[3];
get_configsdir(szDir, charsmax(szDir));
new szMap[32];
get_mapname(szMap, charsmax(szMap));
formatex(szFile, charsmax(szFile), "%s/presents/%s_origins.cfg", szDir, szMap);
if( file_exists(szFile) )
{
delete_file(szFile);
}
while( (iEnt = engfunc(EngFunc_FindEntityByString, iEnt, "classname", gszClass_Present)) )
{
pev(iEnt, pev_origin, fEntOrigin);
formatex(szBuffer, charsmax(szBuffer), "%f %f %f", fEntOrigin[0], fEntOrigin[1], fEntOrigin[2]);
write_file(szFile, szBuffer, -1);
iCount++;
}
Print(id, "Successfully saved all present origins^x04 (%d)^x03 for map^x04 %s^x03!", iCount, szMap);
}
public func_spawn(Float:fOrigin[3])
{
new iEnt = create_entity("info_target");
if( !iEnt || !is_valid_ent(iEnt) )
{
Print(0, "Failed to create MoneyMod-Present!");
return PLUGIN_HANDLED;
}
entity_set_string(iEnt, EV_SZ_classname, gszClass_Present);
entity_set_int(iEnt, EV_INT_solid, SOLID_BBOX);
entity_set_int(iEnt, EV_INT_movetype, MOVETYPE_NONE);
entity_set_model(iEnt, gszModel_Present);
entity_set_size(iEnt, fMins, fMaxs);
entity_set_origin(iEnt, fOrigin);
return PLUGIN_HANDLED;
}
public fwTouch(id, iEnt)
{
if( IsPresent(iEnt) )
{
new szName[32], iCash;
get_user_name(id, szName, charsmax(szName));
set_hudmessage(0, 255, 0, -1.0, 0.3, 0, 0.0, 4.0, 0.1, 0.1, -1);
if( random_num(1, 100) == 1 )
{
iCash = 200;
show_hudmessage(0, "LOL!! %s was lucky and gained a present with 500$!", szName);
}
else
{
iCash = random_num(50, 150);
show_hudmessage(0, "%s: Found the present and was given %i$!", szName, iCash);
}
cm_set_user_cash(id, (cm_get_user_cash(id) + iCash));
remove_entity(iEnt);
}
return FMRES_HANDLED;
}
bool:IsPresent(iEnt)
{
if( is_valid_ent(iEnt) )
{
new szClass[35];
pev(iEnt, pev_classname, szClass, charsmax(szClass));
if( equal(szClass, gszClass_Present) )
{
return true;
}
}
return false;
}