Jump to content
  • 0

how to update #CASHPOINTS in mysql while my character still login in game?


Question

Posted

I mean if I edit acc_reg_num  > #CASHPOINTS while i'm still logining in game

my #CASHPOINTS won't update until I relogin, I want it to refresh without re-login , is it possible? because I saw some server can do this without re login the game

20 answers to this question

Recommended Posts

  • 0
Posted (edited)
On 1/9/2018 at 3:19 AM, Alexandrite said:

It's not work when there multiple same of account_id only donation 100 work while 555 not work but status all become 1

-	script	DonationUpdate	-1,{
OnInit:
start:
initnpctimer;
end;
OnTimer5000:
set $@nb2,query_sql("SELECT COUNT(*) FROM test_donation WHERE status=0",$@count);
if($@count != 0) {
	set $@nb,query_sql("SELECT id, account_id,donate,status FROM test_donation WHERE status='0'",$@id,$@account_id,$@donate,$@status);
	for (.@i = 0; .@i < $@nb; .@i++) {
		if (isloggedin($@account_id[.@i])) { // check if player online
			atcommand "#cash \""+rid2name($@account_id[.@i])+"\" "+$@donate[.@i];
			query_sql("UPDATE test_donation SET status='1' WHERE id='"+$@id[.@i]+"' AND account_id='"+$@account_id[.@i]+"'");
		}
	}
} else
finish:
stopnpctimer;
goto start;
}
CREATE TABLE `test_donation` (
	`id` INT(11) NOT NULL AUTO_INCREMENT,
	`account_id` INT(11) NOT NULL,
	`donate` INT(11) NOT NULL,
	`status` INT(11) NOT NULL DEFAULT '0',
	`time` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
	PRIMARY KEY (`id`)
)
COLLATE='cp1251_general_ci'
ENGINE=InnoDB
AUTO_INCREMENT=1
;

Fixed.

Edited by Balfear
  • 0
Posted (edited)

Why you don`t want use script command or atcommand?
set #CASHPOINTS,#CASHPOINTS + XXX;
or
@cash XXX / #cash charnick XXX

Edited by Balfear
  • 0
Posted (edited)
5 minutes ago, Balfear said:

Why you don`t want use script command or atcommand?
set #CASHPOINTS,#CASHPOINTS + XXX;
or
@cash XXX / #cash charnick XXX

Because I'm planing to make it as a script to php for make it as website donation :3 (Not sure im explaining well)

Edited by Alexandrite
  • 0
Posted (edited)

 

23 minutes ago, Alexandrite said:

Because I'm planing to make a script to php to make it as website donation :3

Try use this script:

//===== rAthena Script =======================================
//= Donate converter
//===== By: ==================================================
//= Balfear
//===== Last Updated: ========================================
//= 20171207
//===== Description: ========================================= 
//= Automatic convert player balance("cp_credits") to cashpoint in game when player login.
//============================================================
-	script	balance2cashpoint	-1,{
OnPCLoginEvent:
	query_sql("select balance from `cp_credits` WHERE account_id = " + getcharid(3) + "", .@balance);
	if (.@balance != 0) {
		query_sql ("UPDATE `cp_credits` SET balance = 0 WHERE account_id = " + getcharid(3) + "");
		set #CASHPOINTS,(#CASHPOINTS + .@balance);
		announce "Gain cash point: "+.@balance+"",bc_self, 0xADFFC5, FW_BOLD;
	}
	end;
}

Read player ballance from `cp_credits` an converting to Cashpoints.

Edited by Balfear
  • 0
Posted (edited)
14 minutes ago, Balfear said:

 

Try use this script:


//===== rAthena Script =======================================
//= Donate converter
//===== By: ==================================================
//= Balfear
//===== Last Updated: ========================================
//= 20171207
//===== Description: ========================================= 
//= Automatic convert player balance("cp_credits") to cashpoint in game when player login.
//============================================================
-	script	balance2cashpoint	-1,{
OnPCLoginEvent:
	query_sql("select balance from `cp_credits` WHERE account_id = " + getcharid(3) + "", .@balance);
	if (.@balance != 0) {
		query_sql ("UPDATE `cp_credits` SET balance = 0 WHERE account_id = " + getcharid(3) + "");
		set #CASHPOINTS,(#CASHPOINTS + .@balance);
		announce "Gain cash point: "+.@balance+"",bc_self, 0xADFFC5, FW_BOLD;
	}
	end;
}

Read player ballance from `cp_credits` an converting to Cashpoints.

from what i read, your code only work for new login

 

I mean for player who actually logined for a long time and not even logout to get cash refresh > <

I mean, I want #CASHPOINTS alway uptime whenever it get update from outside the game, while player still logined in game

Edited by Alexandrite
  • 0
Posted (edited)

Script automaticly check sql table every 10 sec and find line where status = 0 then it use atcommand in game #cash nick xxx

Script: (update)

-	script	DonationUpdate	-1,{
OnInit:
start:
initnpctimer;
end;
OnTimer5000:
set $@nb2,query_sql("SELECT COUNT(*) FROM test_donation WHERE status=0",$@count);
if($@count != 0) {
	set $@nb,query_sql("SELECT id, account_id,donate,status FROM test_donation WHERE status='0'",$@id,$@account_id,$@donate,$@status);
	for (.@i = 0; .@i < $@nb; .@i++) {
		if (isloggedin($@account_id[.@i])) { // check if player online
			atcommand "#cash "+rid2name($@account_id[.@i])+" "+$@donate[.@i];
			query_sql("UPDATE test_donation SET status='1' WHERE id='"+$@id[.@i]+"' AND account_id='"+$@account_id[.@i]+"'");
		}
	}
} else
finish:
stopnpctimer;
goto start;
}

SQL table:

CREATE TABLE `test_donation` (
	`id` INT(11) NOT NULL AUTO_INCREMENT,
	`account_id` INT(11) NOT NULL,
	`donate` INT(11) NOT NULL,
	`status` INT(11) NOT NULL DEFAULT '0',
	`time` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
	PRIMARY KEY (`id`)
)
COLLATE='cp1251_general_ci'
ENGINE=InnoDB
AUTO_INCREMENT=24
;
INSERT INTO `test_donation` (`id`, `account_id`, `donate`, `status`) VALUES (1, 2000000, 100, 0);

I`ll check it, all work fine.

Edited by Balfear
  • 0
Posted

It's also work now just like this

-	script	DonationUpdate	-1,{

OnInit:

OnTimer1000:
set $@nb2,query_sql("SELECT COUNT(*) FROM test_donation WHERE status=0",$@count);
if($@count != 0) {
	set $@nb,query_sql("SELECT account_id,donate,status FROM test_donation WHERE status='0'",$@account_id,$@donate,$@status);
	atcommand "#cash "+rid2name($@account_id)+" "+$@donate;
	query_sql("UPDATE test_donation SET status='1' WHERE account_id='"+$@account_id+"'");
}

initnpctimer;
end;

}

But I'm not sure if this code can handle massive player online?

Or is it check if player online or not?

  • 0
Posted (edited)
31 minutes ago, Balfear said:

Script automaticly check sql table every 10 sec and find line where status = 0 then it use atcommand in game #cash nick xxx

Script: (update)


-	script	DonationUpdate	-1,{
OnInit:
start:
initnpctimer;
end;
OnTimer10000:
set $@nb2,query_sql("SELECT COUNT(*) FROM test_donation WHERE status=0",$@count);
if($@count != 0) {
	set $@nb,query_sql("SELECT account_id,donate,status FROM test_donation WHERE status='0'",$@account_id,$@donate,$@status);
	if (isloggedin($@account_id)) { // check if player online
		atcommand "#cash "+rid2name($@account_id)+" "+$@donate;
		query_sql("UPDATE test_donation SET status='1' WHERE account_id='"+$@account_id+"'");
	}
} else
finish:
stopnpctimer;
goto start;
}

 

 

Just update your script

	if (isloggedin([email protected]_id)) { // check if player online
		atcommand "#cash "+rid2name([email protected]_id)+" "[email protected];
		query_sql("UPDATE test_donation SET status='1' WHERE account_id='"[email protected]_id+"'");
	}
Edited by Balfear
  • 0
Posted
2 minutes ago, Balfear said:

if (isloggedin($@account_id)) { // check if player online

Yeah ! It's work perfectly fine now Thank you

-	script	DonationUpdate	-1,{

OnTimer1000:

OnInit:

	set $@nb2, query_sql("SELECT COUNT(*) FROM test_donation WHERE status=0", $@count);

	if($@count != 0) {
		set $@nb,query_sql("SELECT account_id,donate,status FROM test_donation WHERE status='0'",$@account_id,$@donate,$@status);

		if (isloggedin($@account_id)) { // check if player online
			atcommand "#cash "+rid2name($@account_id)+" "+$@donate;
			query_sql("UPDATE test_donation SET status='1' WHERE account_id='"+$@account_id+"'");
		}
	}

initnpctimer;
end;

}

 

Still wonder if it's work on multiple donation? massive donation?

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.   Paste as plain text instead

  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.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...