Facebook Twitter YouTube Frictional Games | Forum | Privacy Policy | Dev Blog | Dev Wiki | Support | Gametee


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Something Wrong with AddUseItemCallback?
AGP Offline
Senior Member

Posts: 448
Threads: 45
Joined: Dec 2012
Reputation: 23
#1
Something Wrong with AddUseItemCallback?

Honestly, I've been at this for hours and am at my wit's end.

I've checked and double-checked the names inside the level editor and in the hps. I've turned things off and on, restarted the game, I've no idea what's happening.

I found the script through some forum diving, and since in my mod there are three randomly spawning buckets, I had to change the name of the bucket used.

Where it had worked before with the original bucket, it now does nothing. I even tried putting back in the original bucket and turning off the other three, and STILL nothing.

I've tried doing them all separate callbacks and doing them all condensed with the integer, but still nothing is working.

Does anyone see anything that I'm missing?

void OnStart()
{
    string bucket = "bucket_"+RandInt(1, 3);
    string paint = "paint_"+RandInt(1, 3);
    string knife = "knife_"+RandInt(1, 3);
    SetEntityActive(bucket, true);
    SetEntityActive(paint, true);
    SetEntityActive(knife, true);
    
    for(int i=1;i<=2;i++)
    {
        InteractConnectPropWithRope("", "crank_wheel_1", "RopeArea_"+i, false, 1,1,1, false, 0);
    }
    
    SetLocalVarInt("RopeInArea", 0);
    SetLocalVarInt("BucketFilled", 0);

    for(int i = 1; i <= 4; i++)
    {
        AddUseItemCallback("ThisCrapNotWorking", "bucket_"+i, "RopeInteractArea_1", "UseBucketOnRope", false);
    }
    
    ///AddUseItemCallback("ThisCrapNotWorking", "bucket_1", "RopeInteractArea_1", "UseBucketOnRope", false);                                 <---
    ///AddUseItemCallback("ThisCrapNotWorking", "bucket_2", "RopeInteractArea_1", "UseBucketOnRope", false);                                <---
    ///AddUseItemCallback("ThisCrapNotWorking", "bucket_3", "RopeInteractArea_1", "UseBucketOnRope", false);                                <---
    AddEntityCollideCallback("RopeInteractArea_1", "invisible_box_mass_2_1", "CheckRopePosition", false, 0);
    AddEntityCollideCallback("AreaBottomWell", "invisible_box_mass_2_1", "RopeHitsBottomWell", false, 1);
}

void OnEnter()
{

}

void OnLeave()
{

}

///-------------------------------------------------------------------------------
///-------------------------------BUCKET & WELL-----------------------------------
///-------------------------------------------------------------------------------

void CheckRopePosition(string &in asParent, string &in asChild, int alState)
{
    if(alState == 1)
    {
        SetLocalVarInt("RopeInArea", 1);
        AddDebugMessage("Rope inside of Area", false);
    }
    else
    {
        SetLocalVarInt("RopeInArea", -1);
        AddDebugMessage("Rope out of Area", false);
    }
}

void UseBucketOnRope(string &in asItem, string &in asEntity)
{
    for(int i = 1; i <= 3; i++)
    {    if(asItem != "bucket_"+i)
        {
            AddDebugMessage("Item not the bucket, no interaction occurs.", false);
            return;
        }
    }

    if(GetLocalVarInt("RopeInArea") != 1)
    {
    SetMessage("", "", 0);
    AddDebugMessage("Rope outside of area, no interaction occurs.", false);
    return;
    }

    AddAttachedPropToProp("invisible_box_mass_2_1", "wooden_bucket_onrope_1", "wooden_bucket_onrope.ent", 0,0,0,0,0,0);
    RemoveItem(asItem);
    
    SetLocalVarInt("BucketOnRope", 1);
}

void RopeHitsBottomWell(string &in asParent, string &in asChild, int alState)
{
    if(GetLocalVarInt("BucketOnRope") == 0)
    {
        return;
    }
    
    PlaySoundAtEntity("WaterSplash","impact_water_med.snt", "AreaBottomWell", 0, false);
    
    if(GetLocalVarInt("BucketFilled") != 1)
    {
        RemoveAttachedPropFromProp("invisible_box_mass_2_1", "wooden_bucket_onrope_1");
        
        AddAttachedPropToProp("invisible_box_mass_2_1", "wooden_bucket_onrope_filled_1", "wooden_bucket_onrope_filled.ent", 0,0,0,0,0,0);
        
        SetEntityActive("RopeInteractArea_1", false);
        SetLocalVarInt("BucketFilled", 1);
        
        SetEntityCustomFocusCrossHair("invisible_box_mass_2_1","Pick");
        
        SetEntityPlayerInteractCallback("invisible_box_mass_2_1", "PickUpFilledBucket", true);
    }
}

void PickUpFilledBucket(string &in asEntity)
{
    SetLocalVarInt("BucketOnRope", 0);
    SetLocalVarInt("BucketFilled", 0);
    
    RemoveAttachedPropFromProp("invisible_box_mass_2_1", "wooden_bucket_onrope_filled_1");
    PlaySoundAtEntity("pickb", "25_pick_bucket_water.snt", "Player", 0.0f, false);
    GiveItemFromFile("wooden_bucket_filled_1", "wooden_bucket_filled.ent");
}

03-16-2018, 07:59 AM
Find
TimProzz Offline
Junior Member

Posts: 23
Threads: 8
Joined: May 2016
Reputation: 0
#2
RE: Something Wrong with AddUseItemCallback?

So what isn't working you say is the AddUseItemCallback? And when you use a bucket the game just says "Cannot use this item this way!" or doesn't it say anything?

Mod I'm working on: Illusions of the Dead 2
ModDB Illusions of the Dead 2
(This post was last modified: 03-16-2018, 08:58 AM by TimProzz.)
03-16-2018, 08:28 AM
Find
AGP Offline
Senior Member

Posts: 448
Threads: 45
Joined: Dec 2012
Reputation: 23
#3
RE: Something Wrong with AddUseItemCallback?

I spoke with Romulator earlier and he was able to fix it.

He said that it had to do with "for" in the if-statement, from what I understood. Basically, he overhauled a good chunk of it.

Here is what he gave me (in case anyone else ever needs this for future reference):

void OnStart()
{
for(int i = 1; i <= 4; i++)
    {
        AddUseItemCallback("ThisCrapNotWorking", "bucket_"+i, "RopeInteractArea_1", "UseBucketOnRope", false);
    }
for(int i = 1; i <= 4; i++)
    {
        AddUseItemCallback("TheKnifeWillFall", "knife_"+i, "RopeInteractArea_1", "UseBucketOnRope", false);
    }
}

void UseBucketOnRope(string &in asItem, string &in asEntity)
{
    if(StringContains(asItem, "bucket"))
    {
        if(GetLocalVarInt("RopeInArea") != 1)
        {
        SetMessage("", "", 0);
        AddDebugMessage("Rope outside of area, no interaction occurs.", false);
        return;
        }

        AddAttachedPropToProp("invisible_box_mass_2_1", "wooden_bucket_onrope_1", "wooden_bucket_onrope.ent", 0,0,0,0,0,0);
        RemoveItem(asItem);
    
        SetLocalVarInt("BucketOnRope", 1);
        
        AddDebugMessage(asItem, true);
        AddDebugMessage(asEntity, true);
    }
    else if(StringContains(asItem, "knife"))
    {
        AddDebugMessage("That's not a bucket, lol", false);
    }
}

It now works perfectly. Big shout out to Rom for this.

03-16-2018, 07:48 PM
Find
Mudbill Offline
Muderator

Posts: 3,881
Threads: 59
Joined: Apr 2013
Reputation: 179
#4
RE: Something Wrong with AddUseItemCallback?

PHP Code: (Select All)
for(int i 1<= 3i++)
{
    if(
asItem != "bucket_"+i)
    {
            
AddDebugMessage("Item not the bucket, no interaction occurs."false);
            return;
    }


This could potentially be an issue. Here you loop 3 times where i = 1, 2 and 3, but when you do the check for "bucket_1" and it passes, return is called, which ends the entire function, so you never get to try for "bucket_2" or 3.

Other than that, this is a fairly long snippet of code, so it's hard to visualize exactly what you're doing (or trying to do) with just this text. If you can explain what you want to happen and what actually happens, then we can go from there.
I suspect the script could be simplied a lot, and in doing so avoid a lot of confusing bugs like these.

Edit: Well I see you got it fixed. Ah well Smile

(This post was last modified: 03-16-2018, 07:50 PM by Mudbill.)
03-16-2018, 07:49 PM
Find
AGP Offline
Senior Member

Posts: 448
Threads: 45
Joined: Dec 2012
Reputation: 23
#5
RE: Something Wrong with AddUseItemCallback?

Thank you still for hopping in, Mudbill. Yeah, I hadn't realized that you can't combine in if in the for. But hopefully this thread can help someone out if they run into this same thing. Smile

03-17-2018, 05:57 AM
Find




Users browsing this thread: 1 Guest(s)