Jump to content
  • 0

calculate with date


Vincent

Question


  • Group:  Members
  • Topic Count:  130
  • Topics Per Day:  0.03
  • Content Count:  528
  • Reputation:   18
  • Joined:  09/11/12
  • Last Seen:  

Hi,

i want to create a npc where you can pay zeny and it will be rent a house. My question is how can i insert something into the database with the date.

 

Example:

 

Player rent the house at the date: 10.10.13 for 7 days. so the script have to insert into DB the Date: 17.10.13.

How can i calucuate that?

Link to comment
Share on other sites

17 answers to this question

Recommended Posts


  • Group:  Members
  • Topic Count:  130
  • Topics Per Day:  0.03
  • Content Count:  528
  • Reputation:   18
  • Joined:  09/11/12
  • Last Seen:  

yes and no. This house npc is alos to lear scripting, because of that i want to do my own script and ;)

 

learning by doing.

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  2
  • Topics Per Day:  0.00
  • Content Count:  56
  • Reputation:   9
  • Joined:  09/22/12
  • Last Seen:  

	set houserentdate,gettimetick(2)+604800;

That gets the servers timetick, adds 604800 (60x60x24x7 = one week) seconds to it and saves it as a character variable

 

if (houserentdate < gettimetick(2)) { }

This checks if the variable houserentdate is smaller then the current server timetick. Since we added the time of one week into the variable, this will only be true one week after the variable was set.

Edited by Reynard
  • Upvote 1
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  130
  • Topics Per Day:  0.03
  • Content Count:  528
  • Reputation:   18
  • Joined:  09/11/12
  • Last Seen:  

Thanks i will try it. If i have aby problem i will post it in this thread.



Hi,

i try atm to insert the status from the rentnpc into the db. But its buggy and say:

 

script error on npc/custom/rent.txt line 13
    parse_line: need ';'

line 13 is the INSERT INTO comand for sql.

 

1. Is the INSERT INTO comand right?

2. @rentnpcdate the right comand to insert the variable?

set rentnpcdate,gettimetick(2)+604800;
query_sql "INSERT INTO `rentnpc` (`char_id`, `account_id`, `npc`, `date`) VALUES ('"+getcharid(0)+"', '"+getcharid(2)+"', '"1"', "@rentnpcdate")";
 
Edited by King555
Link to comment
Share on other sites


  • Group:  Developer
  • Topic Count:  10
  • Topics Per Day:  0.00
  • Content Count:  2407
  • Reputation:   613
  • Joined:  07/05/12
  • Last Seen:  

'"1"', "@rentnpcdate")";

=>

'1', "+ @rentnpcdate +")";
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  130
  • Topics Per Day:  0.03
  • Content Count:  528
  • Reputation:   18
  • Joined:  09/11/12
  • Last Seen:  

Thanks. My coding skill at rahtena grows up :D

 

Is this a own syntex from rathena or is it based at a other scripting lanugage?

Link to comment
Share on other sites


  • Group:  Developer
  • Topic Count:  10
  • Topics Per Day:  0.00
  • Content Count:  2407
  • Reputation:   613
  • Joined:  07/05/12
  • Last Seen:  

Also change

set rentnpcdate,gettimetick(2)+604800;

rentnpcdate => @rentnpcdate

 

Is this a own syntex from rathena or is it based at a other scripting lanugage?

I'm not sure to understand what you mean. query_sql use synthaxe like mysql

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  130
  • Topics Per Day:  0.03
  • Content Count:  528
  • Reputation:   18
  • Joined:  09/11/12
  • Last Seen:  

i dont mean the sql comand. I mean the hole synthaxe (difine variable ect.)


So i have a other problem my NPC is near to finsih but i cant find the bug.

 

Message from mapserver:

 

[Error]:  Loading NPC file: npc/custom/rent.txt
script error on npc/custom/rent.txt line 39
script:add_word: invalid word. A word consists of undercores and/or alfanumeric characters, and valid variable prefixes/postfixes.

 

 

My script:

 

payon,115,115,1	script	Rent NPC	569,{

switch(select("What can i do here?:Rent a Healer")) {
  case 1:
    mes "If you give me some Coins the Healer will give you also Agi up and Blessing Level 5 for 7 days.";
    break;

  case 2:
  mes "You wanna rent the Healer for ^FF00007 Days^000000? You will lose ^FF000050 Coins^000000!";
  switch(select("Rent the Healer!:Run away.")) {
			
		  case 1:
			set @rentnpcdate,gettimetick(2)+604800;
			set @rentnpcdate2,gettimetick(2);
			query_sql "SELECT `char_id`,`npc`, `date` FROM `rentnpc`", @charid, @npc, @rentime;
			
			if (@charid == getcharid(0) && @npc == 1 && @renttime < gettimetick(2)){
			mes "You already rent the Healer.";
			close;
			}
			
			else if (@charid != getcharid(0) && @npc != 1 ) {
			//set @rentnpcdate,gettimetick(2)+604800;
						
						if (countitem(7539) < 50) {
						mes "Im Sorry, but you dont have enough Coins.";
						close;
												}
						
						else {
							delitem 7539, 50;
							query_sql "INSERT INTO `rentnpc` (`char_id`, `account_id`, `npc`, `date`) VALUES ('"+getcharid(0)+"', '"+getcharid(3)+"', '1', "+ @rentnpcdate +")";
							mes "Done!";
							break;
							}
															  }
			      
				  
			else (@charid == getcharid(0) && @npc == 1 && @renttime > @rentnpcdate) {
			//set @rentnpcdate,gettimetick(2)+604800;
						
						if (countitem(7539) < 50) {
						mes "Im Sorry, but you dont have enough Coins.";
						close;
												}
						
						else {
							delitem 7539, 50;
							query_sql "UPDATE `rentnpc` (`char_id`, `account_id`, `npc`, `date`) VALUES ('"+getcharid(0)+"', '"+getcharid(3)+"', '1', "+ @rentnpcdate +")";
							mes "Done!";
							break;
							}
															  }
			
			case 2:
			mes "...";
			

close;
}
Edited by King555
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  7
  • Topics Per Day:  0.00
  • Content Count:  181
  • Reputation:   53
  • Joined:  04/07/13
  • Last Seen:  

Insert a "if" behind the "else" in line 39:

else (@charid == getcharid(0) && @npc == 1 && @renttime > @rentnpcdate) {

=>

else if (@charid == getcharid(0) && @npc == 1 && @renttime > @rentnpcdate) {
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  130
  • Topics Per Day:  0.03
  • Content Count:  528
  • Reputation:   18
  • Joined:  09/11/12
  • Last Seen:  

thanks for fast help :)



If i talk to the NPC the first time i can rent the Healer all works fine. After that if i try to talk a 2. time to the Healer and choose "Rent a Healer" at the menu the message "..." comes.

But this messages is wrong because the NPC has to say "You already rent the Healer"?!

Edited by King555
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  7
  • Topics Per Day:  0.00
  • Content Count:  181
  • Reputation:   53
  • Joined:  04/07/13
  • Last Seen:  

I am not absolutely sure if this solves your problem because I can't test the script right now, but I suspect line 15 to be the problem. You set "@rentime" at this point, but in further uses you call to the undefined variable "@renttime" (notice the missing "t").

Edited by DeadlySilence
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  130
  • Topics Per Day:  0.03
  • Content Count:  528
  • Reputation:   18
  • Joined:  09/11/12
  • Last Seen:  

Yea this i had changed but dont helps with the problem. And there are no error messages.

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  7
  • Topics Per Day:  0.00
  • Content Count:  181
  • Reputation:   53
  • Joined:  04/07/13
  • Last Seen:  

I hope you don't mind I modified your script a little.

 

payon,115,115,1	script	Rent NPC	569,{

switch(select("What can i do here?:Rent a Healer")) {

    case 1:
    
        mes "If you give me some Coins the Healer will give you also Agi up and Blessing Level 5 for 7 days.";
        break;

    case 2:
    
        mes "You wanna rent the Healer for ^FF00007 Days^000000? You will lose ^FF000050 Coins^000000!";
        switch(select("Rent the Healer!:Run away.")) {
                
            case 1:
            
                set .@rentnpcdate,gettimetick(2)+604800;
                query_sql "SELECT `date` FROM `rentnpc` WHERE `char_id` = " + getcharid(0) + " AND `npc` = 1", .@renttime;
                
                if (.@renttime > gettimetick(2)){
                
                    mes "You already rent the Healer.";
                    close;
                } else {
                            
                    if (countitem(7539) < 50) {
                    
                        mes "Im Sorry, but you don't have enough Coins.";
                        close;
                    } else {
                    
                        delitem 7539, 50;
                        if (.@renttime) {
                            query_sql("UPDATE `rentnpc` SET `date` = " + .@rentnpcdate + " WHERE `char_id` = " + getcharid(0) + " AND `npc` = 1");
                        } else {
                            query_sql "INSERT INTO `rentnpc` (`char_id`, `account_id`, `npc`, `date`) VALUES ('"+getcharid(0)+"', '"+getcharid(3)+"', '1', "+ .@rentnpcdate +")";
                        }
                        mes "Done!";
                    }
                }
                break;
                
            case 2:
            
                mes "...";
                break;
                
        }
    }
    close;
}

It is working for me now.

 

//edit: I modified the SQL query to select only the row which belongs to the current user, so you don't have to check this inside the script. I also changed the second query to use an update rather than inserting a new row with almost the same data.

Edited by DeadlySilence
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  130
  • Topics Per Day:  0.03
  • Content Count:  528
  • Reputation:   18
  • Joined:  09/11/12
  • Last Seen:  

Thanks, no i dont mind because i am here to learn how to script. ;):)



Next Problem: I try to add a rent Warper. Script works but at the menü ingame there are a little bug.

 

If i chosse Upgrade now at the menü the message from the Healer pops up but to rent the warper works.

 

post-7694-0-30251300-1368010723_thumb.jpg

post-7694-0-21959800-1368010730_thumb.jpg

 

my script:

 

payon,99,93,1	script	Rent NPC	429,{

switch(select("Upgrade the Warper:Upgrade the Healer")) {

    case 1:
    
        mes "You wanna upgrade the Warper for ^FF00007 Days^000000? You will lose ^FF000025 Event Coins^000000! But the Warper cost are reduced by 50%.";
        switch(select("Upgrade now.:Run away.")) {
                
            case 1:
            
                set .@rentnpcdate,gettimetick(2)+604800;
                query_sql "SELECT `date` FROM `rentnpc` WHERE `char_id` = " + getcharid(0) + " AND `npc` = 2", .@renttime;
                
                if (.@renttime > gettimetick(2)){
                
                    mes "You already upgrade the Warper.";
                    close;
                } else {
                            
                    if (countitem(7539) < 25) {
                    
                        mes "Im Sorry, but you don't have enough Coins.";
                        close;
                    } else {
                    
                        delitem 7539, 25;
                        if (.@renttime) {
                            query_sql("UPDATE `rentnpc` SET `date` = " + .@rentnpcdate + " WHERE `char_id` = " + getcharid(0) + " AND `npc` = 2");
                        } else {
                            query_sql "INSERT INTO `rentnpc` (`char_id`, `account_id`, `npc`, `date`) VALUES ('"+getcharid(0)+"', '"+getcharid(3)+"', '2', "+ .@rentnpcdate +")";
                        }
                        mes "Done!";
                    }
                }
                break;
                
            case 2:
            
                mes "...";
                break;
                
        } 

    case 2:
    
        mes "You wanna rent the Healer for ^FF00007 Days^000000? You will lose ^FF000025 Event Coins^000000! But you will also get Agi up and Blessing level 10.";
        switch(select("Upgrade now!:Run away.")) {
                
            case 1:
            
                set .@rentnpcdate,gettimetick(2)+604800;
                query_sql "SELECT `date` FROM `rentnpc` WHERE `char_id` = " + getcharid(0) + " AND `npc` = 1", .@renttime;
                
                if (.@renttime > gettimetick(2)){
                
                    mes "You already rent the Healer.";
                    close;
                } else {
                            
                    if (countitem(7539) < 25) {
                    
                        mes "Im Sorry, but you don't have enough Coins.";
                        close;
                    } else {
                    
                        delitem 7539, 25;
                        if (.@renttime) {
                            query_sql("UPDATE `rentnpc` SET `date` = " + .@rentnpcdate + " WHERE `char_id` = " + getcharid(0) + " AND `npc` = 1");
                        } else {
                            query_sql "INSERT INTO `rentnpc` (`char_id`, `account_id`, `npc`, `date`) VALUES ('"+getcharid(0)+"', '"+getcharid(3)+"', '1', "+ .@rentnpcdate +")";
                        }
                        mes "Done!";
                    }
                }
                break;
                
            case 2:
            
                mes "...";
                break;
                
        }
    }
    close;
}

 

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  7
  • Topics Per Day:  0.00
  • Content Count:  181
  • Reputation:   53
  • Joined:  04/07/13
  • Last Seen:  

You forgot to break out of the outer cases after finshing. If you don't use break or any other command that ends the script (like "end;" or "close;"), it will jump into the next case. You have to add a "break;" to line 44.

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  130
  • Topics Per Day:  0.03
  • Content Count:  528
  • Reputation:   18
  • Joined:  09/11/12
  • Last Seen:  

ah i see. Is there a good Tutorial for rookie scripter? i know the ratahena wiki about scripting but this is really short and not so exactly about so small thinks like the break.

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  7
  • Topics Per Day:  0.00
  • Content Count:  181
  • Reputation:   53
  • Joined:  04/07/13
  • Last Seen:  

You could look at the documentation included in the repository, it provides examples for almost every script command and use-case. It is located in doc/script_commands.txt.

 

//edit: By the way, I sent you a message.

Edited by DeadlySilence
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...