AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Suggestions / Requests (https://forums.alliedmods.net/forumdisplay.php?f=12)
-   -   Make 2 tasks chosen randomly. (Solved) (https://forums.alliedmods.net/showthread.php?t=232251)

SkumTomteN 12-27-2013 20:06

Make 2 tasks chosen randomly. (Solved)
 
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.

fysiks 12-27-2013 21:19

Re: Make 2 tasks chosen randomly. (how?)
 
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
                }
        }
}


SkumTomteN 12-28-2013 02:29

Re: Make 2 tasks chosen randomly. (how?)
 
Quote:

Originally Posted by fysiks (Post 2077294)
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?

fysiks 12-28-2013 06:11

Re: Make 2 tasks chosen randomly. (how?)
 
Quote:

Originally Posted by SkumTomteN (Post 2077347)
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

SkumTomteN 12-28-2013 08:42

Re: Make 2 tasks chosen randomly. (how?)
 
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.

fysiks 12-28-2013 15:29

Re: Make 2 tasks chosen randomly. (how?)
 
You should avoid using set_task() if you can.

SkumTomteN 12-28-2013 17:58

Re: Make 2 tasks chosen randomly. (how?)
 
Quote:

Originally Posted by fysiks (Post 2077672)
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.

fysiks 12-28-2013 18:02

Re: Make 2 tasks chosen randomly. (how?)
 
Quote:

Originally Posted by SkumTomteN (Post 2077736)
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.

SkumTomteN 12-28-2013 18:58

Re: Make 2 tasks chosen randomly. (how?)
 
Quote:

Originally Posted by fysiks (Post 2077737)
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


fysiks 12-28-2013 20:00

Re: Make 2 tasks chosen randomly. (how?)
 
Most of the errors you have there are trivial and caused by a lack of basic knowledge of scripting. You need to completely redo that whole function instead of copy/pasting stuff. After you redo the function, if you still have errors, try to read what the error says and try to fix it. It would probably help if you used consistent indentation too.


All times are GMT -4. The time now is 20:38.

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