Jump to content
  • 0
Sign in to follow this  
evilpuncker

Help converting small piece of code to hercules

Question

Hello everyone, I'm trying to add the attendance system requirement to hercules, and there is a small code that need to be added to the clif_parse_attendance_reward_request function, I managed to fix a few errors but there is still some that I wasn't able to fix, the code is the following:

 

	char attendance_requirement[NAME_LENGTH];
	sprintf(attendance_requirement, "#Attendance_%d", date_get(DT_YYYYMMDD));
	if (!pc_readaccountreg2str(sd, attendance_requirement)) {
		clif->msgtable_color(sd, "You don't meet the requirement.", COLOR_RED);
		return;
	}

the errors:

hgZRTtH.png

Share this post


Link to post
Share on other sites

5 answers to this question

Recommended Posts

  • 0

error show what this is not function and not variable

date_get(DT_YYYYMMDD))

Also error said what parameters to

clif->msgtable_color

is wrong

 

Share this post


Link to post
Share on other sites
  • 1
prontera,155,185,5	script	kjhfkhsjd	1_F_MARIA,{
//	#Attendance_require = 0;
//	end;

	mes callsub(YYYYMMDD);
	#Attendance_require = callsub(YYYYMMDD);
	close;
YYYYMMDD:
	return gettime(GETTIME_YEAR) * 10000 + gettime(GETTIME_MONTH) * 100 + gettime(GETTIME_DAYOFMONTH);
}
#include "common/hercules.h"
#include "map/pc.h"
#include "map/clif.h"
#include "plugins/HPMHooking.h"
#include "common/HPMDataCheck.h"

HPExport struct hplugin_info pinfo = {
	"attendance_requirement",
	SERVER_TYPE_MAP,
	"",
	HPM_VERSION,
};

// copy from src\map\date.c
int date_get_date(void)
{
	time_t t;
	struct tm * lt;
	t = time(NULL);
	lt = localtime(&t);

	return
		(lt->tm_year + 1900) * 10000 +
		(lt->tm_mon + 1) * 100 +
		(lt->tm_mday);
}

static void clif_parse_attendance_reward_request_pre(int *fd, struct map_session_data **sd) {
	if ((*sd)->state.trading || pc_isdead(*sd) || pc_isvending(*sd))
		return;
	
	if (pc_readaccountreg(*sd, script->add_variable("#Attendance_require")) != date_get_date()) {
		clif->messagecolor_self((*sd)->fd, COLOR_RED, "You don't meet the requirement.");
		hookStop();
	}
	return;
}

HPExport void plugin_init (void) {
	addHookPre(clif, pAttendanceRewardRequest, clif_parse_attendance_reward_request_pre);
}

this has been tested working

 

btw remember the attendance system are bind to each character in the account

https://github.com/HerculesWS/Hercules/blob/da14478a8c0c616a6aa5481694c550143bc9b9f3/sql-files/main.sql#L245-L246 <-- under `char` table

so I guess what you doing there is the reward can claim for each character in the account once the quest has completed

Share this post


Link to post
Share on other sites
  • 0
52 minutes ago, AnnieRuru said:

btw remember the attendance system are bind to each character in the account

 

they changed it on https://github.com/HerculesWS/Hercules/commit/0b86f2b46bcace0967a04fbc3d85a4c9e3df3c32 (finally!) now its account based, thank you for the plugin!

Share this post


Link to post
Share on other sites
  • 0

I just noticed my newly downloaded test server from a few days ago is stable branch LOL ...

should've been main branch because it just a test server, thanks for reminder

 

anyway yeah the previous post still stand correct, only the DD are not necessary and you are good to go

Share this post


Link to post
Share on other sites
  • 0
2 hours ago, AnnieRuru said:

only the DD are not necessary and you are good to go

 

you mean the day? I don't get it xD now its confused me, btw this is the script I'm using:

//set_attendance_requirement(); allow the player to get the attendance
function	script	set_attendance_requirement	{
	setd "#Attendance_" + gettime(DT_YYYYMMDD),true;
	return;
}
//get_attendance_requirement(); return true if the requirement already met
function	script	get_attendance_requirement	{
	return getd("#Attendance_" + gettime(DT_YYYYMMDD));
}
-	script	DailyLogin	-1,{

OnPCLoginEvent:
	if (Baselevel < 75) {
		dispbottom "You must be at least level 75 before you qualify for Daily Attendance.";
		end;
	}
	if (get_attendance_requirement()) {
		dispbottom "You already got the attendance today.";
		end;
	}
	if (#DailyReward > gettimetick(2)) {
		dispbottom .n$+": You can't currently receive the Daily Reward, you still have to wait "+callfunc("Time2Str", #DailyReward);
		dispbottom .n$+": After this, visit the Attendance NPC in Prontera.";
		end;
	}
	set #DailyReward,0;
	dispbottom .n$+": Stay active for "+( (.rew_login%3600 == 0)?.rew_login/3600+" Hour(s)":.rew_login/60+" Minute(s)")+" to receive the Daily Reward.";
	dispbottom .n$+": Then talk to the Attendance NPC in Prontera.";
	attachnpctimer;
	initnpctimer;
	end;

OnTimer60000: // Every Minute
	stopnpctimer;
	set #daily,#daily + 60;
	if(#daily == .rew_login) {
		set #daily,0;
		set #DailyReward,Daily + 1;
		dispbottom .n$+": You can now receive your Daily Reward. Please visit the Attendance NPC in Prontera.",.bc_self;
		end;
	}
	attachnpctimer;
	initnpctimer;
	end;

OnInit:
	set .n$, "[Attendance]";
	set .rew_time, 72000; // Timer until next Reward in seconds
	// How long does someone have to stay online to recieve the reward in seconds
	// Default: 3600 = 1 Hour
	// Minimum: 60 = 1 Minute, because the Timer checks every Minute
	set .rew_login, 3600;
	end;
}

prontera,147,175,6	script	Attendance Checker	888,{
	if (Baselevel < 75) {
	dispbottom "You must be at least level 75 to get your daily attendance bonus.";
	end;
	}
	if (get_attendance_requirement()) {
		mes "You already got the attendance today.";
		end;
	}
	mes .n$;
	mes "Welcome, "+strcharinfo(0)+"!";
	if (!#DailyReward) {
		mes "I'm sorry, but you can't recieve your Daily Reward yet. You still have to wait for "+callfunc("Time2Str",(getvariableofnpc(.rew_login,"DailyLogin")-#daily)+gettimetick(2));
		next;
		mes "Talk to me when the timer is finished.";
		close;
	}
	mes "Your attendance has been verified. Click at the arrow button below your Alt+V.";
	set_attendance_requirement();
	set #DailyReward,gettimetick(2) + .rew_time;
	set Daily,#DailyReward;
	set #DailyReward,0;
	next;
	mes "Press Alt+V and click Attendance Check";
	next;
	mes "Then click the prize of the day. Your item will be sent via RODex.";
	next;
	mes "Check your RODex mail to get your item.";
	close;
}

 

Share this post


Link to post
Share on other sites
  • 0
setd "#Attendance_" + gettime(DT_YYYYMMDD),true;

bad script design

 

let's say the player has attended this script for 300 days, then it will have 299 unnecessary variables pile up in `acc_reg_num_db` table

this kind of variable only use once, so set only 1 variable enough, with the value on date format

 

 

no.2

from my understanding, your script even use loop ... why not just use gettimetick(2)

when login, `@timelogin` = gettimetick(2), when npc check, (gettimetick(2) - `@timelogin`) ....

 

 

no,3

and why not just write everything with source code =/

no need loop, every variable and function you want is readily served in source code

 

nvm, let me show you if its done entirely with source code

https://gist.github.com/AnnieRuru/82335a62e8a6133511cda473ade8d322

 

 

oh and, my discord is AnnieRuru#1609

 

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
Answer this question...

×   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.

Loading...
Sign in to follow this  

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.