DK22Pac / plugin-sdk

An SDK for developing ASI/CLEO plugins for GTA San Andreas, GTA Vice City and GTA III
zlib License
436 stars 118 forks source link

What is Set Position Function for Vice City #50

Closed EightyVice closed 7 years ago

EightyVice commented 7 years ago

i searched in all headers that for "Peds" in general and didnt find that one that exists in SA

quiret commented 7 years ago

CPed is also a CMatrix. Try using the "SetTranslate" method of CMatrix.

https://github.com/DK22Pac/plugin-sdk/blob/master/plugin_vc/game_vc/CMatrix.h#L49

This is actually very different from SA because CPed is not a CMatrix there but has a CMatrixLink pointer as member.

EightyVice commented 7 years ago

well i wrote that code and it crashes when i press TAB the code

#include "plugin_vc.h"
#include <game_vc\CHud.h>
#include <game_vc\CPed.h>
#include <game_vc\CCivilianPed.h>
#include <game_vc\CWorld.h>
#include <game_vc\CPopulation.h>
#include <game_vc\CPedType.h>
#include <game_vc\ePedType.h>
#include <game_vc\CVector.h>
#include <game_vc\CPlayerPed.h>
#include <iostream>
#include <string>
using namespace plugin;

class MyPlugin {
public:
    MyPlugin() {
        Events::gameProcessEvent += [] {
            if (KeyPressed(VK_TAB))
            {
                const CVector place = CVector::CVector(0.0, 0.0, 0.0);
                //CPed *ped = new CCivilianPed(CPopulation::AddPed(ePedType::PEDTYPE_DUMMY, 0, place, 0));
                CPed *ped = CPopulation::AddPed(ePedType::PEDTYPE_DUMMY, (unsigned int)0, place, 0);
                CWorld::Add(ped);
                CHud::SetHelpMessage((unsigned short*)"Done", false, false, true);
            }
        };
    }
} myPlugin;

and can you show a small example about using CMatrix because its confusing

quiret commented 7 years ago
#include "plugin_vc.h"
#include <game_vc\CHud.h>
#include <game_vc\CPed.h>
#include <game_vc\CCivilianPed.h>
#include <game_vc\CWorld.h>
#include <game_vc\CPopulation.h>
#include <game_vc\CPedType.h>
#include <game_vc\ePedType.h>
#include <game_vc\CVector.h>
#include <game_vc\CPlayerPed.h>
#include <iostream>
#include <string>
using namespace plugin;

class MyPlugin {
public:
    MyPlugin() {
        Events::gameProcessEvent += [] {
            if (KeyPressed(VK_TAB))
            {
                const CVector place = CVector::CVector(0.0, 0.0, 0.0);
                //CPed *ped = new CCivilianPed(CPopulation::AddPed(ePedType::PEDTYPE_CIVMALE, 0, place, 0));
                CPed *ped = CPopulation::AddPed(ePedType::PEDTYPE_CIVMALE, (unsigned int)0, place, 0);
                CWorld::Add(ped);
                CHud::SetHelpMessage((unsigned short*)L"Done", false, false, true);
            }
        };
    }
} myPlugin;

This code should work, I tested it. Regarding CHud class of Vice City, we can hack and use wchar_t mapping to unsigned short. But remember that CHud does not actually support unicode, so be careful. If used wrong it leads to a deadlock.

Also, if you use dxwnd to put Vice City into windowed mode you can attach a debugger to it if your debug ASI is loaded. Then you can put breakpoints into your code. This way you could find out that ped can be NULL sometimes.

quiret commented 7 years ago

"and can you show a small example about using CMatrix because its confusing"

To answer your last question, here is a player teleportation example that moves you up into the sky when you press/hold Tab key.

#include "plugin_vc.h"
#include "game_vc/common.h"

using namespace plugin;

class MyPlugin {
public:
    MyPlugin() {
        Events::gameProcessEvent += []()
        {
            if (KeyPressed(VK_TAB))
            {
                CPed *player = FindPlayerPed();

                if ( player != NULL )
                {
                    CVector oldPos = player->m_placement.pos;
                    player->m_placement.SetTranslateOnly( oldPos.x, oldPos.y, oldPos.z + 3.0f );
                }
            }
        };
    }
} myPlugin;

Please note that CPlacement is a CMatrix. I may have mistakenly said previously that CPed is a CPlacement, but no it just has a member called m_placement (same thing really). So calling player->m_placement.SetTranslateOnly is calling a method of CMatrix.