Jump to content
  • 0

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


Alexandrite

Question


  • Group:  Members
  • Topic Count:  19
  • Topics Per Day:  0.01
  • Content Count:  52
  • Reputation:   0
  • Joined:  02/19/14
  • Last Seen:  

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

Link to comment
Share on other sites

20 answers to this question

Recommended Posts

  • 0

  • Group:  Members
  • Topic Count:  13
  • Topics Per Day:  0.00
  • Content Count:  255
  • Reputation:   232
  • Joined:  07/24/13
  • Last Seen:  

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
Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  19
  • Topics Per Day:  0.01
  • Content Count:  52
  • Reputation:   0
  • Joined:  02/19/14
  • Last Seen:  

Can anyone help me (Or understand me?) I'm not good at explain thing in English

rocash1.png

rocash2.png

rocash3.png

rocash4.png

Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  13
  • Topics Per Day:  0.00
  • Content Count:  255
  • Reputation:   232
  • Joined:  07/24/13
  • Last Seen:  

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

Edited by Balfear
Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  19
  • Topics Per Day:  0.01
  • Content Count:  52
  • Reputation:   0
  • Joined:  02/19/14
  • Last Seen:  

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
Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  13
  • Topics Per Day:  0.00
  • Content Count:  255
  • Reputation:   232
  • Joined:  07/24/13
  • Last Seen:  

 

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
Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  19
  • Topics Per Day:  0.01
  • Content Count:  52
  • Reputation:   0
  • Joined:  02/19/14
  • Last Seen:  

Well I didn't have fluxcp install anymore, is it work on manual table if I made?

Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  19
  • Topics Per Day:  0.01
  • Content Count:  52
  • Reputation:   0
  • Joined:  02/19/14
  • Last Seen:  

Error :V player not attached!

rocash5.png

Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  19
  • Topics Per Day:  0.01
  • Content Count:  52
  • Reputation:   0
  • Joined:  02/19/14
  • Last Seen:  

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
Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  13
  • Topics Per Day:  0.00
  • Content Count:  255
  • Reputation:   232
  • Joined:  07/24/13
  • Last Seen:  

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
Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  19
  • Topics Per Day:  0.01
  • Content Count:  52
  • Reputation:   0
  • Joined:  02/19/14
  • Last Seen:  

It still not working :V

Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  13
  • Topics Per Day:  0.00
  • Content Count:  255
  • Reputation:   232
  • Joined:  07/24/13
  • Last Seen:  

3 minutes ago, Alexandrite said:

It still not working :V

Do you have any error?

Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  19
  • Topics Per Day:  0.01
  • Content Count:  52
  • Reputation:   0
  • Joined:  02/19/14
  • Last Seen:  

4 minutes ago, Balfear said:

Do you have any error?

oh ok it's work now , but i wonder if this code can handle massive player online?

Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  19
  • Topics Per Day:  0.01
  • Content Count:  52
  • Reputation:   0
  • Joined:  02/19/14
  • Last Seen:  

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?

Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  13
  • Topics Per Day:  0.00
  • Content Count:  255
  • Reputation:   232
  • Joined:  07/24/13
  • Last Seen:  

I think is better to use the function OnPCLoginEvent:
I`ll update script. Yes it check.

Edited by Balfear
Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  19
  • Topics Per Day:  0.01
  • Content Count:  52
  • Reputation:   0
  • Joined:  02/19/14
  • Last Seen:  

The Code still change status to 1 even if i'm offline too lol... So if i'm not online it won't work > <"

Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  13
  • Topics Per Day:  0.00
  • Content Count:  255
  • Reputation:   232
  • Joined:  07/24/13
  • Last Seen:  

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
Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  19
  • Topics Per Day:  0.01
  • Content Count:  52
  • Reputation:   0
  • Joined:  02/19/14
  • Last Seen:  

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?

Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  19
  • Topics Per Day:  0.01
  • Content Count:  52
  • Reputation:   0
  • Joined:  02/19/14
  • Last Seen:  

Testing on 2 Account And It's worked fine! :3

Not able to test more tough > <

Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  19
  • Topics Per Day:  0.01
  • Content Count:  52
  • Reputation:   0
  • Joined:  02/19/14
  • Last Seen:  

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

 

rocash6.png

Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  19
  • Topics Per Day:  0.01
  • Content Count:  52
  • Reputation:   0
  • Joined:  02/19/14
  • Last Seen:  

worked fine now, THX! :3

Link to comment
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.   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.

×
×
  • Create New...