ID:147904
 
im tryin to make a Spell called Firewall its supposed to drain your hp slowly when you enter it but its not for some reason and also How would i make it so when your entering/exiting the Firewall you slow down a little.Here's my code


mob
var
Firewall
proc/Firewall()
set category = "Spells"
if(Firewall)
Firewall=0
else
Firewall=1
turf
Click()
if(usr.Firewall)
if(usr.MP <= 29)
usr << "Not enough Mp"
else
usr.MP -= 30
var/obj/a = new/obj/Firewall2(locate(src.x+1,src.y,src.z))
var/obj/b = new/obj/Firewall(locate(src.x,src.y-1,src.z))
var/obj/c = new/obj/Firewall2(locate(src.x+1,src.y-1,src.z))
var/obj/d = new/obj/Firewall(locate(src.x,src.y,src.z))
sleep(50)
del(a)
del(b)
del(c)
del(d)
turf
proc
drain(mob/M)
if(ismob(M))
if(M.client)
while(src.drain)
M.HP-=rand(1,5)
sleep(10)
return 0
Firewall
Entered(mob/M)
if(ismob(M))
if(M.client)
src.drain=1
spawn()
src.drain(M)
return ..()
Exited(mob/M)
if(ismob(M))
if(M.client)
src.drain=0
return ..()
turf
var
drain
Turles9000 wrote:
mob
var
Firewall
proc/Firewall()
set category = "Spells"
if(Firewall)
Firewall=0
else
Firewall=1
just a little note:

ok, lets act like the program is stupid, and only does what you say, ok it would do this:

check for "firewall" variable and if theres a value, it will set to 0
then it will check if theres no "firewall" variable(the else statement) and guess what, you just earlier set it to 0, so it will then put to 1.
ok, you want to use it again, and firewall was defined, so it sets to 0 again, and back to 1... hmm, interesting
uhh ohH? it just always puts firewall on. it should be this:

mob
var
Firewall
proc/Firewall()
set category = "Spells"
if(Firewall)
Firewall=0
return \\this will completely end this proc and do no more
else
Firewall=1


I think that may have been a small problem. of course,Im new to BYOND, but this is REALLY similar to all other ''programming'' systems.And by the looks of the code you have, it would probobly cause a problem.
In response to Evil Incarnate Inc
k thanks also by the way it works if i change the firewall into a turf instead of a obj but then the Firewall Deletes the old turf and it creates a black spot =/
In response to Turles9000
yes, because when 2 turfs are on 1 space, the top layer over-powers them if the icon is completely filled and has no ''masked'' spaced. (i think, if not, it 'mixes' them together) and when it deletes the ''firewall'' since its ''mixed'' with the turfs combined, it deletes them all, making the icon of the location null (therefore- black)
In response to Evil Incarnate Inc
Yea i know,was just making that as a side note
In response to Evil Incarnate Inc
ok, lets act like the program is stupid, and only does what you say, ok it would do this:

check for "firewall" variable and if theres a value, it will set to 0
then it will check if theres no "firewall" variable(the else statement) and guess what, you just earlier set it to 0, so it will then put to 1.
ok, you want to use it again, and firewall was defined, so it sets to 0 again, and back to 1... hmm, interesting
uhh ohH? it just always puts firewall on.

Actually, just to point out:
 mob
var
Firewall
proc/Firewall()
set category = "Spells"
if(Firewall)
Firewall=0
else
Firewall=1

only evaluates the Firewall variable once. If it's 1, then it will be 0. It will NOT perform the ELSE statement unless Firewall is FALSE to begin with. If Firewall is 0, then it will only perform the statement under the ELSE.

That's the whole point of an if-else statment. Now, if he had
        if(Firewall)
Firewall=0
if(!Firewall)
Firewall=1

then it would perform as you say.


Now, to answer the original question.

You have a firewall turf and a firewall obj. I imagine that you only need one or the other. I would recommend setting up a trigger system for this. There's a few posts and demos lying around on how to do this, but I'll give you a crash course. First, you need to add a variable to the base obj called trigger (or whatever you like), like so:
obj
var
trigger = FALSE //by default, objs are NOT triggers


Now, you need a trigger proc for the base obj, like so:
obj
proc
trigger_enter()
trigger_exit()

Notice that we did not define the proc other than it's name. This is because with a trigger, you define how you want it to work for each obj. For your firewall, for example:

obj/Firewall
trigger = TRUE
trigger_enter(mob/M) //only mobs are affected by this
M.drain = TRUE
trigger_exit(mob/M)
M.drain = FALSE


Alright, now that we have our firewall ready to be triggered, we need to actually trigger it. For that, we need to modify the base turf like so:
turf
Entered(mob/M)
..()
for(var/obj/O in contents)
if(O.trigger)
O.trigger_enter(M) //Here we start the burning
Exited(mob/M)
..()
for(var/obj/O in contents)
if(O.trigger)
O.trigger_exit(M) //Here the burning stops


The net effect of this is that when a mob enters a turf with a firewall in it, the firewall's trigger_enter() proc will be called and the mob that entered will be used for further actions within the proc. When a mob exits, the firewall's trigger_exit() proc will be called in the same way.

In order to get a mob to slow down, you first have to implement a movement delay. You might try something like this:
mob
var
movedelay = 5 //Everyone has a half-second movement delay
Move()
sleep(movedelay) //Pause for the delay time
..()


Once you have a delay system implemented, you can play around with the triggers I mentioned earlier. For example:
obj/Firewall
trigger_enter(mob/M)
M.drain = TRUE
M.movedelay += 10 //add a second to the move delay
trigger_exit(mob/M)
M.drain = FALSE
M.movedelay -= 10 //remove the added delay


Phew. Ok, class is over :P Hope it helped some.
In response to sapphiremagus
so i should stick with my original right?Ive been asking around and no one i asked can figure out how to get it to drain hp.
In response to Turles9000
Edited my post, check it again.
In response to sapphiremagus
Alright, now that we have our firewall ready to be triggered, we need to actually trigger it. For that, we need to modify the base turf like so:
> turf
> Entered(mob/M)
> ..()
> for(var/obj/O in contents)
> if(O.trigger)
> O.trigger_enter(M) //Here we start the burning
> Exited(mob/M)
> ..()
> for(var/obj/O in contents)
> if(O.trigger)
> O.trigger_exit(M) //Here the burning stops
>

The net effect of this is that when a mob enters a turf with a firewall in it, the firewall's trigger_enter() proc will be called and the mob that entered will be used for further actions within the proc. When a mob exits, the firewall's trigger_exit() proc will be called in the same way.
___________________________________________________________
should i delete the part in bold?and replace it with what you did or mix them together? One more question It says M.drain is not defined even though i defined it.Sorry for not being able to figure these stuff out by myself >< looked it over three times.Thanks in advance
turf
proc
drain(mob/M)
if(ismob(M))
if(M.client)
while(src.drain)
M.HP-=rand(1,5)
sleep(10)
return 0
Firewall
Entered(mob/M)
if(ismob(M))
if(M.client)
src.drain=1
spawn()
src.drain(M)
return ..()

Exited(mob/M)
if(ismob(M))
if(M.client)
src.drain=0
return ..()
In response to Turles9000
Ok, you have your objs that trigger whenever someone enters the turf. You don't need anything else now. Just create the obj (Firewall) in the turf that you want. Whenever a mob enters that turf - be it grass, sand, or whatever - it will start damaging them. You don't need a seperate turf, just define the variables and procs I outlined above and you should be good to go.

As for the drain not defined, that was my fault. I thought drain was a mob variable. Simply change M.drain to src.drain in the trigger_enter() and trigger_exit() procs.

*-------------------EDIT-------------------------*

After going over your original post with a little more clarity, I realized that this will not work like I expected due to how you have the drain proc set up. Keep the triggers, but remove the calls to src.drain = TRUE and src.drain = FALSE. Instead, we're going to set these when the obj is created.

obj
Firewall
New()
..()
var/turf/T = src.loc //keeping track of where the firewall is
if(istype(T)) //Little know trick to make sure that our turf really is a turf
T.drain = TRUE
Del()
var/turf/T = src.loc
if(istype(T))
T.drain = FALSE
..()


When the firewall is created, the turf it's created on has it's drain variable set to TRUE. When the firewall is deleted, the turf has it's drain variable set to FALSE.

***********************FINAL EDIT*************************
I've gone ahead and written out a fully documented version
of everything so far discussed. This should do what you want it to. Take it and learn from it. If you questions, please ask.

mob
var
movedelay = 5 //Define a movement delay of half a second

Move()
sleep(movedelay) //Pause for half a second (movedelay) before moveing
..()

obj
var
trigger = FALSE //Objs are not triggerable by default

proc
trigger_enter() //Define a trigger_enter()
trigger_exit() //Define a trigger_exit()

Firewall
New()
..()
var/turf/T = src.loc
if(istype(T))
T.drain = TRUE //Set the turf's drain var to TRUE

Del()
var/turf/T = src.loc
if(istype(T))
T.drain = FALSE //Set the turf's drain var to FALSE
..()

trigger_enter(mob/M) //Here we define what happens when the obj is triggered
if(istype(M))
M.movedelay += 10 //Add 1 second to the movement delay

trigger_exit(mob/M) //Here we define what happens when the obj is un-triggered
if(istype(M))
M.movedelay -= 10 //Remove the extra second from the movement delay


turf
var
drain = FALSE //The drain variable

proc
drain(mob/M)
if(istype(M) && M.client) //Combined two lines into one for efficiency
while(src.drain && M.loc == src) //Don't keep looping if there is noone here
M.HP -= rand(1,5)
spawn(10) //Used spawn to avoid possible errors
if(M.loc == src) //Checks to make sure the mob is still here
drain(M) //and drains more HP if it is.

Entered(atom/A)
for(var/obj/O in contents)
if(O.trigger)
O.trigger_enter(A) //Trigger any objs in the turf when entered

if(drain)
drain(A) //Drain HP

Exited(atom/A)
for(var/obj/O in contents)
if(O.trigger)
O.trigger_exit(A) //Trigger any exit effects when exiting
In response to sapphiremagus
2 errors ,sorry for not including this part in code.This is how you get the spell.
__________________________________
Legend of The 2 Kingdoms.dm:2027:error:/mob/proc/Firewall:undefined type path
Legend of The 2 Kingdoms.dm:2032:error:/mob/proc/Firewall:undefined type path
_________________________________________
obj
Firewall_SpellBook
icon = 'Items.dmi'
icon_state = "Firewall"
verb
Get()
set src in oview(0)
if(Move(usr))
usr << "You pick up the [src]"
else
usr << "You cannot pick up the [src]"
Drop()
src.loc = usr.loc
usr << "You drop the [src]"
usr.verbs-=new/mob/proc/Firewall
Learn()
switch(input("Do you Want to Learn Firewall","???")in list("Yes","No"))//This asks the user in a input box if he/she wants to learn the fire spell and gives 2 choices Yes and No//
if("Yes")//This Will Do something if the user clicks Yes//
if(usr.icon == 'Warlock.dmi')
usr.verbs+=new/mob/proc/Firewall
del src
else
usr << "You Must be a Warlock to learn This Move"

if("No")
usr<<"Ok"