diff options
| author | Alexander Pickering <Alexander.Pickering@anondomain.site90.net> | 2016-01-23 00:21:58 -0500 |
|---|---|---|
| committer | Alexander Pickering <Alexander.Pickering@anondomain.site90.net> | 2016-01-23 00:21:58 -0500 |
| commit | 9b1057243fe1db65f351e213f00e41ceca67a8da (patch) | |
| tree | d0d0982175639baaad0a28fee64c5dcbc41c11b9 /gamemode/shared/player_spellcast.lua | |
| parent | e8439ad503f530724f1eae2de1a8ac2c19df52c0 (diff) | |
| download | wintersurvival2-9b1057243fe1db65f351e213f00e41ceca67a8da.tar.gz wintersurvival2-9b1057243fe1db65f351e213f00e41ceca67a8da.tar.bz2 wintersurvival2-9b1057243fe1db65f351e213f00e41ceca67a8da.zip | |
Completed basic framework for setting up spells, and minigames for casting
Diffstat (limited to 'gamemode/shared/player_spellcast.lua')
| -rw-r--r-- | gamemode/shared/player_spellcast.lua | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/gamemode/shared/player_spellcast.lua b/gamemode/shared/player_spellcast.lua new file mode 100644 index 0000000..fcc9484 --- /dev/null +++ b/gamemode/shared/player_spellcast.lua @@ -0,0 +1,45 @@ + +local meta = FindMetaTable("Player") + +--Number of bits used for networking spell casting success rate. Even though by default it shouldn't be more than 100, 8 lets it go to 256 in case you want to add buffs/bonuses. +local BITCOUNT = 256 + +if(SERVER) then + util.AddNetworkString("CastSpell") + util.AddNetworkString("FinishedCasting") + + function meta:Cast(spellname, callback) + if(self.casting) then return end + self.casting = callback + print("Casting " .. spellname) + net.Start("CastSpell") + net.WriteString(spellname) + net.Send(self) + end + + net.Receive("FinishedCasting",function(len,pl) + if(pl.casting) then + print("Finished casting message received by server") + pl.casting(net.ReadInt(BITCOUNT)) + pl.casting = nil + end + end) +else + + function finishedcasting(score) + net.Start("FinishedCasting") + net.WriteInt(score,BITCOUNT) + net.SendToServer() + end + + net.Receive("CastSpell",function() + local spellname = net.ReadString() + print("Request to cast spell" .. spellname) + StartMinigame(spellname) + end) +end + +function meta:IsCasting() + if(self.casting) then return false end + return true +end |
