Posts: 602
Threads: 3
Joined: Jun 2009
Reputation:
0
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.
Posts: 6,129
Threads: 36
Joined: Jan 2009
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.
Posts: 896
Threads: 85
Joined: Mar 2009
Reputation:
0
I want the random event to show for EVERY player.
Posts: 6,129
Threads: 36
Joined: Jan 2009
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.