Friday, February 22, 2019

List pet eggs in your inventory

Just like signed items, which use 255 or 254 in the card1 field


Hercules Pet egg uses -256 in the card1 field
rathena use 256 ... without the negative

the earliest ... traceable topic is over here
https://rathena.org/board/topic/76954-can-i-request-script-evolution-pet/?sortby=date

and now for the latest script available...
https://drive.google.com/file/d/1hQgJO4MbHIQtymKxnsrxsi37nkJ1eruz/view

the way to retrieve the pet ID is almost similar to the signed item

Signed Item
card1 = 255 or 254
card2 = star crumb + element
card3 = CHAR_ID & (( 1 << 16 ) -1)
card4 = CHAR_ID >> 16

Pet ID
card1 = -256 (Hercules) or 256 (rAthena)
card2 = CHAR_ID & (( 1 << 16 ) -1)
card3 = CHAR_ID >> 16
card4 = 0


External Links:

Pet egg renewal fixing

Saturday, February 16, 2019

Hercules script engine is case-sensitive, rAthena isn't

I still remember when I was still Scripting Moderator in rAthena, there was this old bug report ...
...  after rAthena switched to IPB4 ... forum bug tracker down ....
anyway, it goes like this

Joseph open a bug report, claiming some official script doesn't execute the monster label properly
after some debate between the developers, I posted a script and prove them it is true
make one npc with the capital letter, and another one without capital letter -> OnDead - Ondead
click on 'asdf' npc, after kill the monster, the map-server.exe spam error
BrianL immediately add tag [Confirmed] and [Severity-Medium] to this bug report
within a few weeks, both Euphy and Joseph fix all the npc scripts in the emulator, and they mark it as [Solved]

..... the truth is, if you try the above script in latest rAthena, this bug still happen TODAY
this bug can't reproduce in Hercules because Hercules has case-sensitive script engine



Now let's talk about how crazy the script can be, if the script engine is not case-sensitive

other than npc header, 'prontera' and '1_F_MARIA',
script commands, labels, variables and constants are case-insensitive in rAthena
strings that enclosed in " double-quotation mark are not affected
means "this" "--ja--" "all" "All" still has to retain its format


This will throw duplicate label error in rAthena
in Hercules, click on the npc will display "2" properly

So, rAthena users, remember, don't simply use Onmobdead: label in your scripts
because official script already uses OnMobDead, OnMyMobDead, ... etc
... anyways, any official script already using that label name, Don't change into small letters in your scripts


... btw, SQL commands are still case-insensitive,
so me as Hercules user still uses small letters in *query_sql script commands


External Links:

Player Checker NPC
... once rAthena forum bug tracker up, will post that bug tracker ID here ...

Friday, February 15, 2019

messagecolor

make the NPC or monster object display chat-box in colorize message


Download :

Hercules Plugin
rAthena Patch

Note: this 0.3 version can display chat-box for the player
however the chat-box above your head isn't colorize because there are no known way to do it

Hercules' @fontcolor actually use a trick to disguise the player
https://github.com/HerculesWS/Hercules/issues/1217
https://github.com/HerculesWS/Hercules/issues/1930
and it has some bugs, so its better not to emulate that pattern
.... apparently rAthena @fontcolor is broken ...

Saturday, February 9, 2019

What is dynamic_mob and how it affects scripts

What is dynamic_mob ?

conf/map/battle/monster.conf

This setting means, monsters only spawn on the map when there is a player warp in.
if the map is left empty for 5 minutes, all dynamic spawned monsters, except spawn by boss_monster will remove from the map

it is recommend to turn on dynamic_mob because it help save memory on your live server

Example:

Let's say you login in Prontera town, and type "@asdf", poring and golden_bug are not spawn, only poporing has been spawn
"@rura guild_vs2", warp into the map, all 3 monsters are spawned
"@go 0", return to prontera, after 5 minutes, the poring is remove from the map, only golden_bug and poporing remain
"@reloadscript", return everything as normal, only poporing remain

This means :-
1. All monster spawn dynamically are affected by dynamic_mob, *monster script command are not affected
2. once a player warp into the map, all monsters will spawn normally
3. after 5 minutes the map left empty, all non-boss_monster will be remove

This can cause problem to the script if you want to count how many monsters left in the map
because dynamic_mob will NOT load the monster until a player warp into the map


External Links:

mobs on server start
MVP board

Wednesday, February 6, 2019

Allow OnNPCKillEvent to increase kill counter for party members

I still see a lot members struggle with this issue,
however this is entirely done with scripting alone

this is a normal template to increase kill counter normally for the killer alone

and this is for party support


Now to break it down part by part



this part is obvious, prevent *getpartymember throw error when the player doesn't own a party



change the scope of the killedrid from player based to script state
so there is no need to use *getvariableofpc (hercules) or *getvar (rAthena)


copy paste this part from script commands.txt

// loop through both and use 'isloggedin' to count online party members
    for (.@i = 0; .@i < $@partymembercount; ++.@i)
        if (isloggedin($@partymemberaid[.@i], $@partymembercid[.@i]))
            .@count_online++;
// We search accountID & charID because a single party can have
// multiple characters from the same account. Without searching
// through the charID, if a player has 2 characters from the same
// account inside the party but only 1 char online, it would count
// their online char twice.



the first 2 conditions is to check the party members are within range of the killer
means if the attached party member having same map with the killer, and within 30 cells of the killer

Why 30 ?? this is actually a magical number
you see, because the OnNPCKillEvent return the mob ID (1002) instead of game ID (11000021)
we can't really use mob controller system to retrieve the coordinate of the monster
so we use the range from the killer instead
I have actually tried to use getbattleflag("area_size") before, but players complained it doesn't work
so I increased the distance to 30 (about twice the length), and they say the script is fixed
weird ... I know, so the number 30 is kinda stuck in most of my scripts

1 possible explanation is this

if the Archer shoot long distances, like using a bow, throw arrow, or mage firebolt, crusader throw shield
then the party member from across the screen should gets the kill
"area_size" is 14, so 14+14 = 28, so 30 works for them


Hp ... you don't want the counter to increase for dead party member
so if that player is dead, Hp is 0, and the condition will become false there
this is to prevent having players increase the kill count by just AFK there


External Links:

Euphy's Hunting Mission ( check this line )
Party Share Kill ( tr0n's Quest Board )

Regular Expression Replace in Notepad++

Notepad++ can search strings and replace them using regular expression
Regular_Expression (Wikipedia)
it can be use to :-
1. generate a huge list of mapflags
2. fix outdated format on the script commands
3. apply a quick fix on CVS style database
4. convert client side item list into array




Example 1. Generate a huge list of mapflags


1. goto db/map_index.txt, copy over the map list

2. there are some lines commented, so find the line with // and remove them by doing this
Find with regular expression Replace with empty string, this effectively leave the line blank

3. Edit -> Line Operations -> Remove Empty lines

4. Find with regular expression Replace with


Example 2. Fix outdated format on the script commands


Find with regular expression Replace with

Example 3. Apply a quick fix on CVS style database

rathena only, Hercules has switched to libconfig format
goto db/re/item_db.txt

Find with regular expression Replace with Find with regular expression Replace with Find with regular expression Replace with


Example 4: Convert client side item list into array

goto kro/data/cardprefixnametable.txt

Find with regular expression Replace with


External Links:

Disable dead branch (Example 1) 
Convert pow(a,b) into a**b (Example 2)
Swap item type IT_ARMOR and IT_WEAPON (Example 3)
getitemname2 function (Example 4)

Saturday, February 2, 2019

One Character per GM account

Download:

Hercules Patch
Hercules Plugin

Very simple trick, only allow them to create/login their character on slot 0

if you want to make them limit to 3 characters, then allow them to only use slot 0,1,2

 

External Links:

One char per GM Account

Friday, February 1, 2019

OnPCStatCalcEvent

Let's have a little history lesson shall we ?

it all started by me, found this modification in this topic
about update character's status


since then I have been using it VERY frequently
I'm sure those of you dealing with patch understand this,
I have to upkeep the patch to the latest server revision
eventually I was so fed up, and finally brought it to the development suggestion
See -> OnPCStatCalcEvent <- that's how rAthena got it

When I switch to Hercules, somebody else actually made a pull request on it
https://github.com/HerculesWS/Hercules/pull/351
but it was denied, and thus I released it as a plugin

For a long period of time, the *recalculatestat script command is still broken,
but I finally fix it during my time in Hercules period

Download:

Hercules Plugin

here's the catch
the reason why the *recalculatestat is still broken on rathena,
is because how the way script handling the event queue

Supposedly, we want the bonuses from the OnPCStatCalcEvent: to execute before running the status_calc_pc function
but what actually happen is the script queue up the OnPCStatCalcEvent: label, execute status_calc_pc first
thus all the bonuses from equipment/job bonuses etc has been applied, then OnPCStatCalcEvent: come in too late

since I figure it out, my little trick is delay the OnPCStatCalcEvent: to run AFTER the script execution finish, using a delay timer
I actually explained this to Secret, rathena developer, but she doesn't agree with my method, because this is not thread safe
but whatever ~ at least it working for me


OnPCStatCalcEvent can't run during npc dialog, and spam map-server error along with it


easy to reproduce during the npc dialog, keep change the equipment, you'll lose the str bonus and map-server spam error

conf/map/battle/items.conf
change this to false should stop it

showdigit

official documentation from script_commands.txt

there is much more than this

because the decremental counter for type 3 runs 2 ticks per seconds, it is not advise to use type 3
type 2 is much preferred, but it risk in going into negative value, so this is usually how I do it
use showdigit type 2 for the countdown, then sleep for the duration, type 3 with 0 value will remove it

and to use this practically for an event, let's say the event only last 5 minute

========================================================

Now for the weird part of this script command

No.1 it run together with pvp counter

if you enter a PVP map, and try to showdigit, it actually show both of them
 so NEVER use showdigit inside a PVP map


No.2 log out and log in , the counter continues

this is another weird bug about *showdigit, it only send a value to the client
the countdown is totally handle by the client

for example from the script above,
if you log out inside the guild_vs2 map, just change character, log in back, the counter still shows
OnPCLogoutEvent also fail to remove it


External Links:

How to put countdown
showdigit will continue to countdown if the player logout

Linux compiler error that never shown on Visual Studio

let's just admit Visual Studio sux ... ok ? right now, if you want to host a Private Ragnarok Online server, its just better to choose...