ULX

Author Topic: Porting Observation Mode  (Read 1379 times)

0 Members and 1 Guest are viewing this topic.

Offline Zombine

  • Newbie
  • *
  • Posts: 19
  • Karma: 0
Porting Observation Mode
« on: May 16, 2014, 08:33:50 PM »
Hiya! So just recently I discovered that Evolve has an observation mode feature, which allows for a special type of spectate. It stores the user's location, eye position, and angle, then makes the user transparent, sets them to noclip mode, and god modes them. Their name cannot be seen (to my knowledge) while in this mode, and they can still use their weapons and the likes. The neat feature though, is that when the command is executed again/turned off (I'd like to make it a toggleable command) it restores their vulnerability by ungodding them, making them visible and then restores their initial data before the command was executed, meaning it's as if you never moved.

I'm attempting to learn lua and everything, but Evolve is a tad funky for me, so if someone would like to help me out, it would be greatly appreciated. Here is the Evolve code. If something like this has already been made, then please let me know.

The usage I was attempting to put it in was !observe [player] where player is optional, putting the target into the mode or revoking the mode if executed again on the same target.

Code: [Select]
local PLUGIN = {}

PLUGIN.Title = "Observation"
PLUGIN.Description = "Noclip around hidden."
PLUGIN.Author = "`impulse"
PLUGIN.ChatCommand = "observe"
PLUGIN.Usage = "[player] [1/0]"
PLUGIN.Privileges = { "Observation Mode" }

PLUGIN.SavedPoints = {}

function PLUGIN:Call( ply, args )
if ( ply:EV_HasPrivilege( "Observation Mode" ) ) then

local players = evolve:FindPlayer( args, ply, true )
local enabled = ( tonumber( args[ #args ] ) or 1 ) > 0

for _, pl in ipairs( players ) do

if ( !enabled ) then

if ( self.SavedPoints[ pl ] == nil ) then

evolve:Notify( pl, evolve.colors.red, "You are not in observation mode!" )
return ""

end

pl:SetRenderMode( RENDERMODE_NORMAL )
pl:SetColor( 255, 255, 255, 255 )
pl:SetMoveType( MOVETYPE_WALK )
pl:GodDisable()
pl:SetPos( self.SavedPoints[ pl ].pos )
pl:SetEyeAngles( self.SavedPoints[ pl ].ang )
self.SavedPoints[ pl ] = nil

for _, w in ipairs( pl:GetWeapons() ) do

w:SetRenderMode( RENDERMODE_NORMAL )
w:SetColor( 255, 255, 255, 255 )

end

else

if ( self.SavedPoints[ pl ] ~= nil ) then

evolve:Notify( pl, evolve.colors.red, "You are already in observation mode!" )
return ""

end

self.SavedPoints[ pl ] = {
pos = pl:GetPos(),
ang = pl:EyeAngles()
}

pl:SetRenderMode( RENDERMODE_NONE )
pl:SetColor( 255, 255, 255, 0 )
pl:SetMoveType( MOVETYPE_NOCLIP )
pl:GodEnable()

for _, w in ipairs( ply:GetWeapons() ) do

w:SetRenderMode( RENDERMODE_NONE )
w:SetColor( 255, 255, 255, 0 )

end

end

end

if ( #players > 0 ) then

if ( enabled ) then

evolve:Notify( evolve.colors.blue, ply:Nick(), evolve.colors.white, " has made ", evolve.colors.red, evolve:CreatePlayerList( players ), evolve.colors.white, " enter observation mode." )

else

evolve:Notify( evolve.colors.blue, ply:Nick(), evolve.colors.white, " has made ", evolve.colors.red, evolve:CreatePlayerList( players ), evolve.colors.white, " exit observation mode." )

end

else

evolve:Notify( ply, evolve.colors.red, evolve.constants.noplayers )

end

else

evolve:Notify( ply, evolve.colors.red, evolve.constants.notallowed )

end

end

function PLUGIN:Menu( arg, players )

if ( arg ) then

table.insert( players, arg )
RunConsoleCommand( "ev", "observe", unpack( players ) )

else

return "Observation", evolve.category.actions, { { "Enter", 1 }, { "Exit", 0 } }

end

end

evolve:RegisterPlugin( PLUGIN )