Author Topic: [FilterScript] Math reaction-test. (Configurable prize and start time!)  (Read 300 times)

greentarch

  • Global Moderator
  • Newbie
  • ********
  • Posts: 16
  • Reputation: 0
    • View Profile
Title says all, it's a math reaction test system.
It's configurable, you can edit it at the #defines.
Please give me credits if you are gonna use it.
I made this a long time ago (7th of March 2013)

Code: [Select]
/*
mathTest
    coded by greentarch
    at the 7th of March 2013.
   
All rights reserved.
*/

#include    < a_samp >

#define     iTime       1   // A contest start each ... minutes.
#define     minPrize    2000 // Minimum prize
#define    maxPrize    9000 // Max prize

// #define     mathDebug /* For debug purposes only */

new
iNumbers[ 3 ],
iPrize,
bool: mathRunning,
mathTimer[ 2 ];

public OnFilterScriptInit( )
{
print ( "\nMath test has been loaded!\n" );
mathTimer[ 0 ] = SetTimer( "math", iTime * 60000, false );

return true;
}

stock resetNumbers( )
{
for ( new i= 0; i < 3; ++ i )
{
    iNumbers[ i ] = -1;
}

iPrize = -1;

return true;
}

stock randomEx( min, max )
return random( max - min ) + min;

forward math( );
public math( )
{
new
szStr[ 128 ];
iNumbers[ 0 ] = random( 400 );
iNumbers[ 1 ] = random( 700 );
iNumbers[ 2 ] = ( iNumbers[ 0 ] + iNumbers[ 1 ] );
iPrize = randomEx( minPrize, maxPrize );

format( szStr, 128, "{33FF33}[MATH-TEST]: {FFFFFF}%i + %i = ? {33FF33}( Prize : $%i )", iNumbers[ 0 ], iNumbers[ 1 ], iPrize );
SendClientMessageToAll( -1, szStr );
mathTimer[ 1 ] = SetTimer( "mathEnd", iTime * 60000, false );
mathRunning = true;

#if defined mathDebug
print( "math has been called!" );
printf( "%d+%d=%d", iNumbers[ 0 ], iNumbers[ 1 ], iNumbers[ 2 ] );
#endif

return true;
}

forward mathEnd( );
public mathEnd( )
{
new
    szStr[ 128 ];
format( szStr, 128, "{33FF33}[MATH-TEST]: {FFFFFF}No one has answered the math test! ( Answer : %i )", iNumbers[ 2 ] );
SendClientMessageToAll( -1, szStr );
mathRunning = false;
SendClientMessageToAll( -1, "{33FF33}[MATH-TEST]: {FFFFFF}A new test will start in " #iTime " minutes!" );
resetNumbers( );

mathTimer[ 0 ] = SetTimer( "math", iTime * 60000, false );

return true;
}

public OnPlayerText( playerid, text[ ] )
{
if ( mathRunning )
{
    if ( strval( text ) == iNumbers[ 2 ] )
    {
        new
            szName[ MAX_PLAYER_NAME ],
            szStr[ 128 ];
GetPlayerName( playerid, szName, MAX_PLAYER_NAME );
format( szStr, 128, "{33FF33}[MATH-TEST]: {FFFFFF}%s has correctly answered the math test and won $%d! - Answer : %i", szName, iPrize, iNumbers[ 2 ] );
SendClientMessageToAll( -1, szStr );
GivePlayerMoney( playerid, iPrize );
SendClientMessageToAll( -1, "{33FF33}[MATH-TEST]: {FFFFFF}A new test will start in " #iTime " minutes!" );

mathRunning = false;

KillTimer( mathTimer[ 1 ] );
KillTimer( mathTimer[ 0 ] );
mathTimer[ 0 ] = SetTimer( "math", iTime * 60000, false );
}
}

return true;
}

Share on Bluesky Share on Facebook