Author Topic: Events  (Read 867 times)

Could anyone either briefly explain the structure of event scripts, or link me to a tutorial?


Aww crud. I thought I looked. Thanks anyway.

Well, I need to know more than just how to register them. I know that already.

Look at the messageboxOk event. It is very simple and is a good tutorial.

Would something like this work?

Code: [Select]
registeroutputevent("Player", "addGold", "int -500 500 0", 1);

function addGold(%goldamount, %client)
{
%gold[%client] = %gold[%client] + %goldamount;
messageclient(%client, '',"\c3Gold is " @ %gold[%client]);
}

Would something like this work?

Code: [Select]
registeroutputevent("Player", "addGold", "int -500 500 0", 1);

function addGold(%goldamount, %client)
{
%gold[%client] = %gold[%client] + %goldamount;
messageclient(%client, '',"\c3Gold is " @ %gold[%client]);
}
No, you need Player::AddGold I think.
Plus
it would be Player::AddGold(%Player,%goldAmmount){
%cl = %player.client;
$Gold[%cl.bl_id] = $Gold[%cl.bl_id] + %goldAmmount;
messageClient(%cl,'',"\c3Gold \c6is \c3"@$Gold[%cl.bl_id]);
}
I believe.
Edit: I noticed wrong button.
« Last Edit: January 27, 2010, 03:29:35 PM by Pah1023 »

No, you need Player::AddGold I think.
Plus
it would be Player::AddGold(%Player,%goldAmmount){
%cl = %player.client;
$Gold[%cl.bl_id] = $Gold[%cl.bl_id] + %goldAmmount;
messageClient(%cl,'',"\c3Gold \c6is \c3"#$Gold[%cl.bl_id]);
}
I believe.
Oh my god, go away.



Code: [Select]
function Player::addGold(%this, %goldamount)
{
%this.client.gold += %goldamount;
messageclient(%client, '', "\c3Gold is " @ %this.client.gold);
}
1. You need Player::
2. You need a %this, which will be a Player
3. %this.client.gold - assigned the variable "gold" to the player's client.
    By Player, we mean the actual player's object
4. += means add to itself

Code: [Select]
%a = 50;
%a += 3;
%a is now 58

So is the first argument always the player who activated the event?

offtopic question: how do you do the absolute value of something without doing a whole if statement and multiplying by -1?
Code: [Select]
abs(?

Another question: I can call function Player::addgold someplace else without using an event right?
« Last Edit: January 26, 2010, 11:34:28 PM by Deriboy »

So is the first argument always the player who activated the event?

offtopic question: how do you do the absolute value of something without doing a whole if statement and multiplying by -1?
Code: [Select]
abs(?

Another question: I can call function Player::addgold someplace else without using an event right?
Yes, the first argument is always the object calling the method.

And the function you're looking for is mAbs I believe, ie;
Code: [Select]
function Player::addGold(%player,%gold)
{
   %player.client.gold += mAbs(%gold);
   messageClient(%player.client,'',"\c6You have\c3" SPC %gold SPC "gold\c6.");
}
Although, if you leave that mAbs out, then you can use %player.addGold(-10) to subtract gold as well which is convenient enough.

And yes, you can call it from script. Just using %client.player.addGold(1); or whatever. Events are just a way to call functions, you can even use other event outputs for players like %player.spawnProjectile() and things like that, provided you have the right arguments.

K thanks, but the second question is not involved with my event questions.

K thanks, but the second question is not involved with my event questions.
Just so you know, all math functions start with an m

so
Code: [Select]
mabs(-5) = 5
offtopic: I keep thinking you are Ephi because of your new avatar...

« Last Edit: January 30, 2010, 09:13:18 PM by MrBob00 »