23.02.2012, 06:04
I've got this dropped weapon system, and it works like so: it loads through a separate folder OnGameModeInit, and saves on exit, each file handles its own specific weapon, meaning: 1.ini would differ from 2.ini, ect. This is how every one of my dynamic systems are built.
My enum:
GameModeInit & GameModeExit:
/dropwep
LoadWeapons & Loading
Now, my problem is, once I pick up the weapon, it should delete the file (which it does), but the files information still remains in the enum, which I thought LoadWeapons() would update the enum, but apparently it doesn't.
How do I fix this?
My enum:
pawn Код:
enum E_gunVars
{
gunID,
gunAmmo,
Float:gunPos[4],
gunVirtualWorld,
gunInterior
}
new
droppedWepInfo[MAX_DROPPED_WEAPONS][E_gunVars],
WeaponPID[MAX_DROPPED_WEAPONS];
pawn Код:
OnGameModeInit -
for( new w; w < MAX_DROPPED_WEAPONS; w++ )
{
format(wepStr, sizeof(wepStr), "RPMod/Weapons/%d.ini", w);
if(fexist(wepStr))
{
INI_ParseFile(wepStr, "LoadWeapon_%s", .bExtra = true, .extra = w);
WeaponPID[w] = CreateDynamicObject(GetWeaponObjectID(droppedWepInfo[w][gunID]), droppedWepInfo[w][gunPos][0], droppedWepInfo[w][gunPos][1], droppedWepInfo[w][gunPos][2]-1, 0.0, 0.0, 0.0, droppedWepInfo[w][gunVirtualWorld]);
printf("[LOAD] Dropped Weapon ID %d loaded. Weapon ID: %d | Ammo: %d", w, droppedWepInfo[w][gunID], droppedWepInfo[w][gunAmmo]);
}
}
OnGameModeExit -
for( new w; w < MAX_DROPPED_WEAPONS; w++ )
{
format(wepStr, sizeof(wepStr), "RPMod/Weapons/%d.ini", w);
if(fexist(wepStr))
{
new
INI:wepFile = INI_Open(wepStr);
INI_SetTag(wepFile, "weapon");
INI_WriteInt(wepFile, "WeaponID", droppedWepInfo[w][gunID]);
INI_WriteInt(wepFile, "WeaponAmmo", droppedWepInfo[w][gunAmmo]);
INI_WriteFloat(wepFile, "WeaponX", droppedWepInfo[w][gunPos][0]);
INI_WriteFloat(wepFile, "WeaponY", droppedWepInfo[w][gunPos][1]);
INI_WriteFloat(wepFile, "WeaponZ", droppedWepInfo[w][gunPos][2]);
INI_WriteFloat(wepFile, "WeaponA", droppedWepInfo[w][gunPos][3]);
INI_WriteInt(wepFile, "WeaponVirtualWorld", droppedWepInfo[w][gunVirtualWorld]);
INI_WriteInt(wepFile, "WeaponInterior", droppedWepInfo[w][gunInterior]);
INI_Close(wepFile);
DestroyDynamicObject(WeaponPID[w]);
}
}
pawn Код:
CMD:dropwep(playerid, params[])
{
new
Float:wepPos[4],
WeaponID,
fID = GetOpenWeaponID(),
WeaponAmmo,
wepStr[32],
sendStr[128],
p_Name[MAX_PLAYER_NAME]
;
if(GetPlayerWeapon(playerid) != 0 && GetPlayerAmmo(playerid) != 0) //If they have a weapon..
{
GetPlayerPos(playerid, wepPos[0], wepPos[1], wepPos[2]);
GetPlayerFacingAngle(playerid, wepPos[3]);
WeaponID = GetPlayerWeapon(playerid);
WeaponAmmo = GetPlayerAmmo(playerid);
GetPlayerName(playerid, p_Name, sizeof(p_Name));
format(wepStr, sizeof(wepStr), "RPMod/Weapons/%d.ini", fID);
if(!fexist(wepStr))
{
new
INI:wepFile = INI_Open(wepStr);
INI_SetTag(wepFile, "weapon");
INI_WriteInt(wepFile, "WeaponID", WeaponID);
INI_WriteInt(wepFile, "WeaponAmmo", WeaponAmmo);
INI_WriteFloat(wepFile, "WeaponX", wepPos[0]);
INI_WriteFloat(wepFile, "WeaponY", wepPos[1]);
INI_WriteFloat(wepFile, "WeaponZ", wepPos[2]);
INI_WriteFloat(wepFile, "WeaponA", wepPos[3]);
INI_WriteInt(wepFile, "WeaponVirtualWorld", GetPlayerVirtualWorld(playerid));
INI_WriteInt(wepFile, "WeaponInterior", GetPlayerInterior(playerid));
INI_Close(wepFile);
LoadWeapons();
WeaponPID[fID] = CreateDynamicObject(GetWeaponObjectID(droppedWepInfo[fID][gunID]), droppedWepInfo[fID][gunPos][0], droppedWepInfo[fID][gunPos][1], droppedWepInfo[fID][gunPos][2]-1, 80.0, 0.0, 0.0, droppedWepInfo[fID][gunVirtualWorld]);
printf("Test: %d | %d",fID,WeaponPID[fID]);
format(sendStr, sizeof(sendStr), ""#PURPLE"* "#LIME"%s "#PURPLE"has dropped a weapon.", p_Name);
ProxDetector(20.0, playerid, sendStr, c_PURPLE, c_PURPLE, c_PURPLE, c_PURPLE, c_PURPLE);
RemovePlayerWeapon(playerid, WeaponID);
}
}
return 1;
}
pawn Код:
for( new w; w < MAX_DROPPED_WEAPONS; w++ )
{
if(IsPlayerInRangeOfPoint(playerid, 1, droppedWepInfo[w][gunPos][0], droppedWepInfo[w][gunPos][1], droppedWepInfo[w][gunPos][2]))
{
if(GetPlayerVirtualWorld(playerid) == droppedWepInfo[w][gunVirtualWorld] && GetPlayerInterior(playerid) == droppedWepInfo[w][gunInterior])
{
new
wepStr[32];
format(wepStr, sizeof(wepStr), "RPMod/Weapons/%d.ini", w);
GivePlayerWeapon(playerid, droppedWepInfo[w][gunID], droppedWepInfo[w][gunAmmo]);
DestroyDynamicObject(WeaponPID[w]);
printf("%d", WeaponPID[w]);
fremove(wepStr);
LoadWeapons();
}
}
}
pawn Код:
forward LoadWeapon_weapon(wepid, name[], value[]);
public LoadWeapon_weapon(wepid, name[], value[])
{
INI_Int("WeaponID", droppedWepInfo[wepid][gunID]);
INI_Int("WeaponAmmo", droppedWepInfo[wepid][gunAmmo]);
INI_Float("WeaponX", droppedWepInfo[wepid][gunPos][0]);
INI_Float("WeaponY", droppedWepInfo[wepid][gunPos][1]);
INI_Float("WeaponZ", droppedWepInfo[wepid][gunPos][2]);
INI_Float("WeaponA", droppedWepInfo[wepid][gunPos][3]);
INI_Int("WeaponVirtualWorld", droppedWepInfo[wepid][gunVirtualWorld]);
INI_Int("WeaponInterior", droppedWepInfo[wepid][gunInterior]);
return true;
}
stock LoadWeapons()
{
new
wepStr[32];
for( new w = 1; w < MAX_DROPPED_WEAPONS; w++ ) //Reload weapons!
{
format(wepStr, sizeof(wepStr), "RPMod/Weapons/%d.ini", w);
if(fexist(wepStr))
{
INI_ParseFile(wepStr, "LoadWeapon_%s", .bExtra = true, .extra = w);
}
}
return true;
}
How do I fix this?