-
Notifications
You must be signed in to change notification settings - Fork 4
[EN] Seed
For programmers.
Each vehicle has a seed, which is a value that determines how it will appear - that is, which nodes will be selected during Recursive Extras, among other possible future uses.
Because each time a vehicle is created it appears with different variations, it is necessary that the programmer has some control of how the vehicle, just created, should appear.
For example, you have a car containing an assortment of extras: hotdog car. How to create this car with the variation of hotdog using script? Here's the answer:
Sanny Builder:
{$cleo}
const
pVehFuncs = 0@
pExt_GetCarSeed = 1@
pExt_SetCarSeed = 2@
hVehicle = 3@
pVehicle = 4@
x = 5@
y = 6@
z = 7@
iSeed = 8@
end
if 0AA2: pVehFuncs = load_library "VehFuncs.asi"
then
if and
0AA4: pExt_GetCarSeed = get_proc_address "Ext_GetCarSeed" library pVehFuncs
0AA4: pExt_SetCarSeed = get_proc_address "Ext_SetCarSeed" library pVehFuncs
then
0AA3: free_library pVehFuncs
else
0AA3: free_library pVehFuncs
0ACD: show_text_highpriority "~r~Fail to load 'VehFuncs.asi'. Update it." time 5000
0A93: end_custom_thread
end
else
0ACD: show_text_highpriority "~r~'VehFuncs.asi' was not found." time 5000
0A93: end_custom_thread
end
while true
wait 0
if 00DF: actor $PLAYER_ACTOR driving
then
if 0ADC: test_cheat "GET"
then
03C0: hVehicle = actor $PLAYER_ACTOR car
0A97: pVehicle = car hVehicle struct
0AA7: call_function pExt_GetCarSeed num_params 1 pop 1 pVehicle -> iSeed
0AD1: show_formatted_text_highpriority "Seed for this car is: %x" time 5000 iSeed
end
end
if 0ADC: test_cheat "NEW"
then
04C4: store_coords_to x y z from_actor $PLAYER_ACTOR with_offset 0.0 3.0 0.0
0247: load_model #ELEGY
038B: load_requested_models
car.Create(hVehicle, #ELEGY, x, y, z)
0A97: pVehicle = car hVehicle struct
0AA5: call pExt_SetCarSeed num_params 2 pop 2 iSeed pVehicle // Ext_SetCarSeed(CVehicle * vehicle, int seed)
end
end
GTA3script:
SCRIPT_START
{
LVAR_INT scplayer pVehFuncs pExt_GetCarSeed pExt_SetCarSeed hVehicle pVehicle iSeed
LVAR_FLOAT x y z
IF LOAD_DYNAMIC_LIBRARY VehFuncs.asi (pVehFuncs)
IF GET_DYNAMIC_LIBRARY_PROCEDURE "Ext_GetCarSeed" pVehFuncs (pExt_GetCarSeed)
AND GET_DYNAMIC_LIBRARY_PROCEDURE "Ext_SetCarSeed" pVehFuncs (pExt_SetCarSeed)
FREE_DYNAMIC_LIBRARY pVehFuncs
ELSE
FREE_DYNAMIC_LIBRARY pVehFuncs
PRINT_STRING_NOW "~r~Fail to load 'VehFuncs.asi'. Update it." 5000
TERMINATE_THIS_CUSTOM_SCRIPT
ENDIF
ELSE
PRINT_STRING_NOW "~r~'VehFuncs.asi' was not found." 5000
TERMINATE_THIS_CUSTOM_SCRIPT
ENDIF
GET_PLAYER_CHAR 0 scplayer
// https://forum.mixmods.com.br/f16-utilidades/t179-gta3script-while-true-return_true-e-return_false
WHILE TRUE
WAIT 0
IF IS_CHAR_SITTING_IN_ANY_CAR scplayer
IF TEST_CHEAT GET
STORE_CAR_CHAR_IS_IN_NO_SAVE scplayer (hVehicle)
GET_VEHICLE_POINTER hVehicle (pVehicle)
CALL_FUNCTION_RETURN pExt_GetCarSeed 1 1 (pVehicle)(iSeed) // Ext_GetCarSeed(CVehicle * vehicle)
PRINT_FORMATTED_NOW "Seed for this car is: %x" 5000 (iSeed)
ENDIF
ENDIF
IF TEST_CHEAT NEW
GET_OFFSET_FROM_CHAR_IN_WORLD_COORDS scplayer 0.0 3.0 0.0 (x y z)
REQUEST_MODEL ELEGY
LOAD_ALL_MODELS_NOW
CREATE_CAR ELEGY x y z (hVehicle)
GET_VEHICLE_POINTER hVehicle (pVehicle)
CALL_FUNCTION pExt_SetCarSeed 2 2 (iSeed pVehicle) // Ext_SetCarSeed(CVehicle * vehicle, int seed)
ENDIF
ENDWHILE
}
SCRIPT_END
It is self explanatory.
extern "C" void __declspec(dllexport) Ext_SetCarSeed(CVehicle * vehicle, int seed)
extern "C" int32_t __declspec(dllexport) Ext_GetCarSeed(CVehicle * vehicle)
Do note that you can call the Ext_SetCarSeed
function for literally any vehicle, and how many vehicles you want in the same frame, however:
- Just call immediately after vehicle creation (before any car rendering or game processing, such as
WAIT
). - Don't call the function multiple times for the same vehicle (why would you do this?). Because it will cause a leak.
- Sending
0
extras will not be processed. May be useful for tests and some cases.
Tip: WheneverExt_GetCarSeed
is called, the seed value (in decimal) is stored on VehFuncs.log
.
If in doubt, you can ask for help in Forum MixMods or GTA Forums.