Jump to content
  • 0

How to loop parts of item scripts?


dckk

Question


  • Group:  Members
  • Topic Count:  2
  • Topics Per Day:  0.00
  • Content Count:  11
  • Reputation:   0
  • Joined:  01/06/21
  • Last Seen:  

Hi, as the title reads I'm looking for a way to loop an item script while it's equipped.

I've been researching about this but I can't seem to find docs about it or examples, which I'd definitely need since my scripting experience is very limited. 

At the moment what I'd like to do is a simple script: { 1 bonus bFlee,15; bonus bMaxSP,readparam(bFlee); }

My problem is that as I just found out, item scripts only check parameters on equip/player reload and that would make this item very abusable since one could just equip FLEE gear, wear it and then swap it off while keeping the bonus. 

To avoid that (and also to make usable a lot more item scripts I have planned) I'd need to know how to make loop every couple seconds so the bonus is recalculated as the parameter changes.

Any pointers will be greatly appreciated, and if a way to loop does exist I'd be very thankful for an example. 

Link to comment
Share on other sites

5 answers to this question

Recommended Posts

  • 1

  • Group:  Members
  • Topic Count:  34
  • Topics Per Day:  0.01
  • Content Count:  163
  • Reputation:   63
  • Joined:  07/11/14
  • Last Seen:  

5 hours ago, dckk said:

Hi, as the title reads I'm looking for a way to loop an item script while it's equipped.

I've been researching about this but I can't seem to find docs about it or examples, which I'd definitely need since my scripting experience is very limited. 

At the moment what I'd like to do is a simple script: { 1 bonus bFlee,15; bonus bMaxSP,readparam(bFlee); }

My problem is that as I just found out, item scripts only check parameters on equip/player reload and that would make this item very abusable since one could just equip FLEE gear, wear it and then swap it off while keeping the bonus. 

To avoid that (and also to make usable a lot more item scripts I have planned) I'd need to know how to make loop every couple seconds so the bonus is recalculated as the parameter changes.

Any pointers will be greatly appreciated, and if a way to loop does exist I'd be very thankful for an example. 

 

hello, I don't understand very well, could you simulate a situation so that I can set up an example for you?

Link to comment
Share on other sites

  • 1

  • Group:  Members
  • Topic Count:  1
  • Topics Per Day:  0.00
  • Content Count:  23
  • Reputation:   6
  • Joined:  12/28/11
  • Last Seen:  

I'm not sure if looping this would be a good idea.
with all the server load and everything since this script will run for every character that equipped this item on your server.

It has been a very long time since I touched rAthena at all, so I'm not sure if this will work correctly.

while (getequipid(EQI_ACC_L) == item_id || getequipid(EQI_ACC_R) == item_id) { bonus bMaxSP,readparam(bFlee); sleep 2000; }

 

EQI_ACC_L (0) - Accessory 1
EQI_ACC_R (1) - Accessory 2
EQI_SHOES (2) - Footgear (shoes, boots)
EQI_GARMENT (3) - Garment (mufflers, hoods, manteaux)
EQI_HEAD_LOW (4) - Lower Headgear (beards, some masks)
EQI_HEAD_MID (5) - Middle Headgear (masks, glasses)
EQI_HEAD_TOP (6) - Upper Headgear
EQI_ARMOR (7) - Armor (jackets, robes)
EQI_HAND_L (8) - Left hand (weapons, shields)
EQI_HAND_R (9) - Right hand (weapons)
EQI_COSTUME_HEAD_TOP (10) - Upper Costume Headgear
EQI_COSTUME_HEAD_MID (11) - Middle Costume Headgear
EQI_COSTUME_HEAD_LOW (12) - Lower Costume Headgear
EQI_COSTUME_GARMENT (13) - Costume Garment
EQI_AMMO (14) - Arrow/Ammunition
EQI_SHADOW_ARMOR (15) - Shadow Armor
EQI_SHADOW_WEAPON (16) - Shadow Weapon
EQI_SHADOW_SHIELD (17) - Shadow Shield
EQI_SHADOW_SHOES (18) - Shadow Shoes
EQI_SHADOW_ACC_R (19) - Shadow Accessory 2
EQI_SHADOW_ACC_L (20) - Shadow Accessory 1

 

Edited by CrescentSaga
  • Love 1
Link to comment
Share on other sites

  • 1

  • Group:  Members
  • Topic Count:  34
  • Topics Per Day:  0.01
  • Content Count:  163
  • Reputation:   63
  • Joined:  07/11/14
  • Last Seen:  

I analyzed the situation and arrived at the following solution, instead of creating a loop instance for each player, I made a single loop, you must add the callfunc as it is in the comment at the beginning, so the players will have their accid and charid saved, the script will monitor their flee, when there is a change and pass the check within the delay, the script will unequip the item and equip it thus giving the new bMaxSP

 

/*
	add in item_db:
	
	EquipScript: |
           callfunc "ItemSCset",1;
    UnEquipScript: |
           callfunc "ItemSCset",2;
*/

//Main Script
//== by Hyroshima
//==
-	script	ItemSCcontrol	FAKE_NPC,{
OnInit:

	//Delay check in sec
	set .@dSec,5;
	
	//ItemID
	set .@item,2501;

	freeloop(1);
	while(1)
	{
		if(getarraysize($ItemSCaccountid))
		{
			for(set .@i,getarraysize($ItemSCaccountid)-1; .@i>-1; set .@i,.@i-1)
			{
				if(isloggedin($ItemSCaccountid[.@i],$ItemSCcharid[.@i]))
				{
					attachrid($ItemSCaccountid[.@i]);
					if(readparam(bFlee) != ItemSCflee)
					{
						for(set .@x,0; .@x<14; set .@x,.@x+1)
							if(getequipid(.@x) == .@item){ set .@slot,.@x; break; }
						unequip .@slot;
						equip .@item;
						set ItemSCflee,readparam(bFlee);
					}
					detachrid;
				}
			}
		}
	
		sleep (.@dSec*1000);
	}
	freeloop(0);
	
end;
}

//Function Script
//==
function	script	ItemSCset	{

	if(getarg(0) == 1)
	{
		setarray $ItemSCaccountid[getarraysize($ItemSCaccountid)],getcharid(3);
		setarray $ItemSCcharid[getarraysize($ItemSCcharid)],getcharid(0);
		set ItemSCflee,readparam(bFlee);
	}
	else
	{
		deletearray $ItemSCaccountid[inarray($ItemSCaccountid[0],getcharid(3))],1;
		deletearray $ItemSCcharid[inarray($ItemSCcharid[0],getcharid(0))],1;
		set ItemSCflee,0;
	}

return;
}

 

Edited by Hyroshima
  • Love 1
Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  2
  • Topics Per Day:  0.00
  • Content Count:  11
  • Reputation:   0
  • Joined:  01/06/21
  • Last Seen:  

Oh man, yeah sorry I posted that from the phone and formatting looked a lot different lol.
So, my initial item script is:

 { 1 bonus bMaxSP,readparam(bFlee); } <-reads user's total Flee and adds it as Max SP

What I want to do is make whole bonus be reloaded every 2s or so, so that if the player's Flee changes (because of receiving buffs, changing gear or whatever), the bonus will change with it.


From a bit more research I found this:
https://rathena.org/board/topic/69062-repeating-specialeffect-on-item-script/?do=findComment&comment=128591
This seems like the kind of looping that would do the trick, but that item script is a bit complex from me and I don't understand how I could apply the looping outside of that scenario, unfortunately.

(I'm not sure if this is any clearer so please mention if it needs further explanation, haha)

 

Edited by dckk
Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  2
  • Topics Per Day:  0.00
  • Content Count:  11
  • Reputation:   0
  • Joined:  01/06/21
  • Last Seen:  

I had some concerns re: server load but didn't know if it would be a big problem or not. I tried this and it seems to work well, though this was with only 10 test accounts running the 5 items with the scripts.
I suppose there wouldn't be any way to detect players idling and pause the loop in case of implementing it to a larger playerbase?

I found this: https://pastebin.com/raw/7xT5y8yS regarding detecting idle players (in this case to kick them), but I'm out of my depth trying to apply this on an item script.

Thanks for the help btw, prob wouldn't figure it out on my own.

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