-
Content Count
1677 -
Joined
-
Last visited
-
Days Won
246
Content Type
Profiles
Forums
Downloads
Staff Applications
Calendar
Everything posted by AnnieRuru
-
6. How to show the current rank of the player Question : This is the part of the script, output as below .@nb = query_sql("SELECT `name`, `kills` FROM `pvpladder` ORDER BY `kills` DESC LIMIT 5", .@name$, .@kills); for ( .@i = 0; .@i < .@nb; .@i++ ) mes "No."+(.@i+1)+" ["+ .@name$[.@i] +"] ~ "+ .@kills[.@i] +" kills"; No.1 [Alice] ~ 19 kills No.2 [Emily] ~ 11 kills No.3 [Irene] ~ 11 kills No.4 [Brittany] ~ 8 kills No.5 [Fiona] ~ 7 kills 2nd place and 3rd place has the same amount of kills, how do I make both of them display as 2nd place like this ? No.1 [Alice] ~ 19 kills No.2 [Emily] ~ 11 kills No.2 [Irene] ~ 11 kills No.4 [Brittany] ~ 8 kills No.5 [Fiona] ~ 7 kills Answer : Method no.1: Convert the table into InnoDB will return the result faster. Allow to use OFFSET .@nb = query_sql("SELECT `name`, `kills`, FIND_IN_SET(`kills`, (SELECT GROUP_CONCAT(`kills` ORDER BY `kills` DESC) FROM `pvpladder`)) FROM `pvpladder` ORDER BY `kills` DESC LIMIT 5", .@name$, .@kills, .@rank); for ( .@i = 0; .@i < .@nb; ++.@i ) mes "No."+ .@rank[.@i] +" ["+ .@name$[.@i] +"] ~ "+ .@kills[.@i] +" kills"; Method no.2: This method return result faster than method 1 in huge table. Not allow to use OFFSET .@query$ = "SELECT `name`, IF(@d=t.`kills`, @r, @r:=@i), @d:=t.`kills`, @i:=@i+1 "; .@query$ += "FROM `pvpladder` t, (SELECT @d:=0, @r:=0, @i:=1)q "; .@query$ += "ORDER BY `kills` DESC LIMIT 5"; .@nb = query_sql(.@query$, .@name$, .@rank, .@kills, .@dummy); for ( .@i = 0; .@i < .@nb; ++.@i ) mes "No."+ .@rank[.@i] +" ["+ .@name$[.@i] +"] ~ "+ .@kills[.@i] +" kills"; . . Question : How do I show the current ranking of the player ? mes "Your kills -> "+ .@kills; mes "Your rank -> "+ .@rank; Answer : query_sql "SELECT `kills`, 1+(SELECT COUNT(1) FROM `pvpladder` t1 WHERE t1.`kills` > t2.`kills`) FROM `pvpladder` t2 WHERE `char_id` = "+ getcharid(0), .@kills, .@rank; Remember to index the `kills` field Reference : https://dba.stackexchange.com/questions/13703/get-the-rank-of-a-user-in-a-score-table .
-
5. How to do IF-ELSE in SQL query ? Question : I have a PVP ladder script that runs on Points system. Each kill plus 1 point and each death minus 1 point. The problem is, this query will make the points go into negative value if the player is being kill repeatedly query_sql "UPDATE `pvp_points` SET `points` = `points` - 1 WHERE `char_id` = "+ getcharid(0); How do I make the points stop at 0 if the player is already at 0 points ? Answer : query_sql "UPDATE `pvp_points` SET `points` = IF(`points` = 0, 0, `points` - 1) WHERE `char_id` = "+ getcharid(0); query_sql "UPDATE `pvp_points` SET `points` = (CASE WHEN `points` = 0 THEN 0 ELSE `points` - 1 END) WHERE `char_id` = "+ getcharid(0); Explanations: similar to hercules script language, if (<condition>) <execute true condition>; else <execute false condition>; in SQL language IF(<condition>, <execute true condition>, <execute false condition>) CASE WHEN <condition> THEN <execute true condition> ELSE <execute false condition> END Reference : https://www.w3schools.com/sql/func_mysql_if.asp https://stackoverflow.com/questions/63447/how-do-i-perform-an-if-then-in-an-sql-select 5a. How to update multiple rows on different conditions in a single query This query will update multiple rows on different condition UPDATE `pvpladder` SET `points` = CASE WHEN `char_id` = 150000 THEN `points` +1 WHEN `char_id` = 150001 THEN `points` -1 END WHERE `char_id` IN (150000,150001); Reference : https://stackoverflow.com/questions/20255138/sql-update-multiple-records-in-one-query
-
4. AUTO_INCREMENT CREATE TABLE `support_ticket` ( `id` INT(11) AUTO_INCREMENT, `title` VARCHAR(70), `message` VARCHAR(255), PRIMARY KEY (`id`) ) ENGINE = InnoDB; In this kind of query that has AUTO_INCREMENT, many people do .... $support_ticket_id++; query_sql "INSERT INTO `support_ticket` VALUES ( "+ $support_ticket_id +", '"+ escape_sql(.@title$) ... can be optimize .... using NULL query_sql "INSERT INTO `support_ticket` VALUES ( NULL, '"+ escape_sql(.@title$) ... can retrieve the last row with query_sql "SELECT MAX(`id`) FROM `support_ticket`", .@id; // ----- OR ----- query_sql "SELECT LAST_INSERT_ID()", .@id; Question : This question was asked on eathena forum board One of my friend touched my custom table and the AUTO_INCREMENT has jump off the value | 1 | <data set 1> | 2 | <data set 2> | 3 | <data set 3> | 25854 | <data set 4> | 25855 | <data set 5> | 25856 | <data set 6> I want to make the value return back to normal as shown | 1 | <data set 1> | 2 | <data set 2> | 3 | <data set 3> | 4 | <data set 4> | 5 | <data set 5> | 6 | <data set 6> How to do this WITHOUT losing any of the current data ? Answer: The trick is ... just drop that column and rebuild it ALTER TABLE `inventory` DROP COLUMN `id`; ALTER TABLE `inventory` ADD COLUMN `id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST; convert the table into MyISAM will process the query much faster
-
3. Choose a table type, MyISAM or InnoDB ? https://stackoverflow.com/questions/20148/myisam-versus-innodb Before MySQL 5.5, MyISAM is mostly use for read-heavy + table locking storage engine = such as pvp ladder ( always select ... order by kill desc ) InnoDB is mostly use for write-heavy + row locking storage engine = such as quest script ( select ... from char_id ... only 1 row is retrieve ) After MySQL 5.6, (currently is 8.0) just stick to InnoDB there is only 1 reason MyISAM is better than InnoDB - MyISAM use smaller disk usage than InnoDB let's take a look at our MyISAM to InnoDB converter https://github.com/HerculesWS/Hercules/blob/stable/sql-files/tools/convert_engine_innodb.sql This converter is useful if you are using MySQL 5.6 or above There are 4 tables that are commented out the reason is simple, these 4 tables only read once and forgotten when server is live since MyISAM is good at reading (SELECT) + smaller disk usage, its no use to convert these 4 tables into InnoDB 3a How to index a table properly http://mysql.rjweb.org/doc.php/index_cookbook_mysql http://www.dbta.com/Columns/DBA-Corner/Top-10-Steps-to-Building-Useful-Database-Indexes-100498.aspx a simple thumb of rule, anything that is SELECT .... WHERE `field` = ..... that `field` has to be index let's take a look at this PVP Ladder script that use Kill/Death ratio CREATE TABLE `pvpladder` ( `char_id` INT(11), `name` VARCHAR(23), `kills` INT(11), `death` INT(11), PRIMARY KEY (`char_id`), KEY (`kills`, `death`) ) ENGINE = InnoDB; prontera,155,186,6 script PVP Ladder 1_F_MARIA,{ .@nb = query_sql( "SELECT `name`, `kills`/(`death`+1) FROM `pvpladder` WHERE `kills` > 0 ORDER BY `kills`/(`death`+1) DESC LIMIT 10", .@name$, .@ratio$ ); if ( !.@nb ) { mes "no entry"; close; } mes "Current Ranking :"; for ( .@i = 0; .@i < .@nb; ++.@i ) mes "No."+(.@i +1)+" ["+ .@name$[.@i] +"] "+ .@ratio$[.@i] +" kill"; close; OnPCKillEvent: if ( killedrid == getcharid(3) ) { // killing self should only increase death count. EG: Grand-cross query_sql "INSERT INTO `pvpladder` VALUES ( "+ getcharid(0) +", '"+ escape_sql( strcharinfo(0) )+"', 0,1 ) ON DUPLICATE KEY UPDATE `death` = `death` +1"; end; } query_sql "INSERT INTO `pvpladder` VALUES ( "+ getcharid(0) +", '"+ escape_sql( strcharinfo(0) )+"', 1,0 ) ON DUPLICATE KEY UPDATE `kills` = `kills` +1"; attachrid killedrid; query_sql "INSERT INTO `pvpladder` VALUES ( "+ getcharid(0) +", '"+ escape_sql( strcharinfo(0) )+"', 0,1 ) ON DUPLICATE KEY UPDATE `death` = `death` +1"; end; } This kind of query -> ORDER BY kills/death, needs to index them together like this KEY (`kills`, `death`) 3b. Why you shouldn't use `char_reg_num_db` table blame Euphy for spreading this technique There are 2 reasons why you shouldn't even touch all these variable tables Reason no.1 This table is sorely meant for server usage Once these data is loaded, it is process internally, and only save character data according to this configuration Reason no.2 The `value` field is not index ! This line has ORDER BY `value`, try recheck our main.sql file CREATE TABLE IF NOT EXISTS `acc_reg_num_db` ( `account_id` INT(11) UNSIGNED NOT NULL DEFAULT '0', `key` VARCHAR(32) BINARY NOT NULL DEFAULT '', `index` INT(11) UNSIGNED NOT NULL DEFAULT '0', `value` INT(11) NOT NULL DEFAULT '0', PRIMARY KEY (`account_id`,`key`,`index`), KEY `account_id` (`account_id`) ) ENGINE=MyISAM; SQL will search through every single line in the `value` field if that column isn't index Of course you can ... do ALTER table to add KEY to the `value` field but this table has already optimized in that way for server usage the more field you index into the table, the more disk usage space it use Conclusion : If you want to make a custom script, then make a custom table. Leave these table alone !
-
2. How to build a case-sensitive table this is the answer I found http://dba.stackexchange.com/questions/15250/how-to-do-a-case-sensitive-search-in-where-clause by default, the table creation use charset = latin1; means it couldn't do a case-sensitive search if you want to do a case-sensitive in a query, use BINARY SELECT * FROM `char` WHERE `name` = BINARY('AnnieRuru'); however using BINARY might have performance hit if it is a big table so its more recommend to convert your SQL table to collate with latin1_general_cs let's say this is a sample table CREATE TABLE `test` ( `id` INT(11) PRIMARY KEY AUTO_INCREMENT, `name` VARCHAR(23) )ENGINE = InnoDB; do an ALTER table syntax ALTER TABLE `test` MODIFY COLUMN `name` VARCHAR(23) COLLATE latin1_general_cs; or just put it into the table creation CREATE TABLE `test` ( `id` INT(11) PRIMARY KEY AUTO_INCREMENT, `name` VARCHAR(23) )ENGINE = InnoDB DEFAULT CHARSET = latin1 COLLATE latin1_general_cs;
-
1. When to use escape_sql script command . input .@haha$; dispbottom .@haha$; dispbottom escape_sql(.@haha$); it doesn't has much differences, because it only affect 3 special characters ' <- single quotation mark " <- double quotation mark \ <- left slash if I input -> haha"lala'hehe <- it will return -> haha\"lala\'hehe <- this is what we call, Escape a character in hercules script, we also know we can use " symbol in any string input mes "Susan says :\" Today I ate 3 eggs \"."; where in the game client, you can see the " symbol in the npc msg box let's say I have a sql script like this prontera,153,171,5 script Show Characters 1_F_MARIA,{ mes "input name, I'll show you all characters name it has on that player's account"; input .@name$; .@nb = query_sql("SELECT `char_id`, `name` FROM `char` WHERE `name` LIKE '"+ .@name$ +"'", .@cid, .@name$); if ( !.@nb ) { mes "no result"; close; } for ( .@i = 0; .@i < .@nb; ++.@i ) mes .@cid[.@i] +" "+ .@name$[.@i]; close; } this script has a possibility to be hacked because to perform sql injection, I can enclose the string with quotation mark, then use another sql command to hack BUT with an escape_sql command, if the user want to enclose the string with quotation mark to hack the script the escape_sql command escaped the string, the quotation mark the user input will be escaped thus the script will become impossible to hack just now that script was for string input prontera,153,171,5 script Show Characters 1_F_MARIA,{ mes "input account ID, I'll show you all characters name it has on that player's account"; input .@aid$; .@nb = query_sql("SELECT `char_id`, `name` FROM `char` WHERE `account_id` = "+ escape_sql(.@aid$), .@cid, .@name$); if ( !.@nb ) { mes "no result"; close; } for ( .@i = 0; .@i < .@nb; ++.@i ) mes .@cid[.@i] +" "+ .@name$[.@i]; close; } this is another stupid case. 1. the scripter use string input while the script just needed a number 2. even with escape_sql command over there, there is no quotation mark at all yes this script also has a risk to be hack because escape_sql only escape quotation mark. that hacker don't even have to input quotation mark because it is a number and an injection query can be sent without any quotation mark input there are 2 ways to solve this either use numeric variable for the input command or enclose that .... ..... WHERE `account_id` = '"+ escape_sql(.@aid$) +"'", .... with single quotation mark, when the hacker input a quotation mark will be escaped by escape_sql command Reference : https://www.w3schools.com/sql/sql_injection.asp escape_sql command for another thing is if the player register their names containing ' or ", these characters are escaped only happens when the server have no restriction on the creation of players name hercules\conf\char\char-server.conf // Manage possible letters/symbol in the name of charater. Control character (0x00-0x1f) are never accepted. Possible values are: // NOTE: Applies to character, party and guild names. // 0: no restriction (default) // 1: only letters/symbols in 'name_letters' option. // 2: Letters/symbols in 'name_letters' option are forbidden. All others are possibles. name_option: 1 and this was what happened to my SQL dota pvpladder script Silo's Babies <-- this is a guild name you can see the 5th string has a single quotation mark with escape_sql command, that string will turn into Silo\'s Babies <-- the quotation mark is escaped when send to sql query
-
err ... maybe yes, maybe no which bg ? I write my own go make some ideas in script request section and I'll write it out
-
As usual, I only write advance guides This guide is a compilation of SQL commands that I have used, or Questions answered on the forum every single subject here are related to Hercules/Ragnarok Online in some ways, so you won't feel bored reading them XD Table of Content 1. When to use *escape_sql script command 2. How to build a case-sensitive table 3. Choose a table type, MyISAM or InnoDB ? 3a. How to index a table properly 3b. Why you shouldn't use `char_reg_num_db` table 4. AUTO_INCREMENT 5. How to do IF-ELSE in SQL query ? 5a. How to update multiple rows on different conditions in a single query 6. How to show the current rank of the player 7. INSERT INTO ... SELECT ... 8. Table JOIN vs AS 9. What is the maximum string limit for *query_sql 9a. UNION This topic is now open to Suggestions, Ideas, Improvements, and Questions ~ I'm sure many of you have some questions since the creation of this topic You may also post up your tricks if you want to share with us
-
2.4b http://upaste.me/0c8149627b3ddc0c6 - fix a typo in mission limitation can do daily or only once, actually allows to do twice instead of once - fix a typo in mission time limit, if your mission no.2/3/4 has expired, the script always says slot no.1 @Helena 2.4c http://upaste.me/7c9c496344829d36f - fix this f*cking deny usage once again ...this time when submit a mission, the getarraysize calculation is made AFTER declare the datetime format - if the whole board is set to EVERYDAY, remove the player side deny usage variable completely on the next day
-
@caspa try this http://upaste.me/6b6a49616cc4ceec9 kinda know your request because you also post almost identical request on the rathena forum
-
these steps are the same as rAthena, conf\grf-files.txt //----------------------------------------- // GRF Files // Add as many as needed. //----------------------------------------- grf: D:\Ragnarok\client\rdata.grf grf: D:\Ragnarok\client\data.grf //----------------------------------------- // Data Directory // Use the base folder, not the data\ path. //----------------------------------------- data_dir: D:\Ragnarok\client\ conf\map\maps.conf "arathi", db\map_index.txt arathi 1250 actually should do these steps before the above post I assume many people know about this because .... after do these 3 steps, in rathena just have to click mapcache.bat https://rathena.org/board/topic/108109-requesting-guide-on-how-to-create-a-mapcache/ EDIT: for below - wow, how much spoon feeding is weemapcache system ...
-
gvg King of Emperium Hill
AnnieRuru replied to AnnieRuru's topic in PvP, WoE, GvG, & Battleground Releases
got a PM from rAthena member ask me to fix this yeah both rathena patch and hercules plugin ... all broken so .... update to 1.2 Script Plugin for Hercules Patch for rAthena -
killedrid variable don't work with script command monster
AnnieRuru replied to luizragna's question in Script Support
ok this need some testing ... prontera,155,190,5 script test 1_F_MARIA,{ mes "the monster you just killed is "; mes getmonsterinfo( killedrid, MOB_NAME ); select "summon"; monster "this", -1,-1, "--ja--", 1002,1, strnpcinfo(0)+"::Onaaa"; mes "monster summoned"; close; Onaaa: end; } rathena -> yup it shows Poring hercules -> you are right, it shows null you are right, rathena fixed this https://github.com/rathena/rathena/pull/1286 -
function Array manipulation functions
AnnieRuru replied to meko's topic in Quest, Shops, Functions & Algorithms Releases
http://upaste.me/542d49579ec44be6d quick sort = 390~437 miliseconds (str & int) comb sort = 312~344 miliseconds (str & int) counting sort = 47~63 miliseconds (integer only) comb sort still outperform quick sort or merge sort in hercules script engine the reason is just like Haru said, *athena script engine parse function (for/while/goto) very slow, the more function it runs, the more slower it gets and there is no need to use *strcmp script command poring_w01,105,105,5 script test string 1_F_MARIA,{ dispbottom ( "test" == "test" ); // return 1 dispbottom ( "123" > "321" ); // return 0 dispbottom ( "asdf" < "qwer" ); // return 1 end; } -
1st of all, sorry I only know windows environment -- windows sux !! 2nd, yeah I agree too, this took me 2 days to figure out how to do this reference topic Prelude make sure you already know how to install a plugin http://herc.ws/wiki/Building_HPM_Plugin_for_MSVC yup ~ use the new method ~ ( maybe I should've remove the old method already ... ) and add "mapcache" to your "hercules\conf\plugins.conf" Run command prompt 1. [Windows Key] + [R] -> type cmd https://drive.google.com/file/d/19Ni-NUAZusaCgEX6xnXxasZDLHtkW-N-/view?usp=sharing 2. point to your Hercules emulator folder, and type mapserver.exe --help https://drive.google.com/file/d/1EpB4jxaB3VAO0XzB9gJq7t6fmtBb4RZ5/view?usp=sharing 3. type mapserver.exe --map <YourMap> https://drive.google.com/file/d/1Q68HSNaxvGEwsm6UeHEcgL2BY-JpKNgV/view?usp=sharing now that you know the commands ... lets do it easier way Windows Execution File -- Create Shortcut 1. point to your map-server.exe, and create shortcut https://drive.google.com/file/d/15szzAa8Fuef9UQUjB3rsygNafoLtr6Tm/view?usp=sharing 2. right-click, Properties, and edit the Target Location/Target (this example is my hercules directory) D:\Ragnarok\Hercules\map-server.exe --map <YourMap> https://drive.google.com/file/d/1hwqPrJE4M53QkoAeiuA4pFCF1A8ZHPpz/view?usp=sharing whenever I want to add new maps, I just need to edit the Target field, and double click the program ~ fast and easy ~ Fun Facts !! do you know you can use GM command in map-server.bat ? https://drive.google.com/file/d/15gOf4vgl9HWc58Q8Jdn9Vbbza5lY5ek6/view?usp=sharing
-
yup ~ :unhides: I'm was digesting all the changes in last 2 weeks but I think I'm ready to make appearance again ~
-
function Array manipulation functions
AnnieRuru replied to meko's topic in Quest, Shops, Functions & Algorithms Releases
omg .. I've used this quite a lot in my battleground scripts to shuffle the array of the participants, to prevent players predicting they would join in which team :stumble: never encounter a situation require this feature yet ~ reminds me of my old mission board script ... yeah, if I have known about these function, that script would have been much cleaner, rather than having for-loop over and over in that script and I have fun playing with your scripts ~ maybe we can have another algorithm script discussion again some other time ~ -
function Array manipulation functions
AnnieRuru replied to meko's topic in Quest, Shops, Functions & Algorithms Releases
:thumpsup: http://upaste.me/fa9a49576f63f6540 is there any explicit reason why you are using .@index and *getarrayindex ? I play around a little bit and don't think it serve any .... meaning ? -
function Array manipulation functions
AnnieRuru replied to meko's topic in Quest, Shops, Functions & Algorithms Releases
ohhhh ~ yesh algorithm script ~~~ not really sure about myself getting to use any of these, but the array_shuffle(<array>) makes me very interested testing .... EDIT : Oops ... I edited your script, sry ... it didn't throw error actually http://upaste.me/5b17495746d1cbe0e yup ~ a stable shuffle algorithm, gives 100 cases averagely each time but do you know about the existence of Fisher-Yates shuffle ? because if I understand your script correctly, you are using pencil and paper method and how about ... ahem ~ ahem ~ the sorting algorithm function ... that you can sort an array 4,3,5,1,2 into 1,2,3,4,5 ? PS: do a forum search "merge sort" or "counting sort" -
russian roulette ... this is old school .. I've seen this a lot during eathena days a few things that I like to point out 1. try use queue iterator script commands instead of needlessly using SQL table 2. instead of using areaannounce, try use announce with bc_npc flag oh ... I miss this one ... setd("$RRREGISTRED_"+uniqueid$+"", 0) this is bad ... really bad scripting practice ... never ever misuse the global permanent server variable, this can potentially kill your server like in this case, if enough players are playing this game using this script, in time your server will start to hang up
-
requesting hexed client compatible with 20170705
AnnieRuru replied to AnnieRuru's question in General Server Support
viola ~ .... and I thought it already works ... still the same small font langtype 0 https://drive.google.com/file/d/1nfDT7bBXKujvbevJx5vjlx97UG8xJNP0/view langtype 1 https://drive.google.com/file/d/1BY8OXomPxG9mIH6D-yzOlOVdUJ8iwbiU/view it get worse ? but thanks for the links, I just need the chat log looks normal, langtype 0 should work fine for me ~ EDIT: I hexed the client with "use custom font" setting, now no more small fonts ~ -
requesting hexed client compatible with 20170705
AnnieRuru replied to AnnieRuru's question in General Server Support
like all other members has posted too, this has nothing to do with langtype my langtype is 0 on a side note, the client you listed ... are quite dated ? I was expecting more recent client like year 2017 ... or something later .... (PS: playing oldies game Diablo 2 at the moment, Necromancer level23 ~) -
requesting hexed client compatible with 20170705
AnnieRuru posted a question in General Server Support
I start to feel lazy at this moment and hoping for the help from the community again ~ hurray ~~ anyway I have successfully setup my RO server, and connect with my damn old 2014-01-15 client successfully but this damn old hexed client give me very small font (other has posted similar problem), and this doesn't help me at all in scripting so I guess I come here and ask the community again and just provide me with a hexed client ...I already download recent clean KRO from this topic now I just need a hexed client that works with this KRO -
@@cxx you mean this one ? https://en.wikipedia.org/wiki/Ragnarok_%28manhwa%29 this is the concept of this RO game come from you can read it online at mangafox @@Skyline ROFL now I remember those days I woke up early every morning and make my own lunch box to school, so my pocket money is not spent in the canteen, but to buy these access cards XD