Author Topic: Item help  (Read 723 times)

Two quick questions guys.

First off, I need to know how would I go around to adding a variable that is accessible to VCE?
Like being able to display it in chat using <var:cl:yadaya>

Second is a bit more complex.

I need to create an item that when used affects a clients variable, I've tried looking at the pill script, as well as the chocolate bars script.
Can someone explain them to me, parts of it I do not understand why they are needed and what they are doing.

Thanks a lot guys!

I need to create an item that when used affects a clients variable, I've tried looking at the pill script, as well as the chocolate bars script.
Can someone explain them to me, parts of it I do not understand why they are needed and what they are doing.

Second is a bit more complex.

I need to create an item that when used affects a clients variable, I've tried looking at the pill script, as well as the chocolate bars script.
Can someone explain them to me, parts of it I do not understand why they are needed and what they are doing.

Code: [Select]
function YourItemImage::onFire(%this,%obj,%slot)
{
   %client = %obj.client;
   %client.player.addHealth(10);
}

For example, that item would increase your health by 10. You can also do other %client and %client.player variables like for example %client.hunger += 10;

Replace YourItemImage with the image name of your item (where your code says ImageData(Blah);) So for example it would be Blah::onFire.

Make sure the datablock actually calls "OnFire", though. If you're copy-pasting a datablock, it might actually call "onUse" or something.



%client.hunger += 10;
Also, just to clarify because I know Yola is newish to coding, that's called an operator; the one above would be the same as typing %client.hunger = %client.hunger + 10; and you can probably figure out what -=, *=, and /= do.

For the first one, check out an add-on that does this. Perhaps my Event_Bricktext

registerSpecialVar(fxDTSbrick,"bricktext","%this.bricktext");
This line will make it so <var:brick:bricktext> accesses the bricktext variable on the brick.
So, if you wanted to register %client.testVar as <var:cl:testVar> you would do:
registerSpecialVar(gameConnection,"testVar","%this.testVar");
I believe, that add-on is the only time I've ever done an addition to VCE so I don't know for sure

Thanks guys, meant to tell you I already figured out the VCE thing using the code from variable replaces as help.  As with the item, I sat down and read the chocolate bars script and understood most of it and what I didn't I found out later. 

However the whole += thing just blew my entire mind.

Thanks guys !

+=

Say you wanted to increase %client.hunger by 10.

Normally you would do this :

Code: [Select]
%client.hunger = %client.hunger + 10;

But instead you can do this :

Code: [Select]
%client.hunger += 10;

Both do the same thing, but option 2 is short and quick.

Same for variables, for example if you wanted to increase %client.hunger BY %foodInPack :

Code: [Select]
%client.hunger = %client.hunger + %foodInPack;

or

Code: [Select]
%client.hunger += %foodInPack;

+=

For the first one, check out an add-on that does this. Perhaps my Event_Bricktext

registerSpecialVar(fxDTSbrick,"bricktext","%this.bricktext");
This line will make it so <var:brick:bricktext> accesses the bricktext variable on the brick.
So, if you wanted to register %client.testVar as <var:cl:testVar> you would do:
registerSpecialVar(gameConnection,"testVar","%this.testVar");
I believe, that add-on is the only time I've ever done an addition to VCE so I don't know for sure
Code: [Select]
package blah
{
    function VcE_initserver()
    {
        registerspecialvar(fxdtsbrick, asdf, "%brick.asdf", "%brick.setasdf");
        parent::vce_initserver();
    }
};