Jump to content
  • 0

drop on all monsters


worn

Question


  • Group:  Members
  • Topic Count:  16
  • Topics Per Day:  0.00
  • Content Count:  40
  • Reputation:   6
  • Joined:  09/17/13
  • Last Seen:  

Hey guys, I would like to know if there is a way to make all monsters drop a certain item with drop percentage, without putting it in drop one by one in mob_db I would also like to know if you can only put it on certain example maps lhz_dun03 all monsters from lhz drop this item and other maps do not

Link to comment
Share on other sites

Recommended Posts

  • 0

  • Group:  Content Moderator
  • Topic Count:  55
  • Topics Per Day:  0.02
  • Content Count:  1676
  • Reputation:   702
  • Joined:  12/21/14
  • Last Seen:  

all monsters

-	script	monsterdrop	-1,{
OnNPCKillEvent:
	if(rand(100) <= 9){//9%
		getitem(502,1);//item id is the 502
	}
end;
}

 

only in lhz_dun03

-	script	monsterdrop	-1,{
OnNPCKillEvent:
	if(strcharinfo(3) == "lhz_dun03"){//map name lhz_dun03
		if(rand(100) <= 9){//9%
			getitem(502,1);//item id is the 502
		}
	}
end;
}

 

  • Upvote 1
Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  31
  • Topics Per Day:  0.01
  • Content Count:  491
  • Reputation:   19
  • Joined:  11/19/11
  • Last Seen:  

12 hours ago, worn said:

Hey guys, I would like to know if there is a way to make all monsters drop a certain item with drop percentage, without putting it in drop one by one in mob_db I would also like to know if you can only put it on certain example maps lhz_dun03 all monsters from lhz drop this item and other maps do not

try edit in : db/mob_item_ratio.txt

Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  107
  • Topics Per Day:  0.02
  • Content Count:  770
  • Reputation:   69
  • Joined:  02/10/12
  • Last Seen:  

-	script	dropallmonster	-1,{
OnInit:
.listmonster$ = "1096|1388|1307|1283";
end;

OnNPCKillEvent:
	if( compare( "|"+.listmonster$+"|","|"+killedrid+"|" ) ){
		if(rand(100)>75){
			getitem 501,1; 
			end;
		}
		end;
	}
	
}

 

Edited by LearningRO
Link to comment
Share on other sites

  • 0

  • Group:  Forum Moderator
  • Topic Count:  47
  • Topics Per Day:  0.01
  • Content Count:  796
  • Reputation:   101
  • Joined:  05/23/12
  • Last Seen:  

I can't recommend too much calls of OnNPCKillEvent its could crash the map server.

Rynbef~

Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  16
  • Topics Per Day:  0.00
  • Content Count:  40
  • Reputation:   6
  • Joined:  09/17/13
  • Last Seen:  

@sader1992

 

can i use this in several maps the second example? or is there any problem? example I'll create one just for lhz, another just for pay_dun another just for x map

Link to comment
Share on other sites

  • 0

  • Group:  Content Moderator
  • Topic Count:  55
  • Topics Per Day:  0.02
  • Content Count:  1676
  • Reputation:   702
  • Joined:  12/21/14
  • Last Seen:  

8 hours ago, worn said:

@sader1992

 

can i use this in several maps the second example? or is there any problem? example I'll create one just for lhz, another just for pay_dun another just for x map

-	script	monsterdrop	-1,{
OnNPCKillEvent:
	if(inarray(.maps$,strcharinfo(3)) != -1){
		if(rand(100) <= 9){//9%
			getitem(502,1);//item id is the 502
		}
	}
end;

OnInit:
	setarray .maps$,"lhz_dun03","prontera";
end;
}

 

Link to comment
Share on other sites

  • 0

  • Group:  Forum Moderator
  • Topic Count:  47
  • Topics Per Day:  0.01
  • Content Count:  796
  • Reputation:   101
  • Joined:  05/23/12
  • Last Seen:  

I hope I can help u with my script I've written for u. It's a few time ago after I had an own server. The script isn't tested. 

/*
rAthena Script
Author: @Rynbef
Date: 2021-19-12

Information:
    Dont forget to set "loadevent" mapflag for each map you will use this function

Description:
    Give a specified item (getarg(1)) of amount getarg(2) on specified map getarg(0) with a percentage of getarg(3) (0.1 to 100 percent)

Terms:
    Dont name this as yours
    Dont sell this script
    Dont upload this script on download-/s section
    Otherwise feel free to edit or contact me as pm

Example:
*/
-   script  GetItemByMap    -1,{

OnNPCLoadEvent:
    set .retval,callfunc ("F_GetItemByMap",$#maps$,$#items,$#item_amounts);
    //You can debug if it causes error or not
    if(.retval == 1)
        debugmes "[F_GetItemByMap]: Works fine! Player get item.";
    else if(.retval == 2)
        debugmes "[F_GetItemByMap]: Works fine! Player is unlucky and get no item.";
    else
        debugmes "[F_GetItemByMap]: Causes in errors. Debug logs below!";
    end;

OnInit:
    setarray $#maps$[0],"prontera","alberta","izlude";
    serarray $#items[0],501,4012,512;
    setarray $#item_amounts[0],100,1,5;
    setarray $#item_chance[0],1000,500,800;//Chance begins by 0.1 percentage. 1 = 0.1 and 1000 = 100 percent
    callfunc($#maps$,$#items,$#item_amounts,$#item_chance);
    end;
}

function    script    F_GetItemByMap    {

if(((!getarg(0) || !getarg(1) || !getarg(2))) || ((getarraysize(getarg(0)) != getarraysize(getarg(1))) ||(getarraysize(getarg(0)) != getarraysize(2)) || (getarraysize(0)) != getarraysize(3))){
    debugmes "[F_GetItemByMap]: An error is occurupted";
    debugmes "[Function arguments]: Function arguments are empty or to short.";
    debugmes "[Array sizes]: Maps:"+getarraysize(getarg(0))+" - Items:"+getarraysize(getarg(1))+" - Amounts:"+getarraysize(getarg(2))+" - Chances:"+getarg(3);
    debugmes "[Function arguments]: Maps:"+getarg(0)+" - Items:"+getarg(1)+" - Amounts:"+getarg(2)+" - Chances:"+getarg(3);
    return 0;
} else {
    for(.@i,0; getarraysize(getarg(0); .@i++){
        if(rand(1,1000) <= (getarraysize(getarg(3))-1)){
            debugmes "[F_GetItemByMap]: The player doesnt get item because hes an unlucky player";
            if(strcharinfo(3) == getarg(0)[.@i])
                getitem getarg(1)[.@i],getarg(2)[.@i];
            return 1;
        }
        return 2;
      }
    }
}
    set .retval,callfunc ("F_GetItemByMap",$#maps$,$#items,$#item_amounts);
    //You can debug if it causes error or not
    if(.retval == 1)
        debugmes "[F_GetItemByMap]: Works fine! Player get item."
    else if(.retval == 2)
        debugmes "[F_GetItemByMap]: Works fine! Player is unlucky and get no item."
    else
        debugmes "[F_GetItemByMap]: Causes in errors. Debug logs below!"
    end;

OnInit:
    setarray $#maps$[0],"prontera","alberta","izlude";
    serarray $#items[0],501,4012,512;
    setarray $#item_amounts[0],100,1,5;
    setarray $#item_chance[0],1000,500,800;//Chance begins by 0.1 percentage. 1 = 0.1 and 1000 = 100 percent
    callfunc($#maps$,$#items,$#item_amounts,$#item_chance);
    end;
}

function    script    F_GetItemByMap    {

if(((!getarg(0) || !getarg(1) || !getarg(2))) || ((getarraysize(getarg(0)) != getarraysize(getarg(1))) ||(getarraysize(getarg(0)) != getarraysize(2)) || (getarraysize(0)) != getarraysize(3))){
    debugmes "[F_Inarray]: Function arguments are empty or to short.";
    debugmes "[Array sizes]: Maps:"+getarraysize(getarg(0))+" - Items:"+getarraysize(getarg(1))+" - Amounts:"+getarraysize(getarg(2))+" - Chances:"+getarg(3);
    debugmes "[Function arrguments]: Maps:"+getarg(0)+" - Items:"+getarg(1)+" - Amounts:"+getarg(2)+" - Chances:"+getarg(3);
    return 0;
} else {
    for(.@i,0; getarraysize(getarg(0); .@i++){
        if(rand(1,1000) <= (getarraysize(getarg(3))-1)){
            debugmes "[F_GetItemByMap]: The player doesnt get item because hes an unlucky player";
            if(strcharinfo(3) == getarg(0)[.@i])
                getitem getarg(1)[.@i],getarg(2)[.@i];
            return 1;
        }
        return 2;
      }
    }
}

 

Rynbef~

Edited by Rynbef
Small changes
Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  16
  • Topics Per Day:  0.00
  • Content Count:  40
  • Reputation:   6
  • Joined:  09/17/13
  • Last Seen:  

14 hours ago, Rynbef said:

I hope I can help u with my script I've written for u. It's a few time ago after I had an own server. The script isn't tested. 

/*
rAthena Script
Author: @Rynbef
Date: 2021-19-12

Information:
    Dont forget to set "loadevent" mapflag for each map you will use this function

Description:
    Give a specified item (getarg(1)) of amount getarg(2) on specified map getarg(0) with a percentage of getarg(3) (0.1 to 100 percent)

Terms:
    Dont name this as yours
    Dont sell this script
    Dont upload this script on download-/s section
    Otherwise feel free to edit or contact me as pm

Example:
*/
-   script  GetItemByMap    -1,{

OnNPCLoadEvent:
    set .retval,callfunc ("F_GetItemByMap",$#maps$,$#items,$#item_amounts);
    //You can debug if it causes error or not
    if(.retval == 1)
        debugmes "[F_GetItemByMap]: Works fine! Player get item.";
    else if(.retval == 2)
        debugmes "[F_GetItemByMap]: Works fine! Player is unlucky and get no item.";
    else
        debugmes "[F_GetItemByMap]: Causes in errors. Debug logs below!";
    end;

OnInit:
    setarray $#maps$[0],"prontera","alberta","izlude";
    serarray $#items[0],501,4012,512;
    setarray $#item_amounts[0],100,1,5;
    setarray $#item_chance[0],1000,500,800;//Chance begins by 0.1 percentage. 1 = 0.1 and 1000 = 100 percent
    callfunc($#maps$,$#items,$#item_amounts,$#item_chance);
    end;
}

function    script    F_GetItemByMap    {

if(((!getarg(0) || !getarg(1) || !getarg(2))) || ((getarraysize(getarg(0)) != getarraysize(getarg(1))) ||(getarraysize(getarg(0)) != getarraysize(2)) || (getarraysize(0)) != getarraysize(3))){
    debugmes "[F_GetItemByMap]: An error is occurupted";
    debugmes "[Function arguments]: Function arguments are empty or to short.";
    debugmes "[Array sizes]: Maps:"+getarraysize(getarg(0))+" - Items:"+getarraysize(getarg(1))+" - Amounts:"+getarraysize(getarg(2))+" - Chances:"+getarg(3);
    debugmes "[Function arguments]: Maps:"+getarg(0)+" - Items:"+getarg(1)+" - Amounts:"+getarg(2)+" - Chances:"+getarg(3);
    return 0;
} else {
    for(.@i,0; getarraysize(getarg(0); .@i++){
        if(rand(1,1000) <= (getarraysize(getarg(3))-1)){
            debugmes "[F_GetItemByMap]: The player doesnt get item because hes an unlucky player";
            if(strcharinfo(3) == getarg(0)[.@i])
                getitem getarg(1)[.@i],getarg(2)[.@i];
            return 1;
        }
        return 2;
      }
    }
}
    set .retval,callfunc ("F_GetItemByMap",$#maps$,$#items,$#item_amounts);
    //You can debug if it causes error or not
    if(.retval == 1)
        debugmes "[F_GetItemByMap]: Works fine! Player get item."
    else if(.retval == 2)
        debugmes "[F_GetItemByMap]: Works fine! Player is unlucky and get no item."
    else
        debugmes "[F_GetItemByMap]: Causes in errors. Debug logs below!"
    end;

OnInit:
    setarray $#maps$[0],"prontera","alberta","izlude";
    serarray $#items[0],501,4012,512;
    setarray $#item_amounts[0],100,1,5;
    setarray $#item_chance[0],1000,500,800;//Chance begins by 0.1 percentage. 1 = 0.1 and 1000 = 100 percent
    callfunc($#maps$,$#items,$#item_amounts,$#item_chance);
    end;
}

function    script    F_GetItemByMap    {

if(((!getarg(0) || !getarg(1) || !getarg(2))) || ((getarraysize(getarg(0)) != getarraysize(getarg(1))) ||(getarraysize(getarg(0)) != getarraysize(2)) || (getarraysize(0)) != getarraysize(3))){
    debugmes "[F_Inarray]: Function arguments are empty or to short.";
    debugmes "[Array sizes]: Maps:"+getarraysize(getarg(0))+" - Items:"+getarraysize(getarg(1))+" - Amounts:"+getarraysize(getarg(2))+" - Chances:"+getarg(3);
    debugmes "[Function arrguments]: Maps:"+getarg(0)+" - Items:"+getarg(1)+" - Amounts:"+getarg(2)+" - Chances:"+getarg(3);
    return 0;
} else {
    for(.@i,0; getarraysize(getarg(0); .@i++){
        if(rand(1,1000) <= (getarraysize(getarg(3))-1)){
            debugmes "[F_GetItemByMap]: The player doesnt get item because hes an unlucky player";
            if(strcharinfo(3) == getarg(0)[.@i])
                getitem getarg(1)[.@i],getarg(2)[.@i];
            return 1;
        }
        return 2;
      }
    }
}

 

Rynbef~

https://prnt.sc/255zzey

gave error

https://prnt.sc/25601yd

Link to comment
Share on other sites

  • 0

  • Group:  Forum Moderator
  • Topic Count:  33
  • Topics Per Day:  0.01
  • Content Count:  1268
  • Reputation:   381
  • Joined:  02/03/12
  • Last Seen:  

@worn I think a more practical way to do this would be...

https://github.com/rathena/rathena/blob/master/doc/script_commands.txt#L6663

-	script	AllMobDrop	-1,{
OnInit:
	query_sql("SELECT `ID` FROM `mob_db_re` UNION SELECT `ID` FROM `mob_db2_re`;", .@mob_ids);
	.@len = getarraysize(.@mob_ids);
	for(.@a = 0; .@a < .@len; .@a++) {
		addmonsterdrop .@mob_ids[.@a],501,100; //Red Potion at 1% drop. 
	}
	end;
}

or...
https://github.com/rathena/rathena/blob/master/doc/item_bonus.txt#L465

-	script	AllMobDrop	-1,{
OnPCLoginEvent:
	bonus_script "bonus2 bAddMonsterDropItem,501,100;",86400,8,0; //Red Potion at 1% drop for 24 hours.
	end;
}

 

Link to comment
Share on other sites

  • 0

  • Group:  Forum Moderator
  • Topic Count:  47
  • Topics Per Day:  0.01
  • Content Count:  796
  • Reputation:   101
  • Joined:  05/23/12
  • Last Seen:  

I've found a way to check the screenshots. I've updated today and added a changelog. 

NOTE: U don't need loadevent. U now can/should remove it. 

Just to say: I've written this script with my smartphone and therefore no way to test it.

Spoiler
/*
rAthena Script
Author: @Rynbef
Create Date: 2021-19-12
Last Updated: 2022-01-01

Changelogs:
    2022-01-01:
        *changed OnNPCLoadEvent to OnNPCKillEvent
        *added check if killed enemie is player
        *removed space on callfunc after OnNPCKillEvent
        *fixed if statement syntax error
        *fixed if statement getarraysize of integer to getarraysize of specified getarg
        *removed callfunc OnInit
        *added console debugging can be disabled or enabled
        *changed variable types
        *fixed cant get item cause of wrong if statement
        *fixed for loop used array size instead random chance from argument getarg(3)
        *fixed player can't get item if random chance was equals to specified item chance
        *added argument amount to debug message
        *added map notification if player get lucky but not on a listed map. This can disabled or enabled seperat at OnInit below. Debugging needs to be enabled
        *added notification if everything works fine. Can be disabled or enabled on bottom of OnInit. Debugging needs to disabled

Feature planned:
    #Player get zeny if he get lucky
    #Player get zeny only if items disabled
    #Player get zeny or item if both enabled

Description:
    Give a specified item getarg(1) of amount getarg(2) on specified map getarg(0) with a percentage of getarg(3) (0.1 to 100 percent) to a player
    
IMPORTANT:
    All arrays needs to have the same sizes
    It's importent to set all 3 arguments to callfunc

Terms:
    Dont name this as yours
    Dont sell this script
    Dont upload this script on download-/s section or share it otherwise for pay
    Modifications are included from this terms
    Otherwise feel free to edit

Other:
    Don't hestiate to contact me at the forum as pm if u've any error,question,suggestion or want a modification

Script:
*/

-   script  GetItemByMap    -1,{

OnNPCKillEvent:
    if(killedrid >= 150000)
        end;
    set .retval,callfunc("F_GetItemByMap",$@maps$,$@items,$@item_amounts);
    if(!$@debug)
        end;
    if(.retval == 1)
        debugmes "[F_GetItemByMap]: Works fine! Player get item.";
    else if(.retval == 2)
        debugmes "[F_GetItemByMap]: Works fine! Player is unlucky and get no item.";
    else if(.retval == 3 && $@debugmap)
        debugmes "[F_GetItemByMap]: Player isn't on a listed map. Current map: "+strcharinfo(3);
    else if(.retval == 4 && $@debugworking)
        debugmes "[F_GetItemByMap]: Everything works fine!";
    else
        debugmes "[F_GetItemByMap]: Causes in errors. Debug logs on top!";
    end;

OnInit:
    setarray $@maps$[0],"prontera","alberta","izlude";
    serarray $@items[0],501,4012,512;
    setarray $@item_amounts[0],100,1,5;
    setarray $@item_chance[0],1000,500,800;//Chance begins by 0.1 percentage. 1 = 0.1 and 1000 = 100 percent
    set $@debug,1;//0 = disable debugging,1 = enable
    set $@debugmap,1;//0 = disable map notification,1 = enable
    set $@debugworking,1;//0 = disable notification if everything works fine,1 = enable
    end;
}

function    script    F_GetItemByMap    {

if(!getarg(0) || !getarg(1) || !getarg(2) || !getarg(3) || getarraysize(getarg(0)) != getarraysize(getarg(1)) || getarraysize(getarg(0)) != getarraysize(getarg(2)) || getarraysize(getarg(0)) != getarraysize(getarg(3))){
    if($@debug){
        debugmes "[F_GetItemByMap]: An error is occurupted";
        debugmes "[Function arguments]: Function arguments are empty or to short. Arguments: "+getargcount();
        debugmes "[Array sizes]: Maps:"+getarraysize(getarg(0))+" - Items:"+getarraysize(getarg(1))+" - Amounts:"+getarraysize(getarg(2))+" - Chances:"+getarraysize(getarg(3));
        debugmes "[Function arguments]: Maps:"+getarg(0)+" - Items:"+getarg(1)+" - Amounts:"+getarg(2)+" - Chances:"+getarg(3);
    }
    return 0;
} else {
    for(.i = 0; .i<getarraysize(getarg(0)); .i++){
        if(rand(1,1000) < getarg(3)[.i])
            return 2;
        if(strcharinfo(3) == getarg(0)[.i]){
            getitem getarg(1)[.i],getarg(2)[.i];
            return 1;
        } else if($@debugmap){
            return 3;
        }
    }
    }
    return 4;
}

I'll attach a downloadable file too

getItemByMapFunction v2.txt

I hope this helps u and will works fine now.

 

Rynbef~

Edited by Rynbef
A lot of updates, fixes and features. Added changelog to script
Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  16
  • Topics Per Day:  0.00
  • Content Count:  40
  • Reputation:   6
  • Joined:  09/17/13
  • Last Seen:  

On 1/1/2022 at 9:41 AM, Rynbef said:

Eu encontrei uma maneira de verificar as imagens. Eu atualizei hoje e adicionei um changelog. 

NOTA: Você não precisa de loadevent. Agora você pode / deve removê-lo. 

Só para dizer: escrevi este script com meu smartphone e, portanto, não há como testá-lo.

  Esconder o conteúdo




    







Vou anexar um arquivo para download também

getItemByMapFunction v2.txt 4,07 kB  ·  3 downloads

Espero que isso te ajude e funcione bem agora.

 

Rynbef ~

agora deu isso

https://prnt.sc/25lzasj

 

On 12/31/2021 at 5:41 PM, Skorm said:

@worn I think a more practical way to do this would be...

https://github.com/rathena/rathena/blob/master/doc/script_commands.txt#L6663

-	script	AllMobDrop	-1,{
OnInit:
	query_sql("SELECT `ID` FROM `mob_db_re` UNION SELECT `ID` FROM `mob_db2_re`;", .@mob_ids);
	.@len = getarraysize(.@mob_ids);
	for(.@a = 0; .@a < .@len; .@a++) {
		addmonsterdrop .@mob_ids[.@a],501,100; //Red Potion at 1% drop. 
	}
	end;
}

or...
https://github.com/rathena/rathena/blob/master/doc/item_bonus.txt#L465

-	script	AllMobDrop	-1,{
OnPCLoginEvent:
	bonus_script "bonus2 bAddMonsterDropItem,501,100;",86400,8,0; //Red Potion at 1% drop for 24 hours.
	end;
}

 

in this case it would be for all maps correct? I would like to put on some maps just not all

example in pay_dun04 I want to drop x item on any monster that is killed on the map native monsters even on the map already in lhz I want another item to drop in all monsters on the map and so on with a percentage at the time of the drop, in addition to gaining the standard mob drops

Edited by worn
Link to comment
Share on other sites

  • 0

  • Group:  Forum Moderator
  • Topic Count:  47
  • Topics Per Day:  0.01
  • Content Count:  796
  • Reputation:   101
  • Joined:  05/23/12
  • Last Seen:  

Just now, worn said:

in this case it would be for all maps correct? I would like to put on some maps just not all

example in pay_dun04 I want to drop x item on any monster that is killed on the map native monsters even on the map already in lhz I want another item to drop in all monsters on the map and so on with a percentage at the time of the drop, in addition to gaining the standard mob drops

@wornthat's exactly what I've scripted.

 

Rynbef~

Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  16
  • Topics Per Day:  0.00
  • Content Count:  40
  • Reputation:   6
  • Joined:  09/17/13
  • Last Seen:  

Just now, Rynbef said:

@wornthat's exactly what I've scripted.

 

Rynbef~

yes, I was explaining to him, you got to see

https://prnt.sc/25lzasj

Link to comment
Share on other sites

  • 0

  • Group:  Forum Moderator
  • Topic Count:  47
  • Topics Per Day:  0.01
  • Content Count:  796
  • Reputation:   101
  • Joined:  05/23/12
  • Last Seen:  

@wornThis should fix the error.

/*
rAthena Script
Author: @Rynbef
Create Date: 2021-19-12
Last Updated: 2022-01-01

Changelogs:
    2022-01-01:
        *changed OnNPCLoadEvent to OnNPCKillEvent
        *added check if killed enemie is player
        *removed space on callfunc after OnNPCKillEvent
        *fixed if statement syntax error
        *fixed if statement getarraysize of integer to getarraysize of specified getarg
        *removed callfunc OnInit
        *added console debugging can be disabled or enabled
        *changed variable types
        *fixed cant get item cause of wrong if statement
        *fixed for loop used array size instead random chance from argument getarg(3)
        *fixed player can't get item if random chance was equals to specified item chance
        *added argument amount to debug message
        *added map notification if player get lucky but not on a listed map. This can disabled or enabled seperat at OnInit below. Debugging needs to be enabled
        *added notification if everything works fine. Can be disabled or enabled on bottom of OnInit. Debugging needs to disabled

Feature planned:
    #Player get zeny if he get lucky
    #Player get zeny only if items disabled
    #Player get zeny or item if both enabled

Description:
    Give a specified item getarg(1) of amount getarg(2) on specified map getarg(0) with a percentage of getarg(3) (0.1 to 100 percent) to a player
    
IMPORTANT:
    All arrays needs to have the same sizes
    It's importent to set all 3 arguments to callfunc

Terms:
    Dont name this as yours
    Dont sell this script
    Dont upload this script on download-/s section or share it otherwise for pay
    Modifications are included from this terms
    Otherwise feel free to edit

Other:
    Don't hestiate to contact me at the forum as pm if u've any error,question,suggestion or want a modification

Script:
*/

-   script  GetItemByMap    -1,{

OnNPCKillEvent:
    if(killedrid >= 150000)
        end;
    set .retval,callfunc("F_GetItemByMap",$@maps$,$@items,$@item_amounts);
    if(!$@debug)
        end;
    if(.retval == 1)
        debugmes "[F_GetItemByMap]: Works fine! Player get item.";
    else if(.retval == 2)
        debugmes "[F_GetItemByMap]: Works fine! Player is unlucky and get no item.";
    else if(.retval == 3 && $@debugmap)
        debugmes "[F_GetItemByMap]: Player isn't on a listed map. Current map: "+strcharinfo(3);
    else if(.retval == 4 && $@debugworking)
        debugmes "[F_GetItemByMap]: Everything works fine!";
    else
        debugmes "[F_GetItemByMap]: Causes in errors. Debug logs on top!";
    end;

OnInit:
    setarray $@maps$[0],"prontera","alberta","izlude";
    serarray $@items[0],501,4012,512;
    setarray $@item_amounts[0],100,1,5;
    setarray $@item_chance[0],1000,500,800;//Chance begins by 0.1 percentage. 1 = 0.1 and 1000 = 100 percent
    set $@debug,1;//0 = disable debugging,1 = enable
    set $@debugmap,1;//0 = disable map notification,1 = enable
    set $@debugworking,1;//0 = disable notification if everything works fine,1 = enable
    end;
}

function    script    F_GetItemByMap    {

if(!getarg(0) || !getarg(1) || !getarg(2) || !getarg(3) || getarraysize(getarg(0)) != getarraysize(getarg(1)) || getarraysize(getarg(0)) != getarraysize(getarg(2)) || getarraysize(getarg(0)) != getarraysize(getarg(3))){
    if($@debug){
        debugmes "[F_GetItemByMap]: An error is occurupted";
        debugmes "[Function arguments]: Function arguments are empty or to short. Arguments: "+getargcount();
        debugmes "[Array sizes]: Maps:"+getarraysize(getarg(0))+" - Items:"+getarraysize(getarg(1))+" - Amounts:"+getarraysize(getarg(2))+" - Chances:"+getarraysize(getarg(3));
        debugmes "[Function arguments]: Maps:"+getarg(0)+" - Items:"+getarg(1)+" - Amounts:"+getarg(2)+" - Chances:"+getarg(3);
    }
    return 0;
} else {
    for(.i = 0; .i<getarraysize(getarg(0)); .i++){
        if(rand(1,1000) < getelementofarray(getarg(3),.i))
            return 2;
        if(strcharinfo(3) == getelementofarray(getarg(0),.i)){
            getitem getelementofarray(getarg(1),.i),getelementofarray(getarg(2),.i);
            return 1;
        } else if($@debugmap){
            return 3;
        }
    }
    }
    return 4;
}

 

getItemByMapFunction v3.txt

 

Rynbef~

Edited by Rynbef
Fixed
Link to comment
Share on other sites

  • 0

  • Group:  Content Moderator
  • Topic Count:  55
  • Topics Per Day:  0.02
  • Content Count:  1676
  • Reputation:   702
  • Joined:  12/21/14
  • Last Seen:  

27 minutes ago, Rynbef said:

@wornThis should fix the error.

/*
rAthena Script
Author: @Rynbef
Create Date: 2021-19-12
Last Updated: 2022-01-01

Changelogs:
    2022-01-01:
        *changed OnNPCLoadEvent to OnNPCKillEvent
        *added check if killed enemie is player
        *removed space on callfunc after OnNPCKillEvent
        *fixed if statement syntax error
        *fixed if statement getarraysize of integer to getarraysize of specified getarg
        *removed callfunc OnInit
        *added console debugging can be disabled or enabled
        *changed variable types
        *fixed cant get item cause of wrong if statement
        *fixed for loop used array size instead random chance from argument getarg(3)
        *fixed player can't get item if random chance was equals to specified item chance
        *added argument amount to debug message
        *added map notification if player get lucky but not on a listed map. This can disabled or enabled seperat at OnInit below. Debugging needs to be enabled
        *added notification if everything works fine. Can be disabled or enabled on bottom of OnInit. Debugging needs to disabled

Feature planned:
    #Player get zeny if he get lucky
    #Player get zeny only if items disabled
    #Player get zeny or item if both enabled

Description:
    Give a specified item getarg(1) of amount getarg(2) on specified map getarg(0) with a percentage of getarg(3) (0.1 to 100 percent) to a player
    
IMPORTANT:
    All arrays needs to have the same sizes
    It's importent to set all 3 arguments to callfunc

Terms:
    Dont name this as yours
    Dont sell this script
    Dont upload this script on download-/s section or share it otherwise for pay
    Modifications are included from this terms
    Otherwise feel free to edit

Other:
    Don't hestiate to contact me at the forum as pm if u've any error,question,suggestion or want a modification

Script:
*/

-   script  GetItemByMap    -1,{

OnNPCKillEvent:
    if(killedrid >= 150000)
        end;
    set .retval,callfunc("F_GetItemByMap",$@maps$,$@items,$@item_amounts);
    if(!$@debug)
        end;
    if(.retval == 1)
        debugmes "[F_GetItemByMap]: Works fine! Player get item.";
    else if(.retval == 2)
        debugmes "[F_GetItemByMap]: Works fine! Player is unlucky and get no item.";
    else if(.retval == 3 && $@debugmap)
        debugmes "[F_GetItemByMap]: Player isn't on a listed map. Current map: "+strcharinfo(3);
    else if(.retval == 4 && $@debugworking)
        debugmes "[F_GetItemByMap]: Everything works fine!";
    else
        debugmes "[F_GetItemByMap]: Causes in errors. Debug logs on top!";
    end;

OnInit:
    setarray $@maps$[0],"prontera","alberta","izlude";
    serarray $@items[0],501,4012,512;
    setarray $@item_amounts[0],100,1,5;
    setarray $@item_chance[0],1000,500,800;//Chance begins by 0.1 percentage. 1 = 0.1 and 1000 = 100 percent
    set $@debug,1;//0 = disable debugging,1 = enable
    set $@debugmap,1;//0 = disable map notification,1 = enable
    set $@debugworking,1;//0 = disable notification if everything works fine,1 = enable
    end;
}

function    script    F_GetItemByMap    {

if(!getarg(0) || !getarg(1) || !getarg(2) || !getarg(3) || getarraysize(getarg(0)) != getarraysize(getarg(1)) || getarraysize(getarg(0)) != getarraysize(getarg(2)) || getarraysize(getarg(0)) != getarraysize(getarg(3))){
    if($@debug){
        debugmes "[F_GetItemByMap]: An error is occurupted";
        debugmes "[Function arguments]: Function arguments are empty or to short. Arguments: "+getargcount();
        debugmes "[Array sizes]: Maps:"+getarraysize(getarg(0))+" - Items:"+getarraysize(getarg(1))+" - Amounts:"+getarraysize(getarg(2))+" - Chances:"+getarraysize(getarg(3));
        debugmes "[Function arguments]: Maps:"+getarg(0)+" - Items:"+getarg(1)+" - Amounts:"+getarg(2)+" - Chances:"+getarg(3);
    }
    return 0;
} else {
    for(.i = 0; .i<getarraysize(getarg(0)); .i++){
        if(rand(1,1000) < getelementofarray(getarg(3),.i))
            return 2;
        if(strcharinfo(3) == getelementofarray(getarg(0),.i)){
            getitem getelementofarray(getarg(1),.i),getelementofarray(getarg(2),.i);
            return 1;
        } else if($@debugmap){
            return 3;
        }
    }
    }
    return 4;
}

 

getItemByMapFunction v3.txt 4.14 kB · 1 download

 

Rynbef~

https://github.com/rathena/rathena/blob/bdf568979dd53702494d3a6b3b9d35054c44594a/doc/script_commands.txt#L432

Link to comment
Share on other sites

  • 0

  • Group:  Forum Moderator
  • Topic Count:  47
  • Topics Per Day:  0.01
  • Content Count:  796
  • Reputation:   101
  • Joined:  05/23/12
  • Last Seen:  

@sader1992I think u means to change to scope variables. Next time I bet u to tell me what u mean.

Spoiler
/*
rAthena Script
Author: @Rynbef
Create Date: 2021-19-12
Last Updated: 2022-01-01

Changelogs:
    2022-01-01:
        *changed OnNPCLoadEvent to OnNPCKillEvent
        *added check if killed enemie is player
        *removed space on callfunc after OnNPCKillEvent
        *fixed if statement syntax error
        *fixed if statement getarraysize of integer to getarraysize of specified getarg
        *removed callfunc OnInit
        *added console debugging can be disabled or enabled
        *changed variable types
        *fixed cant get item cause of wrong if statement
        *fixed for loop used array size instead random chance from argument getarg(3)
        *fixed player can't get item if random chance was equals to specified item chance
        *added argument amount to debug message
        *added map notification if player get lucky but not on a listed map. This can disabled or enabled seperat at OnInit below. Debugging needs to be enabled
        *added notification if everything works fine. Can be disabled or enabled on bottom of OnInit. Debugging needs to disabled
        #fixed wrong array output in for loop from getarg(0)[.i] to getelementofarray(getarg(0),.i)
        #changed .retval and .i vsriables to scope variables .@retval and .@i

Feature planned:
    #Player get zeny if he get lucky
    #Player get zeny only if items disabled
    #Player get zeny or item if both enabled

Description:
    Give a specified item getarg(1) of amount getarg(2) on specified map getarg(0) with a percentage of getarg(3) (0.1 to 100 percent) to a player
    
IMPORTANT:
    All arrays needs to have the same sizes
    It's importent to set all 3 arguments to callfunc

Terms:
    Dont name this as yours
    Dont sell this script
    Dont upload this script on download-/s section or share it otherwise for pay
    Modifications are included from this terms
    Otherwise feel free to edit

Other:
    Don't hestiate to contact me at the forum as pm if u've any error,question,suggestion or want a modification

Script:
*/

-   script  GetItemByMap    -1,{

OnNPCKillEvent:
    if(killedrid >= 150000)
        end;
    set .@retval,callfunc("F_GetItemByMap",$@maps$,$@items,$@item_amounts);
    if(!$@debug)
        end;
    if(.@retval == 1)
        debugmes "[F_GetItemByMap]: Works fine! Player get item.";
    else if(.@retval == 2)
        debugmes "[F_GetItemByMap]: Works fine! Player is unlucky and get no item.";
    else if(.@retval == 3 && $@debugmap)
        debugmes "[F_GetItemByMap]: Player isn't on a listed map. Current map: "+strcharinfo(3);
    else if(.@retval == 4 && $@debugworking)
        debugmes "[F_GetItemByMap]: Everything works fine!";
    else
        debugmes "[F_GetItemByMap]: Causes in errors. Debug logs on top!";
    end;

OnInit:
    setarray $@maps$[0],"prontera","alberta","izlude";
    serarray $@items[0],501,4012,512;
    setarray $@item_amounts[0],100,1,5;
    setarray $@item_chance[0],1000,500,800;//Chance begins by 0.1 percentage. 1 = 0.1 and 1000 = 100 percent
    set $@debug,1;//0 = disable debugging,1 = enable
    set $@debugmap,1;//0 = disable map notification,1 = enable
    set $@debugworking,1;//0 = disable notification if everything works fine,1 = enable
    end;
}

function    script    F_GetItemByMap    {

if(!getarg(0) || !getarg(1) || !getarg(2) || !getarg(3) || getarraysize(getarg(0)) != getarraysize(getarg(1)) || getarraysize(getarg(0)) != getarraysize(getarg(2)) || getarraysize(getarg(0)) != getarraysize(getarg(3))){
    if($@debug){
        debugmes "[F_GetItemByMap]: An error is occurupted";
        debugmes "[Function arguments]: Function arguments are empty or to short. Arguments: "+getargcount();
        debugmes "[Array sizes]: Maps:"+getarraysize(getarg(0))+" - Items:"+getarraysize(getarg(1))+" - Amounts:"+getarraysize(getarg(2))+" - Chances:"+getarraysize(getarg(3));
        debugmes "[Function arguments]: Maps:"+getarg(0)+" - Items:"+getarg(1)+" - Amounts:"+getarg(2)+" - Chances:"+getarg(3);
    }
    return 0;
} else {
    for(.@i = 0; .@i<getarraysize(getarg(0)); .@i++){
        if(rand(1,1000) < getelementofarray(getarg(3),.@i))
            return 2;
        if(strcharinfo(3) == getelementofarray(getarg(0),.@i)){
            getitem getelementofarray(getarg(1),.@i),getelementofarray(getarg(2),.@i);
            return 1;
        } else if($@debugmap){
            return 3;
        }
    }
    }
    return 4;
}

Download is attached bellow

 

getItemByMapFunction v4.txt

 

Rynbef~

Link to comment
Share on other sites

  • 0

  • Group:  Content Moderator
  • Topic Count:  55
  • Topics Per Day:  0.02
  • Content Count:  1676
  • Reputation:   702
  • Joined:  12/21/14
  • Last Seen:  

1 hour ago, Rynbef said:

@sader1992I think u means to change to scope variables. Next time I bet u to tell me what u mean.

  Reveal hidden contents
/*
rAthena Script
Author: @Rynbef
Create Date: 2021-19-12
Last Updated: 2022-01-01

Changelogs:
    2022-01-01:
        *changed OnNPCLoadEvent to OnNPCKillEvent
        *added check if killed enemie is player
        *removed space on callfunc after OnNPCKillEvent
        *fixed if statement syntax error
        *fixed if statement getarraysize of integer to getarraysize of specified getarg
        *removed callfunc OnInit
        *added console debugging can be disabled or enabled
        *changed variable types
        *fixed cant get item cause of wrong if statement
        *fixed for loop used array size instead random chance from argument getarg(3)
        *fixed player can't get item if random chance was equals to specified item chance
        *added argument amount to debug message
        *added map notification if player get lucky but not on a listed map. This can disabled or enabled seperat at OnInit below. Debugging needs to be enabled
        *added notification if everything works fine. Can be disabled or enabled on bottom of OnInit. Debugging needs to disabled
        #fixed wrong array output in for loop from getarg(0)[.i] to getelementofarray(getarg(0),.i)
        #changed .retval and .i vsriables to scope variables .@retval and .@i

Feature planned:
    #Player get zeny if he get lucky
    #Player get zeny only if items disabled
    #Player get zeny or item if both enabled

Description:
    Give a specified item getarg(1) of amount getarg(2) on specified map getarg(0) with a percentage of getarg(3) (0.1 to 100 percent) to a player
    
IMPORTANT:
    All arrays needs to have the same sizes
    It's importent to set all 3 arguments to callfunc

Terms:
    Dont name this as yours
    Dont sell this script
    Dont upload this script on download-/s section or share it otherwise for pay
    Modifications are included from this terms
    Otherwise feel free to edit

Other:
    Don't hestiate to contact me at the forum as pm if u've any error,question,suggestion or want a modification

Script:
*/

-   script  GetItemByMap    -1,{

OnNPCKillEvent:
    if(killedrid >= 150000)
        end;
    set .@retval,callfunc("F_GetItemByMap",$@maps$,$@items,$@item_amounts);
    if(!$@debug)
        end;
    if(.@retval == 1)
        debugmes "[F_GetItemByMap]: Works fine! Player get item.";
    else if(.@retval == 2)
        debugmes "[F_GetItemByMap]: Works fine! Player is unlucky and get no item.";
    else if(.@retval == 3 && $@debugmap)
        debugmes "[F_GetItemByMap]: Player isn't on a listed map. Current map: "+strcharinfo(3);
    else if(.@retval == 4 && $@debugworking)
        debugmes "[F_GetItemByMap]: Everything works fine!";
    else
        debugmes "[F_GetItemByMap]: Causes in errors. Debug logs on top!";
    end;

OnInit:
    setarray $@maps$[0],"prontera","alberta","izlude";
    serarray $@items[0],501,4012,512;
    setarray $@item_amounts[0],100,1,5;
    setarray $@item_chance[0],1000,500,800;//Chance begins by 0.1 percentage. 1 = 0.1 and 1000 = 100 percent
    set $@debug,1;//0 = disable debugging,1 = enable
    set $@debugmap,1;//0 = disable map notification,1 = enable
    set $@debugworking,1;//0 = disable notification if everything works fine,1 = enable
    end;
}

function    script    F_GetItemByMap    {

if(!getarg(0) || !getarg(1) || !getarg(2) || !getarg(3) || getarraysize(getarg(0)) != getarraysize(getarg(1)) || getarraysize(getarg(0)) != getarraysize(getarg(2)) || getarraysize(getarg(0)) != getarraysize(getarg(3))){
    if($@debug){
        debugmes "[F_GetItemByMap]: An error is occurupted";
        debugmes "[Function arguments]: Function arguments are empty or to short. Arguments: "+getargcount();
        debugmes "[Array sizes]: Maps:"+getarraysize(getarg(0))+" - Items:"+getarraysize(getarg(1))+" - Amounts:"+getarraysize(getarg(2))+" - Chances:"+getarraysize(getarg(3));
        debugmes "[Function arguments]: Maps:"+getarg(0)+" - Items:"+getarg(1)+" - Amounts:"+getarg(2)+" - Chances:"+getarg(3);
    }
    return 0;
} else {
    for(.@i = 0; .@i<getarraysize(getarg(0)); .@i++){
        if(rand(1,1000) < getelementofarray(getarg(3),.@i))
            return 2;
        if(strcharinfo(3) == getelementofarray(getarg(0),.@i)){
            getitem getelementofarray(getarg(1),.@i),getelementofarray(getarg(2),.@i);
            return 1;
        } else if($@debugmap){
            return 3;
        }
    }
    }
    return 4;
}

Download is attached bellow

 

getItemByMapFunction v4.txt 4.33 kB · 1 download

 

Rynbef~

what I meant is the other variables too, if the variable is only used inside the npc , you should use npc variable , also you might get problems when editing the npc and reload only that npc because $@ is global

the function will return if any of the chances failed , (setarray $@item_chance[0],1,1,1000;) [try getting the 3rd item from the 3rd map with this chance]

also there is no need for the function if it will only be called once.

with other mistakes in the script ,you can check it if you test the script (I rarely test my scripts when replying to a post , so that's understandable xD)

 

the debug messages are too much but that's my opinion

with optimization this is the result

-	script	GetItemByMap	-1,{
OnNPCKillEvent:
	if((.@n = inarray(.maps$,strcharinfo(3))) == -1) end;
	if(rand(1000) <= .item_chance[.@n])
		getitem(.items[.@n],.item_amounts[.@n]);
end;

OnInit:
	setarray .maps$[0],"prontera","alberta","izlude";
	setarray .items[0],501,4012,512;
	setarray .item_amounts[0],100,1,5;
	setarray .item_chance[0],1000,500,800;//Chance begins by 0.1 percentage. 1 = 0.1 and 1000 = 100 percent
end;
}

this optimized script doesn't support inputting the same map twice , you can edit it to do so if you want that

 

Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  16
  • Topics Per Day:  0.00
  • Content Count:  40
  • Reputation:   6
  • Joined:  09/17/13
  • Last Seen:  

31 minutes ago, sader1992 said:

o que eu quis dizer são as outras variáveis também, se a variável é usada apenas dentro do npc, você deve usar a variável npc, também você pode ter problemas ao editar o npc e recarregar apenas esse npc porque $ @ é global

a função retornará se alguma das chances falhar, (setarray $ @ item _chance [0], 1,1,1000;) [tente obter o terceiro item do terceiro mapa com esta chance]

também não há necessidade da função se ela for chamada apenas uma vez.

com outros erros no script, você pode verificar se testar o script (raramente testo meus scripts ao responder a uma postagem, então é xD compreensível)

 

as mensagens de depuração são demais, mas essa é minha opinião

com otimização este é o resultado



este script otimizado não suporta a entrada do mesmo mapa duas vezes, você pode editá-lo para fazer isso se quiser

 

Oops this one worked perfectly, can I add as many maps as I want? can you tell if in the future this could give a problem with normal monster drops?

 

Link to comment
Share on other sites

  • 0

  • Group:  Forum Moderator
  • Topic Count:  47
  • Topics Per Day:  0.01
  • Content Count:  796
  • Reputation:   101
  • Joined:  05/23/12
  • Last Seen:  

@sader1992I now understand what u mean. I've improved it now. The function is if someone whould call it another way.

@worn

Spoiler
/*
rAthena Script
Author: @Rynbef
Create Date: 2021-19-12
Last Updated: 2022-01-01

Changelogs:
    2022-01-01:
        *changed OnNPCLoadEvent to OnNPCKillEvent
        *added check if killed enemie is player
        *removed space on callfunc after OnNPCKillEvent
        *fixed if statement syntax error
        *fixed if statement getarraysize of integer to getarraysize of specified getarg
        *removed callfunc OnInit
        *added console debugging can be disabled or enabled
        *changed variable types
        *fixed cant get item cause of wrong if statement
        *fixed for loop used array size instead random chance from argument getarg(3)
        *fixed player can't get item if random chance was equals to specified item chance
        *added argument amount to debug message
        *added map notification if player get lucky but not on a listed map. This can disabled or enabled seperat at OnInit below. Debugging needs to be enabled
        *added notification if everything works fine. Can be disabled or enabled on bottom of OnInit. Debugging needs to disabled
        #fixed wrong array output in for loop from getarg(0)[.i] to getelementofarray(getarg(0),.i)
        #changed .retval and .i vsriables to scope variables .@retval and .@i

Feature planned:
    #Player get zeny if he get lucky
    #Player get zeny only if items disabled
    #Player get zeny or item if both enabled

Description:
    Give a specified item getarg(1) of amount getarg(2) on specified map getarg(0) with a percentage of getarg(3) (0.1 to 100 percent) to a player
    
IMPORTANT:
    All arrays needs to have the same sizes
    It's importent to set all 3 arguments to callfunc

Terms:
    Dont name this as yours
    Dont sell this script
    Dont upload this script on download-/s section or share it otherwise for pay
    Modifications are included from this terms
    Otherwise feel free to edit

Other:
    Don't hestiate to contact me at the forum as pm if u've any error,question,suggestion or want a modification

Script:
*/

-   script  GetItemByMap    -1,{

OnNPCKillEvent:
    if(killedrid >= 150000)
        end;
    set .@retval,callfunc("F_GetItemByMap",.@maps$,.@items,.@item_amounts);
    if(!.@debug)
        end;
    if(.@retval == 1)
        debugmes "[F_GetItemByMap]: Works fine! Player get item.";
    else if(.@retval == 2)
        debugmes "[F_GetItemByMap]: Works fine! Player is unlucky and get no item.";
    else if(.@retval == 3 && .@debugmap)
        debugmes "[F_GetItemByMap]: Player isn't on a listed map. Current map: "+strcharinfo(3);
    else if(.@retval == 4 && .@debugworking)
        debugmes "[F_GetItemByMap]: Everything works fine!";
    else
        debugmes "[F_GetItemByMap]: Causes in errors. Debug logs on top!";
    end;

OnInit:
    setarray .@maps$[0],"prontera","alberta","izlude";
    serarray .@items[0],501,4012,512;
    setarray .@item_amounts[0],100,1,5;
    setarray .@item_chance[0],1000,500,800;//Chance begins by 0.1 percentage. 1 = 0.1 and 1000 = 100 percent
    set .@debug,1;//0 = disable debugging,1 = enable
    set .@debugmap,1;//0 = disable map notification,1 = enable
    set .@debugworking,1;//0 = disable notification if everything works fine,1 = enable
    end;
}

function    script    F_GetItemByMap    {

if(!getarg(0) || !getarg(1) || !getarg(2) || !getarg(3) || getarraysize(getarg(0)) != getarraysize(getarg(1)) || getarraysize(getarg(0)) != getarraysize(getarg(2)) || getarraysize(getarg(0)) != getarraysize(getarg(3))){
    if(.@debug){
        debugmes "[F_GetItemByMap]: An error is occurupted";
        debugmes "[Function arguments]: Function arguments are empty or to short. Arguments: "+getargcount();
        debugmes "[Array sizes]: Maps:"+getarraysize(getarg(0))+" - Items:"+getarraysize(getarg(1))+" - Amounts:"+getarraysize(getarg(2))+" - Chances:"+getarraysize(getarg(3));
        debugmes "[Function arguments]: Maps:"+getarg(0)+" - Items:"+getarg(1)+" - Amounts:"+getarg(2)+" - Chances:"+getarg(3);
    }
    return 0;
} else {
    for(.@i = 0; .@i<getarraysize(getarg(0)); .@i++){
        if(rand(1,1000) < getelementofarray(getarg(3),.@i))
            return 2;
        if(strcharinfo(3) == getelementofarray(getarg(0),.@i)){
            getitem getelementofarray(getarg(1),.@i),getelementofarray(getarg(2),.@i);
            return 1;
        } else {
            return 3;
        }
    }
    }
    return 4;
    
OnInit:
    set .@debug,1;//0 = disable debugging,1 = enable
    end;
}

Download file below

getItemByMapFunction v5.txt

 

Rynbef~

Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  16
  • Topics Per Day:  0.00
  • Content Count:  40
  • Reputation:   6
  • Joined:  09/17/13
  • Last Seen:  

Just now, Rynbef said:

@sader1992I now understand what u mean. I've improved it now. The function is if someone whould call it another way.

@worn

  Reveal hidden contents
/*
rAthena Script
Author: @Rynbef
Create Date: 2021-19-12
Last Updated: 2022-01-01

Changelogs:
    2022-01-01:
        *changed OnNPCLoadEvent to OnNPCKillEvent
        *added check if killed enemie is player
        *removed space on callfunc after OnNPCKillEvent
        *fixed if statement syntax error
        *fixed if statement getarraysize of integer to getarraysize of specified getarg
        *removed callfunc OnInit
        *added console debugging can be disabled or enabled
        *changed variable types
        *fixed cant get item cause of wrong if statement
        *fixed for loop used array size instead random chance from argument getarg(3)
        *fixed player can't get item if random chance was equals to specified item chance
        *added argument amount to debug message
        *added map notification if player get lucky but not on a listed map. This can disabled or enabled seperat at OnInit below. Debugging needs to be enabled
        *added notification if everything works fine. Can be disabled or enabled on bottom of OnInit. Debugging needs to disabled
        #fixed wrong array output in for loop from getarg(0)[.i] to getelementofarray(getarg(0),.i)
        #changed .retval and .i vsriables to scope variables .@retval and .@i

Feature planned:
    #Player get zeny if he get lucky
    #Player get zeny only if items disabled
    #Player get zeny or item if both enabled

Description:
    Give a specified item getarg(1) of amount getarg(2) on specified map getarg(0) with a percentage of getarg(3) (0.1 to 100 percent) to a player
    
IMPORTANT:
    All arrays needs to have the same sizes
    It's importent to set all 3 arguments to callfunc

Terms:
    Dont name this as yours
    Dont sell this script
    Dont upload this script on download-/s section or share it otherwise for pay
    Modifications are included from this terms
    Otherwise feel free to edit

Other:
    Don't hestiate to contact me at the forum as pm if u've any error,question,suggestion or want a modification

Script:
*/

-   script  GetItemByMap    -1,{

OnNPCKillEvent:
    if(killedrid >= 150000)
        end;
    set .@retval,callfunc("F_GetItemByMap",.@maps$,.@items,.@item_amounts);
    if(!.@debug)
        end;
    if(.@retval == 1)
        debugmes "[F_GetItemByMap]: Works fine! Player get item.";
    else if(.@retval == 2)
        debugmes "[F_GetItemByMap]: Works fine! Player is unlucky and get no item.";
    else if(.@retval == 3 && .@debugmap)
        debugmes "[F_GetItemByMap]: Player isn't on a listed map. Current map: "+strcharinfo(3);
    else if(.@retval == 4 && .@debugworking)
        debugmes "[F_GetItemByMap]: Everything works fine!";
    else
        debugmes "[F_GetItemByMap]: Causes in errors. Debug logs on top!";
    end;

OnInit:
    setarray .@maps$[0],"prontera","alberta","izlude";
    serarray .@items[0],501,4012,512;
    setarray .@item_amounts[0],100,1,5;
    setarray .@item_chance[0],1000,500,800;//Chance begins by 0.1 percentage. 1 = 0.1 and 1000 = 100 percent
    set .@debug,1;//0 = disable debugging,1 = enable
    set .@debugmap,1;//0 = disable map notification,1 = enable
    set .@debugworking,1;//0 = disable notification if everything works fine,1 = enable
    end;
}

function    script    F_GetItemByMap    {

if(!getarg(0) || !getarg(1) || !getarg(2) || !getarg(3) || getarraysize(getarg(0)) != getarraysize(getarg(1)) || getarraysize(getarg(0)) != getarraysize(getarg(2)) || getarraysize(getarg(0)) != getarraysize(getarg(3))){
    if(.@debug){
        debugmes "[F_GetItemByMap]: An error is occurupted";
        debugmes "[Function arguments]: Function arguments are empty or to short. Arguments: "+getargcount();
        debugmes "[Array sizes]: Maps:"+getarraysize(getarg(0))+" - Items:"+getarraysize(getarg(1))+" - Amounts:"+getarraysize(getarg(2))+" - Chances:"+getarraysize(getarg(3));
        debugmes "[Function arguments]: Maps:"+getarg(0)+" - Items:"+getarg(1)+" - Amounts:"+getarg(2)+" - Chances:"+getarg(3);
    }
    return 0;
} else {
    for(.@i = 0; .@i<getarraysize(getarg(0)); .@i++){
        if(rand(1,1000) < getelementofarray(getarg(3),.@i))
            return 2;
        if(strcharinfo(3) == getelementofarray(getarg(0),.@i)){
            getitem getelementofarray(getarg(1),.@i),getelementofarray(getarg(2),.@i);
            return 1;
        } else {
            return 3;
        }
    }
    }
    return 4;
    
OnInit:
    set .@debug,1;//0 = disable debugging,1 = enable
    end;
}

Download file below

getItemByMapFunction v5.txt 4.39 kB · 0 downloads

 

Rynbef~

[Error]: script:op_1: argument is not a number (op=C_LNOT)
[Debug]: Data: string value=""
[Debug]: Source (NPC): GetItemByMap (invisible/not on a map)
[Error]: script:op_1: argument is not a number (op=C_LNOT)
[Debug]: Data: string value=""
[Debug]: Source (NPC): GetItemByMap (invisible/not on a map)

Link to comment
Share on other sites

  • 0

  • Group:  Forum Moderator
  • Topic Count:  47
  • Topics Per Day:  0.01
  • Content Count:  796
  • Reputation:   101
  • Joined:  05/23/12
  • Last Seen:  

@wornim sorry I'm not able to test the script cause I just have my mobile phone. If it yet won't works I'll give up. I just want to help.

Spoiler
/*
rAthena Script
Author: @Rynbef
Create Date: 2021-19-12
Last Updated: 2022-01-01

Changelogs:
    2022-01-01:
        *changed OnNPCLoadEvent to OnNPCKillEvent
        *added check if killed enemie is player
        *removed space on callfunc after OnNPCKillEvent
        *fixed if statement syntax error
        *fixed if statement getarraysize of integer to getarraysize of specified getarg
        *removed callfunc OnInit
        *added console debugging can be disabled or enabled
        *changed variable types
        *fixed cant get item cause of wrong if statement
        *fixed for loop used array size instead random chance from argument getarg(3)
        *fixed player can't get item if random chance was equals to specified item chance
        *added argument amount to debug message
        *added map notification if player get lucky but not on a listed map. This can disabled or enabled seperat at OnInit below. Debugging needs to be enabled
        *added notification if everything works fine. Can be disabled or enabled on bottom of OnInit. Debugging needs to disabled
        #fixed wrong array output in for loop from getarg(0)[.i] to getelementofarray(getarg(0),.i)
        #changed .retval and .i vsriables to scope variables .@retval and .@i

Feature planned:
    #Player get zeny if he get lucky
    #Player get zeny only if items disabled
    #Player get zeny or item if both enabled

Description:
    Give a specified item getarg(1) of amount getarg(2) on specified map getarg(0) with a percentage of getarg(3) (0.1 to 100 percent) to a player
    
IMPORTANT:
    All arrays needs to have the same sizes
    It's importent to set all 3 arguments to callfunc

Terms:
    Dont name this as yours
    Dont sell this script
    Dont upload this script on download-/s section or share it otherwise for pay
    Modifications are included from this terms
    Otherwise feel free to edit

Other:
    Don't hestiate to contact me at the forum as pm if u've any error,question,suggestion or want a modification

Script:
*/

-   script  GetItemByMap    -1,{

OnNPCKillEvent:
    if(killedrid >= 150000)
        end;
    set .@retval,callfunc("F_GetItemByMap",.@maps$,.@items,.@item_amounts,.@item_chance);
    if(!.@debug)
        end;
    if(.@retval == 1)
        debugmes "[F_GetItemByMap]: Works fine! Player get item.";
    else if(.@retval == 2)
        debugmes "[F_GetItemByMap]: Works fine! Player is unlucky and get no item.";
    else if(.@retval == 3 && .@debugmap)
        debugmes "[F_GetItemByMap]: Player isn't on a listed map. Current map: "+strcharinfo(3);
    else if(.@retval == 4 && .@debugworking)
        debugmes "[F_GetItemByMap]: Everything works fine!";
    else
        debugmes "[F_GetItemByMap]: Causes in errors. Debug logs on top!";
    end;

OnInit:
    setarray .@maps$[0],"prontera","alberta","izlude";
    serarray .@items[0],501,4012,512;
    setarray .@item_amounts[0],100,1,5;
    setarray .@item_chance[0],1000,500,800;//Chance begins by 0.1 percentage. 1 = 0.1 and 1000 = 100 percent
    set .@debug,1;//0 = disable debugging,1 = enable
    set .@debugmap,1;//0 = disable map notification,1 = enable
    set .@debugworking,1;//0 = disable notification if everything works fine,1 = enable
    end;
}

function    script    F_GetItemByMap    {

if(getarg(0) != "" || !getarg(1) || !getarg(2) || !getarg(3) || getarraysize(getarg(0)) != getarraysize(getarg(1)) || getarraysize(getarg(0)) != getarraysize(getarg(2)) || getarraysize(getarg(0)) != getarraysize(getarg(3))){
    if(.@debug){
        debugmes "[F_GetItemByMap]: An error is occurupted";
        debugmes "[Function arguments]: Function arguments are empty or to short. Arguments: "+getargcount();
        debugmes "[Array sizes]: Maps:"+getarraysize(getarg(0))+" - Items:"+getarraysize(getarg(1))+" - Amounts:"+getarraysize(getarg(2))+" - Chances:"+getarraysize(getarg(3));
        debugmes "[Function arguments]: Maps:"+getarg(0)+" - Items:"+getarg(1)+" - Amounts:"+getarg(2)+" - Chances:"+getarg(3);
    }
    return 0;
} else {
    for(.@i = 0; .@i<getarraysize(getarg(0)); .@i++){
        if(rand(1,1000) < getelementofarray(getarg(3),.@i))
            return 2;
        if(strcharinfo(3) == getelementofarray(getarg(0),.@i)){
            getitem getelementofarray(getarg(1),.@i),getelementofarray(getarg(2),.@i);
            return 1;
        } else {
            return 3;
        }
    }
    }
    return 4;
    
OnInit:
    set .@debug,1;//0 = disable debugging,1 = enable
    end;
}

Download file below

getItemByMapFunction v6.txt

 

Rynbef~

Edited by Rynbef
Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  16
  • Topics Per Day:  0.00
  • Content Count:  40
  • Reputation:   6
  • Joined:  09/17/13
  • Last Seen:  

4 minutes ago, Rynbef said:

@desgastadoLamento, mas não consigo testar o script porque estou apenas com o meu telemóvel. Se ainda não funcionar, desisto. Eu só quero ajudar.

  Revelar conteúdos ocultos




    








    

Baixe o arquivo abaixo

 

 

Rynbef ~

ou helped a lot friend, a lot I know you can't test, but you created a base for the other to help me, I'm saying that I can't run your script, just the simplified @sader script

Link to comment
Share on other sites

  • 0

  • Group:  Forum Moderator
  • Topic Count:  47
  • Topics Per Day:  0.01
  • Content Count:  796
  • Reputation:   101
  • Joined:  05/23/12
  • Last Seen:  

Just now, worn said:

ou helped a lot friend, a lot I know you can't test, but you created a base for the other to help me, I'm saying that I can't run your script, just the simplified @sader script

I've edited a few seconds ago. Maybe it works now. I've forgot to add all arrays to the callfunc.

 

Best regards,

Rynbef~

Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  16
  • Topics Per Day:  0.00
  • Content Count:  40
  • Reputation:   6
  • Joined:  09/17/13
  • Last Seen:  

3 minutes ago, Rynbef said:

Eu editei alguns segundos atrás. Talvez funcione agora. Esqueci de adicionar todos os arrays ao callfunc.

 

Atenciosamente,

Rynbef ~

well the script ran without errors, but the drop is not working

Link to comment
Share on other sites

  • 0

  • Group:  Forum Moderator
  • Topic Count:  47
  • Topics Per Day:  0.01
  • Content Count:  796
  • Reputation:   101
  • Joined:  05/23/12
  • Last Seen:  

Do u activated debugging? What does the console debug? @worn

 

Rynbef~

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...