ID:147914
 
Yet another error that eludes me. This proc is called when the player talks to an NPC and requests a custom car, all of the prompts are displayed and appear to work, but the car doesn't appear after all the parameters are set.

mob/proc/CustomCar()
var/mob/Car/C = new /mob/Car/Custom(usr.x, usr.y - 1, usr.z)
var/choice = input("What kind of Car?","Car Setup") in list("Custom")
if(choice == "Custom") {
C.icon = input("Choose a file.","Custom Car") as file
C.icon_state = input("Icon State?")
nameit
C.name = input("Car name?")
if(C.name == "")
alert("You have to name your car.")
goto nameit
}

mob/Car
Custom
Click(Custom)
usr << "The [src] is being driven by [src.driver] with [src.currentpassengers] passengers."
dir = 8
maxpassengers = 1
see_invisible = 100
icon = 'Invis.dmi'
Enigmaster2002 wrote:
Yet another error that eludes me. This proc is called when the player talks to an NPC and requests a custom car, all of the prompts are displayed and appear to work, but the car doesn't appear after all the parameters are set.

C.icon = input("Choose a file.","Custom Car") as file
C.icon_state = input("Icon State?")

If you don't specify a proper icon state that exists in the file, the icon will not appear.

Plus, I wouldn't recommend allowing people to specify their own car icons -- it would be abused. People would be driving around in mint condition '03 Saiyan Gokus (the latest line of tailless vehicles from Saiyan Motors) before you know it.

Much better to give them a set of choices:

//Pick from a set of car makes
var/car_icon = input("Choose your car make:","Custom Car") as anything in list("Car 1", "Car 2", "Car 3")
switch(car_icon)
if("Car 1") C.icon = 'car1.dmi'
if("Car 2") C.icon = 'car2.dmi'
if("Car 3") C.icon = 'car3.dmi'

//Allow them to pick only from the icon states that exist in the icon file
var/icon_state = input("Choose a model:","Custom Car") as anything in icon_states(C.icon)


If you really want people to be able to specify their own custom icons, then you should have a far more restrictive process about it.


nameit
C.name = input("Car name?")
if(C.name == "")
alert("You have to name your car.")
goto nameit


Very bad way to make a loop. In all forms of programming, "goto" is to be avoided unless absolutely critically necessary (and it is extremely rare that it is absolutely critically necessary -- the cases in which it is needed are far too complex to explain by example). Try this instead:

var/car_name
while(!car_name)
car_name = input("Car name?") as text
if(cKey(car_name)) C.name = cKey(car_name) //strip bad characters and set C.name
else alert("You have to name your car!")