View Single Post
  #13  
Old 01-02-2008, 12:00 AM
projectigi projectigi is offline
Registered User
Join Date: Jan 2004
Posts: 403
projectigi is an unknown quantity at this point
well got a little more complicated than i thought in the beginning xD
I'm stuck because of the Bug with the param going to 0(see my other thread here for that), but If you want I will post it even if its not fully finished

NPC VotingControlSystem

PHP Code:
enum
  
{
  
MSG_RES_ERROR,   // 0 == false
  
MSG_RES_OK       // 1 == true
  
}

function 
onCreated()
  {
  
//#CONFIG SECTION
  
this.maxpoints = 5; //Maximum Points per Player
  
this.staff = { "projectigi" };
  
//#END CONFIG SECTION
  
}
  
public function 
applyVPoint( vID, vText, vPoint, pAcc )
  {
  if( 
vPoint % 1 != 0 || vPoint == 0 ) return( MSG_RES_ERROR );
  if( 
player.account.length() <= 0 ) return( MSG_RES_ERROR );
  if( 
this.(@ "votepoints_" @ player.account ).size() == 0 || this.(@ "votepoints_" @ player.account ).length() == 0 )
    {
    
this.(@ "votepoints_" @ player.account ).add( "0" );
    }
  if( ( 
vID != 0 && vID == null ) || vID < 0 || vID.length() <= 0 )
    {
    
vID = getvID( vText );
    if( 
vID == -1 ) return( MSG_RES_ERROR );
    }  
  
temp.fID = -1;
  
temp.pPoints = 0;

  for( 
j = 1; j < this.(@ "votepoints_" @ player.account ).size(); j++ )
    {
    if( 
this.(@ "votepoints_" @ player.account )[ j ][ 0 ] == vID )
      
temp.fID = j;
    
temp.pPoints += ( this.(@ "votepoints_" @ player.account )[ j ][ 1 ] < 0 ? this.(@ "votepoints_" @ player.account )[ j ][ 1 ] * -1 : this.(@ "votepoints_" @ player.account )[ j ][ 1 ] ) * this.votes[ vID ][ 1 ];
    }
  
//if( temp.pPoints == this.maxpoints && vPoint > 0 ) return( MSG_RES_ERROR );
  
if( temp.pPoints > this.maxpoints )
    {
    
sendtorc( "{Vote-Error] Player " @ player.account @ " has more than " @ this.maxpoints @ " points on votes.(Hacker?)" );
    return( 
MSG_RES_ERROR );
    }
//echo( ( vPoint > 0 ? vPoint : vPoint * -1 ) SPC temp.pPoints );
  
if( temp.pPoints + ( vPoint > 0 ? vPoint : vPoint * -1 ) > this.maxpoints && this.votes[ vID ][ 2 ] + this.votes[ vID ][ 3 ] >= 0 ) return( MSG_RES_ERROR );
  if( 
vPoint != this.votes[ vID ][ 1 ] && vPoint != this.votes[ vID ][ 1 ] * -1 ) return( MSG_RES_ERROR );
  if( 
temp.fID == -1 ) this.(@ "votepoints_" @ player.account ).add( { vID, vPoint } );
  else
    {
    
this.(@ "votepoints_" @ player.account )[ temp.fID ][ 1 ] += vPoint;
    
this.(@ "votepoints_" @ player.account )[ 0 ] = temp.pPoints + ( vPoint < 0 ? vPoint * -1 : vPoint );
    }
  
reCalcVotePoints( vID );
  return( 
getVoteList( pAcc ) );
  }
  
public function 
getVoteList( pAcc )
  {
  if( 
pAcc == null || pAcc.length() <= 0 ) return( MSG_RES_ERROR );
  return( { 
this.votes, this.(@ "votepoints_" @ pAcc ) } );
  }
  
function 
reCalcVotePoints( vID )
  {
  
temp.pPointsP = 0;
  
temp.pPointsN = 0;  
  if( ( 
vID != 0 && vID == null ) || vID < 0 || vID.length() <= 0 ) return( MSG_RES_ERROR );
  for( 
temp.a: getstringkeys( "this.votepoints_" ) )
    {
    if( 
this.(@ "votepoints_" @ temp.a ) == null || this.(@ "votepoints_" @ temp.a ).length() == 0 || this.(@ "votepoints_" @ temp.a ).size() <= 1 ) continue;
    
temp.skipfirst = true;
    for( 
temp.b: this.(@ "votepoints_" @ temp.a ) )
      {
      if( 
temp.skipfirst == true )
        {
        
temp.skipfirst = false;
        continue;
        }
      if( 
temp.b[ 0 ] == vID )
        {
        
temp.(@ "pPoints" @ ( temp.b[ 1 ] > 0 ? "P" : "N" ) ) += temp.b[ 1 ];
        }
      }
    }
  
this.votes[ vID ][ 2 ] = temp.pPointsP;
  
this.votes[ vID ][ 3 ] = temp.pPointsN;
  }  
  
public function 
addVote( voteText )
  {
  if( 
player.account in this.staff )
    {
    
this.votes.add( { voteText, 1, 0, 0 } );
    return( 
MSG_RES_OK );  
    }
  return( 
MSG_RES_ERROR );
  }
  
public function 
removeVote( vID, vText )
  {
  if( !( 
player.account in this.staff ) ) return( MSG_RES_ERROR );
  if( 
vID == null || vID < 0 || vID.length() <= 0 )
    {
    
vID = getvID( vText );
    if( 
vID == -1 ) return( MSG_RES_ERROR );
    }
  if( 
this.votes[ vID ][ 0 ] != vText || ( vText.length() == 0 || vText == null || vText <= 0 ) ) return( MSG_RES_ERROR );
  
this.votes.delete( vID );
  return( 
MSG_RES_OK );
  }  
  
function 
getvID( vText )
  {
  if( 
vText == null || vText < 0 || vText.length() <= 0 ) return( -1 );
  
vID = -1;
  for( 
i = 0; i < this.votes.size(); i++ )
    {
    if( 
vText == this.votes[ i ][ 0 ] )
      {
      
vID = i;
      break;
      }
    }
  if( 
vID == -1 ) return( -1 );
  return( 
vID );  
  } 
Weapon:

too long for a post...(17k characters, 10k is limit lol)
http://nopaste.info/1e0eb25243.html
__________________
Reply With Quote