Jump to content
Ximboliex

[GUIDE] Daily Prize

Recommended Posts

You Need serialize.lua run in your server

 

WeekFolder = "scripts/addons/weekprize/"
 
function CheckWeek(role)
    if exists_file(GetResPath(WeekFolder..""..GetCharID(role)..".txt")) == false then
        table.save({Week = -1,Registered = 0},GetResPath(WeekFolder..""..GetCharID(role)..".txt"),"a")
    end
    local DailyPrize = table.load(GetResPath(WeekFolder..""..GetCharID(role)..".txt"),"r")
    local NowWeek = GetNowWeek()
    if DailyPrize.Week ~= NowWeek then
        GiveWeekPrize(role)
    else
        HelpInfo(role,0,"You already have received your award today, come back tomorrow to receive again.")
    return
    end
end
 
 
function GiveWeekPrize(role)
    local DailyPrize = table.load(GetResPath(WeekFolder..""..GetCharID(role)..".txt"),"r")
    local NowWeek = GetNowWeek()
    if DailyPrize.Registered >= 6 and NowWeek == 0 then
    GiveItem(role,0,xxxx,5,1)       
    DailyPrize.Week = NowWeek
    DailyPrize.Registered = -1
    table.save(DailyPrize,GetResPath(WeekFolder..""..GetCharID(role)..".txt"),"w")
    HelpInfo(role,0,"Congratulations, you collected all the daily prizes and obtained 5 Forbidden Keys")
    else
    local WeekPrize = {}
    WeekPrize[0] = xxx         
    WeekPrize[1] = xxx             
    WeekPrize[2] = xxx                
    WeekPrize[3] = xxx            
    WeekPrize[4] = xxx            
    WeekPrize[5] = xxx            
    WeekPrize[6] = xxx        
    GiveItem(role,0,WeekPrize[NowWeek],1,1)
    DailyPrize.Week = NowWeek
    DailyPrize.Registered = DailyPrize.Registered + 1
    table.save(DailyPrize,GetResPath(WeekFolder..""..GetCharID(role)..".txt"),"w")
    HelpInfo(role,0,"You received "..GetItemName(WeekPrize[NowWeek]).."! You can obtain another award again tomorrow.")
    end
end

*************************************
in NpcSdk: ( under  JumpPage )

    elseif item.func == CheckWeek then
        return CheckWeek(character)

************************************

npc function;

function blabla()
        Talk(1,"Test 1 2 3")
        Text(1,"Daily Prize",CheckWeek)
end

-By @Yomazu

Edited by Ximboliex
  • Like 1

xbx3.png

Share this post


Link to post
Share on other sites
33 minutes ago, FapFap said:

@Ximboliex can u help me solve this error?
zzz.png
zzz1.png

 

add the following code somewhere inside functions.lua

function exists_file(name)
	local f=io.open(name,"r")
	if f~=nil then io.close(f) return true else return false end
end

 

Edited by iZae

Share this post


Link to post
Share on other sites
On 11/15/2019 at 6:43 PM, Graf said:

May be i`m very stupid, but...

image.png.14cb7e3663e364df503fe82b20ebb8a0.png

and see

image.png.d950a1ed794b9f9e79dbac0af6eddc8b.png

Hello @Graf!

Maybe you're missing exists_file function or it called with other name within ur file, check lua_err for a concret answer about the error and tell us.


lelouch_signature_by_vahntheknight-d4uafwj.png

Share this post


Link to post
Share on other sites
4 hours ago, Graf said:

No see((

A good idea to fixing that is you making sure u got all functions needed which are being called in codes.
Start from CheckWeek(role), ensure the data file being created and if all working fine.
You can replace the GiveWeekPrize(role) which being called in the function CheckWeek(role) to ensure it working.
Feel free to pm me if you get no success.


lelouch_signature_by_vahntheknight-d4uafwj.png

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...