Quantcast

Jump to content

» «
Photo

Help with my mod

14 replies to this topic
Wiebrendh
  • Wiebrendh

    C# Programmer

  • Members
  • Joined: 22 Mar 2014
  • Netherlands

#1

Posted 01 May 2014 - 10:18 AM

Hi all, i am currently working on The Heist for my robbery mod, but i have some troubles with one part..

How do i spawn a a car, with niko on the drivers seat, and a ped on the other seat. And when niko leaves the car, the ped will follow niko and kill the police.

Thanks in advance!


Rugz007
  • Rugz007

    Scripters ... roll out !

  • Members
  • Joined: 19 Apr 2014
  • India

#2

Posted 01 May 2014 - 10:24 AM Edited by Rugz007, 01 May 2014 - 10:25 AM.

let me give you the code for it....


julionib
  • julionib

    Coder

  • Feroci
  • Joined: 13 Sep 2012
  • Brazil

#3

Posted 01 May 2014 - 11:24 AM Edited by julionib, 01 May 2014 - 11:24 AM.

you can create a gta group and add the passenger to it, then this guy will follow niko and help him, give some guns to him

the car you can create then task warp player inside


Wiebrendh
  • Wiebrendh

    C# Programmer

  • Members
  • Joined: 22 Mar 2014
  • Netherlands

#4

Posted 01 May 2014 - 11:35 AM

you can create a gta group and add the passenger to it, then this guy will follow niko and help him, give some guns to him

the car you can create then task warp player inside

 

Could you give me an example? I don't understand natives very good.. Especially when there is no description attached

http://www.gtamoddin...=CREATE_GROUPto it :(


NTAuthority
  • NTAuthority

    hell, no, tunnel, no

  • Feroci
  • Joined: 09 Sep 2008
  • European-Union
  • Most Knowledgeable [Technology] 2013
    Best Map 2013 "ViceCityStories PC Edition"
    Contribution Award [Modding]

#5

Posted 01 May 2014 - 01:55 PM

you typically don't create a group, you'd GET_PLAYER_GROUP the player's group which automatically has the player as a leader


julionib
  • julionib

    Coder

  • Feroci
  • Joined: 13 Sep 2012
  • Brazil

#6

Posted 01 May 2014 - 02:14 PM

you typically don't create a group, you'd GET_PLAYER_GROUP the player's group which automatically has the player as a leader

 

cool


@Wiebrendh: example of warp:

 

player.character.task.warpIntoVehicle(desiredVeh, vehicleSeat.driver) 

or, less safe way:

 

player.character.warpIntoVehicle(desiredVeh, vehicleSeat.driver) 


Wiebrendh
  • Wiebrendh

    C# Programmer

  • Members
  • Joined: 22 Mar 2014
  • Netherlands

#7

Posted 01 May 2014 - 02:22 PM

you typically don't create a group, you'd GET_PLAYER_GROUP the player's group which automatically has the player as a leader

 

Oke, that is kinda logic :)

And, how do i spawn a ped? And set the ped id into an int


LordOfTheBongs
  • LordOfTheBongs

    Deceased

  • Members
  • Joined: 21 Sep 2013
  • None

#8

Posted 01 May 2014 - 04:39 PM Edited by LordOfTheBongs, 01 May 2014 - 04:47 PM.

Hi all, i am currently working on The Heist for my robbery mod, but i have some troubles with one part..

How do i spawn a a car, with niko on the drivers seat, and a ped on the other seat. And when niko leaves the car, the ped will follow niko and kill the police.

Thanks in advance!

namespace PlayerGroupExample
{
    using System;
    using System.Windows.Forms;
    using GTA;
 
    public class Main : Script
    {
        private Ped bodyguard;
        public Main()
        {
            BindKey(Keys.Insert, delegate
            {
                if (Game.Exists(bodyguard)) return;
 
                Vehicle v = World.CreateVehicle(World.GetNextPositionOnStreet(Game.LocalPlayer.Character.Position.Around(5f)));
                Game.LocalPlayer.Character.WarpIntoVehicle(v, VehicleSeat.Driver);
                bodyguard = v.CreatePedOnSeat(VehicleSeat.RightFront);
                bodyguard.Weapons.MP5.Ammo = 500;
                Game.LocalPlayer.Group.AddMember(bodyguard);
                Tick += BodyguardTick;
            });
        }
 
        private void BodyguardTick(object sender, EventArgs e)
        {
            if (!Game.Exists(bodyguard))
            {
                Tick -= BodyguardTick;
                return;
            }
 
            if (!bodyguard.isAliveAndWell)
            {
                if (Game.LocalPlayer.Group.isMember(bodyguard))
                {
                    BugFreeRemovePlayerGroupMember(bodyguard);
                }
 
                bodyguard.NoLongerNeeded();
                bodyguard = null;
                Tick -= BodyguardTick;
                return;
            }
 
            //in this method u can provide any specific instructions u like for your bodyguard
            // I already made sure he exists and is alive... so do whatever u want with him ;)
        }

        private void BugFreeRemovePlayerGroupMember(Ped groupMember)
        {
            //removing members is bugged so u have to remove all and add back who u wanted to keep
            Ped[] group = Game.LocalPlayer.Group.ToArray(false);
            Game.LocalPlayer.Group.RemoveAllMembers();
 
            for (int i = 0; i < group.Length; i++)
            {
                if (group[i] == groupMember) continue;
                Game.LocalPlayer.Group.AddMember(group[i]);
            }
        }
    }
}

btw i notice lots of new scripthookdotnet developers constantly trying to use natives that are already wrapped in the scripthookdotnet. U dont need to lookup native functions most of the time. The scripthookdotnet already does most of what u need to do ;)


Wiebrendh
  • Wiebrendh

    C# Programmer

  • Members
  • Joined: 22 Mar 2014
  • Netherlands

#9

Posted 01 May 2014 - 06:43 PM

 

Hi all, i am currently working on The Heist for my robbery mod, but i have some troubles with one part..

How do i spawn a a car, with niko on the drivers seat, and a ped on the other seat. And when niko leaves the car, the ped will follow niko and kill the police.

Thanks in advance!

namespace PlayerGroupExample
{
    using System;
    using System.Windows.Forms;
    using GTA;
 
    public class Main : Script
    {
        private Ped bodyguard;
        public Main()
        {
            BindKey(Keys.Insert, delegate
            {
                if (Game.Exists(bodyguard)) return;
 
                Vehicle v = World.CreateVehicle(World.GetNextPositionOnStreet(Game.LocalPlayer.Character.Position.Around(5f)));
                Game.LocalPlayer.Character.WarpIntoVehicle(v, VehicleSeat.Driver);
                bodyguard = v.CreatePedOnSeat(VehicleSeat.RightFront);
                bodyguard.Weapons.MP5.Ammo = 500;
                Game.LocalPlayer.Group.AddMember(bodyguard);
                Tick += BodyguardTick;
            });
        }
 
        private void BodyguardTick(object sender, EventArgs e)
        {
            if (!Game.Exists(bodyguard))
            {
                Tick -= BodyguardTick;
                return;
            }
 
            if (!bodyguard.isAliveAndWell)
            {
                if (Game.LocalPlayer.Group.isMember(bodyguard))
                {
                    BugFreeRemovePlayerGroupMember(bodyguard);
                }
 
                bodyguard.NoLongerNeeded();
                bodyguard = null;
                Tick -= BodyguardTick;
                return;
            }
 
            //in this method u can provide any specific instructions u like for your bodyguard
            // I already made sure he exists and is alive... so do whatever u want with him ;)
        }

        private void BugFreeRemovePlayerGroupMember(Ped groupMember)
        {
            //removing members is bugged so u have to remove all and add back who u wanted to keep
            Ped[] group = Game.LocalPlayer.Group.ToArray(false);
            Game.LocalPlayer.Group.RemoveAllMembers();
 
            for (int i = 0; i < group.Length; i++)
            {
                if (group[i] == groupMember) continue;
                Game.LocalPlayer.Group.AddMember(group[i]);
            }
        }
    }
}

btw i notice lots of new scripthookdotnet developers constantly trying to use natives that are already wrapped in the scripthookdotnet. U dont need to lookup native functions most of the time. The scripthookdotnet already does most of what u need to do ;)

 

 

nice, thanks! This will definitely help me a lot! Thanks mate!

  • LordOfTheBongs likes this

LordOfTheBongs
  • LordOfTheBongs

    Deceased

  • Members
  • Joined: 21 Sep 2013
  • None

#10

Posted 01 May 2014 - 06:44 PM Edited by LordOfTheBongs, 01 May 2014 - 07:44 PM.

 

you typically don't create a group, you'd GET_PLAYER_GROUP the player's group which automatically has the player as a leader

 

cool


@Wiebrendh: example of warp:

 

player.character.task.warpIntoVehicle(desiredVeh, vehicleSeat.driver) 

or, less safe way:

 

player.character.warpIntoVehicle(desiredVeh, vehicleSeat.driver) 

 

 

they both do the exact same thing, what do u mean by safer? they do use different natives... maybe one wasnt meant to be used

 

Ped: http://i.imgur.com/QuuR66u.png

Task: http://i.imgur.com/8l1PMoH.png


pedro2555
  • pedro2555

    Open Sourcer

  • Members
  • Joined: 02 Sep 2012
  • Portugal

#11

Posted 01 May 2014 - 09:05 PM

 

 

you typically don't create a group, you'd GET_PLAYER_GROUP the player's group which automatically has the player as a leader

 

cool


@Wiebrendh: example of warp:

 

player.character.task.warpIntoVehicle(desiredVeh, vehicleSeat.driver) 

or, less safe way:

 

player.character.warpIntoVehicle(desiredVeh, vehicleSeat.driver) 

 

 

they both do the exact same thing, what do u mean by safer? they do use different natives... maybe one wasnt meant to be used

 

Ped: http://i.imgur.com/QuuR66u.png

Task: http://i.imgur.com/8l1PMoH.png

 

 

I might be wrong on this, I've never tested it. But it looks like to me, that Ped.WarpIntoVehicle() simply warps the ped to a specified vehicle upon calling, whitest Taks.WarpIntoVehicle() warps the ped to a specified vehicle respecting a task sequence execution. 


pedro2555
  • pedro2555

    Open Sourcer

  • Members
  • Joined: 02 Sep 2012
  • Portugal

#12

Posted 01 May 2014 - 09:24 PM

@LordOfTheBongs

 

I've noticed you using iLSpy for finding the underlying operations from .NET Scripthook, but actually .NET Scripthook is open source and the full solution is available for download at HazardX website. You get a better acurary reading the actual source, Ped.WarpIntoVehicle is actually like this:

void Ped::WarpIntoVehicle(GTA::Vehicle^ Vehicle, VehicleSeat Seat) {
	NON_EXISTING_CHECK();
	OBJECT_NON_EXISTING_CHECK(Vehicle);
	if (Seat <= VehicleSeat::None) return;
	if (Seat == VehicleSeat::Driver) {
		Scripting::WarpCharIntoCar(pHandle,Vehicle->Handle);
	} else {
		if (isInVehicle(Vehicle))
			Scripting::WarpCharFromCarToCar(pHandle,Vehicle->Handle,(int)Seat); // change seat
		else
			Scripting::WarpCharIntoCarAsPassenger(pHandle,Vehicle->Handle,(int)Seat);
	}
}

LordOfTheBongs
  • LordOfTheBongs

    Deceased

  • Members
  • Joined: 21 Sep 2013
  • None

#13

Posted 01 May 2014 - 10:45 PM Edited by LordOfTheBongs, 01 May 2014 - 10:47 PM.

 

@LordOfTheBongs

 

I've noticed you using iLSpy for finding the underlying operations from .NET Scripthook, but actually .NET Scripthook is open source and the full solution is available for download at HazardX website. You get a better acurary reading the actual source, Ped.WarpIntoVehicle is actually like this:

void Ped::WarpIntoVehicle(GTA::Vehicle^ Vehicle, VehicleSeat Seat) {
	NON_EXISTING_CHECK();
	OBJECT_NON_EXISTING_CHECK(Vehicle);
	if (Seat <= VehicleSeat::None) return;
	if (Seat == VehicleSeat::Driver) {
		Scripting::WarpCharIntoCar(pHandle,Vehicle->Handle);
	} else {
		if (isInVehicle(Vehicle))
			Scripting::WarpCharFromCarToCar(pHandle,Vehicle->Handle,(int)Seat); // change seat
		else
			Scripting::WarpCharIntoCarAsPassenger(pHandle,Vehicle->Handle,(int)Seat);
	}
}

i know i have it, i like using the treeview control in ilspy than navigating the files in the project... for me it's faster

 

plus c++/clr coding style is ugly, id rather read it in c#

  • Wiebrendh likes this

pedro2555
  • pedro2555

    Open Sourcer

  • Members
  • Joined: 02 Sep 2012
  • Portugal

#14

Posted 02 May 2014 - 07:37 AM

 

 

@LordOfTheBongs

 

I've noticed you using iLSpy for finding the underlying operations from .NET Scripthook, but actually .NET Scripthook is open source and the full solution is available for download at HazardX website. You get a better acurary reading the actual source, Ped.WarpIntoVehicle is actually like this:

void Ped::WarpIntoVehicle(GTA::Vehicle^ Vehicle, VehicleSeat Seat) {
	NON_EXISTING_CHECK();
	OBJECT_NON_EXISTING_CHECK(Vehicle);
	if (Seat <= VehicleSeat::None) return;
	if (Seat == VehicleSeat::Driver) {
		Scripting::WarpCharIntoCar(pHandle,Vehicle->Handle);
	} else {
		if (isInVehicle(Vehicle))
			Scripting::WarpCharFromCarToCar(pHandle,Vehicle->Handle,(int)Seat); // change seat
		else
			Scripting::WarpCharIntoCarAsPassenger(pHandle,Vehicle->Handle,(int)Seat);
	}
}

i know i have it, i like using the treeview control in ilspy than navigating the files in the project... for me it's faster

 

plus c++/clr coding style is ugly, id rather read it in c#

 

 Fair enough.

  • LordOfTheBongs likes this

julionib
  • julionib

    Coder

  • Feroci
  • Joined: 13 Sep 2012
  • Brazil

#15

Posted 02 May 2014 - 10:46 AM

the thing about use Task.Warp... instead of Warp... is that sometimes the direct warp causes memory error in script and we cant handle in exception, this result in script crash :)

i had this issue in the first mod i made (myTelekinesis powers) and started to use Task, the problem with task is that it may take some extra time to warp even to a free passenger seat

  • pedro2555, LordOfTheBongs and Wiebrendh like this




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users