How I can add daily rewards on my server? :)

10/19/2018 11:20 yeyeyeeee#1
Im searching a way to add daily rewards.
10/19/2018 11:29 Blowa#2
Learn programming. :lul:

What you want to do :
OnPlayerConnection : Check if the player has already got the daily gift
If DailyGiftNotGivenYet
GiftTonOfMoney

:kappa:
10/27/2018 12:58 [NH]Pyro#3
RewardHelper.cs
10/27/2018 20:45 Singleplayer™#4
how val already wrote , write a new function for the daily reward , which works like this :
-check last given reward (use a new table on db for this)
-if LastRewardDate != DateOfToday then -> give out the reward to player and set the dateoftoday as LastRewardDate (in db)
and put this function to the OnPlayerConnect event ...
this is maybe not the best solution but it works :)
10/27/2018 21:06 Fizo55#5
Quote:
Originally Posted by Singleplayer™ View Post
how val already wrote , write a new function for the daily reward , which works like this :
-check last given reward (use a new table on db for this)
-if LastRewardDate != DateOfToday then -> give out the reward to player and set the dateoftoday as LastRewardDate (in db)
and put this function to the OnPlayerConnect event ...
this is maybe not the best solution but it works :)
Or you can use GeneralLog to check if we've already had the Daily reward
10/27/2018 21:53 MANUEL PERES#6

Code:
if (Session.Character.LastLogin.Date != DateTime.Now.Date)
            {
                Session.Character.SpAdditionPoint += Session.Character.SpPoint;
                Session.Character.SpPoint = 10000;

                short[] rewardItems = { 1011, 1011, 1011, 1011, 1011 };
                byte[] rewardCount = { 1, 2, 3, 4, 5 };

                int rnd = new Random().Next(rewardItems.Length - 1);

                Session.Character.GiftAdd(rewardItems[rnd], rewardCount[rnd]);
                Session.Character.GenerateSay($"You received your daily reward: {ServerManager.GetItem(rewardItems[rnd]).Name} x {rewardCount[rnd]}", 14);

            }
            Session.Character.LastLogin = DateTime.Now;
10/27/2018 22:05 Singleplayer™#7
this works too .... lul
10/27/2018 22:20 Fizo55#8
Code:
var LastDaily = Session.Character.GeneralLogs.LastOrDefault(s => s.LogData == "World" && s.LogType == "Daily" && s.CharacterId == Session.Character.CharacterId && s.Timestamp.Day == DateTime.Now.Day);
if(LastDaily == null)
{
	//Give your item
	var GeneralLogAdd = new GeneralLogDTO
	{
		LogData = "World",
		LogType = "Daily",
		CharacterId = Session.Character.CharacterId,
		AccountId = Session.Account.AccountId,
		Timestamp = DateTime.Now
	};
	DAOFactory.GeneralLogDAO.InsertOrUpdate(GeneralLogAdd);
}
10/27/2018 23:25 Singleplayer™#9
Quote:
Originally Posted by Fizo55 View Post
Code:
var LastDaily = Session.Character.GeneralLogs.LastOrDefault(s => s.LogData == "World" && s.LogType == "Daily" && s.CharacterId == Session.Character.CharacterId && s.Timestamp.Day == DateTime.Now.Day);
if(LastDaily == null)
{
	//Give your item
	var GeneralLogAdd = new GeneralLogDTO
	{
		LogData = "World",
		LogType = "Daily",
		CharacterId = Session.Character.CharacterId,
		AccountId = Session.Account.AccountId,
		Timestamp = DateTime.Now
	};
	DAOFactory.GeneralLogDAO.InsertOrUpdate(GeneralLogAdd);
}
nice °-° , can u maybe explain the first line a lil bit more there are some strange things i cant understand there ...
10/28/2018 03:39 0Lucifer0#10
Manuel peres solution is a lot better.
For the answer it just get the last reward log of today. If null this mean there is no log so no reward.
10/28/2018 07:06 lorenx911#11
Quote:
Originally Posted by MANUEL PERES View Post

Code:
if (Session.Character.LastLogin.Date != DateTime.Now.Date)
            {
                Session.Character.SpAdditionPoint += Session.Character.SpPoint;
                Session.Character.SpPoint = 10000;

                short[] rewardItems = { 1011, 1011, 1011, 1011, 1011 };
                byte[] rewardCount = { 1, 2, 3, 4, 5 };

                int rnd = new Random().Next(rewardItems.Length);

                Session.Character.GiftAdd(rewardItems[rnd], rewardCount[rnd]);
                Session.Character.GenerateSay($"You received your daily reward: {ServerManager.GetItem(rewardItems[rnd]).Name} x {rewardCount[rnd]}", 14);

            }
            Session.Character.LastLogin = DateTime.Now;
:kappa:

Where add this.
10/28/2018 09:01 0Lucifer0#12
... common at least understand before copy past... obviously you put it on the connection...
10/28/2018 09:31 BladeTiger12#13
Quote:
Originally Posted by MANUEL PERES View Post

Code:
if (Session.Character.LastLogin.Date != DateTime.Now.Date)
            {
                Session.Character.SpAdditionPoint += Session.Character.SpPoint;
                Session.Character.SpPoint = 10000;

                short[] rewardItems = { 1011, 1011, 1011, 1011, 1011 };
                byte[] rewardCount = { 1, 2, 3, 4, 5 };

                int rnd = new Random().Next(rewardItems.Length);

                Session.Character.GiftAdd(rewardItems[rnd], rewardCount[rnd]);
                Session.Character.GenerateSay($"You received your daily reward: {ServerManager.GetItem(rewardItems[rnd]).Name} x {rewardCount[rnd]}", 14);

            }
            Session.Character.LastLogin = DateTime.Now;
:kappa:
Btw fix ur crash ;) (IndexOutOfRangeException)
Code:
int rnd = new Random().Next(rewardItems.Length - 1);