Script Question

Anything to do with GTA1/GTA2 modding (tools, scripts and more).
Post Reply
BeepBoop
Car Jacker
Car Jacker
Posts: 46
Joined: 14 Oct 2016, 01:32
GH nick: BeepBoop

Script Question

Post by BeepBoop »

Do you think it's possible to find the Closest Ped/Nearest to the Player structure? I want to change the nearest peds health to zero easily.
Logofero
Serial Killer
Serial Killer
Posts: 264
Joined: 09 Dec 2015, 14:18
Location: Russia, Gelendzhik
Contact:

Re: Script Question

Post by Logofero »

BeepBoop wrote:Do you think it's possible to find the Closest Ped/Nearest to the Player structure? I want to change the nearest peds health to zero easily.
Yes. It's possible.

I planned to add in MISI v0.2.2b a method GET ped from point, which will get the random ped's structure from point.

This is also possible using ready-made methods: GetPedStruct(id), GetPedPos(ped) and GetPedRangeOfPoint(ped, x, y, z) (or GetDisnanceOfPoints(x1, y1, z1, x2, y2, z2)) Then we need to go through all the ped in the loop and get the structure of the player closest to the player.

Example get ped from point
scripts/allpedcops.txt:

Code: Select all

-- Since: v0.2.1b
while(true) do
    if (IsKeyDown(4)) then -- Down key left mouse key
      local ped = GetPedStruct(1)
      for id = 2, 65535, 1 do
           local targetped = GetPedStruct(id)
           if (targetped ~= 0) then -- Cheak ped is exist
               local x, y, z = GetPedPos(targetped)
               if (GetPedRangeOfPoints(ped, x, y, z) < 20.0) then -- Distane for find
                   SetPedModel(targetped, 2) -- Set model
                   SetPedSkin(targetped, 0) -- Set skin cop
                   SetPedOccupation(targetped, 24)
                   SetPedThreatReaction(targetped, 2)
                   SetPedReactionType(targetped, 2)
               end
           end
       end
    end
    wait(200)
end
Edite: Example code.
Last edited by Logofero on 28 Feb 2018, 15:19, edited 6 times in total.
BeepBoop
Car Jacker
Car Jacker
Posts: 46
Joined: 14 Oct 2016, 01:32
GH nick: BeepBoop

Re: Script Question

Post by BeepBoop »

I have seem to have found the address for [Last PED Touched] will post it in a bit.
BeepBoop
Car Jacker
Car Jacker
Posts: 46
Joined: 14 Oct 2016, 01:32
GH nick: BeepBoop

Re: Script Question

Post by BeepBoop »

Okay can confirm structure works for Last Ped Touched.

Address:
Ped Structure + Offset #1 = 0x138 + Offset #2 = 0x7C + Offset #3 = 0x216.
BeepBoop
Car Jacker
Car Jacker
Posts: 46
Joined: 14 Oct 2016, 01:32
GH nick: BeepBoop

Re: Script Question

Post by BeepBoop »

I was thinking of making a Medic mod or script, but I am currently not well trained in lua scripting. I almost have everything to make it work just need to put all in a readable script.
Logofero
Serial Killer
Serial Killer
Posts: 264
Joined: 09 Dec 2015, 14:18
Location: Russia, Gelendzhik
Contact:

Re: Script Question

Post by Logofero »

BeepBoop wrote:Okay can confirm structure works for Last Ped Touched.

Address:
Ped Structure + Offset #1 = 0x138 + Offset #2 = 0x7C + Offset #3 = 0x216.
Use the methods:

Code: Select all

local pointer = ReadProcessMemory(address, size) -- For read address (get pointer)
WriteProcessMemory(address, value, size) -- For write value in address
As I cited in the example http://gtamp.com/forum/viewtopic.php?f= ... =60#p10570
Logofero
Serial Killer
Serial Killer
Posts: 264
Joined: 09 Dec 2015, 14:18
Location: Russia, Gelendzhik
Contact:

Re: Script Question

Post by Logofero »

BeepBoop wrote:I was thinking of making a Medic mod or script, but I am currently not well trained in lua scripting. I almost have everything to make it work just need to put all in a readable script.
In this case i recommend studying the basics of LUA, it is a very easy language. Here is the official documentation http://www.lua.org/manual/5.3/
Logofero
Serial Killer
Serial Killer
Posts: 264
Joined: 09 Dec 2015, 14:18
Location: Russia, Gelendzhik
Contact:

Re: Script Question

Post by Logofero »

BeepBoop, I checked your addresses today. Got a prototype of the GetPedTouch(ped)

Code: Select all

-- Prototype method GetPedTouch(ped)
-- Since: v0.2.1b
function GetPedTouch(ped)
    local ped_touch_ptr = ReadProcessMemory(ped + 138, 4)
    local ped_touch_struct = ReadProcessMemory(ped_touch_ptr + 0x7C, 4)
    return ped_touch_struct
end

while(true)
    local ped = GetPedStruct(1) -- Get ped ID 1 (it player 1)
    if (ped ~= 0) then -- Cheak player 1 is exist
        local touchped = GetPedTouch(ped) -- Get touched ped struct
        if (touchped ~= 0) then -- Cheak touched ped is exist
            SetPedModel(touched, GetPedModel(ped)) -- Set touched ped model as player 1
            SetPedSkin(touchped, GetPedSkin(ped)) -- Set touched ped skin as player 1
        end
    end
    wait(200)
end
BeepBoop
Car Jacker
Car Jacker
Posts: 46
Joined: 14 Oct 2016, 01:32
GH nick: BeepBoop

Re: Script Question

Post by BeepBoop »

Very Cool, I'll see if I can find anything else that is useful. Is there anything or addresses that you are looking for in-game that would be useful in your project? [respect]
Logofero
Serial Killer
Serial Killer
Posts: 264
Joined: 09 Dec 2015, 14:18
Location: Russia, Gelendzhik
Contact:

Re: Script Question

Post by Logofero »

BeepBoop wrote:Very Cool, I'll see if I can find anything else that is useful. Is there anything or addresses that you are looking for in-game that would be useful in your project? [respect]
Yes there are. The most important thing now for the progress of the project is to find an addres to the procedure for creating new car. Need to find a permanent address, how to call it through memory:

Code: Select all

CAR_DATA car = CREATE_CAR (x, y, z) rotation color model END 
And delete object:

Code: Select all

DELETE_ITEM ( car )
Search the procedure you need in assembler code. The Sector wrote the memory address, where the current map is actually loaded with all SCR structures. Http://gtamp.com/forum/viewtopic.php?f=4&t=1124#p10549

You also need a link to the name car, the current speed car. You can also find all the handling for car (speed, acceleration, mass, etc.). For the player, you can find a link to the structure of all his weapons. Number of continuations. Pager enable/disable (messanger). How to enable/disable the new gang counters. Also the address to display the dialog (address for show/hide/rewrite messange text). The address for label text in the menu.

If you find this it will be great.
Post Reply