Yeah, sure, but items don't have passive effects if you don't create them.
Another option is just increase %ATTACK by 2 on the page you get the first sword, then increase it again by whatever the difference is when you get the improved one (so if the second sword is 4, increase it by another 2). This stops your code being reliant on items, and so it is easier to do.
If you have some puzzle where they need to drop the sword early, then I think you could use a global script.
Global scripts can be ran before every page/link (or was it on every page/link?), so you can check the state of items and modify variables based on that. I'm a little iffy on the timing for this stuff, so beware undesired defects!
Here is an article on items: https://chooseyourstory.com/help/articles/article.aspx?ArticleId=66
Of note is:
'The $ITEMSTATE variable can only be set to 0 or 1.
- 0 means that the item is not in your inventory.
- 1 means that the item is in your inventory.'
There are more articles under the Help & Info section.
Anyway, what I'd do is:
GLOBAL SCRIPT:
IF %FOUNDSWORD = 1 THEN IF $ITEMSTATE1 = 1 THEN %ATTACK := %ATTACK + 2
IF $ITEMSTATE1 = 1 THEN %FOUNDSWORD := 2
%FOUNDSWORD starts as 1, so when you find the ITEM with id 1 AND have it in inventory it's state ($ITEMSTATE1) will be 1. This means I modify the attack based on the sword.
The second line also changes %FOUNDSWORD to 2, so that I don't keep increasing attack every page (and this is also done if the item state is 1).
GLOBAL SCRIPT
IF %FOUNDSWORD = 2 THEN IF $ITEMSTATE1 = 0 THEN %ATTACK := %ATTACK - 2
Here IF you have found the sword already, and the sword is NOT in your inventory (the $ITEMSTATE1 = 0), then the attack needs to be reduced. If there is a way to get this sword again, you might want to reset the %FOUNDSWORD variable (so that attack can be increased again).
The issue with this system is that you'd need a extra variable for each sword, which could get annoying.
I'd just create these variables in scripts so their names can be longer than 10 letters (or so I hear), and have them be %FOUNDSWORD1 %FOUNDSWORD2 etc. This is kinda a bad implementation, but assuming it doesn't somehow cause lag, I wouldn't care.
The above seems to work for me, but I will note the timing for creating the variable in a script and having that noticed by global scripts is iffy, so I don't suggest having %FOUNDSWORD = 0 for the check (which is why I have it as %FOUNDSWORD = 1, since it stops my implementation from counting the attack boost twice).
ANYHOW, others might have a better way. I haven't really messed around with items much, so hopefully this gives you some ideas.
P.S. I don't recommend making an RPG, they tend to suck since just clicking a button to whittle down HP can be boring, but if you're determined, I won't stop you (as good storygame RPGs can exist, but it does seem to be a lot of work). This isn't what this thread is about tho, so I'll leave it at that. Good luck!