ID:155631
 
Hey guys,

I was wondering if someone could help me with a small example of a code making a buff spell.
The idea is that you can buff someone or yourself, increasing str, int or evasion or what else there is to buff.
I tried to create somethink myself.
Protect()
set category="Spells"
if(src.MP <30+(src.protectlevel*3))src<<"Not enough MP"
else
src.MP-=30+(src.protectlevel*3)
var/list/J[1],C=1,mob/players/M
for(M in view(5))
J[C]=M
C++
J.len++
M=(input("Protect","Who") as mob in J)
if(M.ps==0)
M.ps=1
if(src.protectlevel<25)missile(/obj/spells/healing,src,M)
else if(src.protectlevel>24)missile(/obj/spells/ghealing,src,M)
sleep(get_dist(src,M))
var/amount=round(((rand(src.protectlevel*3))))
M.tempdefense+=amount
s_damage(M,amount,"yellow")
src.overlays += /obj/spells/shield
M.<<"You have been protected!"
sleep(100*(0.5*divineshieldlevel))
if(M.psp==1)
M.psp=0
M.ps=0
M.tempdefense-=amount
M.overlays -= /obj/spells/shield
s_damage(M,amount,"purple")
M.<<"Your protection is down!"
else
usr<<"That person is already protected wait till his buff is finished!"

the problem is atm when you are buffed and you logg out and back on again you still are having the boost but you can get buffed again. Also i would like to make it so when you are buffed and someone buffs you again your buff goes back to beginning of time so the last buff is gone instant.

I hope someone would like to help me with this one.

Greetings,
Chaokai
Hi there Chaokai,

Just want to go over a few things with the snippet you showed:

1)
 for(M in view(5))
J[C]=M
C++
J.len++
M=(input("Protect","Who") as mob in J)


DM has a really good array system. If you do J += M, what happens is that M is appended to the J array (aka list). This means that you no longer have to define C and don't need to manually increase the length size - making things a lot more faster for you to program with.

Of course, you can bypass that whole new list thing just by replacing the above snippet with this:
                    M=(input("Protect","Who") as mob in view(src, 5))
view() and its related procedures returns a list ^_^


2) I noticed you have a tempdefense variable... what you should do is define this variable as a /tmp variable which makes the variable unsavable, which means upon relogging, the tempdefense will be 0 once again
mob
var
health = -1 // *shrugs*
tmp
tempattack = 0
tempdefense = 0



3)
                        if(src.protectlevel<25)missile(/obj/spells/healing,src,M)
else if(src.protectlevel>24)missile(/obj/spells/ghealing,src,M)


For the "else if" statement, you can just have "else" since... well, that is what you are looking for, a value that is NOT < 24:
if(src.protectlevel<25)missile(/obj/spells/healing,src,M)
else missile(/obj/spells/ghealing,src,M)



4) You should redo your buff system. I would recommend having an array with the type of buff a person had an taking advantage of that, for example:
mob/var/tmp/buffed[0] // A list containing all the buffs.

Protect()
...etc... before you buff the person:
if("def" in M.buffed) // If M already has been buffed for defence
M.tempdefence -= buffed["def"] // Removes the previous buff
M.tempdefence += amount
buffed["def"] += amount

...etc, when removing the buff:
if(("def" in buffed) && buffed["def"] == amount) // making sure that the person has not been buffed with something else
M.tempdefence -= amount
buffed["def"] = 0</DM>

That is merely an example. "def" can be anything you want but I would recommend it be something you can keep track of and that a similar buff can remove the previous one if needed.
In response to GhostAnime
Thank you for your comment, helps alot im remaking the whole system atm i will post it here again once its done.

greetings,
chaokai