Ghetto Recruiting Ability HELP!!!!

The place to post your WML questions and answers.

Moderator: Forum Moderators

Forum rules
  • Please use [code] BBCode tags in your posts for embedding WML snippets.
  • To keep your code readable so that others can easily help you, make sure to indent it following our conventions.
User avatar
zengetsu88
Posts: 72
Joined: March 29th, 2010, 7:25 pm
Location: This Universe

Ghetto Recruiting Ability HELP!!!!

Post by zengetsu88 »

Alright... I'm at a lost on this one... I want to be able to right click a unit, and select a command (already have the menu item worked out... don't worry about this)... that command says "make unit" (lets call unit... bob)... in technicality it will say "make bob"
now the code that I will need help with...
an event name=menu_item_build_bob, first time only=no... blah blah blah...

This ability or recruiting thing will allow me to create one type of unit (only one... a.k.a. bob) on any unfilled tile adjacent to the unit with the right click command "build bob" (i hope this makes sense) at the cost of 5 gold to the user of that unit... So my question is how do I store adjacent tiles and then discern from them which ones are vacant and which ones are filled? Also I only want one to build per click of the command so how do I get the event to selct a random tile out of the ones that are available... Once I get how to discern between the tiles I also want it to show an error message to the user if they try to make a unit with no available tiles around that unit...

anyways... im pretty sure it is possible I just need a push in the right direction... especially with the tiles thing...

oh I don't do well with references because most of them I don't understand so please put up example code...

thanks for any help!!!
my logic is sound
Max
Posts: 1449
Joined: April 13th, 2008, 12:41 am

Re: Ghetto Recruiting Ability HELP!!!!

Post by Max »

http://wiki.wesnoth.org/InternalActions ... cations.5D

this should work (for the SUF part) to return all vacant tiles:

Code: Select all

[filter]
   [not]
   [/not]
[/filter]
User avatar
zengetsu88
Posts: 72
Joined: March 29th, 2010, 7:25 pm
Location: This Universe

Re: Ghetto Recruiting Ability HELP!!!!

Post by zengetsu88 »

Thanks!

I know this is completely wrong (haven't tested it because I know it wouldn't work) but this is the general Idea...

Code: Select all

[event]
    name=menu item build_zealot
    first_time_only=no

    [store_unit]
        [filter]
            x,y=$x1,$y1
        [/filter]
        variable=self
    [/store_unit]

    [store_side]
        side=$self.side
        variable=my_side
    [/store_side]

    [store_location]
        [filter_adjacent_location]
            count=1
        [/filter_adjacent_location]
        [filter]
            [not]
            [/not]
        [/filter]
        variable=empty_tile
    [/store_location]
        
    [if]
        [then]
            {NAMED_GENERIC_UNIT my_side((zealot)$empty_tile.x,$empty_tile.y)}
        [/then]
    [/if]

    {CLEAR_VARIABLE my_side}
    {CLEAR_VARIABLE empty_tile}
    {CLEAR_VARIABLE self}
[/event]
I also replaced bob with zealot...

Any help would be great!
Thanks for the help!
my logic is sound
User avatar
Luke the Flaming
Posts: 215
Joined: October 18th, 2006, 6:25 pm

Re: Ghetto Recruiting Ability HELP!!!!

Post by Luke the Flaming »

Maybe I'm missing something, but why the event rather than having the desired behaviour as the effect of the custom menu button?

In your code, apart that it may not do what you want, I'm not sure why do you need to store the side (wouldn't it always be equal to $side_number?) and you are missing the condition in the [if] statement (what must be true to do the [then] part?).
O, Wind, if Winter comes, can Spring be far behind?
User avatar
zengetsu88
Posts: 72
Joined: March 29th, 2010, 7:25 pm
Location: This Universe

Re: Ghetto Recruiting Ability HELP!!!!

Post by zengetsu88 »

To answer your question... yes it would be simpler to leave it in the menu item... but I'm just leaving that out for now to test the code than I will merge the pieces... secondly I realize the [if] statement needs somthing... but something is not working...

here is the updated version...

Code: Select all

[event]
    name=menu item build_zealot
    first_time_only=no

    [store_side]
        side=$self.number
        variable=my_side
    [/store_side]

    [store_gold]
        side=$my_side
        variable=my_gold
    [/store_gold]

    [store_location]
        [filter_adjacent_location]
            count=1
        [/filter_adjacent_location]
        [filter]
            [not]
            [/not]
        [/filter]
        variable=empty_tile
    [/store_location]
        
    [if]
        [variable]
            name=my_gold
            greater_than_equal_to=5
        [/variable]
        [then]
            {GENERIC_UNIT my_side[0] (Zealot) $empty_tile.x,$empty_tile.y}
            {VARIABLE_OP my_gold[0] add -1}
        [/then]
        [else]
            {DEBUG_MSG "Not Enough Gold!"}
        [/else]
    [/if]

    {CLEAR_VARIABLE my_side}
    {CLEAR_VARIABLE empty_tile}
    {CLEAR_VARIABLE my_gold}
[/event]
What else do I need?
my logic is sound
User avatar
Luke the Flaming
Posts: 215
Joined: October 18th, 2006, 6:25 pm

Re: Ghetto Recruiting Ability HELP!!!!

Post by Luke the Flaming »

In GENERIC_UNIT you need a $ before my_side (and do not need the [0]) and the X and Y coordinates must be separated (two arguments of the macro, not by a comma)... besides, you wanted a tile at random between the eligible (empty ones) to be selected, so:

Code: Select all

{VARIABLE_OP i rand 0.."$($empty_tile.length - 1)"}
{GENERIC_UNIT $my_side Zealot $empty_tile[$i].x $empty_tile[$i].y}
{CLEAR_VARIABLE i}
[gold]
   side=$my_side
   amount=-5
[/gold]
# {VARIABLE_OP my_gold add -5} would modify the variable, not the real gold owned by the player... 
# and it is 5 not 1, isn't it?
O, Wind, if Winter comes, can Spring be far behind?
User avatar
zengetsu88
Posts: 72
Joined: March 29th, 2010, 7:25 pm
Location: This Universe

Re: Ghetto Recruiting Ability HELP!!!!

Post by zengetsu88 »

yeah sry it was supposed to be 5 not 1...

anyways... here is what I got so far

Code: Select all

[event]
    name=select
        [filter]
            type=Carrier
        [/filter]
        [set_menu_item]
            id=build_zealot
            image=dark-missile.png   
            description= _ "Build Zealot"
                [show_if]
                    [have_unit]
                        type=Carrier                                         
                        side=$side_number
                         [filter_wml]
                             [not]
                                 moves=0
                             [/not]
                         [/filter_wml]
                        x,y=$x1,$y1
                    [/have_unit]
                [/show_if]
            [command]

                [store_side]
                    side=$self.number
                    variable=my_side
                [/store_side]

                [store_gold]
                    side=$self.side
                    variable=my_gold
                [/store_gold]

                [store_location]
                    [filter_adjacent_location]
                    [/filter_adjacent_location]
                    [filter]
                        [not]
                        [/not]
                    [/filter]
                    variable=empty_tile
                [/store_location]
        
                [if]
                    [variable]
                        name=my_gold
                        greater_than_equal_to=5
                    [/variable]
                    [then]
                        {VARIABLE_OP i rand 0.."$($empty_tile.length - 1)"}
                        {GENERIC_UNIT $my_side Zealot $empty_tile[$i].x $empty_tile[$i].y}
                        [gold]
                           side=$my_side
                           amount=-5
                       [/gold]
                    [/then]
                    [else]
                        {DEBUG_MSG "Not Enough Gold!"}
                    [/else]
                [/if]

                {CLEAR_VARIABLE i}
                {CLEAR_VARIABLE my_side}
                {CLEAR_VARIABLE empty_tile}
                {CLEAR_VARIABLE my_gold}
            [/command]
        [/set_menu_item]
[/event]
something is still not working right... When I try to load the game... the game just quits without any explanation... and I know it is because of this code... so what's next...


Thanks for the help so far...
my logic is sound
User avatar
Luke the Flaming
Posts: 215
Joined: October 18th, 2006, 6:25 pm

Re: Ghetto Recruiting Ability HELP!!!!

Post by Luke the Flaming »

[not] should be outside [filter_wml] (I did that error in your other thread... I try not to be fooled twice in a row by the same mistake :lol2: ).

In [store_side] there's side=$self.number (that you wanted to be either $self.side or $side_number).

Try to fix those and see if it is enough...
O, Wind, if Winter comes, can Spring be far behind?
User avatar
zengetsu88
Posts: 72
Joined: March 29th, 2010, 7:25 pm
Location: This Universe

Re: Ghetto Recruiting Ability HELP!!!!

Post by zengetsu88 »

which [not]?
my logic is sound
Mabuse
Posts: 2327
Joined: November 6th, 2007, 1:38 pm

Re: Ghetto Recruiting Ability HELP!!!!

Post by Mabuse »

no, this is basically all wrong.
make it like this:

first off, teh event just "loads" the menu item so its availble in game.
in this example, you have to right-click on an empty hex NEXT to the carrier, and then yu can select the "carrier recruit" option.

then a menu will pop up (i didnt define any images or stuff),

and you can select "cancel" or "Buy a Zealot" (also here, no fancy things like images or other text (stats ect.) included atm. lm lazy and you can look this all up yourself from other add ons))

the buy zealot option will only be shown if the carrier has 1 move left, the rest of the stuff i left out, i guess from now on you can make it

Code: Select all

	[event]
		name=prestart

[set_menu_item]
		id=recruit
		description="carrier recruit"
		[show_if]
			[not]
				[have_unit]
					x,y=$x1,$y1
				[/have_unit]
			[/not]
		[/show_if]
	
		[filter_location]
			[filter]
                        type=Carrier                                         
                        side=$side_number
			[/filter]
			radius=1
		[/filter_location]

[command]

	[store_gold]
		side=$side_number
		variable=gold
	[/store_gold]

	[store_unit]
		[filter]
                        type=Carrier                                         
                        side=$side_number
		[filter_location]
			x,y=$x1,$y1
			radius=1
		[/filter_location]
		[/filter]
		variable=carrier
	[/store_unit]

[message]
	speaker=narrator
	message= _ "Which Unit do you want to you recruit?"

[option]
message= _ "Return To Game"
[/option]

[option]
    [show_if]
[variable]
name="carrier.moves"
greater_than_equal_to=1
[/variable]
    [/show_if]

message=_ "Buy a Zealot"
[command]
              [if]
                    [variable]
                        name=gold
                        greater_than_equal_to=5
                    [/variable]
                    [then]

... do stuff ...

[/then]
[else]

......

[/else]
[/if]
[/command]
[/option]

... do more stuff here if needed....

[/message]
[/command]
[/set_menu_item]
[/event]
The best bet is your own, good Taste.
User avatar
zengetsu88
Posts: 72
Joined: March 29th, 2010, 7:25 pm
Location: This Universe

Re: Ghetto Recruiting Ability HELP!!!!

Post by zengetsu88 »

Wow... I really like the help you have given me and I have been playing with this code... BUT everything I do is done for MULTIPLAYER.... NOT CAMPAIGN

So I like this code but I need to know what event name should be used... cause I'm pretty sure prestart will not work if I put this code on the unit "carrier"
This code is to be used as an ability for the particular unit.

Also I need to make sure that this code is not shown to the opposing player/players....

I think maybe a good integration of our codes should work...

And an additional question... shouldn't the [filter_location] be in the [show_if] tag?
like this?

Code: Select all

          [show_if]
             [not]
                [have_unit]
                   x,y=$x1,$y1
                [/have_unit]
             [/not]
             [filter_location]
                 [filter]
                     type=Carrier                                         
                     side=$side_number
                 [/filter]
                 radius=1
              [/filter_location]
          [/show_if]
plus I believe the [not] tags need to be inside a [filter_wml] tag...

thanks for the help so far!
my logic is sound
User avatar
Luke the Flaming
Posts: 215
Joined: October 18th, 2006, 6:25 pm

Re: Ghetto Recruiting Ability HELP!!!!

Post by Luke the Flaming »

zengetsu88 wrote:plus I believe the [not] tags need to be inside a [filter_wml] tag...
Wrong. I also wrote it above. ;)
Do not you remember? I did that error in your other thread (see http://forums.wesnoth.org/viewtopic.php ... 28#p423028).
O, Wind, if Winter comes, can Spring be far behind?
User avatar
zengetsu88
Posts: 72
Joined: March 29th, 2010, 7:25 pm
Location: This Universe

Re: Ghetto Recruiting Ability HELP!!!!

Post by zengetsu88 »

yeah i know so how is that wrong... im confused
my logic is sound
fog_of_gold
Posts: 637
Joined: December 20th, 2009, 5:59 pm
Location: Germany

Re: Ghetto Recruiting Ability HELP!!!!

Post by fog_of_gold »

zengetsu88 wrote:[...]And an additional question... shouldn't the [filter_location] be in the [show_if] tag?[...]
No.
User avatar
zengetsu88
Posts: 72
Joined: March 29th, 2010, 7:25 pm
Location: This Universe

Re: Ghetto Recruiting Ability HELP!!!!

Post by zengetsu88 »

I know this code is possible but it is still not working... Whenever I add the unit with this code on it to the wesnoth folders, the game won't load all the way. It will start to load but then just quit by itself without telling me an error....
It is starting to piss me off...

this is what I have so far... and it is on the actual Carrier unit...
Spoiler:
So maybe should I turn this code into a macro or an actual ability instead of just putting it on a unit?
I have never done that before... so i'm not sure how to do that if that were the case....

I just really need some help on this code... Everyone has been so helpful so far... so I thank you...
my logic is sound
Post Reply