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.

 1 :Pickup2Object
 2 // 0@ - input param (pickup handle)
 3 // get pickup pointer
 4 0085: 1@ = 0@ 
 5 0A91: 3@ = 1@ / 65536
 6 0A90: 4@ = 3@ * 65536
 7 0062: 1@ -= 4@
 8 1@ *= 32
 9 1@ += 0x9788C0
10 // read index
11 0A8E: 4@ = 1@ + 0x1A
12 0A8D: 4@ = read_memory 4@ size 2 virtual_protect 0
13 if
14     003B: 3@ == 4@
15 then    
16     // obtain pickup's object pointer
17     1@ += 4
18     0A8D: 1@ = read_memory 1@ size 4 virtual_protect 0
19     if
20         1@ > 0
21     then
22         // convert object pointer to a handle
23         0A8D: 8@ = read_memory 0xB7449C size 4 virtual_protect 0
24         0AA8: call_function_method 0x465070 struct 8@ num_params 1 pop 0 1@ 1@
25         if
26             03CA:   object 1@ exists 
27         then
28             0485: return_true
29             0AB2: ret 1 1@
30         end
31     end
32 end
33 059A: return_false
34 0AB2: ret 1 0@

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: 10@ = 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 10@ 11@

[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 11@ visibility 0

The pickup will immediately become invisible.

Full test code

0213: 10@ = 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 10@ 10@
        then 
            // the function succeed
            0750: set_object 11@ visibility 0
        end   
    end
end

The questions are welcome on the discussion page.

External link

GTA Net GTAForums: Mission coding