SA-MP Forums Archive
Random Events - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Random Events (/showthread.php?tid=126340)



Random Events - HydraX - 07.02.2010

pawn Код:
C:\Users\Stunt Paradise\Desktop\SAMP R4\pawno\include\cps.inc(140) : warning 208: function with tag result used before definition, forcing reparse
C:\Users\Stunt Paradise\Desktop\SAMP R4\gamemodes\SPV4.pwn(4264) : error 017: undefined symbol "RandomEvent"
C:\Users\Stunt Paradise\Desktop\SAMP R4\gamemodes\SPV4.pwn(4265) : error 017: undefined symbol "RandomEvent"
C:\Users\Stunt Paradise\Desktop\SAMP R4\gamemodes\SPV4.pwn(4271) : error 017: undefined symbol "RandomEvent"
C:\Users\Stunt Paradise\Desktop\SAMP R4\gamemodes\SPV4.pwn(4277) : error 017: undefined symbol "RandomEvent"
C:\Users\Stunt Paradise\Desktop\SAMP R4\gamemodes\SPV4.pwn(4283) : error 017: undefined symbol "RandomEvent"
Pawn compiler 3.2.3664          Copyright (c) 1997-2006, ITB CompuPhase


5 Errors.
pawn Код:
public Events()
{
    for(new i=0; i<MAX_PLAYERS; i++)
    {
        if(IsPlayerConnected(i))
        {
            RandomEvent = random(4);
            if (RandomEvent == 0)
            {
            GivePlayerWeapon(i, 38, 1);
                GameTextForAll("~r~~h~Minigun~n~~h~Fight!",15000,5);
            print("Debug Minigun");
            }
            if (RandomEvent == 1)
            {
                GivePlayerWeapon(i, 16, 5);
                GameTextForAll("~r~~h~Grenade~n~~h~Fight!",15000,5);
                print("Debug Grenade");
            }
            if (RandomEvent == 2)
            {
                GivePlayerWeapon(i, 9, 1);
                GameTextForAll("~r~~h~Chainsaw~n~~h~Fight!",15000,5);
                print("Debug Chainsaw");
            }
            if (RandomEvent == 3)
            {
                GivePlayerWeapon(i, 35, 3);
                GameTextForAll("~r~~h~Rocket~n~~h~Fight!",15000,5);
                print("Debug Rocket");
            }
        }
    }
}



Re: Random Events - hvampire - 08.02.2010

top of gamemode/filterscript :

new RandomEvent;

that will fix the 5 errors , but for the warning its something wrong in ur .inc file not the pwn


Re: Random Events - HydraX - 08.02.2010

Quote:
Originally Posted by Etch
top of gamemode/filterscript :

new RandomEvent;
Wow, I was so stupid I didn't realize it. Thanks


Re: Random Events - hvampire - 08.02.2010

np


Re: Random Events - HydraX - 08.02.2010

This is for everyone..

There is another problem.
It only shows

Grenade
and..
Rocket

Any solutions?

Код:
Debug Rocket
Debug Grenade
Debug Rocket
Debug Rocket
Debug Grenade



Re: Random Events - hvampire - 08.02.2010

i am sorry dude , but i am just a new scripter , can't help sorry


Re: Random Events - mansonh - 08.02.2010

That should be random as it is, try testing it a bit more and see if you get different random.
Oh and for efficiency, you might want to either use
else if or a switch instead of if, if, if
because it has to evaluate all the if's each time, where as the others it only evaluates till it finds a match.




Re: Random Events - Calgon - 08.02.2010

Quote:
Originally Posted by HydraX
pawn Код:
C:\Users\Stunt Paradise\Desktop\SAMP R4\pawno\include\cps.inc(140) : warning 208: function with tag result used before definition, forcing reparse
C:\Users\Stunt Paradise\Desktop\SAMP R4\gamemodes\SPV4.pwn(4264) : error 017: undefined symbol "RandomEvent"
C:\Users\Stunt Paradise\Desktop\SAMP R4\gamemodes\SPV4.pwn(4265) : error 017: undefined symbol "RandomEvent"
C:\Users\Stunt Paradise\Desktop\SAMP R4\gamemodes\SPV4.pwn(4271) : error 017: undefined symbol "RandomEvent"
C:\Users\Stunt Paradise\Desktop\SAMP R4\gamemodes\SPV4.pwn(4277) : error 017: undefined symbol "RandomEvent"
C:\Users\Stunt Paradise\Desktop\SAMP R4\gamemodes\SPV4.pwn(4283) : error 017: undefined symbol "RandomEvent"
Pawn compiler 3.2.3664          Copyright (c) 1997-2006, ITB CompuPhase


5 Errors.
pawn Код:
public Events()
{
    for(new i=0; i<MAX_PLAYERS; i++)
    {
        if(IsPlayerConnected(i))
        {
            RandomEvent = random(4);
            if (RandomEvent == 0)
            {
            GivePlayerWeapon(i, 38, 1);
                GameTextForAll("~r~~h~Minigun~n~~h~Fight!",15000,5);
            print("Debug Minigun");
            }
            if (RandomEvent == 1)
            {
                GivePlayerWeapon(i, 16, 5);
                GameTextForAll("~r~~h~Grenade~n~~h~Fight!",15000,5);
                print("Debug Grenade");
            }
            if (RandomEvent == 2)
            {
                GivePlayerWeapon(i, 9, 1);
                GameTextForAll("~r~~h~Chainsaw~n~~h~Fight!",15000,5);
                print("Debug Chainsaw");
            }
            if (RandomEvent == 3)
            {
                GivePlayerWeapon(i, 35, 3);
                GameTextForAll("~r~~h~Rocket~n~~h~Fight!",15000,5);
                print("Debug Rocket");
            }
        }
    }
}
Let me improve your code:

pawn Код:
public Events()
{
    for( new i = 0; i < MAX_PLAYERS; i++ )
    {
        if( IsPlayerConnected( i ) )
        {
            RandomEvent = random( 4 );
           
            switch( RandomEvent )
            {
              case 0:
              {
                GameTextForPlayer( i, "~r~~h~Minigun~n~~h~Fight!", 15000, 5 );
                GivePlayerWeapon( i, 38, 1 );
                print( "Debug Minigun" );
              }
              case 1:
              {
                    GivePlayerWeapon( i, 16, 5 );
                    GameTextForPlayer( i, "~r~~h~Grenade~n~~h~Fight!", 15000, 5 );
                    print( "Debug Grenade" );
              }
              case 2:
              {
                    GivePlayerWeapon( i, 9, 1 );
                    GameTextForPlayer( i, "~r~~h~Chainsaw~n~~h~Fight!", 15000, 5 );
                    print( "Debug Chainsaw" );
              }
              case 3:
              {
                    GivePlayerWeapon( i, 35, 3 );
                    GameTextForPlayer( i, "~r~~h~Rocket~n~~h~Fight!", 15000, 5 );
                    print( "Debug Rocket" );
              }
              default:
              {
                printf( "No event could be executed, as RandomEvent = %d.", RandomEvent );
              }
            }
        }
    }
    return 1;
}
Since you were looping GameTextForAll, I thought instead of creating ANOTHER switch. And anyway, your system would show a different event for EACH player, so looping the text for ALL would be pretty stupid.

Quote:
Originally Posted by mansonh
That should be random as it is, try testing it a bit more and see if you get different random.
Oh and for efficiency, you might want to either use
else if or a switch instead of if, if, if
because it has to evaluate all the if's each time, where as the others it only evaluates till it finds a match.

^ this again.


Re: Random Events - HydraX - 08.02.2010

I want the random event to show for EVERY player.


Re: Random Events - Calgon - 09.02.2010

Quote:
Originally Posted by HydraX
I want the random event to show for EVERY player.
Yes, but you don't understand that your code will loop. Meaning a DIFFERENT EVENT will occur for EACH player as you get a NEW RandomEvent every player loop.