SphereCommunity
Tags.... - Printable Version

+- SphereCommunity (https://forum.spherecommunity.net)
+-- Forum: Sphere 0.56d (/Forum-Sphere-0-56d)
+--- Forum: Script Help (/Forum-Script-Help)
+--- Thread: Tags.... (/Thread-Tags)



Tags.... - Lincoln - 11-25-2016 12:51 AM

Hello All,

I am trying to make a system that when a monster is killed it applies a tag to an item...
So with every monster killed the tag on the item increases...

Any suggestions on how I would accomplish this?
I really do struggle with tags, not sure why


RE: Tags.... - darksun84 - 11-25-2016 02:46 AM

Simple Example:
PHP Code:
[ITEMDEF i_monster_counter]
ID i_crystal_green
NAME
Monster counter
type 
t_script

ON
=@Create
color 
colors_all

ON
=@Dclick
src
.sysmessage @100 You have killed <dtag0.monsterKillmonsters.
return 
1

[EVENTS e_monster_kill]
ON=@Kill
ref1 
= <findid.i_monster_counter>
if (<
ref1>)
      
ref1.tag0.monsterKill += 1
      sysmessage 
@100 Your monster counter is increasedis now <ref1.dtag0.monsterKill>
      return 
0
endif
//This will install the e_monster_kill event on the player.
//For removing the event type .events -e_monster_kill.
[FUNCTION testMonster]
events +e_monster_kill
src
.sysmessage @100 Monster kill event installed

In some line of code:
PHP Code:
sysmessage @100 Your monster counter is increasedis now <ref1.dtag0.monsterKill
I add the prefix d before the tag, that means display the result in decimal (instead of hexdecimal), it's a shortcut for avoiding writing <eval <ref1.tag0.monsterKill>>

Difference betweeen TAG,TAG0:
TAG0 just tell Sphere to set to 0 the value of the TAG when the TAG is accessed AND the TAG doesn't have any value.
Example:
PHP Code:
[function testApples]
sysmessage  I have <tag0.applesapples//Output will be: I have 0 apples.
sysmessage I have <tag.applesapples.  //Output will be: I have apples.   
tag.apples 2
sysmessage  I have 
<tag0.applesapples//Output will be: I have 02 apples.
sysmessage I have <tag.applesapples.  //Output will be: I have 02 apples. 
//The following line will clear the tag.
tag.apples 
It's important to use TAG0 when checking the tag value.
PHP Code:
[FUNCTION checkApples]
//This will throw an error in the console if the tag is empty.
//By using tag0 you can avoid the error.
if <tag.apples> > 1
    say I have at least an apple
.
else
    
say I have no apples.
endif 



RE: Tags.... - Lincoln - 11-25-2016 03:45 AM

Thanks for the response Darksun!

However,
The tag on the i_monster_counter would only increase if the player had the event correct?

I would prefer not to add an event to the player, but rather add it to the monster
so that ON=@DEATH of the monster the tag on i_monster_counter increases, if that makes any sense...
Could I still use the same example that you provided?

Really appreciate the help


RE: Tags.... - darksun84 - 11-25-2016 05:07 AM

You have to use @DeathCorpse instead @Death
With this trigger the event will look a little different

PHP Code:
[EVENTS e_monster_kill]
ON=@DeathCorpse
ref1 
= <argo.more2// <argo> holds the uid of the corpse while more2 the uid of the character that killed it.
ref2 = <ref1.findid.i_monster_counter>
if (<
ref2>)
      
ref2.tag0.monsterKill += 1
      ref1
.sysmessage @100 Your monster counter is increasedis now <ref2.dtag0.monsterKill>
      return 
0
endif