Página 1 de 1

[CLEO] EnhancedPickup

Enviado: 18 Ago 2020, 23:20
por HzanRsxa2959
Note: This version is very outdated. Here is the latest version:
f302-utilities/t6254-cleo-enhancedpickupplus




Updated (overhauled, actually) my previous mod with numerous bugs.
I rewrote the script about 4 times. I don't know if I have OCD, but it sucks. :(
But the script did turn out better each time. So there is a silver lining, I guess.

Description:
This is a custom script that creates and manages pickups in such a way that they are not saved with the game.

Download:
1.0
1.1
1.2
1.3
1.4
1.5

Note:
CLEO+ is required.

Features:
Pickup limit is taken care of in a unique way by hiding each pickup when:
  • Camera is not looking at its position.
  • Camera is far away from its position based on pickups' draw distance.
There are lots of options to customize pickups.

Usage:
Put the EnhancedPickup.s file along with your CLEO script, and launch as a custom script, passing your desired values:

Código: Selecionar tudo

0A92: create_custom_thread "EnhancedPickup.s" _pMemory 0 _iModelID 1212 _iAmmo 100 _fXYZ 2498.1343 -1670.9431 13.3354 _iRespawnTimeMs 1000 _fRespawnDistance 2.0 _iPickupType 1 _iBlipColor -1 _bHideOnMission false _bCollectedUntilRespawn false

Example Script:
Compile and put in the same folder as the EnhancedPickup.s file:
SpoilerAbrir
EnhancedPickup - Test.cs

Código: Selecionar tudo

{$CLEO .cs}

//adds a save, a tec9 and a bat pickup near CJ's house in Ganton, Grove Street
//also a cash pickup that stacks on every script reload
//  save pickup controls:
//      1 - toggle blip
//      2 - hide*
//      3 - delete
//      4 - release memory (no longer manageable)
//  collect it to show save menu
//  type 'RSEPT' to reload this script
//  * key must be held


//only required if you need to manage pickup later, otherwise use 0
//take a variable pointer, e.g. 10@
//you can also use allocated memory of 4 bytes
0AC7: 20@ = var 10@ offset

//start custom script, passing arguments
//  _iRespawnTimeMs:
//      -1: respawn never
//      -2: respawn after short time (default 30000, type 2, used in missions)
//      -3: respawn after long time (default 360000, type 15, used outside missions)
//      any other value will use that value
//      compatible with memory addresses
//  _fRespawnDistance:
//      -1: (default 10.0)
//      any other value will use that value
//    _iPickupType:
//        any other value = default pickup
//        1/true = Money *
//        2 = Available asset *
//        3 = Unavailable asset *
//        4 = Asset money * (does not seem to work, not tested)
//        * _iModelID does not work as it has its own model ID.
//  _iBlipColor
//      -1: (default green)
//      any other value will use that value
0A92: create_custom_thread "EnhancedPickup.s" _pMemory 20@ _iModelID 1277 _iAmmo 0 _fXYZ 2492.1343 -1670.9431 13.3354 _iRespawnTimeMs 0 _fRespawnDistance 0 _iPickupType 0 _iBlipColor -1 _bHideOnMission true _bCollectedUntilRespawn false

0AC7: 21@ = var 11@ offset
0A92: create_custom_thread "EnhancedPickup.s" _pMemory 21@ _iModelID 372 _iAmmo 0 _fXYZ 2494.1343 -1670.9431 13.3354 _iRespawnTimeMs -3 _fRespawnDistance -1 _iPickupType 0 _iBlipColor -1 _bHideOnMission false _bCollectedUntilRespawn false
0A92: create_custom_thread "EnhancedPickup.s" _pMemory 21@ _iModelID 336 _iAmmo 0 _fXYZ 2496.1343 -1670.9431 13.3354 _iRespawnTimeMs -3 _fRespawnDistance -1 _iPickupType 0 _iBlipColor -1 _bHideOnMission false _bCollectedUntilRespawn false

0A92: create_custom_thread "EnhancedPickup.s" _pMemory 0 _iModelID 1212 _iAmmo 100 _fXYZ 2498.1343 -1670.9431 13.3354 _iRespawnTimeMs 1000 _fRespawnDistance 2.0 _iPickupType 1 _iBlipColor -1 _bHideOnMission false _bCollectedUntilRespawn false

//only required if you need to manage pickup later
wait 0

//managing the pickup:
//  bits of 10@ will be set and cleared based on the condition of the pickup
//      if bit 0 is set (for one frame), then pickup has been collected
//      set bit 1 to delete
//      set bit 2 to toggle blip
//      set bit 3 to hide for one frame
//      if bit 3 is set (for one frame), then pickup has been hidden
//      set bit 4 to release variable (pickup will no longer be manageable)

01F5: 0@ = get_player_actor 0

while true
    if 08B7: test 10@ bit 0
    then
        00A1: put_actor 0@ at 2492.1343 -1665.9431 12.3354
        0173: set_actor 0@ Z_angle_to 0
        03D8: show_save_screen
    end
    if 0AB0: key_pressed 49
    then
        08BD: set 10@ bit 2
        wait 250
    end
    if or
        0AB0: key_pressed 50
        0E1D: is_on_mission
    then
        08BD: set 10@ bit 3
    end
    if 08B7: test 10@ bit 3
    then
        0AD1: show_formatted_text_highpriority "HIDDEN" time 0
    end
    if 0AB0: key_pressed 51
    then
        08BD: set 10@ bit 1
    end
    if 0AB0: key_pressed 52
    then
        08BD: set 10@ bit 4
    end
    wait 0
    if 0ADC: test_cheat "RSEPT"
    then
        08BD: set 10@ bit 1
        08BD: set 11@ bit 1
        0ACE: show_formatted_text_box "EnhancedPickup - Test Script Reloaded."
        0A92: create_custom_thread "EnhancedPickup - Test.cs"
        0A93: end_custom_thread
    end
end

Source:
SpoilerAbrir

Código: Selecionar tudo

{$CLEO .s}

//1.4

//0A92: create_custom_thread "EnhancedPickup.s" _pMemory 20@ _iModelID 1277 _iAmmo 0 _fXYZ 2492.1343 -1670.9431 13.3354 _iRespawnTimeMs -2 _fRespawnDistance 0 _iPickupType false _iBlipColor -1 _bHideOnMission true _bCollectedUntilRespawn false

const
    pMemory = 0@
    iModelID = 1@
    iAmmo = 2@
    fX = 3@
    fY = 4@
    fZ = 5@
    iRespawnTimeMs = 6@
    fRespawnDistance = 7@
    iPickupType = 8@
    iBlipColor = 9@
    bHideOnMission = 10@
    bCollectedUntilRespawn = 11@
//11, 12, 13
end

const
    bCollected = 14@ = false
    bBlip = 15@ = false
    iCollectionTimeMs = 16@ = 0
    hPlayerPed = 17@
    iCurrentTimeMs = 18@
    hBlip = 19@
    hPickup = 20@ = 0
    pPickup = 21@
    bHidden = 22@
//23, 24, 25
end

01F5: hPlayerPed = get_player_actor 0

while true
    if bCollectedUntilRespawn == false
    then
        bCollected = false
    end
    01BD: iCurrentTimeMs = current_time_in_ms
    if and
        bBlip == false
        075C: marker hBlip enabled
    then
        0164: disable_marker hBlip
    end
    if and
        bBlip == true
        875C: not marker hBlip enabled
        hPickup <> 0
    then
        03DC: hBlip = create_marker_above_pickup hPickup

        if iBlipColor <> -1
        then
            0165: set_marker hBlip color_to iBlipColor
        end
    end
    if iCollectionTimeMs <> 0
    then
        if fRespawnDistance == -1
        then
            26@ = 10.0 //need memory address
        else
            0087: 26@ = fRespawnDistance
        end
        if 80FE: not actor hPlayerPed sphere 0 in_sphere fX fY fZ radius 26@ 26@ 26@
        then
            if iRespawnTimeMs == -1
            then
                break
            else
                if iRespawnTimeMs == -2
                then
                    0A8D: 26@ = read_memory 0x457F66 size 4 virtual_protect 0 //regen time for pickup type 2
                else
                    if iRespawnTimeMs == -3
                    then
                        0A8D: 26@ = read_memory 0x457F5E size 4 virtual_protect 0 //regen time for pickup type 15
                    else
                        0085: 26@ = iRespawnTimeMs
                    end
                end
                005A: 26@ += iCollectionTimeMs
                if 001D: iCurrentTimeMs > 26@
                then
                    iCollectionTimeMs = 0
                    if bCollectedUntilRespawn == true
                    then
                        bCollected = false
                    end
                end
            end
        end
    else
        if gosub @hide
        then
            gosub @destroy
        else
            gosub @create
            0A8C: write_memory pPickup size 4 value iCurrentTimeMs virtual_protect 0
            if 0214: pickup hPickup picked_up
            then
                gosub @destroy
                0085: iCollectionTimeMs = iCurrentTimeMs
                bCollected = true
            end
        end
    end
    if pMemory <> 0
    then
        26@ = 0
        if bCollected == true
        then
            08BD: set 26@ bit 0
        end
        0A8C: write_memory pMemory size 4 value 26@ virtual_protect 0
    end
    bHidden = false
    wait 0
    if pMemory <> 0
    then
        0A8D: 26@ = read_memory pMemory size 4 virtual_protect 0
        if 08B7: test 26@ bit 1
        then
            gosub @destroy
            break
        end
        if 08B7: test 26@ bit 2
        then
            if bBlip == false
            then
                bBlip = true
            else
                bBlip = false
            end
        end
        if 08B7: test 26@ bit 3
        then
            bHidden = true
        end
        if 08B7: test 26@ bit 4
        then
            pMemory = 0
        end
    end
end
0A93: end_custom_thread

:hide
    26@ = false
    if and
        bHideOnMission == true
        0E1D: is_on_mission
    then
        26@ = true
    else
        if bHidden == true
        then
            26@ = true
        else
            if bBlip == false
            then
                if 80C2: not sphere_onscreen fX fY fZ radius 1.0
                then
                    26@ = true
                else
                    0A8D: 27@ = read_memory 0x454CC9 size 4 virtual_protect 0
                    0A8D: 27@ = read_memory 27@ size 4 virtual_protect 0 //pickups draw distance
                    068D: get_camera_position_to 28@ 29@ 30@
                    050A: 31@ = distance_between_XYZ fX fY fZ and_XYZ 28@ 29@ 30@
                    if 0025: 31@ > 27@
                    then
                        26@ = true
                    end
                end
            end
        end
    end
    if 26@ == true
    then
        0485: return_true
    end
return

:destroy
    if hPickup <> 0
    then
        0215: destroy_pickup hPickup
        hPickup = 0
    end
return

:create
    if hPickup == 0
    then
        if iPickupType == true
        then
            if iModelID == 0
            then
                02E1: hPickup = create_cash_pickup iAmmo at fX fY fZ permanence_flag 0
            else
                032B: hPickup = create_weapon_pickup iModelID group 8 ammo iAmmo at fX fY fZ
            end
        else
            if iPickupType == 2
            then
                if iModelID == 0
                then
                    0518: hPickup = create_available_asset_pickup 'DUMMY' at fX fY fZ price iAmmo
                else
                    032B: hPickup = create_weapon_pickup iModelID group 18 ammo iAmmo at fX fY fZ
                end
            else
                if iPickupType == 3
                then
                    if iModelID == 0
                    then
                        0517: hPickup = create_unavailable_asset_pickup 'DUMMY' at fX fY fZ
                    else
                        032B: hPickup = create_weapon_pickup iModelID group 17 ammo iAmmo at fX fY fZ
                    end
                else
                    if iPickupType == 4
                    then
                        if iModelID == 0
                        then
                            04A6: hPickup = create_asset_money_pickup_at fX fY fZ money iAmmo 100
                        else
                            032B: hPickup = create_weapon_pickup iModelID group 16 ammo iAmmo at fX fY fZ
                        end
                    else
                        032B: hPickup = create_weapon_pickup iModelID group 4 ammo iAmmo at fX fY fZ
                    end
                end
            end
        end
        0E38: get_pickup_pointer hPickup store_to pPickup
        0A8E: 26@ = pPickup + 0x1C
        0A8C: write_memory 26@ size 1 value 4 virtual_protect 0
        pPickup += 0xC
    end
return

Bugs:
All previous bugs have been resolved! If you find any, please report!

Re: [CLEO] AddNonSavingPickup

Enviado: 19 Ago 2020, 09:13
por Junior_Djjr
Just a note: Any pickup with type "4" doesn't save.

So:

Código: Selecionar tudo

// CLEO+ is required
CREATE_PICKUP 1250 4 x y z (hPickup)
GET_PICKUP_POINTER hPickup (pPickup)
WRITE_STRUCT_OFFSET pPickup 0xC 4 2147483646 // considering signed
It will only despawns after 596 hours (24 real life days).

But: maybe doesn't save because the game despawns it automatically, so, in fact, it's saving, just the game automatically despawns.
In this case, my example will not work, and your script will not work for saves without passing hours (MixSets and some save-anywhere mods removes the passing hours).

Test it.

Re: [CLEO] AddNonSavingPickup

Enviado: 19 Ago 2020, 19:17
por HzanRsxa2959
Junior_Djjr escreveu:
19 Ago 2020, 09:13
But: maybe doesn't save because the game despawns it automatically, so, in fact, it's saving, just the game automatically despawns.
I wonder, does the pickup disappear when saving because:
the game forwards the time and its lifetime runs out
or
the game set its lifetime to 0.

Either way, there is a lot of room for improvement.
Thanks for the report. I will test it and try to fix any bugs I can.

Also, I forgot to add the source in the main topic. Fixed.

Re: [CLEO] AddNonSavingPickup

Enviado: 19 Ago 2020, 20:01
por Junior_Djjr
If it works, I create some command to set pickup lifetime.
If doesn't work, I'll create some command to mark pickup to not save, storing to make it ignored on save, something like this.

Re: [CLEO] AddNonSavingPickup

Enviado: 19 Ago 2020, 20:07
por HzanRsxa2959
Yes, that seems to be the best method.

I think the first method will only work for pickups with type 4 or 5, while second will also work for pickups with special types like property.

Re: [CLEO] EnhancedPickup

Enviado: 01 Set 2020, 09:26
por HzanRsxa2959
Major update:
  • Rewritten completely from scratch with better structure.
  • Mod has been renamed to EnhancedPickup.
  • Quicksaving bug has been resolved.
  • Memory addresses for the default pickup respawn times have been found and used.

Re: [CLEO] EnhancedPickup

Enviado: 02 Set 2020, 11:50
por HzanRsxa2959
Update 1.1
Minor update:
  • Before, bit 0 (collected) was not being set when collecting pickup with _iRespawnTimeMs set to -1. Some code has been reordered to fix this issue.
Not many changes in this update, but this seemed like a major bug so I thought I should update.

Re: [CLEO] EnhancedPickup

Enviado: 06 Set 2020, 05:29
por HzanRsxa2959
Update 1.2:
Minor update:
  • Added option _bHideOnMission to hide pickup while on mission, so that you don't have to waste variables to hide the pickup while on mission.
  • You can test bit 3 (hidden) to check if pickup has been hidden.
Not really an update that fixes bugs, but more of a quality of life (coding?) update.

Re: [CLEO] EnhancedPickup

Enviado: 18 Set 2020, 07:33
por HzanRsxa2959
Update 1.3:

Changed _bIsMoney to _iPickupType (backwards compatible):
  • any other value = default pickup
  • 1/true = Money *
  • 2 = Available asset *
  • 3 = Unavailable asset *
  • 4 = Asset money * (does not seem to work, not tested)
* _iModelID does not work as it has its own model ID.

Added _bCollectedUntilRespawn:
    Bit 0 (collected) will remain set until pickup has respawned if this is true. It may never clear if _iRespawnTimeMs is set to -1.

Freed some local vars for future extensibility.

Other minor and major code improvements and reordering.

Re: [CLEO] EnhancedPickup

Enviado: 21 Set 2020, 18:56
por HzanRsxa2959
Update 1.4:
Modified _iPickupType: Default model ID for non-default pickups will only work if _iModelID is set to 0, e.g:​​​​
  • Using _iPickupType 2 with _iModelID 1277 will create a property pickup with save disk model.
  • Using _iPickupType 2 with _iModelID 0 will create a property pickup with default property pickup model.
Note: Property pickup does not behave the same as the default game property pickups.

Re: [CLEO] EnhancedPickup

Enviado: 25 Set 2020, 15:25
por HzanRsxa2959
Update 1.5:
  • Fixed _iPickupType = 2 not creating a cash pickup.
Small update but important fix.

Re: [CLEO] EnhancedPickup

Enviado: 01 Abr 2021, 17:38
por HzanRsxa2959
New version released: f302-utilities/t6254-cleo-enhancedpickupplus.
Main post has been edited with link at top.