AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Approved Plugins (https://forums.alliedmods.net/forumdisplay.php?f=8)
-   -   Ghost Recorder (https://forums.alliedmods.net/showthread.php?t=87314)

TeddyDesTodes 03-09-2009 20:34

Ghost Recorder
 
4 Attachment(s)
Ghost Recorder
TeddyDesTodes 2009

.: Description / Features :.

This plugin let player record their movements and saves them for later replay
this is useful for jumping against urself on kreedzmaps(or bhop or whatever)
like in racegame the ghost driver
Default settings are :
- 6 Saveslots per map and player
- unlimited recording time
- recording with 1,5Kbyte/s


.: CVars :.
  • recorder_ignore_velocity <0|1> | Default: 0 Switch to ignore Velocity data disabled by default (very buggy and not useful)
  • recorder_maxsize <size in kb> | Default: 2048 to disable set to 0
.: Client Commands :.
  • say /demomenu - shows the menu
.: Credits :.
  • Empī - helping me with cast stuff
.: Changelog :.

version 0.24 (record_rendermode.amxx)
  • added addToFullPack forward that only the owner of the Ghost can see it
  • added menuItem for visibility in rendermenu
  • possibly fixed servercrash when someone is recording and replaying and server is restarting/mapchanging
  • fixed Loading of other recording
  • added progress indicator to playback hud
  • fixed missing sequences
  • changed fileformat and lowered size of header (new FileVersion is 24) (still compatible with FileVersion 22)
version 0.23
  • moved recorddir to "addons/amxmodx/data/record/"
  • added menu to choose Rendermode for the Ghost
  • added the possibility to load recordings from other players
  • changed filelayout a bit
  • added extension ".rec" to files
  • added Possibility to restrict filesizes
  • optimized old code
version 0.21(record.amxx)
  • added automatic dir creation
  • removed unused vars
version 0.2 initially release

.: Known Bugs :.
  • Problems with pev_sequence and pev_gaitsequence (some sequences are not shown (upper body goes to default position)) (dont know how to fix this)(fixed in 0.24)
  • Sizerestriction not working hopefully fixed inn next version)
.: How to install :.
  • Install like normal plugin
  • create a folder called "record/" in your data direcory (files will be save to this directory)(created automatically since 0.23)
.: Note :.
  • Server need write and read rights fro save directory
  • per default files will be written with 1.5Kbyte/sec ( 15 min equal 1.4MB) so be sure u have enought space on your server or change RECLIMITER to a bigger value or loweer the amount of save slots
  • byterate is calculated like this : 48*(1/RECLIMITER) this is max byterate per sec
  • if you set RECLIMITER to 0.0 every playerthink will be recorded wich on normal server is approx. 66 times/sec (3.1Kbyte/s (2.7MB for 15 min))
  • EDIT: just tested 20 min produced 1.5MB file
  • didn't test on 64bit system dont know if it will work since datatypes are a bit different
  • only tested in CStrike
  • you could test it here 85.14.217.35:1338
.: ToDo :.
  • tweaking visual stuff if needed
.: FileStructure (Version 22) :.

[HEADER][FLOAT][THINK][THINK][THINK][THINK]... ...[THINK]

the file is read until no data is found first float is useless

Header:
Code:

INT        Version [22]
INT        Unix Timestamp
String[33]    PLayer Name
String[33]    Steam ID
String[33]    Map
String[33]    Hostname
String[65]    Weapon Model
String[65]    Player Model

Think:
Code:

Float    origin[0]
Float    origin[1]
Float    origin[2]
Float    angles[0]
Float    angles[1]
Float    angles[2]
Float    velocity[0]
Float    velocity[1]
Float    velocity[2]
Int    sequence
Int    gaitsequence
Float    Time to next think

See servers running Ghost Recorder

FuZ!on 03-09-2009 20:47

Re: Ghost Recorder
 
Very, very interesting.

Exolent[jNr] 03-09-2009 21:17

Re: Ghost Recorder
 
1. g_TotalThink is never used for any purpose.

2. You should use mkdir() if the save directory doesn't exist in the plugin_init().

That's all I looked at right now. I may look more later.

TeddyDesTodes 03-09-2009 21:21

Re: Ghost Recorder
 
1. ok will change but why is no warning thrown...

2. does file_exists work for dirs?

EDIT: nvm all...

uploaded fixed version

Brad 03-09-2009 23:18

Re: Ghost Recorder
 
Edit your initial post and make sure the bulk of it is in the normal font and format. You must post in a manner consistent with the norm here.

Wentix 03-10-2009 03:36

Re: Ghost Recorder
 
Can you add support for play recorded actions on current player, not ghost-player?

Very interesting plugin =).

xPaw 03-10-2009 04:19

Re: Ghost Recorder
 
@Wentix:
pwned 255 block, ands lets do it 60x? :mrgreen:

BOYSplayCS 03-10-2009 05:25

Re: Ghost Recorder
 
Wow, this is great!

TeddyDesTodes 03-10-2009 07:10

Re: Ghost Recorder
 
@xPaw
??????

xPaw 03-10-2009 07:54

Re: Ghost Recorder
 
You should store mapname at plugin_init, and players steamid on client_authorized(), instead of getting it tons of times

Brad 03-10-2009 08:29

Re: Ghost Recorder
 
Quote:

Originally Posted by Brad (Post 777500)
Edit your initial post and make sure the bulk of it is in the normal font and format. You must post in a manner consistent with the norm here.

Do this, please. I don't look the part, but I am a moderator and plugin approver.

TeddyDesTodes 03-10-2009 20:36

Re: Ghost Recorder
 
Fixed Post(hopefully)
Fixed plugin and added some more features

BOYSplayCS 03-10-2009 20:58

Re: Ghost Recorder
 
That is a perfect balance that you used, good job fixing it. Use that format from now on.

joaquimandrade 03-10-2009 21:56

Re: Ghost Recorder
 
Hello.

I like to review code so i leave you some tips:

Don't do

PHP Code:

register_forward(FM_Think,"fm_ghost_think",0)
register_forward(FM_PlayerPostThink,"fm_plr_prethink",0

in plugin_init.

Use instead two counters. One for players recording other for ghosts. Then, inside start_replay (if the ghost is created sucessfully) check the ghost counter. If its 0, call the register_forward(FM_Think.... If its value is bigger don't do nothing. Increment it. In fm_ghost_think after doing
PHP Code:

fm_remove_entity(g_GhostWeapon[owner]);
fm_remove_entity(g_Ghost[owner]); 

decrement it. If its value is 0 do unregister_forward.

The same for plr_prethink. I think you get the point.

I also recommend you to use the same approach to
PHP Code:

set_task(1.0,"hud",_,_,_,"b",0

Other tip, less useful but good for code reading:

When dealing with coordinates use a enum like:

PHP Code:

enum COORDINATES
{
    
X,
    
Y,
    
Z


Why?

Because its more easier to read:


PHP Code:

fwrite(g_FileHandler[id],_:origin[X],BLOCK_INT)
fwrite(g_FileHandler[id],_:origin[Y],BLOCK_INT)
fwrite(g_FileHandler[id],_:origin[Z],BLOCK_INT

than
PHP Code:

fwrite(g_FileHandler[id],_:origin[0],BLOCK_INT)
fwrite(g_FileHandler[id],_:origin[1],BLOCK_INT)
fwrite(g_FileHandler[id],_:origin[2],BLOCK_INT

Other thing. Check if you need to remove ghosts on disconnect.

Other thing.

Use a function to compare vectors like:

PHP Code:

equal_vectors(vector1[COORDINATES],vector2[COORDINATES])
{
    for (new 
COORDINATES:i=X;i<COORDINATES;i++)
        if(
vector1[i] != vector2[i])
            return 
false;
    
    return 
true;


Then you can change this:

PHP Code:

if((g_LastAngle[id][0] == angles[0] && g_LastAngle[id][1] == angles[1] && g_LastAngle[id][2] == angles[2] ) && (g_LastOrigin[id][0] == origin[0] && g_LastOrigin[id][1] == origin[1] && g_LastOrigin[id][2] == origin[2] ) && (g_LastVelocity[id][0] == veloc[0] &&    g_LastVelocity[id][1] == veloc[1] && g_LastVelocity[id][2] == veloc[2])) return FMRES_IGNORED 

to

PHP Code:

if(equal_vectors(g_LastAngle[id],angles) && equal_vectors(g_LastOrigin[id],origin) && equal_vectors(g_LastVelocity[id],veloc))
            return 
FMRES_IGNORED 

Other thing. Use enums to make groups of data when needed. Example:

PHP Code:

enum COORDINATES
{
    
X,
    
Y,
    
Z
}  

enum POSITION_DATA
{
    
ANGLES,
    
ORIGIN,
    
VELOCITY
}

new 
Float:positionData[POSITION_DATA][COORDINATES

With that you could then change:

PHP Code:

fwrite(g_FileHandler[id],_:angles[0],BLOCK_INT)
fwrite(g_FileHandler[id],_:angles[1],BLOCK_INT)
fwrite(g_FileHandler[id],_:angles[2],BLOCK_INT)
fwrite(g_FileHandler[id],_:origin[0],BLOCK_INT)
fwrite(g_FileHandler[id],_:origin[1],BLOCK_INT)
fwrite(g_FileHandler[id],_:origin[2],BLOCK_INT)
fwrite(g_FileHandler[id],_:veloc[0],BLOCK_INT)
fwrite(g_FileHandler[id],_:veloc[1],BLOCK_INT)
fwrite(g_FileHandler[id],_:veloc[2],BLOCK_INT

to
PHP Code:

for(new POSITION_DATA:i=ANGLES;i<POSITION_DATA;i++)
    for(new 
COORDINATES:j=X;j<COORDINATES;j++)
        
fwrite(g_FileHandler[id],_:positionData[i][j] ,BLOCK_INT

and

PHP Code:

        g_LastAngle[id][0] = angles[0]
        
g_LastAngle[id][1] = angles[1]
        
g_LastAngle[id][2] = angles[2]
        
g_LastOrigin[id][0] = origin[0]
        
g_LastOrigin[id][1] = origin[1]
        
g_LastOrigin[id][2] = origin[2]
        
g_LastVelocity[id][0] = veloc[0]
        
g_LastVelocity[id][1] = veloc[1]
        
g_LastVelocity[id][2] = veloc[2

to

PHP Code:

for(new POSITION_DATA:i=ANGLES;i<POSITION_DATA;i++)
    for(new 
COORDINATES:j=X;j<COORDINATES;j++)
        
g_LastPositionData[id][i][j] = positionData[i][j

Another thing.

Use the bool tag.

Then change
PHP Code:

g_isRecording[id] == 

to

PHP Code:

!g_isRecording[id

and

PHP Code:

g_isRecording[id] = 

to

PHP Code:

g_isRecording[id] = true 


BOYSplayCS 03-10-2009 22:02

Re: Ghost Recorder
 
When using coordinates with Origin always use x, y and z - not 0, 1 and 2.

xPaw 03-11-2009 04:21

Re: Ghost Recorder
 
PHP Code:

enum COORDINATES
{
    
X,
    
Y,
    
Z


its total useless...

TeddyDesTodes 03-11-2009 06:57

Re: Ghost Recorder
 
ok i will commit some changes later today
but i dont need this:
Quote:

Originally Posted by joaquimandrade (Post 778205)
Other thing. Check if you need to remove ghosts on disconnect.

because if i close the file via fclose ghost cant read data anymore and kills itself checked that

joaquimandrade 03-11-2009 09:33

Quote:

Originally Posted by xPaw (Post 778290)
PHP Code:

enum COORDINATES
{
    
X,
    
Y,
    
Z


its total useless...

Yes. Making the code more readable totally sucks.

Quote:

Originally Posted by TeddyDesTodes (Post 778341)
ok i will commit some changes later today
but i dont need this:

because if i close the file via fclose ghost cant read data anymore and kills itself checked that

You have
PHP Code:

if(!is_user_connected(owner)) return FMRES_IGNORED

in fm_ghost_think so double check if the ghost entity is really removed on client_disconnect. You need to have it removed so that the first part of what i've said to you works like it have to.

YamiKaitou 03-11-2009 10:14

Re: Ghost Recorder
 
Quote:

Originally Posted by joaquimandrade (Post 778430)
Yes. Making the code more readable totally sucks.

IMO, I find it easier to read the numbers than the letters in this case, but it depends on your coding style. Using the enum is not required and will not have any effect on approval status (just mentioning this in case others believe otherwise)

TeddyDesTodes 03-11-2009 10:20

Re: Ghost Recorder
 
Quote:

Originally Posted by joaquimandrade
You have PHP Code:
if(!is_user_connected(owner)) return FMRES_IGNORED;

in fm_ghost_think so double check if the ghost entity is really removed on client_disconnect. You need to have it removed so that the first part of what i've said to you works like it have to.

haha stupid me i think im goin to remove this check since it destroys itself if there is no owner

crazyeffect 03-11-2009 10:40

Re: Ghost Recorder
 
is not working...


--

Also maybe make it ML

TeddyDesTodes 03-11-2009 11:06

Re: Ghost Recorder
 
ofc its working showing 2 servers one of 'em is mine

ML? maybe later? just need to fix some errors can some of you please try to reproduce a crash i've got (dont know weather its related to this plugin) if someone replays a Ghost please mapchange (if server crashes its probably this plugin) thx and please post serverlog

joaquimandrade 03-11-2009 11:08

Re: Ghost Recorder
 
Quote:

Originally Posted by YamiKaitou (Post 778456)
IMO, I find it easier to read the numbers than the letters in this case, ...

This is that kind of situation where each one should decide for himself. I prefer the enum because i prefer:

PHP Code:

for(new COORDINATES:j=X;j<COORDINATES;j++)
        
g_LastPositionData[id][i][j] = positionData[i][j

or

PHP Code:

for(new COORDINATES:j=X;j<=Z;j++)
        
g_LastPositionData[id][i][j] = positionData[i][j


to
PHP Code:

 for(new j=0;j<3;j++)
        
g_LastPositionData[id][i][j] = positionData[i][j

and

PHP Code:

g_LastPositionData[id][ANGLES][Y] = positionData[ANGLES][Y



to

PHP Code:

g_LastPositionData[id][ANGLES][1] = positionData[ANGLES][1

Quote:

Originally Posted by YamiKaitou (Post 778456)
Using the enum is not required and will not have any effect on approval status (just mentioning this in case others believe otherwise)

I believe that in fact this plugin would be promptly approved even if Teddy didn't change a line to it since it seems to me that the idea is very original, and its well coded.
__

Teddy, other thing:

avoid to return in the middle of the code.

Example:

Instead of:

PHP Code:

if(ago RECLIMITER) return FMRES_IGNORED
        rate 
floatdiv(1.0,ago)
        
rate floatmul(rate,48.0)
        
g_Rate[id] = floatround(rate);
        
pev(id,pev_origin,origin)
        
pev(id,pev_velocity,veloc)
        ... 

make it:

PHP Code:

if(ago >= RECLIMITER)
{
    
rate floatdiv(1.0,ago)
    
rate floatmul(rate,48.0)
    
g_Rate[id] = floatround(rate);
    
pev(id,pev_origin,origin)
    
pev(id,pev_velocity,veloc)
    
pev(id,pev_angles,angles)
    
sequence pev(id,pev_sequence)
    
gaitsequence pev(id,pev_gaitsequence)
    ... 

Its easier to see how the code flux.

TeddyDesTodes 03-11-2009 12:58

Re: Ghost Recorder
 
Quote:

Originally Posted by joaquimandrade
Teddy, other thing:

avoid to return in the middle of the code.

dont know weather its bad coding style to make return but i hate long/big if clauses and i've seen the return thing in many plugins

joaquimandrade 03-11-2009 14:14

Re: Ghost Recorder
 
Quote:

Originally Posted by TeddyDesTodes (Post 778534)
dont know weather its bad coding style to make return but i hate long/big if clauses and i've seen the return thing in many plugins

But with that clauses (big or not), you better see what's happening in the plugin. Anyway, this is my opinion and i just wanted to telling it to you.

TeddyDesTodes 03-11-2009 16:02

Re: Ghost Recorder
 
Uploaded new version with some fixes
if someone could take a look at addToFullPack im not happy with it but thats the only way i've got it to work

r14170 09-03-2010 15:31

Re: Ghost Recorder
 
AWESOME!

caffeine 01-09-2011 13:08

Re: Ghost Recorder
 
gj, i will copy some code soon.

wombad321 08-05-2016 04:33

Re: Ghost Recorder
 
Cool plugin, but it only works on amxmodx 1.8.2. Is it possible to rewrite the plug on amxmodx 1.8.3?

JocAnis 03-06-2019 21:31

Re: Ghost Recorder
 
ye i want to ask same quesiton...does anyone know how to convert code to 1.9 ? problem is: it is recording the demo, but when you try to play that demo its just:

Playback started
after 0.1
Playback finished

maybe 1.9 doesnt work well with fread(..) ?

krudge137 06-27-2022 21:26

Re: Ghost Recorder
 
Quote:

Originally Posted by JocAnis (Post 2642262)
ye i want to ask same quesiton...does anyone know how to convert code to 1.9 ? problem is: it is recording the demo, but when you try to play that demo its just:

Playback started
after 0.1
Playback finished

maybe 1.9 doesnt work well with fread(..) ?

Exactly, it's so sad it doesn't work with upper amxx versions, such a good plugin!

Infamanious 06-27-2022 23:42

Re: Ghost Recorder
 
Interesting plugin. I'm surprised noone has attempted to create a plugin similar to one i saw on sourcemod where a bot copies your exact movements and completes surf levels to showcase your record and/or to show people how to complete those particular levels. Also this plugin could be pretty dangerous if someone decided to use it to execute malicious code lol.

krudge137 06-28-2022 04:06

Re: Ghost Recorder
 
Quote:

Originally Posted by Infamanious (Post 2782605)
Interesting plugin. I'm surprised noone has attempted to create a plugin similar to one i saw on sourcemod where a bot copies your exact movements and completes surf levels to showcase your record and/or to show people how to complete those particular levels. Also this plugin could be pretty dangerous if someone decided to use it to execute malicious code lol.

++

bigdaddy424 01-21-2023 18:10

Re: Ghost Recorder
 
Quote:

Originally Posted by Infamanious (Post 2782605)
Interesting plugin. I'm surprised noone has attempted to create a plugin similar to one i saw on sourcemod where a bot copies your exact movements and completes surf levels to showcase your record and/or to show people how to complete those particular levels. Also this plugin could be pretty dangerous if someone decided to use it to execute malicious code lol.

tru


All times are GMT -4. The time now is 19:20.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.