Pickup to object

From GTAMods Wiki
Jump to navigation Jump to search

Pickups itself are objects with some additional properties. But opcodes that work for objects do not accept pickup handles, so many interesting features are unavailable for the pickups, such as making it invisible. The following code converts a given pickup handle to an object one, thus allowing to use such opcodes with pickups.

Requirements

The Code

This code is made as an SCM function. It could be used both in main.scm or CLEO scripts. It accepts the one parameter (pickup handle) and returns converted object handle. Note that it is also made as a proper condition, so you can use the 0AB1 in a conditional statement to check if the conversion was failed (see Example below).

Paste the code somewhere in your script.

:Pickup2Object
// [email protected] - input param (pickup handle)
// get pickup pointer
0085: [email protected] = [email protected] 
0A91: [email protected] = [email protected] / 65536
0A90: [email protected] = [email protected] * 65536
0062: [email protected] -= [email protected]
[email protected] *= 32
[email protected] += 0x9788C0
// read index
0A8E: [email protected] = [email protected] + 0x1A
0A8D: [email protected] = read_memory [email protected] size 2 virtual_protect 0
if
    003B: [email protected] == [email protected]
then    
    // obtain pickup's object pointer
    [email protected] += 4
    0A8D: [email protected] = read_memory [email protected] size 4 virtual_protect 0
    if
        [email protected] > 0
    then
        // convert object pointer to a handle
        0A8D: [email protected] = read_memory 0xB7449C size 4 virtual_protect 0
        0AA8: call_function_method 0x465070 struct [email protected] num_params 1 pop 0 [email protected] [email protected]
        if
            03CA:   object [email protected] exists 
        then
            0485: return_true
            0AB2: ret 1 [email protected]
        end
    end
end
059A: return_false
0AB2: ret 1 [email protected]

Now you could call this function to obtain the object handle and use it (see Example).

Example

To test the code create a new pickup.

0213: [email protected] = create_pickup #INFO type 3 at 2491.8301 -1681.1062 13.3362

This pickup will be placed near CJ's house on Groove Street.

Now call the function.

0AB1: call_scm_func @Pickup2Object 1 [email protected] [email protected]

[email protected] there is the created pickup. If you used another variable in opcode 0213, replace [email protected] in 0AB1 with the needed variable name. The result (object handle) will be copied to [email protected] (once again, you can use any other variable there).

After calling the function [email protected] will contain either an object handle OR (if the function failed) the passed pickup's handle.

Now you can work with the pickup as an object using obtained handle.

0750: set_object [email protected] visibility 0

The pickup will immediately become invisible.

Full test code

0213: [email protected] = create_pickup #INFO type 3 at 2491.8301 -1681.1062 13.3362 
while true
    wait 250
    if 
        0AB0:  key_pressed 85 // U button
    then   
        if
            0AB1: call_scm_func @Pickup2Object 1 [email protected] [email protected]
        then 
            // the function succeed
            0750: set_object [email protected] visibility 0
        end   
    end
end

The questions are welcome on the discussion page.

External link

GTA Net GTAForums: Mission coding