I am developing a submod with WSE2 and I need help

Users who are viewing this thread

Hello fellow modders, I am developing a submod for Persistent Kingdoms with WSE2 and i need help. For Storing things i use mysql database and PHP's framework Laravel for the api. My problem is whenever i set a scene prop slot it doesn't work and leaves slots as 0 in load_doors_success and load_chests_success. Slot name is slot_scene_prop_id
Code:
after_mission_start_setup = (
    ti_after_mission_start,
    0,
    0,
    [],  # spawn and move certain things after most other set up is done
    [
        (str_store_string, s1, "str_url"),
        (send_post_message_to_url_advanced, "str_load_chests", "str_http_agent", "@d", "script_load_chests_success", "script_load_chests_failure", 0, 1), # http://127.0.0.1/warband/backend/public/loadchest
        (send_post_message_to_url_advanced, "str_load_doors", "str_http_agent", "@d", "script_load_doors_success", "script_load_doors_failure", 0, 1), # http://127.0.0.1/warband/backend/public/loaddoors
    ],
)

PHP:
public function loadDoors()
    {
        $doors = [];
        $doors_ = Door::with('contents')->get(); // Eager load contents

        // $val = 1;
        foreach ($doors_ as $door_) {
            // \Log::debug($val);
            // $val += 1;
            $door = [
                'posx' => $door_->pos_x,
                'posy' => $door_->pos_y,
                'posz' => $door_->pos_z,
                'contents' => $door_->contents->map(function ($item) {
                    return [
                        'keyid' => $item->key_id,
                        'order' => $item->order
                    ];
                })->toArray()
            ];

            $doors[$door_->door_id] = $door;
        }

        return wbResponse([$doors]);
    }

PHP:
public function loadChests()
    {
        $chests = [];
        $chests_ = Chest::with('contents')->get(); // Eager load contents

        // $val = 1;
        foreach ($chests_ as $chest_) {
            // \Log::debug($val);
            // $val += 1;
            $chest = [
                'posx' => $chest_->pos_x,
                'posy' => $chest_->pos_y,
                'posz' => $chest_->pos_z,
                'contents' => $chest_->contents->map(function ($item) {
                    return [
                        'itemid' => $item->item_id,
                        'itemorder' => $item->item_order
                    ];
                })->toArray()
            ];

            $chests[$chest_->chest_id] = $chest;
        }

        return wbResponse([$chests]);
    }

PHP:
class DoorKeys extends Model
{
    protected $table = 'door_keys';
    protected $primaryKey = ['door_id', 'order'];
    public $incrementing = false;
    public $timestamps = false;
    protected $guarded = [];
}

PHP:
class ChestContents extends Model
{
    protected $table = 'chest_contents';
    protected $primaryKey = ['chest_id', 'item_order'];
    public $incrementing = false;
    public $timestamps = false;
    protected $guarded = [];

}

PHP:
function wbResponse($content)
{
    if (is_array($content)) {
        foreach ($content as $k => $v) {
            $content[$k] = wbResponse($v);
        }
        return urlencode(json_encode($content, JSON_FORCE_OBJECT));
    }

    return $content;
}

Code:
(
            "load_doors_success",
            [
                # Assuming s0 contains the JSON string
                (dict_create, ":load_doors"),
                (dict_create, ":door_contents"),
                (dict_create, ":load"),
                (dict_create, ":contents"),
                (dict_create, ":k"),
                (dict_create, ":m"),
                # (server_add_message_to_log, "@doors {s0}"),
                (dict_from_url_encoded_json, ":load_doors", s0),
                # Logging the raw string for debug purposes
                # (server_add_message_to_log, "@{s0}"),
                # Checking if the key exists and accessing the first layer
                (try_for_dict_keys, s1, ":load_doors"),
                    # (server_add_message_to_log, "@s1-1 {s1}"),
                    (dict_get_str, s1, ":load_doors", "@{s1}"),
                    # (server_add_message_to_log, "@s1-2 {s1}"),
                    (dict_from_url_encoded_json, ":door_contents", s1),
                    (try_for_dict_keys, s1, ":door_contents"),
                        (str_store_string, s6, s1),
                        # (server_add_message_to_log, "@s1-3 {s1}"),
                        (dict_get_str, s1, ":door_contents", "@{s1}"),
                        # (server_add_message_to_log, "@s1-4 {s1}"),
                        (dict_from_url_encoded_json, ":load", s1),
                        (dict_get_size, ":size", ":load"),
                        (val_add, ":size", 1),
                        (try_for_range, ":object_id", "spr_pw_door_teleport_small_arch_a", "spr_pw_wooden_bridge_a"),
                            (try_for_prop_instances, ":instance_id", ":object_id"),
                                (prop_instance_get_position, pos31, ":instance_id"),
                                (position_get_x, ":pos_x", pos31),
                                (position_get_y, ":pos_y", pos31),
                                (position_get_z, ":pos_z", pos31),
                                # (assign, reg1, ":size"),
                                # (display_message, "@{reg1} reg1"),
                                (try_for_range, ":iterator", 0, ":size"),
                                    (dict_get_key_by_iterator, s31, ":load", ":iterator"),
                                    (dict_get_str, s1, ":load", "@{s31}"),
                                    (dict_from_url_encoded_json, ":contents", s1),
                                    (dict_get_str, s3, ":contents", "@posx"),
                                    (dict_get_str, s4, ":contents", "@posy"),
                                    (dict_get_str, s5, ":contents", "@posz"),
                                    (str_to_num, ":o_pos_x", s3),
                                    (str_to_num, ":o_pos_y", s4),
                                    (str_to_num, ":o_pos_z", s5),
                                    (str_to_num, reg31, s6),
                                    # (assign, reg65, ":door_id"),
                                    (try_begin),
                                        (eq, ":pos_x", ":o_pos_x"),
                                        (eq, ":pos_y", ":o_pos_y"),
                                        (eq, ":pos_z", ":o_pos_z"),
                                        (prop_instance_is_valid, ":instance_id"),
                                        (scene_prop_set_slot, ":instance_id", slot_scene_prop_id, reg31),
                                        (dict_get_str, s6, ":contents", "@contents"),
                                        (dict_from_url_encoded_json, ":k", s6),
                                        (dict_get_size, reg1, ":k"),
                                        (try_for_range, ":iterator", 0, reg1),
                                            (dict_get_key_by_iterator, s31, ":k", ":iterator"),
                                            (dict_get_str, s1, ":k", "@{s31}"),
                                            (dict_from_url_encoded_json, ":m", s1),
                                            (dict_get_str, s3, ":m", "@keyid"),
                                            (dict_get_str, s4, ":m", "@order"),
                                            (str_to_num, reg4, s3),
                                            (str_to_num, reg5, s4),
                                            (store_add, ":slot", slot_scene_prop_key_1, reg5),
                                            (scene_prop_set_slot, ":instance_id", ":slot", reg4),
                                        (try_end),
                                        (break_loop),
                                    (try_end),
                                (try_end),
                            (try_end),
                        (try_end),
                    (try_end),
                (try_end),
            ],
        ),

Code:
(
            "load_chests_success",
            [
                # Assuming s0 contains the JSON string
                (dict_create, ":load_chests"),
                (dict_create, ":chest_contents"),
                (dict_create, ":load"),
                (dict_create, ":contents"),
                (dict_create, ":k"),
                (dict_create, ":m"),
                # (server_add_message_to_log, "@chests {s0}"),
                (dict_from_url_encoded_json, ":load_chests", s0),
                # Logging the raw string for debug purposes
                # (server_add_message_to_log, "@{s0}"),
                # Checking if the key exists and accessing the first layer
                (try_for_dict_keys, s1, ":load_chests"),
                    # (server_add_message_to_log, "@s1-1 {s1}"),
                    (dict_get_str, s1, ":load_chests", "@{s1}"),
                    # (server_add_message_to_log, "@s1-2 {s1}"),
                    (dict_from_url_encoded_json, ":chest_contents", s1),
                    (try_for_dict_keys, s1, ":chest_contents"),
                        (str_store_string, s6, s1),
                        # (server_add_message_to_log, "@s1-3 {s1}"),
                        (dict_get_str, s1, ":chest_contents", "@{s1}"),
                        # (server_add_message_to_log, "@s1-4 {s1}"),
                        (dict_from_url_encoded_json, ":load", s1),
                        (dict_get_size, ":size", ":load"),
                        (val_add, ":size", 1),
                        (try_for_range, ":object_id", "spr_pw_cart_a", "spr_pw_signpost_castle"),
                            (neg | is_between, ":object_id", "spr_pw_ship_a", "spr_pw_item_chest_a"),
                            (try_for_prop_instances, ":instance_id", ":object_id"),
                                (prop_instance_get_position, pos31, ":instance_id"),
                                (position_get_x, ":pos_x", pos31),
                                (position_get_y, ":pos_y", pos31),
                                (position_get_z, ":pos_z", pos31),
                                # (assign, reg1, ":size"),
                                # (display_message, "@{reg1} reg1"),
                                (try_for_range, ":iterator", 0, ":size"),
                                    (dict_get_key_by_iterator, s31, ":load", ":iterator"),
                                    (dict_get_str, s1, ":load", "@{s31}"),
                                    (dict_from_url_encoded_json, ":contents", s1),
                                    (dict_get_str, s3, ":contents", "@posx"),
                                    (dict_get_str, s4, ":contents", "@posy"),
                                    (dict_get_str, s5, ":contents", "@posz"),
                                    (str_to_num, ":o_pos_x", s3),
                                    (str_to_num, ":o_pos_y", s4),
                                    (str_to_num, ":o_pos_z", s5),
                                    (str_to_num, reg31, s6),
                                    (try_begin),
                                        (eq, ":pos_x", ":o_pos_x"),
                                        (eq, ":pos_y", ":o_pos_y"),
                                        (eq, ":pos_z", ":o_pos_z"),
                                        # (assign, reg65, ":chest_id"),
                                        (prop_instance_is_valid, ":instance_id"),
                                        (scene_prop_set_slot, ":instance_id", slot_scene_prop_id, reg31),
                                        (dict_get_str, s6, ":contents", "@contents"),
                                        (dict_from_url_encoded_json, ":k", s6),
                                        (dict_get_size, reg1, ":k"),
                                        (try_for_range, ":iterator", 0, reg1),
                                            (dict_get_key_by_iterator, s31, ":k", ":iterator"),
                                            (dict_get_str, s1, ":k", "@{s31}"),
                                            (dict_from_url_encoded_json, ":m", s1),
                                            (dict_get_str, s3, ":m", "@itemid"),
                                            (dict_get_str, s4, ":m", "@itemorder"),
                                            (str_to_num, reg4, s3),
                                            (str_to_num, reg5, s4),
                                            (store_add, ":slot", slot_scene_prop_inventory_begin, reg5),
                                            (scene_prop_set_slot, ":instance_id", ":slot", reg4),
                                        (try_end),
                                        (break_loop),
                                    (try_end),
                                (try_end),
                            (try_end),
                        (try_end),
                    (try_end),
                (try_end),
            ],
        ),


I tried to post the scripts in chronogical order in triggering. Thank you people in advance.
 
Last edited:
Solution
I did manage to work it after I removed excess code that wasn't necessary
Code:
(
            "load_doors_success",
            [
                # Assuming s0 contains the JSON string
                (dict_create, ":load_doors"),
                (dict_create, ":door_contents"),
                (dict_create, ":load"),
                (dict_create, ":k"),
                (dict_create, ":m"),
                # (server_add_message_to_log, "@doors {s0}"),
                (dict_from_url_encoded_json, ":load_doors", s0),
                # Logging the raw string for debug purposes
                # (server_add_message_to_log, "@{s0}"),
                # Checking if the key exists and accessing the first layer...
I did manage to work it after I removed excess code that wasn't necessary
Code:
(
            "load_doors_success",
            [
                # Assuming s0 contains the JSON string
                (dict_create, ":load_doors"),
                (dict_create, ":door_contents"),
                (dict_create, ":load"),
                (dict_create, ":k"),
                (dict_create, ":m"),
                # (server_add_message_to_log, "@doors {s0}"),
                (dict_from_url_encoded_json, ":load_doors", s0),
                # Logging the raw string for debug purposes
                # (server_add_message_to_log, "@{s0}"),
                # Checking if the key exists and accessing the first layer
                (try_for_dict_keys, s1, ":load_doors"),
                    # (server_add_message_to_log, "@s1-1 {s1}"),
                    (dict_get_str, s1, ":load_doors", "@{s1}"),
                    # (server_add_message_to_log, "@s1-2 {s1}"),
                    (dict_from_url_encoded_json, ":door_contents", s1),
                    (try_for_dict_keys, s1, ":door_contents"),
                        (str_to_num, reg31, s1),
                        # (server_add_message_to_log, "@s1-3 {s1}"),
                        (dict_get_str, s1, ":door_contents", "@{s1}"),
                        # (server_add_message_to_log, "@s1-4 {s1}"),
                        (dict_from_url_encoded_json, ":load", s1),
                        (dict_get_size, ":size", ":load"),
                        (val_add, ":size", 1),
                        (try_for_range, ":object_id", "spr_pw_door_teleport_small_arch_a", "spr_pw_wooden_bridge_a"),
                            (try_for_prop_instances, ":instance_id", ":object_id"),
                                (prop_instance_get_position, pos31, ":instance_id"),
                                (position_get_x, ":pos_x", pos31),
                                (position_get_y, ":pos_y", pos31),
                                (position_get_z, ":pos_z", pos31),
                                # (assign, reg1, ":size"),
                                # (display_message, "@{reg1} reg1"),
                                (dict_get_str, s3, ":load", "@posx"),
                                (dict_get_str, s4, ":load", "@posy"),
                                (dict_get_str, s5, ":load", "@posz"),
                                (str_to_num, ":o_pos_x", s3),
                                (str_to_num, ":o_pos_y", s4),
                                (str_to_num, ":o_pos_z", s5),
                                # (assign, reg65, ":door_id"),
                                (try_begin),
                                    (eq, ":pos_x", ":o_pos_x"),
                                    (eq, ":pos_y", ":o_pos_y"),
                                    (eq, ":pos_z", ":o_pos_z"),
                                    (prop_instance_is_valid, ":instance_id"),
                                    (scene_prop_set_slot, ":instance_id", slot_scene_prop_id, reg31),
                                    (dict_get_str, s6, ":load", "@contents"),
                                    (dict_from_url_encoded_json, ":k", s6),
                                    (dict_get_size, reg1, ":k"),
                                    (try_for_range, ":iterator", 0, reg1),
                                        (dict_get_key_by_iterator, s31, ":k", ":iterator"),
                                        (dict_get_str, s1, ":k", "@{s31}"),
                                        (dict_from_url_encoded_json, ":m", s1),
                                        (dict_get_str, s3, ":m", "@keyid"),
                                        (dict_get_str, s4, ":m", "@order"),
                                        (str_to_num, reg4, s3),
                                        (str_to_num, reg5, s4),
                                        (store_add, ":slot", slot_scene_prop_key_1, reg5),
                                        (scene_prop_set_slot, ":instance_id", ":slot", reg4),
                                    (try_end),
                                    (break_loop),
                                (try_end),
                            (try_end),
                        (try_end),
                    (try_end),
                (try_end),
            ],
        ),

Code:
(
            "load_chests_success",
            [
                # Assuming s0 contains the JSON string
                (dict_create, ":load_chests"),
                (dict_create, ":chest_contents"),
                (dict_create, ":load"),
                (dict_create, ":k"),
                (dict_create, ":m"),
                # (server_add_message_to_log, "@chests {s0}"),
                (dict_from_url_encoded_json, ":load_chests", s0),
                # Logging the raw string for debug purposes
                # (server_add_message_to_log, "@{s0}"),
                # Checking if the key exists and accessing the first layer
                (try_for_dict_keys, s1, ":load_chests"),
                    # (server_add_message_to_log, "@s1-1 {s1}"),
                    (dict_get_str, s1, ":load_chests", "@{s1}"),
                    # (server_add_message_to_log, "@s1-2 {s1}"),
                    (dict_from_url_encoded_json, ":chest_contents", s1),
                    (try_for_dict_keys, s1, ":chest_contents"),
                        (str_to_num, reg31, s1),
                        # (server_add_message_to_log, "@s1-3 {s1}"),
                        (dict_get_str, s1, ":chest_contents", "@{s1}"),
                        # (server_add_message_to_log, "@s1-4 {s1}"),
                        (dict_from_url_encoded_json, ":load", s1),
                        (try_for_range, ":object_id", "spr_pw_cart_a", "spr_pw_signpost_castle"),
                            (neg | is_between, ":object_id", "spr_pw_ship_a", "spr_pw_item_chest_a"),
                            (try_for_prop_instances, ":instance_id", ":object_id"),
                                (prop_instance_get_position, pos31, ":instance_id"),
                                (position_get_x, ":pos_x", pos31),
                                (position_get_y, ":pos_y", pos31),
                                (position_get_z, ":pos_z", pos31),
                                # (assign, reg1, ":size"),
                                # (display_message, "@{reg1} reg1"),
                                (dict_get_str, s3, ":load", "@posx"),
                                (dict_get_str, s4, ":load", "@posy"),
                                (dict_get_str, s5, ":load", "@posz"),
                                (display_message, "@{s3} s3 {s4} s4 {s5} s5"),
                                (str_to_num, ":o_pos_x", s3),
                                (str_to_num, ":o_pos_y", s4),
                                (str_to_num, ":o_pos_z", s5),
                                (try_begin),
                                    (eq, ":pos_x", ":o_pos_x"),
                                    (eq, ":pos_y", ":o_pos_y"),
                                    (eq, ":pos_z", ":o_pos_z"),
                                    # (assign, reg65, ":chest_id"),
                                    (prop_instance_is_valid, ":instance_id"),
                                    (scene_prop_set_slot, ":instance_id", slot_scene_prop_id, reg31),
                                    (dict_get_str, s6, ":load", "@contents"),
                                    (dict_from_url_encoded_json, ":k", s6),
                                    (dict_get_size, reg1, ":k"),
                                    (try_for_range, ":iterator", 0, reg1),
                                        (dict_get_key_by_iterator, s31, ":k", ":iterator"),
                                        (dict_get_str, s1, ":k", "@{s31}"),
                                        (dict_from_url_encoded_json, ":m", s1),
                                        (dict_get_str, s3, ":m", "@itemid"),
                                        (dict_get_str, s4, ":m", "@itemorder"),
                                        (str_to_num, reg4, s3),
                                        (str_to_num, reg5, s4),
                                        (store_add, ":slot", slot_scene_prop_inventory_begin, reg5),
                                        (scene_prop_set_slot, ":instance_id", ":slot", reg4),
                                    (try_end),
                                (try_end),
                            (try_end),
                        (try_end),
                    (try_end),
                (try_end),
            ],
        ),
 
Upvote 0
Solution
Back
Top Bottom