Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

What is Set Position Function for Vice City #50

Closed
EightyVice opened this issue Sep 11, 2017 · 4 comments
Closed

What is Set Position Function for Vice City #50

EightyVice opened this issue Sep 11, 2017 · 4 comments

Comments

@EightyVice
Copy link
Collaborator

EightyVice commented Sep 11, 2017

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

@quiret
Copy link
Collaborator

quiret commented Sep 12, 2017

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
Copy link
Collaborator Author

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
Copy link
Collaborator

quiret commented Sep 13, 2017

#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
Copy link
Collaborator

quiret commented Sep 13, 2017

"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.

@quiret quiret closed this as completed Sep 13, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants