Vincent Posted May 5, 2013 Group: Members Topic Count: 130 Topics Per Day: 0.03 Content Count: 528 Reputation: 18 Joined: 09/11/12 Last Seen: March 5, 2020 Share Posted May 5, 2013 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? Quote Link to comment Share on other sites More sharing options...
Jaburak Posted May 5, 2013 Group: Members Topic Count: 48 Topics Per Day: 0.01 Content Count: 1125 Reputation: 236 Joined: 07/30/12 Last Seen: Sunday at 01:45 AM Share Posted May 5, 2013 Like this? http://rathena.org/board/topic/79823-zephyrus-housing-system/ Quote Link to comment Share on other sites More sharing options...
Vincent Posted May 5, 2013 Group: Members Topic Count: 130 Topics Per Day: 0.03 Content Count: 528 Reputation: 18 Joined: 09/11/12 Last Seen: March 5, 2020 Author Share Posted May 5, 2013 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. Quote Link to comment Share on other sites More sharing options...
Reynard Posted May 5, 2013 Group: Members Topic Count: 2 Topics Per Day: 0.00 Content Count: 56 Reputation: 9 Joined: 09/22/12 Last Seen: August 16, 2020 Share Posted May 5, 2013 (edited) 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 May 5, 2013 by Reynard 1 Quote Link to comment Share on other sites More sharing options...
Vincent Posted May 6, 2013 Group: Members Topic Count: 130 Topics Per Day: 0.03 Content Count: 528 Reputation: 18 Joined: 09/11/12 Last Seen: March 5, 2020 Author Share Posted May 6, 2013 (edited) 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 May 6, 2013 by King555 Quote Link to comment Share on other sites More sharing options...
Capuche Posted May 6, 2013 Group: Developer Topic Count: 10 Topics Per Day: 0.00 Content Count: 2407 Reputation: 616 Joined: 07/05/12 Last Seen: March 20 Share Posted May 6, 2013 '"1"', "@rentnpcdate")"; => '1', "+ @rentnpcdate +")"; Quote Link to comment Share on other sites More sharing options...
Vincent Posted May 6, 2013 Group: Members Topic Count: 130 Topics Per Day: 0.03 Content Count: 528 Reputation: 18 Joined: 09/11/12 Last Seen: March 5, 2020 Author Share Posted May 6, 2013 Thanks. My coding skill at rahtena grows up Is this a own syntex from rathena or is it based at a other scripting lanugage? Quote Link to comment Share on other sites More sharing options...
Capuche Posted May 6, 2013 Group: Developer Topic Count: 10 Topics Per Day: 0.00 Content Count: 2407 Reputation: 616 Joined: 07/05/12 Last Seen: March 20 Share Posted May 6, 2013 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 Quote Link to comment Share on other sites More sharing options...
Vincent Posted May 6, 2013 Group: Members Topic Count: 130 Topics Per Day: 0.03 Content Count: 528 Reputation: 18 Joined: 09/11/12 Last Seen: March 5, 2020 Author Share Posted May 6, 2013 (edited) 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.txtscript error on npc/custom/rent.txt line 39script: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 May 6, 2013 by King555 Quote Link to comment Share on other sites More sharing options...
DeadlySilence Posted May 6, 2013 Group: Members Topic Count: 7 Topics Per Day: 0.00 Content Count: 181 Reputation: 53 Joined: 04/07/13 Last Seen: August 23, 2014 Share Posted May 6, 2013 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) { Quote Link to comment Share on other sites More sharing options...
Vincent Posted May 6, 2013 Group: Members Topic Count: 130 Topics Per Day: 0.03 Content Count: 528 Reputation: 18 Joined: 09/11/12 Last Seen: March 5, 2020 Author Share Posted May 6, 2013 (edited) 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 May 6, 2013 by King555 Quote Link to comment Share on other sites More sharing options...
DeadlySilence Posted May 7, 2013 Group: Members Topic Count: 7 Topics Per Day: 0.00 Content Count: 181 Reputation: 53 Joined: 04/07/13 Last Seen: August 23, 2014 Share Posted May 7, 2013 (edited) 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 May 7, 2013 by DeadlySilence Quote Link to comment Share on other sites More sharing options...
Vincent Posted May 7, 2013 Group: Members Topic Count: 130 Topics Per Day: 0.03 Content Count: 528 Reputation: 18 Joined: 09/11/12 Last Seen: March 5, 2020 Author Share Posted May 7, 2013 Yea this i had changed but dont helps with the problem. And there are no error messages. Quote Link to comment Share on other sites More sharing options...
DeadlySilence Posted May 7, 2013 Group: Members Topic Count: 7 Topics Per Day: 0.00 Content Count: 181 Reputation: 53 Joined: 04/07/13 Last Seen: August 23, 2014 Share Posted May 7, 2013 (edited) 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 May 7, 2013 by DeadlySilence Quote Link to comment Share on other sites More sharing options...
Vincent Posted May 8, 2013 Group: Members Topic Count: 130 Topics Per Day: 0.03 Content Count: 528 Reputation: 18 Joined: 09/11/12 Last Seen: March 5, 2020 Author Share Posted May 8, 2013 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. 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; } Quote Link to comment Share on other sites More sharing options...
DeadlySilence Posted May 8, 2013 Group: Members Topic Count: 7 Topics Per Day: 0.00 Content Count: 181 Reputation: 53 Joined: 04/07/13 Last Seen: August 23, 2014 Share Posted May 8, 2013 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. Quote Link to comment Share on other sites More sharing options...
Vincent Posted May 8, 2013 Group: Members Topic Count: 130 Topics Per Day: 0.03 Content Count: 528 Reputation: 18 Joined: 09/11/12 Last Seen: March 5, 2020 Author Share Posted May 8, 2013 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. Quote Link to comment Share on other sites More sharing options...
DeadlySilence Posted May 8, 2013 Group: Members Topic Count: 7 Topics Per Day: 0.00 Content Count: 181 Reputation: 53 Joined: 04/07/13 Last Seen: August 23, 2014 Share Posted May 8, 2013 (edited) 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 May 8, 2013 by DeadlySilence Quote Link to comment Share on other sites More sharing options...
Question
Vincent
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
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.