ID:1113548
 
Keywords: combat, help, lag, pokemon, system
(See the best response by Rotem12.)
Code:
mob
var
list
slot_1 = list("attack" = null, "slot occupied" = 0)

mob/proc
assign_attack(id, mob/pokemon/x)
if(x.slot_1["slot occupied"]==1)
if(x.slot_2["slot occupied"]==1)
if(x.slot_3["slot occupied"]==1)
if(x.slot_4["slot occupied"]==1)
var/forget_move = input("Please decide which move you would like to forget","") in list (x.slot_1["attack"],x.slot_2["attack"],x.slot_3["attack"],x.slot_4["attack"])
if(forget_move == x.slot_1["attack"])
usr << output("<b><font color=blue>Congratulations [x] has forgotten [x.slot_1["attack"]] and has learned [id]","battle_output")
x.slot_1["attack"] = id
if(forget_move == x.slot_2["attack"])
usr << output("<b><font color=blue>Congratulations [x] has forgotten [x.slot_1["attack"]] and has learned [id]","battle_output")
x.slot_2["attack"] = id
if(forget_move == x.slot_3["attack"])
usr << output("<b><font color=blue>Congratulations [x] has forgotten [x.slot_1["attack"]] and has learned [id]","battle_output")
x.slot_3["attack"] = id
if(forget_move == x.slot_4["attack"])
usr << output("<b><font color=blue>Congratulations [x] has forgotten [x.slot_1["attack"]] and has learned [id]","battle_output")
x.slot_4["attack"] = id
else
usr << output("<b><font color=blue>Congratulations [x] has learned [id]","battle_output")
x.slot_4["attack"] = id
else
usr << output("<b><font color=blue>Congratulations [x] has learned [id]","battle_output")
x.slot_3["attack"] = id
else
usr << output("<b><font color=blue>Congratulations [x] has learned [id]","battle_output")
x.slot_2["attack"] = id
else
usr << output("<b><font color=blue>Congratulations [x] has learned [id]","battle_output")
x.slot_1["attack"] = id

proc
get_info(mob/pokemon/src)
if(istype(src,/mob/pokemon/Bulbasaur))
if(src.level <= 5) src.assign_attack(TACKLE, src)

mob
verb
Slot_1()
for(var/mob/pokemon/x in world)
if(x.owner == "[usr.trainer_name]" && x.cooldown <= 0)
usr.Attack(x.slot_1["attack"])


mob/verb
Attack(id)
if(id==TACKLE)
AttackType = "Normal"
Move_Poke = "Physical"
Attack = "Tackle"
AttackPower = 50
Accuracy = 100
//The rest of the attack code, but doesnt need to be included


Problem description:
My issue is that the system above would cause a lot of lag when i have something like 300+ moves that it has to run through to decide which matches and imagine 2-4 people activating that verb at the same time.

I would like some help and tips in how i can improve/change the system so very little code is needed to prevent any lag issues.
Examples would be helpful as well :)
Best response
I would use datums:
attacks
proc/Attack()

Tackle
Attack()
// code for tackle

Water_Gun
Attack()
// code for water gun

We define a datum, attacks, each datum has a proc called Attack only each of those attacks have a different code.

We later use it like so:
mob/pokemon/var/list/Slots = list()

mob/proc
Assign(id, mob/pokemon/x, attacks/A)
x.Slots[id] = A

mob/verb
Assign_Tackle()
Assign("1", some_pokemon, new/attacks/Tackle)

Attack()
var/attacks/A = some_pokemon.Slots["1"]
A.Attack()


Notes:
- Notice that we do "new/attacks/Tackle", it needs to exist, you can keep a list of all attacks or something like that.
- Slots list is built like so "Slotname" = attack, it isn't what you originally made. (slot_1, slot_2, slot_3 and slot_4 are all joined together inside Slots)
- You can take it further and have those slots become hotkeys when slotname is the key.

One final thing, if each pokemon has a list of attacks, we can also do attack levels:
attacks
var/level = 1
proc/Attack()
Tackle
level++ // levels each use, ofcourse you can define exp vars and create a forumla
damage = level * something
Thank you ^_^ I will implement it :P