Telemenu: Fix some bugs and add some improvements

Bugfixes
- a typo error induced by me, id instead of player
- The second teleportation way of this plugin can only be done when the menuactor is not alive.
There is no crouch in death mod or spectator mod, so i remove this useless call. (Line 134 - 139)
Improvements :
- Check mod VEC_DUCK_VIEW only one time.
- Removal of code duplication
This commit is contained in:
Freeman-AM 2014-05-24 15:53:30 +02:00
parent 44b4ff6f05
commit aa67fae7b9

View File

@ -75,12 +75,13 @@ public actionTelMenu(id, key)
if (g_menuOption[id] < 0) /* unlocking position for the first time */ if (g_menuOption[id] < 0) /* unlocking position for the first time */
g_menuOption[id] = 0 g_menuOption[id] = 0
pev(id, pev_origin, g_menuOrigin[id]) getTeleportData(id, g_menuOrigin[id], g_menuVAngle[id])
pev(id, pev_v_angle, g_menuVAngle[id])
if (pev(id, pev_flags) & FL_DUCKING && is_user_alive(id)) if (pev(id, pev_flags) & FL_DUCKING && is_user_alive(id))
SaveInDuckingState(id) SaveInDuckingState(id)
else else
SaveNoDuckingState(id) SaveNoDuckingState(id)
displayTelMenu(id, g_menuPosition[id]) displayTelMenu(id, g_menuPosition[id])
} }
case 8: displayTelMenu(id, ++g_menuPosition[id]) case 8: displayTelMenu(id, ++g_menuPosition[id])
@ -101,79 +102,41 @@ public actionTelMenu(id, key)
if (g_menuOption[id] > 0) if (g_menuOption[id] > 0)
{ {
if ( HasInDuckingStateSaved(id) ) if (HasInDuckingStateSaved(id))
{ {
new sz_modname[16] static Float:VEC_DUCK_VIEW[3] = -1.0
get_modname(sz_modname, charsmax(sz_modname)) if (VEC_DUCK_VIEW[0])
if (equal(sz_modname, "cstrike") // Counter-Strike 1.6
|| equal(sz_modname, "czero") // Counter-Strike: Condition Zero
|| equal(sz_modname, "valve") // Half-Life
|| equal(sz_modname, "tfc") // Team Fortress Classic
|| equal(sz_modname, "gearbox")) // Half-Life: Opposing Force
{ {
set_pev(player, pev_flags, pev(player, pev_flags) | FL_DUCKING) VEC_DUCK_VIEW[0] = 0.0
set_pev(id, pev_view_ofs, {0.0, 0.0, 12.0})
new modname[16]
get_modname(modname, charsmax(modname))
if (equal(modname, "cstrike") // Counter-Strike 1.6
|| equal(modname, "czero") // Counter-Strike: Condition Zero
|| equal(modname, "valve") // Half-Life
|| equal(modname, "tfc") // Team Fortress Classic
|| equal(modname, "ns") // Natural Selection
|| equal(modname, "gearbox")) // Half-Life: Opposing Force
VEC_DUCK_VIEW[2] = 12.0
else if (equal(modname, "dod")) // Day of Defeat
VEC_DUCK_VIEW[2] = 18.0
else if (equal(modname, "ts")) // The Specialists
VEC_DUCK_VIEW[2] = 16.0
} }
else if (equal(sz_modname, "dod")) // Day of Defeat if (VEC_DUCK_VIEW[2])
{ {
set_pev(player, pev_flags, pev(player, pev_flags) | FL_DUCKING) set_pev(id, pev_flags, pev(id, pev_flags) | FL_DUCKING)
set_pev(id, pev_view_ofs, {0.0, 0.0, 18.0}) set_pev(id, pev_view_ofs, VEC_DUCK_VIEW)
} }
else if (equal(sz_modname, "ns")) // Natural Selection
{
set_pev(player, pev_flags, pev(player, pev_flags) | FL_DUCKING)
// Natural Selection handle view_ofs by itself
} }
else if (equal(sz_modname, "ts")) // The Specialists doTeleport(player, g_menuOrigin[id], g_menuVAngle[id])
{
set_pev(player, pev_flags, pev(player, pev_flags) | FL_DUCKING)
set_pev(id, pev_view_ofs, {0.0, 0.0, 16.0})
}
// Don't add this feature for mods that we don't know how their view_ofs work
}
engfunc(EngFunc_SetOrigin, player, g_menuOrigin[id])
set_pev(player, pev_angles, g_menuVAngle[id])
set_pev(player, pev_fixangle, 1)
} else { } else {
new Float:f_origin[3], Float:f_vangle[3] new Float:origin[3], Float:vAngle[3]
pev(id, pev_origin, f_origin) getTeleportData(id, origin, vAngle)
pev(id, pev_v_angle, f_vangle) doTeleport(player, origin, vAngle)
if ( HasInDuckingStateSaved(id) )
{
new sz_modname[16]
get_modname(sz_modname, charsmax(sz_modname))
if (equal(sz_modname, "cstrike") // Counter-Strike 1.6
|| equal(sz_modname, "czero") // Counter-Strike: Condition Zero
|| equal(sz_modname, "valve") // Half-Life
|| equal(sz_modname, "tfc") // Team Fortress Classic
|| equal(sz_modname, "gearbox")) // Half-Life: Opposing Force
{
set_pev(player, pev_flags, pev(player, pev_flags) | FL_DUCKING)
set_pev(id, pev_view_ofs, {0.0, 0.0, 12.0})
}
else if (equal(sz_modname, "dod")) // Day of Defeat
{
set_pev(player, pev_flags, pev(player, pev_flags) | FL_DUCKING)
set_pev(id, pev_view_ofs, {0.0, 0.0, 18.0})
}
else if (equal(sz_modname, "ns")) // Natural Selection
{
set_pev(player, pev_flags, pev(player, pev_flags) | FL_DUCKING)
// Natural Selection handle view_ofs by itself
}
else if (equal(sz_modname, "ts")) // The Specialists
{
set_pev(player, pev_flags, pev(player, pev_flags) | FL_DUCKING)
set_pev(id, pev_view_ofs, {0.0, 0.0, 16.0})
}
// Don't add this feature for mods that we don't know how their view_ofs work
}
engfunc(EngFunc_SetOrigin, player, f_origin)
set_pev(player, pev_angles, f_vangle)
set_pev(player, pev_fixangle, 1)
} }
new authid[32], authid2[32], name[32] new authid[32], authid2[32], name[32]
@ -193,6 +156,19 @@ public actionTelMenu(id, key)
return PLUGIN_HANDLED return PLUGIN_HANDLED
} }
getTeleportData(id, Float:origin[3], Float:vAngle[3])
{
pev(id, pev_origin, origin)
pev(id, pev_v_angle, vAngle)
}
doTeleport(id, const Float:origin[3], const Float:vAngle[3])
{
engfunc(EngFunc_SetOrigin, id, origin)
set_pev(id, pev_angles, vAngle)
set_pev(id, pev_fixangle, 1)
}
displayTelMenu(id, pos) displayTelMenu(id, pos)
{ {
if (pos < 0) if (pos < 0)