Raised This Month: $ Target: $400
 0% 

Make 2 tasks chosen randomly. (Solved)


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
SkumTomteN
Veteran Member
Join Date: Oct 2013
Location: Asgard
Old 12-27-2013 , 20:06   Make 2 tasks chosen randomly. (Solved)
Reply With Quote #1

How do i make 2 tasks, and those will be generated randomly?.

like this one, but this one does not work, only 1 expression or statement can be used in 1 "case",

possible to change that?

the code
Code:
public make_hero(id)
{		
switch (random_num(0, 1))	
	{
		case 0:
		{
		zp_override_user_model(id, "heroine")
		zp_force_buy_extra_item(id, zp_get_extra_item_id("ddeagle"), 2)	
                zp_force_buy_extra_item(id, zp_get_extra_item_id("Quad Barrel"), 3) 
                set_user_health( id , get_user_health( id ) + HEALTH ); 
                set_user_armor(id , get_user_armor( id ) + ARMOR ); 
                             }
		case 1:
		{
		zp_override_user_model(id, "hero")
                zp_force_buy_extra_item(id, zp_get_extra_item_id("ddeagle"), 2)		
                zp_force_buy_extra_item(id, zp_get_extra_item_id("SVDEX"), 4) 
                set_user_health( id , get_user_health( id ) + HEALTH ); 
                set_user_armor(id , get_user_armor( id ) + ARMOR ); 
                             }
as u see, this is the only necessery code u need. and u can see clearly what im trying to do.

this is amxmodx 1.8.2, tell me if you know any natives that can make this possible.

2 hero's. chosen randomly to players.
__________________
Contact: Steam
Videos: Youtube

Last edited by SkumTomteN; 12-29-2013 at 04:34.
SkumTomteN is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 12-27-2013 , 21:19   Re: Make 2 tasks chosen randomly. (how?)
Reply With Quote #2

There are no issues with the code that you have posted (assuming you have it complete which it isn't in the posted code).

I.E. This compiles just fine:

Code:
public make_hero(id)
{	
	switch (random_num(0, 1))	
	{
		case 0:
		{
			// stuff 0
		}
		case 1:
		{
			// stuff 1
		}
	}
}
__________________

Last edited by fysiks; 12-27-2013 at 21:20.
fysiks is offline
SkumTomteN
Veteran Member
Join Date: Oct 2013
Location: Asgard
Old 12-28-2013 , 02:29   Re: Make 2 tasks chosen randomly. (how?)
Reply With Quote #3

Quote:
Originally Posted by fysiks View Post
There are no issues with the code that you have posted (assuming you have it complete which it isn't in the posted code).

I.E. This compiles just fine:

Code:
public make_hero(id)
{	
	switch (random_num(0, 1))	
	{
		case 0:
		{
			// stuff 0
		}
		case 1:
		{
			// stuff 1
		}
	}
}
But there is a problem, you cant add more then 1 thing lets say if i do like this :

Code:
case 0:
		{
	         1 thing
                 1 thing
                 1 thing
		}
If i compile it. it will show this error :

Code:
// C:\Users\Billy\Desktop\Compiler\zp_hero.sma(65) : error 002: only a single st
atement (or expression) can follow each "case"
But i want it to select a hero randomly.

meaning i want it to select 2 tasks randomly.

1st task will switch the player model to hero and gives a svdex dual deagle etc.

2nd task will switch the player model to "heroine" and gives a quad barrel and dual deagle etc.

hope you understand better now. im bad at explaining, sorry for that.

EDIT! :

Got an idea, If i do it like this :

setting 2 tasks

set_task(0.5,"make_hero")
set_task(0.5,"make_heroine")

Then the
public make_heroine(id)

etc-.-

But im gonna need a code that randomizes what task to choose.

I coded the plugin to make 2 hero's now, but i need something that can randomize what task to use.

Will this work? correct the code if not please.

Code:
public random_task(id) 
{	
	switch (random_num(0, 1))	
	{
		case 0:
		{
                             set_task(0.5,"make_heroine")	
		}
                             case 1:
		{
                             set_task(0.5,"make_hero")	
		}
	}
}
That compiled great, but will it work?


EDIT 2 :

So that was wrong, it had already set the tasks before my code above. so i change it to this.

Code:
public zp_round_started(round)
{
if (zp_get_human_count( ) < MINPEOPLE )
		return;
			
if(round == MODE_MULTI || round == MODE_INFECTION)
switch (random_num(0, 1))	
	{
		case 0:
		{
                             set_task(0.5,"make_heroine")	;
		}
                             case 1:
		{
                             set_task(0.5,"make_hero");	
		}
	}
           
}
That should do it right?
__________________
Contact: Steam
Videos: Youtube

Last edited by SkumTomteN; 12-28-2013 at 03:03.
SkumTomteN is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 12-28-2013 , 06:11   Re: Make 2 tasks chosen randomly. (how?)
Reply With Quote #4

Quote:
Originally Posted by SkumTomteN View Post
But there is a problem, you cant add more then 1 thing lets say if i do like this :

Code:
case 0:
		{
	         1 thing
                 1 thing
                 1 thing
		}
If i compile it. it will show this error :

Code:
// C:\Users\Billy\Desktop\Compiler\zp_hero.sma(65) : error 002: only a single st
atement (or expression) can follow each "case"
There is nothing wrong with that code. You can have as many lines as you wish inside of a case as long as you have the braces (which you have). So, I can't believe that the error is coming from this switch() structure. If you want further help, you will need to attach your whole plugin to your next post.

EDIT:
If I had to guess, you are not closing all of your braces. HINT: The switch that you posted is not complete. If that hint doesn't help, attach your whole plugin
__________________

Last edited by fysiks; 12-28-2013 at 06:15.
fysiks is offline
SkumTomteN
Veteran Member
Join Date: Oct 2013
Location: Asgard
Old 12-28-2013 , 08:42   Re: Make 2 tasks chosen randomly. (how?)
Reply With Quote #5

I cant do that, its my private.

Quote:
public zp_round_started(round)
{
if (zp_get_human_count( ) < MINPEOPLE )
return;

if(round == MODE_MULTI || round == MODE_INFECTION)
switch (random_num(0, 1))
{
case 0:
{
set_task(0.5,"make_heroine") ;
}
case 1:
{
set_task(0.5,"make_hero");
}
}

}
so whats wrong with this?, ive already made the plugin, compiled great.

I have made 2 plugins in 1. 1 for heroine and 1 for hero.

And with the code above, it should randomize the tasks right?.

Then it should work like i want.

EDIT : i guess i forgot about the closing bracets, only used 1 for it. but this should work the same way, just a bit more complicated.
__________________
Contact: Steam
Videos: Youtube

Last edited by SkumTomteN; 12-28-2013 at 08:44.
SkumTomteN is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 12-28-2013 , 15:29   Re: Make 2 tasks chosen randomly. (how?)
Reply With Quote #6

You should avoid using set_task() if you can.
__________________
fysiks is offline
SkumTomteN
Veteran Member
Join Date: Oct 2013
Location: Asgard
Old 12-28-2013 , 17:58   Re: Make 2 tasks chosen randomly. (how?)
Reply With Quote #7

Quote:
Originally Posted by fysiks View Post
You should avoid using set_task() if you can.
I will try the other way, can you explain why?, is it unstable or something.

EDIT: That worked too, so i guess i will be testing soon.
__________________
Contact: Steam
Videos: Youtube

Last edited by SkumTomteN; 12-28-2013 at 18:40.
SkumTomteN is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 12-28-2013 , 18:02   Re: Make 2 tasks chosen randomly. (how?)
Reply With Quote #8

Quote:
Originally Posted by SkumTomteN View Post
I will try the other way, can you explain why?, is it unstable or something
If you don't absolutely need a significant delay you shouldn't use it. The code is less readable and it's less efficient.
__________________
fysiks is offline
SkumTomteN
Veteran Member
Join Date: Oct 2013
Location: Asgard
Old 12-28-2013 , 18:58   Re: Make 2 tasks chosen randomly. (how?)
Reply With Quote #9

Quote:
Originally Posted by fysiks View Post
If you don't absolutely need a significant delay you shouldn't use it. The code is less readable and it's less efficient.
So then it would be like this?

Code:
public zp_round_started(round)
{
if (zp_get_human_count( ) < MINPEOPLE )
		return;
			
if(round == MODE_MULTI || round == MODE_INFECTION)
	{
switch (random_num(0, 1))	
	{
		case 0:
		{
g_hero[id] = true 
zp_force_buy_extra_item(id, zp_get_extra_item_id("ddeagle"), 1)
zp_force_buy_extra_item(id, zp_get_extra_item_id("SVDEX"), 1) 
set_user_health( id , get_user_health( id ) + HEALTH ); 
set_user_armor(id , get_user_armor( id ) + ARMOR ); 
zp_override_user_model(id, "hero")				
new id
static iPlayersNum
iPlayersNum = gAlive()
id = gRandomAlive(random_num(1, iPlayersNum))
new szName[ 32 ]
get_user_name( id, szName, 31 )
set_dhudmessage( 0, 190, 0, 0.05, 0.45, 1, 0.0, 5.0, 1.0, 1.0)                                
show_dhudmessage( 0, TEXT, szName )                            
                             }
		case 1:
		{
g_hero[id] = true 
zp_force_buy_extra_item(id, zp_get_extra_item_id("ddeagle"), 1)
zp_force_buy_extra_item(id, zp_get_extra_item_id("Quad Barrel"), 1) 
set_user_health( id , get_user_health( id ) + HEALTH ); 
set_user_armor(id , get_user_armor( id ) + ARMOR ); 
zp_override_user_model(id, "heroine")		
new id
static iPlayersNum
iPlayersNum = gAlive()
id = gRandomAlive(random_num(1, iPlayersNum))
new szName[ 32 ]
get_user_name( id, szName, 31 )
set_dhudmessage( 0, 190, 0, 0.05, 0.45, 1, 0.0, 5.0, 1.0, 1.0)                       
show_dhudmessage( 0, TEXT2, szName )                     
                       }
           }
}
Correct the code please, that didnt work.

Code:
//// zp_addon_heros.sma
// C:\Users\Billy\Desktop\Compiler\zp_addon_heros.sma(49) : warning 209: functio
n "zp_round_started" should return a value
// C:\Users\Billy\Desktop\Compiler\zp_addon_heros.sma(51) : error 029: invalid e
xpression, assumed zero
// C:\Users\Billy\Desktop\Compiler\zp_addon_heros.sma(51) : error 088: number of
 arguments does not match definition
// C:\Users\Billy\Desktop\Compiler\zp_addon_heros.sma(54) : warning 209: functio
n "zp_round_started" should return a value
// C:\Users\Billy\Desktop\Compiler\zp_addon_heros.sma(62) : error 017: undefined
 symbol "id"
// C:\Users\Billy\Desktop\Compiler\zp_addon_heros.sma(62 -- 63) : warning 215: e
xpression has no effect
// C:\Users\Billy\Desktop\Compiler\zp_addon_heros.sma(63) : error 017: undefined
 symbol "id"
// C:\Users\Billy\Desktop\Compiler\zp_addon_heros.sma(63) : warning 215: express
ion has no effect
// C:\Users\Billy\Desktop\Compiler\zp_addon_heros.sma(63) : error 001: expected
token: ";", but found ")"
// C:\Users\Billy\Desktop\Compiler\zp_addon_heros.sma(63) : fatal error 107: too
 many error messages on one line
__________________
Contact: Steam
Videos: Youtube
SkumTomteN is offline
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 20:38.


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