PDA

View Full Version : Charmfile vs Scriptfileid


NatedogEZ
10-09-2013, 11:07 AM
When using a quest for an item.. is there any reason to use Scriptfileid?

I have yet to see something that the charmfile can't do that the scriptfileid can do...


Scriptfileid is restricted to ONE slot -- Meaning if you have two items that need scripts that are similar.. you would need TWO scripts to get them to BOTH work when equipping both items... (I am guessing this is unintended behavior?)


Charmfile is not restricted to ONE slot (thank god) .. I can have all my custom gear use the same exact charmfile and they all work well using the same quest to get what I need done.


TL;DR ... is scriptfileid useless / broken / or am I missing something...

wolfwalkereci
10-11-2013, 04:01 AM
I use one scriptfileid for 3 pieces of gear, all of which have their own thing going on and it works for me.
Guess it depends on what your goal is and how you coded it.

trevius
10-11-2013, 08:30 AM
The Charmfile scripts are for scaling items and the scripts are ran automatically on regular intervals. The scriptfileid field is used for scripts that are triggered when right clicking an item similar to a clicky item that would normally cast a spell. I am not sure what you mean by the slot restrictions or by it only being useable by 1 item.

Here is a simple example of a charm script that uses qglobals:

#Aug Scale

sub EVENT_SCALE_CALC {


if (defined($qglobals{Example_Qglobal_Value}))
{
$questitem->SetScale($qglobals{Example_Qglobal_Value}/100);
}
else
{
$questitem->SetScale(0);
}

}

Here is a very simple script file id script that sends a message to the client that clicked it. The nice thing about this is that it does not require a clicky spell to be on the item in order to trigger a script when right clicked. Keep in mind that this only works for clients later than Titanium, as Titanium does not send anything to the server if a non-clicky item is right clicked:
# Clicky Item Test Script

sub EVENT_ITEM_CLICK {
if ($client)
{
$client->Message(15,"Click Event Worked for $itemname ($itemid)!");
}
}

You can also use spell IDs in the quests/spells folder for scripts that trigger when a spell is cast from an item (or any regular cast as well). Here is an example that enforces size limits to a growth spell:
# Script for setting a cap on Growth spells

%RaceSizes = (
1 => 6, # Human
2 => 8, # Barbarian
3 => 6, # Erudite
4 => 5, # Wood Elf
5 => 5, # High Elf
6 => 5, # Dark Elf
7 => 5, # Half Elf
8 => 4, # Dwarf
9 => 9, # Troll
10 => 9, # Ogre
11 => 3, # Halfling
12 => 3, # Gnome
128 => 6, # Iksar
130 => 6, # Vah Shir
330 => 5, # Froglok
522 => 6, # Drakkin
);

# Sub to handle the growth limits so it doesn't have to be repeated multiple times
sub DoGrowth {
my $Mob = $_[0]; # This is the Mob that was passed into the sub
my $CurSize = $Mob->GetSize();
if (!$CurSize) {
$CurSize = 6;
}
my $CurRace = $Mob->GetRace();
my $BaseSize = $RaceSizes{$CurRace};
if (!$BaseSize) {
$BaseSize = 6;
}
if ($CurSize < $BaseSize + 5) {
$Mob->ChangeSize($CurSize + 1);
}
}

sub EVENT_SPELL_EFFECT_CLIENT {
my $ClientID = $entity_list->GetClientByID($caster_id);
if ($ClientID) {
$ClientTarget = $ClientID->GetTarget();
if ($ClientTarget) {
DoGrowth($ClientTarget);
}
else {
DoGrowth($ClientID);
}
}
}

sub EVENT_SPELL_EFFECT_NPC {
my $NPCID = $entity_list->GetMobByID($caster_id);
if ($NPCID) {
$NPCTarget = $NPCID->GetTarget();
if ($NPCTarget) {
DoGrowth($NPCTarget);
}
else {
DoGrowth($NPCID);
}
}
}

It isn't much, but this wiki page shows the events related to different types of item scripts:
http://www.eqemulator.net/wiki/wikka.php?wakka=ItemQuests

In short; the different types of scripts are all fully functional. You are probably just not using them correctly.

NatedogEZ
10-11-2013, 09:09 AM
I am not sure what you mean by the slot restrictions or by it only being useable by 1 item.



Create a script called... "Script_1.pl" ...

Now add it to a Helm / Chest / Bracer / ect / ect...

Add a debug line of some sort like so...


$DEBUG = 1;

sub EVENT_ITEM_CLICK {

if($DEBUG == 1) { $client->Message(335, "CLICKED item!"); }

}



It seems I could get 2 of the same EXACT bracer to both work on the same script... but if it was a Bracer and a Helm the script would not work for both.. only worked for one... hmm


I was testing the Charmfile on 2 of the same weapns as well which is why I thought it worked for Charmfile... when I used 2 different weapons.. only of the of scripts would work and the other did not. (when using the same charmfile on both)

KLS
10-11-2013, 08:08 PM
The way item scripts have changed a bit in the past few months Trev, it no longer really works like that and any item event can be triggered by any script.

This is from the Lua documentation but it should work the same for Perl with pl instead of lua extension:

Item Scripts are quest scripts attached to Items. Items will load a script on the first event that triggers them and will load one and only one from the following location. Which ever it finds first in the following order:

./quests/zone/items/item_script.lua
./quests/global/items/item_script.lua
./quests/zone/items/default.lua
./quests/global/items/default.lua
The format of the item_script is as follows:

If ScriptFileID != 0
item_script = "script_" + ScriptFileID
Else If CharmFile != ""
item_script = CharmFile
Else
item_script = item_id

Items will only load one script but all events will get pushed to that based on that precedence order. If it doesn't work like this for both Lua and Perl then there's a bug that needs to be fixed.

Though I suspect you may be tripping over the precedence + item_script format unintentionally.

NatedogEZ
10-11-2013, 09:36 PM
So KLS lets say script_1.pl is on my bracers I can't use script_1.pl on my boots as well?

Only one of the items can load that script at a time? (because that is how it is working currently)

KLS
10-12-2013, 06:36 AM
In theory no that should work. I'm not seeing that behavior but I'm using Lua. I'll try Perl tomorrow and make sure it's not bugged.

NatedogEZ
10-20-2013, 11:21 PM
In theory no that should work. I'm not seeing that behavior but I'm using Lua. I'll try Perl tomorrow and make sure it's not bugged.



I figured out the problem actually.. was something I was completely overlooking till now ...


I had a hash outside of a sub so that I didn't have to copy paste it into each sub.. but doing that only allowed it to work for a single item with that script file. (doh)


I just copied the hash into both ... EVENT_EQUIP_ITEM and EVENT_UNEQUIP_ITEM and now it works for all items with the same exact script... yay!

I kinda feel stupid now.. :(