Raised This Month: $32 Target: $400
 8% 

Ghost Recorder


Post New Thread Reply   
 
Thread Tools Display Modes
Brad
AMX Mod X Team Member
Join Date: Jun 2004
Old 03-10-2009 , 08:29   Re: Ghost Recorder
Reply With Quote #11

Quote:
Originally Posted by Brad View Post
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.
Brad is offline
TeddyDesTodes
Senior Member
Join Date: Oct 2008
Location: 10.25.15.210
Old 03-10-2009 , 20:36   Re: Ghost Recorder
Reply With Quote #12

Fixed Post(hopefully)
Fixed plugin and added some more features
__________________
TeddyDesTodes is offline
Send a message via ICQ to TeddyDesTodes
BOYSplayCS
BANNED
Join Date: Apr 2008
Location: Gainesville, FL
Old 03-10-2009 , 20:58   Re: Ghost Recorder
Reply With Quote #13

That is a perfect balance that you used, good job fixing it. Use that format from now on.
BOYSplayCS is offline
joaquimandrade
Veteran Member
Join Date: Dec 2008
Location: Portugal
Old 03-10-2009 , 21:56   Re: Ghost Recorder
Reply With Quote #14

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 
__________________

Last edited by joaquimandrade; 03-11-2009 at 01:56.
joaquimandrade is offline
BOYSplayCS
BANNED
Join Date: Apr 2008
Location: Gainesville, FL
Old 03-10-2009 , 22:02   Re: Ghost Recorder
Reply With Quote #15

When using coordinates with Origin always use x, y and z - not 0, 1 and 2.
BOYSplayCS is offline
xPaw
Retired AMX Mod X Moderator
Join Date: Jul 2008
Old 03-11-2009 , 04:21   Re: Ghost Recorder
Reply With Quote #16

PHP Code:
enum COORDINATES
{
    
X,
    
Y,
    
Z

its total useless...
__________________
xPaw is offline
TeddyDesTodes
Senior Member
Join Date: Oct 2008
Location: 10.25.15.210
Old 03-11-2009 , 06:57   Re: Ghost Recorder
Reply With Quote #17

ok i will commit some changes later today
but i dont need this:
Quote:
Originally Posted by joaquimandrade View Post
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
__________________
TeddyDesTodes is offline
Send a message via ICQ to TeddyDesTodes
joaquimandrade
Veteran Member
Join Date: Dec 2008
Location: Portugal
Old 03-11-2009 , 09:33  
Reply With Quote #18

Quote:
Originally Posted by xPaw View Post
PHP Code:
enum COORDINATES
{
    
X,
    
Y,
    
Z

its total useless...
Yes. Making the code more readable totally sucks.

Quote:
Originally Posted by TeddyDesTodes View Post
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.
__________________

Last edited by YamiKaitou; 03-11-2009 at 10:15.
joaquimandrade is offline
YamiKaitou
Has a lovely bunch of coconuts
Join Date: Apr 2006
Location: Texas
Old 03-11-2009 , 10:14   Re: Ghost Recorder
Reply With Quote #19

Quote:
Originally Posted by joaquimandrade View Post
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)
__________________
ProjectYami Laboratories

I do not browse the forums regularly anymore. If you need me for anything (asking questions or anything else), then PM me (be descriptive in your PM, message containing only a link to a thread will be ignored).
YamiKaitou is offline
TeddyDesTodes
Senior Member
Join Date: Oct 2008
Location: 10.25.15.210
Old 03-11-2009 , 10:20   Re: Ghost Recorder
Reply With Quote #20

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
__________________
TeddyDesTodes is offline
Send a message via ICQ to TeddyDesTodes
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 02:14.


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