ID:174366
 
Hello! I am trying to get it so that when you click "Build" it asks you what you want to build, then when you have chosen you click on the map, and it is built there!

This is what I have so far :
    verb
Build()
alert("Choose to build something.")
switch(input("What do you want to build?", text) in list ("Hovel","Farm","Nothing"))
if("Hovel")
alert("Click where you want to build it!")
Click(0)
new /obj/Building/Hovel
usr<<"Built"
if("Farm")
alert("Click where you want to build it!")
Click(0)
new /obj/Building/Farm
usr<<"Built!"


But I can't work out the rest!

~GokuSS4Neo~
Gokuss4neo wrote:
Hello! I am trying to get it so that when you click "Build" it asks you what you want to build, then when you have chosen you click on the map, and it is built there!

Let me show you how I'd do it then. Its basically a two step process; you create a proc to let the player choose what to build, then you modify the turf/Click() proc to let the player build it. A player variable will determine which type of building to build.

<code>mob/var cur_building list/buildings_list = list("Hovel", "Farm")</code>

The buildings list is a player variable so that different players can build different buildings. If you want everyone to build anything, just make it a global variable (var/buildings instead of mob/var/buildings).

<code>mob/verb/Build(building as null|anything in src.buildings_list) switch(building) if("Hovel") src.cur_building = /obj/Building/Hovel if("Farm") src.cur_building = /obj/Building/Farm if(building) src << "[building] selected."</code>

Note that I avoid popups like alert and input as much as possible if there is a way to make the input directly from the verb instead. It makes it possible to macro the verb (which can be a good or bad thing, but in this case a good thing, since you could have F1 build Hovels and F2 build farms, etc...), and lets people type it out in one string if they want, without switching to the mouse and selecting.

<code>turf/Click() if(usr.cur_building) new usr.cur_building (src)</code>

That should pretty much cover it.
In response to Foomer
Thank you Foomer! You Rule!

~GokuSS4Neo~