ID:161257
 
Ok theres 2 codes i need to make 1 is a proc and 1 is a mob
Proc:
i want the proc to say if your hp is less than a certain number you lose control of your body and its like you turn into an npc who keeps attacking anything that it sees

Mob:
*this the blue book had something similar to i just couldnt get it to work using their instructions

well im not sure if this goes in the mob category but uh i need to make a car mob that drives right for a certain number of squares then up for a certain number etc etc i thought i could use step_towards but it didnt work..

If you can even point me in the right direction or give me the link to a page of the blue book i couldve missed somehow i'd apprieciate it thanks.
I hope you don't think that programming works by copying and pasting what others have written. The DM Guide isn't going to list everything under the sun that you'd ever need. If that's what you believe, you're greatly mistaken.

For the first one, you would have to make sure that keyboard and mouse input do nothing (likely with a simple boolean variable and checks in Move() and any instance of Click()). To remove verbs, you could either follow a similiar system, or simply remove all the verbs from the player, storing them in a list until needed again, and then re-add them.

Note: To make grabbing the verbs from the player easier, you can use one of the new list operations, which most people probably don't know about. In this case, you can use &. This will grab all the elements that are in both lists.

Example code on how to do this:
var/list/verbs_to_remove = list(/mob/verb/attack, /mob/verb/defend, /mob/verb/teleport)

mob
var/uncontrolled_state = 0 //They can't control themselves.

verb
//These three will be removed as long as the player
//isn't in control.
attack()
defend()
teleport()

//There's no reason they shouldn't be able to talk
//to other people out-of-character while they're in
//this state.
global_say()

proc/remove_verbs()
//Grab the verbs that should be removed...
var/list/to_remove = src.verbs & verbs_to_remove
//...and then removed them.
src.verbs -= to_remove

//Wait until they regain control...
while(uncontrolled_state) sleep(1)

//...and then re-add the verbs.
src.verbs += to_remove


For the second one, if you really want something that just drives in straight lines, you'll simply need something like this:
mob/proc/step_in_line_to_(atom/a)
var/directions = get_dir(src, a)
var/x_step = abs(a.x - src.x)
var/y_step = abs(a.y - src.y)

//First, we'll make it move on the x-axis.
for(var/e = 1, (directions & (EAST|WEST)) && e <= x_step, e ++)
step(src, (directions & (EAST|WEST)))
sleep(5) //Wait five ticks before stepping again.

//And then move on the y-axis.
for(var/e = 1, (directions & (NORTH|SOUTH)) && e <= y_step, e ++)
step(src, (directions & (NORTH|SOUTH)))
sleep(5) //Again, wait five ticks.

This code makes one assumption. Firstly, a has to be on the same z-level. It will still move the appropriate location, but only for the x and y coordinates. It also won't go around obstacles, which would require a pathfinding algorithm and a slightly more complex bit of code.

Unless you know and understand bitwise math (in which case you should get it anyways), don't ask about the directions & (...)) stuff.
In response to Popisfizzy
If he's going to be using this for a lot of cars, it might be better to use a game loop to call each car's drive() proc which would just step_towards() the current target turf every so often. All he'd really need is a list of waypoints to step_towards() each time the game loop tells the car to drive, keeping track of the current target point and moving on to the next in the list when it reaches it, or if it can't reach it. That would allow him to create a control system to create a list of waypoints for new cars or new paths at runtime.
In response to Xooxer
If he's going to be using a lot of cars, I can only assume he's going to be making something GTA-esque, in which case each car should handle it's own AI and just drive in random straight lines on roads unless forced to do otherwise. =P
In response to Popisfizzy
Um, isn't that doable with a game loop too? I mean, I think my system does that (minus the random, with little AI). Plus, your system lacks a control, giving each car it's own. If you need to slow them all down a bit to save CPU, it's going to be easier with a game loop.

Meh, we're probably looking into it too much. He might just want one car.
In response to Xooxer
Yea, I'm not going to debate here because this isn't design philosophy. =P
In response to Popisfizzy
Well that was a funny arguement >.> as far as more than one car goes yeah i'll have maybe five most now back to the real subject O_O your codes are helping alot thank you very much PS: no i did not copy and paste.