i3670
Posting Freak
Posts: 1,308
Threads: 74
Joined: Oct 2011
Reputation:
36
LocalVar
Hi got this small problem with my script.
Spoiler below!
void OnStart()
{
SetLocalVarInt("InsaneImages", 0);
AddEntityCollideCallback("Player", "AreaActivateInteract", "ActivateInsaneImages", true, 1);
}
void ActivateInsaneImages(string &in asParent, string &in asChild, int alState)
{
for(int i=1;i<=3;i++) {
SetEntityPlayerInteractCallback("Flask_"+i+"", "AddLocalNumber", false);
}
}
void AddLocalNumber(string &in asEntity)
{
if(GetLocalVarInt("InsaneImages") == 1)
{
SetEntityActive("armour_nice_complete_1", true);
SetEntityActive("", true);
}
if(GetLocalVarInt("InsaneImages") == 2)
{
SetEntityActive("armour_nice_complete_2", true);
SetEntityActive("", true);
}
AddLocalVarInt("InsaneImages", 1);
All_Active();
}
void All_Active()
{
if(GetLocalVarInt("InsaneImages") == 3)
{
SetEntityActive("armour_nice_complete_3", true);
SetEntityActive("", true);
}
}
After I've interacted with 1 flask, doesn't matter which one, 1 armour is supposed to get active This, however, doesn't really work exactly to plan.
If I for instance interact with flask_3 first all armours gets activated, regardless if I've interacted with the other 2. If I interact with flask_1 nothing happens, this also goes for flask_2. However if I interact with 1 and then 2 or the other way around only 1 armour gets activated.
(This post was last modified: 09-12-2012, 12:46 PM by i3670 .)
09-11-2012, 10:43 PM
Adny
Posting Freak
Posts: 1,766
Threads: 6
Joined: Mar 2012
Reputation:
173
RE: LocalVar
Try something like this:
void OnStart()
{
SetLocalVarInt("InsaneImages", 0);
AddEntityCollideCallback("Player", "AreaActivateInteract", "ActivateInsaneImages", true, 1);
}
void ActivateInsaneImages(string &in asParent, string &in asChild, int alState)
{
for(int i=1;i<=3;++i)
SetEntityPlayerInteractCallback("Flask_" + i, "AddLocalNumber", false);
}
void AddLocalNumber(string &in asEntity)
{
AddLocalVarInt("InsaneImages", 1);
CheckArmor();
}
void CheckArmor()
{
if(GetLocalVarInt("InsaneImages") == 1)
{
SetEntityActive("armour_nice_complete_1", true);
}
if(GetLocalVarInt("InsaneImages") == 2)
{
SetEntityActive("armour_nice_complete_2", true);
}
if(GetLocalVarInt("InsaneImages") == 3)
{
SetEntityActive("armour_nice_complete_3", true);
}
}
The only problem I see (with the original) is that since the callback doesn't remove automatically, the player can interact with 1 flask 3 times and achieve the same effect. You would have to make 3 separate callbacks (1 for each flask) to get rid of that problem.
Hope that helped :o
I rate it 3 memes.
(This post was last modified: 09-11-2012, 11:17 PM by Adny .)
09-11-2012, 11:16 PM
Tomato Cat
Senior Member
Posts: 287
Threads: 2
Joined: Sep 2012
Reputation:
20
RE: LocalVar
*edit*
NINJA'D >.<
I think that this line:
SetEntityPlayerInteractCallback("Flask_"+i+"", "AddLocalNumber", false);
should be this instead:
SetEntityPlayerInteractCallback("Flask_"+i, "AddLocalNumber", false);
And I would put your if statements into the "All_Active" function.
Spoiler below!
void OnStart()
{
SetLocalVarInt("InsaneImages", 0);
AddEntityCollideCallback("Player", "AreaActivateInteract", "ActivateInsaneImages", true, 1);
}
void ActivateInsaneImages(string &in asParent, string &in asChild, int alState)
{
for(int i=1;i<=3;i++) {
SetEntityPlayerInteractCallback("Flask_"+i+"", "AddLocalNumber", false);
}
}
void AddLocalNumber(string &in asEntity)
{
AddLocalVarInt("InsaneImages", 1);
All_Active();
}
void All_Active()
{
if(GetLocalVarInt("InsaneImages") == 1)
{
SetEntityActive("armour_nice_complete_1", true);
SetEntityActive("", true);
}
if(GetLocalVarInt("InsaneImages") == 2)
{
SetEntityActive("armour_nice_complete_2", true);
SetEntityActive("", true);
}
if(GetLocalVarInt("InsaneImages") == 3)
{
SetEntityActive("armour_nice_complete_3", true);
SetEntityActive("", true);
}
}
Try that and see if it fixes it.
RAISE YOUR DONGERS ヽ༼ຈل͜ຈ༽ノ
(This post was last modified: 09-11-2012, 11:18 PM by Tomato Cat .)
09-11-2012, 11:16 PM
FlawlessHappiness
Posting Freak
Posts: 3,980
Threads: 145
Joined: Mar 2012
Reputation:
171
RE: LocalVar
Yes. Before you ask "if(GetLocalVarInt("InsaneImages") == 1)" you will have to "AddLocalVarInt("InsaneImages", 1)" Because otherwise it would just be 0 since you haven't added anything to it
Trying is the first step to success.
09-12-2012, 07:01 AM