Page 1 of 1

[THUG2][PC] How to spawn a ped

Posted: Sun Aug 07, 2011 4:28 am
by Anteara
I've decided to make a tutorial of this just so people who want to do it don't have to go back to that thread.




This tutorial shows you how to spawn a ped as a composite object.

For the anim you want to play, go to the allanims.qb file.

Find an anim you want, for example I want $Ped_Bikini_LyingFrontToBack$.


When you have the anim you want, go up, and find the function name. The function $Ped_Bikini_LyingFrontToBack$ is in is called:

Code: Select all

:i function call $animload_Ped_Bikini$ arguments
      $LoadFunction$ = $LoadAnim$
   :i call $SetReferenceChecksum$ arguments
      $Ped_Female$


take note of the function name and checksum.

Go back to your composite object script,

Code: Select all

:i function $anteara_ped12lol$
   :i $Skater$.$Obj_GetPosition$
      :i $CreateCompositeObject$:s{
         :i $Components$ =
         :i :a{
            :i :s{$component$ = $motion$:s}
            :i :s{$component$ = call $Suspend$ arguments
                  $NeverSuspend$:s}
            :i :s{$component$ = $skeleton$
               :i $SkeletonName$ = $Ped_Female$
               :i $max_bone_skip_lod$ = %i(0,00000000)
            :i :s}
            :i :s{$component$ = $model$
            :i :s}
            :i :s{$component$ = $AnimBlender$
               :i $AnimName$ = $animload_Ped_Bikini$
               :i $SkeletonName$ = $Ped_Female$
            :i :s}
            :i :a}
         :i $params$ = :s{$pos$ = %GLOBAL%$pos$$model$ = %s(43,"Peds\Ped_FemaleFull01\Ped_FemaleFull01.skin")$name$ = $Pedestrian$:s}
      :i :s}
   :i $Pedestrian$.call $Obj_PlayAnim$ arguments
      $anim$ = $Ped_Bikini_LyingFrontToBack$$cycle$
:i endfunction


Code: Select all

            :i :s{$component$ = $skeleton$
               :i $SkeletonName$ = $Ped_Female$
               :i $max_bone_skip_lod$ = %i(0,00000000)
            :i :s}
   




The skeleton name must be $Ped_Female$, or else the anim won't play. This is because the ReferenceChecksum is called Ped_Female.



Code: Select all

            :i :s{$component$ = $AnimBlender$
               :i $AnimName$ = $animload_Ped_Bikini$
               :i $SkeletonName$ = $Ped_Female$
            :i :s}




Here, again, the skeleton name is $Ped_Female$. The AnimName is $animload_Ped_Bikini$ because that is the function name.



Code: Select all

:i function call $animload_Ped_Bikini$ arguments




So this is how you spawn a ped, I already created the function for you, so all you have to do is find an anim you want, put the function name of the anim you want in $AnimName$, and put the ReferenceChecksum in the $SkeletonName$.

Now you need to play the anim, you already have the $SkeletonName$, and $AnimName$ set up, so now you need to set up the anim itself.

Code: Select all

         :i $params$ = :s{$pos$ = %GLOBAL%$pos$$model$ = %s(43,"Peds\Ped_FemaleFull01\Ped_FemaleFull01.skin")$name$ = $Pedestrian$:s}
      :i :s}
   :i $Pedestrian$.call $Obj_PlayAnim$ arguments
      $anim$ = $Ped_Bikini_LyingFrontToBack$$cycle$
:i endfunction


Code: Select all

$model$ = %s(43,"Peds\Ped_FemaleFull01\Ped_FemaleFull01.skin")


This is the model of your ped, you can choose anything, but it must be a "Full" ped, as shown in the name. It also must be .skin.

Code: Select all

   :i $Pedestrian$.call $Obj_PlayAnim$ arguments
      $anim$ = $Ped_Bikini_LyingFrontToBack$$cycle$


This is the anim. Remember at the start, in the allanims file, I chose $Ped_Bikini_LyingFrontToBack$. You can look for any anim you want in the allanims file, just remember to go back up to the function its in, get the function name and reference Checksum.

Re: [THUG2][PC] How to spawn a ped

Posted: Mon Oct 31, 2011 11:09 am
by Lezzer
Don't work.

Re: [THUG2][PC] How to spawn a ped

Posted: Mon Oct 31, 2011 11:59 am
by Anteara
Lezzer wrote:Don't work.


I wouldn't write a tutorial if it doesn't work. It DOES WORK. FOR THUG2. Hence why it says THUG2 in the title! It does NOT work for THAW. If it worked for THAW I would say so!

WhoElseButMe knows how to make it work in THAW, there was a thread where he explained in detail how to make it work in THAW, so try and find it. If you can't then maybe you can ask WhoElseButMe very nicely to explain it to you...

Re: [THUG2][PC] How to spawn a ped

Posted: Fri Sep 28, 2012 9:59 pm
by ZurePitchmen83
I'm having problems with this tutorial, when i try to use your tutorial script for a ped spawning menu, the game crashes! :cry: , no matter which level i go to, can you give me a way for this to properly work in a spawning menu, BTW, I'm using THUG2, not THAW

Re: [THUG2][PC] How to spawn a ped

Posted: Sat Sep 29, 2012 7:51 pm
by WhoElseButMe
This tutorial is for THUG2 NOT THAW perhaps what you're trying to spawn isn't loaded.

Re: [THUG2][PC] How to spawn a ped

Posted: Sat Sep 29, 2012 10:24 pm
by ZurePitchmen83
WhoElseButMe wrote:This tutorial is for THUG2 NOT THAW perhaps what you're trying to spawn isn't loaded.


I know, but this is my attempt for ped spawning menu in THUG2, i don't see why this doesn't work

Code: Select all

:i function $peds_menu$
   :i call $make_new_themed_scrolling_menu$ arguments
      $title$ = %s(17,"Ped spawner menu")
   :i $SetScreenElementProps$:s{
   :i $id$ = $sub_menu$
   :i $event_handlers$ = :a{:s{call $pad_back$ arguments
      $generic_menu_pad_back$$params$ = :s{$callback$ = $create_zure_menu$:s}:s}
      :i :a}
      :i $replace_handlers$
   :i :s}
   :i call $theme_menu_add_item$ arguments
      $text$ = %s(11,"Bam Margera")$pad_choose_script$ = $anteara_ped12lol$$no_bg$$centered$ = $centered$
   :i call $theme_menu_add_item$ arguments
      $text$ = %s(4,"Done")$pad_choose_script$ = $create_zure_menu$$no_bg$$centered$ = $centered$
   :i $finish_themed_scrolling_menu$
:i endfunction
:i function $anteara_ped12lol$
   :i $Skater$.$Obj_GetPosition$
   :i $CreateCompositeObject$:s{
      :i $Components$ =
      :i :a{
         :i :s{$component$ = $motion$:s}
         :i :s{$component$ = call $Suspend$ arguments
            $NeverSuspend$:s}
         :i :s{$component$ = $skeleton$
         :i $SkeletonName$ = $THPS6_human$
         :i $max_bone_skip_lod$ = %i(0,00000000)
         :i :s}
         :i :s{$component$ = $model$
         :i :s}
         :i :s{$component$ = $AnimBlender$
            :i $AnimName$ = $animload_THPS6_human_unloadable_1$
            :i $SkeletonName$ = $THPS6_human$
         :i :s}
      :i :a}
               :i $params$ = :s{$pos$ = %GLOBAL%$pos$$model$ = %s(47,"Peds\PedPros\PedPro_Margera\PedPro_Margera.skin")$name$ = $Pedestrian$:s}
   :i :s}
   :i $Pedestrian$.call $Obj_PlayAnim$ arguments
      $anim$ = $Ped_M_LookAround$$cycle$
:i endfunction


That code above is my attempt of spawning a ped in a menu, can anyone tell me what i need to do to this this to work :/

Re: [THUG2][PC] How to spawn a ped

Posted: Sat Sep 29, 2012 10:35 pm
by WhoElseButMe
When does it crash, when you open the menu or when you select a menu option?

Re: [THUG2][PC] How to spawn a ped

Posted: Sat Sep 29, 2012 10:37 pm
by ZurePitchmen83
when i press the button

Re: [THUG2][PC] How to spawn a ped

Posted: Sat Sep 29, 2012 10:52 pm
by WhoElseButMe
Are you creating the object with the same name more than once?
Perhaps check to make sure the object doesnt already exist before creating it

Code: Select all

   :i $Skater$.$Obj_GetPosition$
   :i if call $ObjectExists$ arguments
      $id$ = $Pedestrian$
   :i $Pedestrian$.call $obj_PlayAnim$ arguments
      $anim$ = $Ped_M_LookAround$$cycle$
   :i else
      :i $CreateCompositeObject$:s{
      // and all its construction code go here
   :i endif

An example of this, tested in THAW but the same principles apply, can be found here

Re: [THUG2][PC] How to spawn a ped

Posted: Sat Sep 29, 2012 10:54 pm
by ZurePitchmen83
Thanks, i'll try that and see if it worked

EDIT:it doesn't work, i tried it this way and it crashed, maybe i did it wrong

Code: Select all

    :i function $anteara_ped12lol$
       :i $Skater$.$Obj_GetPosition$
       :i if call $ObjectExists$ arguments
          $id$ = $Pedestrian$
       :i $Pedestrian$.call $obj_PlayAnim$ arguments
          $anim$ = $Ped_M_LookAround$$cycle$
       :i else
          :i $CreateCompositeObject$:s{
      :i $Components$ =
      :i :a{
         :i :s{$component$ = $motion$:s}
         :i :s{$component$ = call $Suspend$ arguments
            $NeverSuspend$:s}
         :i :s{$component$ = $skeleton$
         :i $SkeletonName$ = $THPS6_human$
         :i $max_bone_skip_lod$ = %i(0,00000000)
         :i :s}
         :i :s{$component$ = $model$
         :i :s}
         :i :s{$component$ = $AnimBlender$
            :i $AnimName$ = $animload_THPS6_human_unloadable_1$
            :i $SkeletonName$ = $THPS6_human$
         :i :s}
      :i :a}
               :i $params$ = :s{$pos$ = %GLOBAL%$pos$$model$ = %s(47,"Peds\PedPros\PedPro_Margera\PedPro_Margera.skin")$name$ = $Pedestrian$:s}
   :i :s}
   :i endif
   :i $Pedestrian$.call $Obj_PlayAnim$ arguments
    :i endfunction

Re: [THUG2][PC] How to spawn a ped

Posted: Sat Sep 29, 2012 11:05 pm
by WhoElseButMe
Try this same code on an object you know is loaded like a combo O or something and give it a more unique name like my_combo_o to insure no name clash.
It all looks to be proper but I might be overlooking something and it still leads me to believe the object isn't loading into memory and that's the culprit to your crashing.

Re: [THUG2][PC] How to spawn a ped

Posted: Sun Sep 30, 2012 6:38 am
by ZurePitchmen83
It works now, i had to mess with the script, but i still have one issue, the anim doesn't play, instead, my ped is T-Posed rather than being animated, i'd like to know how to fix, the code is the same except for one change here

Code: Select all

:i :s{$component$ = $AnimBlender$
:i $AnimName$ = $animload_THPS6_human_unloadable_1$
:i $SkeletonName$ = $THPS6_human$
:i :s}
:i :a}
:i $params$ = :s{$pos$ = %GLOBAL%$pos$$model$ = %s(47,"Peds\PedPros\PedPro_Vallely\PedPro_Vallely.skin")$name$ = $Pedestrian$:s}
:i :s}
:i endif
:i endfunction


i'd like to know how to fix this