PDA

View Full Version : Thư viện mẩu dành cho team



sangpronhat
28-10-09, 10:24 PM
----------------------------------------------------------------------------------
--have many function of team
----------------------------------------------------------------------------------
--Khi su dung Include("\\script\\lib\\team_lib.lua")

-----------------------------------CAC HAM-----------------------------------
-- 1 : MoveTeam(idteam,idmap,posx,posy)
-- 2 : TeamInfo(idteam)
-- 3 : ChoPhepTanCong(idteam,num) [num={0,1}]
-- 3 : SetDeathScriptTeam(idteam,scriptdir)
-- 4 : SetTaskTeam(idteam,taskid,num)
-- 5 : GetTaskTeam(idteam,taskid)
-- 6 : XemTaskTamThoi(idteam,taskid)
-- 7 : SuaTaskTamThoi(idteam,taskid,num)
-- 8 : XemPK(idteam)
-- 9 : SuaPK(idteam)
-- 10 : SetTimerTeam(idteam,timerid,thoigian)
-- 11 : StopTimerTeam(idteam)
-- 12 : SetTempRevPosTeam(idteam,idmap,posx,posy)
-- 13 : SetRevPos(idteam,idmap,posx,posy)
-- 14 : SayTeam(idteam,loithoai)
-- 15 : CaptainTeam(idteam)
-- 16 : AllMemberTeam(idteam)
-- 17 : SetCurCampTeam(idteam,camp)
--------------------------------------------------------------------------------------
function MoveTeam(idteam,idmap,posx,posy)
if SubWorldID2Idx(idmap) == -1 then
Msg2Player("Ban do khong duoc mo trong qua trinh khoi dong !")
return
end
for i=1,GetPlayerCount() do
PlayerIndex = i
if GetTeam() == idteam then
NewWorld(idmap,posx*8,posy*16)
end
end
end
function TeamInfo(idteam)
for i=1,GetPlayerCount() do
PlayerIndex = i
if GetTeam() == idteam then
teamsize = GetTeamSize()
if IsCaptain() == 1 then
totruong = GetName()
end
end
end
str = "Info To Doi [Ma so] : "..idteam..", [So Nguoi] : "..teamsize..", [Doi Truong] : "..totruong
return str
end
function ChoPhepTanCong(idteam,num)
if num == nil then return end
for i=1,GetPlayerCount() do
PlayerIndex = i
if GetTeam() == idteam then
SetFightState(num)
end
end
end
function SetDeathScriptTeam(idteam,scriptdir)
for i=1,GetPlayerCount() do
PlayerIndex = i
if GetTeam() == idteam then
SetDeathScript(scriptdir)
end
end
end
function SetTaskTeam(idteam,taskid,num)
for i=1,GetPlayerCount() do
PlayerIndex = i
if GetTeam() == idteam then
SetTask(taskid,num)
end
end
end
function GetTaskTeam(idteam,taskid)
local task = 0
for i=1,GetPlayerCount() do
PlayerIndex = i
if GetTeam() == idteam then
if task == 0 then task = GetTask(taskid) end
if task == GetTask(taskid) then
task = GetTask(taskid)
else
return 0
end
end
end
return task
end
function XemTaskTamThoi(idteam,taskid)
local task = 0
for i=1,GetPlayerCount() do
PlayerIndex = i
if GetTeam() == idteam then
if task == 0 then task = GetTaskTemp(taskid) end
if task == GetTaskTemp(taskid) then
task = GetTaskTemp(taskid)
else
return 0
end
end
end
return task
end
function SuaTaskTamThoi(idteam,taskid,num)
for i=1,GetPlayerCount() do
PlayerIndex = i
if GetTeam() == idteam then
SetTaskTemp(taskid,num)
end
end
end
function XemPK(idteam)
local pksum = 0
for i=1,GetPlayerCount() do
PlayerIndex = i
if GetTeam() == idteam then
pksum = pksum+GetPK()
end
end
return pksum
end
function SuaPK(idteam,num)
for i=1,GetPlayerCount() do
PlayerIndex = i
if GetTeam() == idteam then
SetPK(num)
end
end
end
function SetTimerTeam(idteam,timerid,thoigian)
for i=1,GetPlayerCount() do
PlayerIndex = i
if GetTeam() == idteam then
SetTimer(timerid,thoigian)
end
end
end
function StopTimerTeam(idteam)
for i=1,GetPlayerCount() do
PlayerIndex = i
if GetTeam() == idteam then
StopTimer()
end
end
end
function SetTempRevPosTeam(idteam,idmap,posx,posy)
for i=1,GetPlayerCount() do
PlayerIndex = i
if GetTeam() == idteam then
SetTempRevPos(idmap,posx*8,posy*16)
end
end
end
function SetRevPos(idteam,idmap,posx,posy)
if posx == nil and posy == nil then return end
for i=1,GetPlayerCount() do
PlayerIndex = i
if GetTeam() == idteam then
SetRevPos(idmap,posx*8,posy*16)
end
end
end
function SayTeam(idteam,loithoai)
local loinoi,loithoailen = "","";
local loidoithoai = "";
loithoailen = getn(loithoai)
if type(loithoai) == "table" then
if loithoailen > 2 then
for i=2,loithoailen - 1 do
loinoi = loinoi..format("%q",loithoai[i])..","
end
loinoi = loinoi..format("%q",loithoai[loithoailen])
loidoithoai = "Say("..format("%q",loithoai[1])..","..(loithoailen-1)..","..loinoi..")"
elseif loithoailen == 2 then
loidoithoai = "Say("..format("%q",loithoai[1])..",1,"..format("%q",loithoai[2])..")"
elseif loithoailen < 2 then
if loithoailen == 1 then
loidoithoai = "Say("..format("%q",loithoai[1])..",0)"
else
return nil
end
end
else print("Ham SayTeam khong chay duco do loi du lieu") return end
for i=1,GetPlayerCount() do
PlayerIndex = i
if GetTeam() == idteam then
dostring(loidoithoai)
end
end
return loidoithoai
end
function CaptainTeam(idteam)
for i=1,GetPlayerCount() do
PlayerIndex = i
if GetTeam() == idteam then
if IsCaptain() == 1 then
totruong = GetName()
end
end
end
return totruong
end
function AllMemberTeam(idteam)
local name = ""
for i=1,GetPlayerCount() do
PlayerIndex = i
if GetTeam() == idteam then
name=name..GetName()..","
end
end
return name
end
function SetCurCampTeam(idteam,camp)
if camp == nil then return end
for i=1,GetPlayerCount() do
PlayerIndex = i
if GetTeam() == idteam then
SetCurCamp(camp)
end
end
end


Chức năng
đơn giản hóa các cấu trúc đụng đến team
Viết các event hay mission có liên quan đến team :D

thaihoa91
29-10-09, 07:33 AM
Dạo này Sangpronhat lại Dev Jx típ àh ^__^