Skip to content

Commit

Permalink
Added SA_PedSpawner example.
Browse files Browse the repository at this point in the history
  • Loading branch information
Halo14- committed May 29, 2016
1 parent 09a00bc commit 3bcc5c8
Show file tree
Hide file tree
Showing 7 changed files with 241 additions and 6 deletions.
35 changes: 35 additions & 0 deletions examples/SA_PedSpawner/Main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include <plugin.h>
#include <game_sa\common.h>
#include <game_sa\CHud.h>
#include <game_sa\CTimer.h>
#include <game_sa\CStreaming.h>
#include <game_sa\CPopulation.h>

using namespace plugin;

int maleSkins[171] = { 0, 7, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 32, 33, 34, 35, 36, 37, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 57, 58, 59, 60, 61, 62, 66, 67, 68, 70, 71, 72, 73, 78, 79, 80, 81, 82, 83, 84, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 120, 121, 122, 123, 124, 125, 126, 127, 128, 132, 133, 134, 135, 136, 137, 142, 143, 144, 146, 147, 153, 154, 155, 156, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 170, 171, 173, 174, 175, 176, 177, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 200, 202, 203, 204, 206, 209, 210, 212, 213, 217, 220, 221, 222, 223, 227, 228, 229, 230, 234, 235, 236, 239, 240, 241, 242, 247, 248, 249, 250, 252, 253, 254, 255, 258, 259, 260, 261, 262 };
int femaleSkins[79] = { 9, 10, 11, 12, 13, 31, 38, 39, 40, 41, 53, 54, 55, 56, 63, 64, 69, 75, 76, 77, 85, 87, 88, 89, 90, 91, 92, 93, 129, 130, 131, 138, 139, 140, 141, 145, 148, 150, 151, 152, 157, 169, 172, 178, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 201, 205, 207, 211, 214, 215, 216, 218, 219, 224, 225, 226, 231, 232, 233, 237, 238, 243, 244, 245, 246, 251, 256, 257, 263 };

int GetRandomSkin(bool bMale = true) { return (bMale ? maleSkins[rand() % 171] : femaleSkins[rand() % 79]); }

class PedSpawner {
public:
PedSpawner() {
static int keyPressTime = 0;
Events::gameProcessEvent += [] {
if (FindPlayerPed() && KeyPressed(VK_F9) && CTimer::m_snTimeInMilliseconds - keyPressTime > 500) {
keyPressTime = CTimer::m_snTimeInMilliseconds;
const int bMale = rand() % 2;
int modelID = GetRandomSkin(bMale);
CStreaming::RequestModel(modelID, 0);
CStreaming::LoadAllRequestedModels(false);
CPed* ped = CPopulation::AddPed((bMale?PED_TYPE_CIVMALE:PED_TYPE_CIVFEMALE), modelID, FindPlayerPed()->TransformFromObjectSpace(CVector(0.0f, 5.0f, 3.0f)), false);
if (ped) {
ped->SetCharCreatedBy(2);
ped->PositionAnyPedOutOfCollision();
CHud::SetHelpMessage("PED SPAWNED", true, false, false);
}
}
};
}
} pedSpawner;
7 changes: 7 additions & 0 deletions examples/SA_PedSpawner/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
## Ped Spawner
Spawns random male and female pedestrians in front of the player when F9 is pressed.

![Img1](http://i.imgur.com/J1m0lHH.png) ![Img2](http://i.imgur.com/BrkDKbn.png)

#### Controls (keyboard)
* F9 - Spawn Ped
144 changes: 144 additions & 0 deletions examples/SA_PedSpawner/SA_PedSpawner.vcxproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{7CA511A0-BAF6-4636-A0C9-0BDA27DD709B}</ProjectGuid>
<RootNamespace>SA_PedSpawner</RootNamespace>
<WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<TargetExt>.asi</TargetExt>
<OutDir>..\..\output\asi\$(ProjectName)\$(Configuration)\</OutDir>
<IncludePath>$(IncludePath)</IncludePath>
<IntDir>obj\$(Configuration)\</IntDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<TargetExt>.asi</TargetExt>
<OutDir>..\..\output\asi\$(ProjectName)\$(Configuration)\</OutDir>
<TargetName>$(ProjectName)_d</TargetName>
<IntDir>obj\$(Configuration)\</IntDir>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<SDLCheck>true</SDLCheck>
<AdditionalIncludeDirectories>..\..\plugin_sa\;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
</ClCompile>
<Link>
<AdditionalLibraryDirectories>..\..\output\lib\plugin_sa\Debug\;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalDependencies>plugin_d.lib;%(AdditionalDependencies)</AdditionalDependencies>
<LinkTimeCodeGeneration>Default</LinkTimeCodeGeneration>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<SDLCheck>true</SDLCheck>
</ClCompile>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<AdditionalIncludeDirectories>..\..\plugin_sa\;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>No</GenerateDebugInformation>
<LinkTimeCodeGeneration>Default</LinkTimeCodeGeneration>
<AdditionalLibraryDirectories>..\..\output\lib\plugin_sa\Release\;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalDependencies>plugin.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
</ClCompile>
<Link>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="Main.cpp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
6 changes: 6 additions & 0 deletions examples/SA_PedSpawner/SA_PedSpawner.vcxproj.filters
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<ClCompile Include="Main.cpp" />
</ItemGroup>
</Project>
13 changes: 12 additions & 1 deletion plugin.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.24720.0
VisualStudioVersion = 14.0.25123.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "plugin_sa", "plugin_sa\proj\plugin_sa.vcxproj", "{0F442363-6D2C-4C0C-A157-287DCC49DD84}"
EndProject
Expand All @@ -19,6 +19,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SA_HandSignals", "examples\
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SA_VehicleSpawner", "examples\SA_VehicleSpawner\SA_VehicleSpawner.vcxproj", "{8423DBF9-94F8-4E12-AA76-BD3525718EBA}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SA_PedSpawner", "examples\SA_PedSpawner\SA_PedSpawner.vcxproj", "{7CA511A0-BAF6-4636-A0C9-0BDA27DD709B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
Expand Down Expand Up @@ -81,6 +83,14 @@ Global
{8423DBF9-94F8-4E12-AA76-BD3525718EBA}.Release|Win32.Build.0 = Release|Win32
{8423DBF9-94F8-4E12-AA76-BD3525718EBA}.Release|x64.ActiveCfg = Release|x64
{8423DBF9-94F8-4E12-AA76-BD3525718EBA}.Release|x64.Build.0 = Release|x64
{7CA511A0-BAF6-4636-A0C9-0BDA27DD709B}.Debug|Win32.ActiveCfg = Debug|Win32
{7CA511A0-BAF6-4636-A0C9-0BDA27DD709B}.Debug|Win32.Build.0 = Debug|Win32
{7CA511A0-BAF6-4636-A0C9-0BDA27DD709B}.Debug|x64.ActiveCfg = Debug|x64
{7CA511A0-BAF6-4636-A0C9-0BDA27DD709B}.Debug|x64.Build.0 = Debug|x64
{7CA511A0-BAF6-4636-A0C9-0BDA27DD709B}.Release|Win32.ActiveCfg = Release|Win32
{7CA511A0-BAF6-4636-A0C9-0BDA27DD709B}.Release|Win32.Build.0 = Release|Win32
{7CA511A0-BAF6-4636-A0C9-0BDA27DD709B}.Release|x64.ActiveCfg = Release|x64
{7CA511A0-BAF6-4636-A0C9-0BDA27DD709B}.Release|x64.Build.0 = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -92,5 +102,6 @@ Global
{074FF5E2-3D43-4E60-8559-0792F295B1CF} = {D4C3848F-BB59-45D2-95A2-A40707FCF238}
{DA11E5A5-CE5D-4027-AD65-EEA072C91987} = {D4C3848F-BB59-45D2-95A2-A40707FCF238}
{8423DBF9-94F8-4E12-AA76-BD3525718EBA} = {D4C3848F-BB59-45D2-95A2-A40707FCF238}
{7CA511A0-BAF6-4636-A0C9-0BDA27DD709B} = {D4C3848F-BB59-45D2-95A2-A40707FCF238}
EndGlobalSection
EndGlobal
12 changes: 9 additions & 3 deletions plugin_sa/proj/plugin_sa.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,9 @@
<ClInclude Include="..\game_sa\CAttractorScanner.h" />
<ClInclude Include="..\game_sa\CEventHandler.h" />
<ClInclude Include="..\game_sa\CEventScanner.h" />
<ClInclude Include="..\game_sa\CLoadedCarGroup.h" />
<ClInclude Include="..\game_sa\CRunningScriptWrapper.h" /> <ClInclude Include="..\game_sa\CLoadedCarGroup.h" />
<ClInclude Include="..\game_sa\CPopCycle.h" />
<ClInclude Include="..\game_sa\CPopulation.h" />
<ClInclude Include="..\game_sa\CTaskTimer.h" />
<ClInclude Include="..\game_sa\CPopulation.h" /> <ClInclude Include="..\game_sa\CTaskTimer.h" />
<ClInclude Include="..\game_sa\CAnimBlendAssociation.h" />
<ClInclude Include="..\game_sa\CAnimBlendClumpData.h" />
<ClInclude Include="..\game_sa\CAtomicModelInfo.h" />
Expand Down Expand Up @@ -278,6 +277,9 @@
<ClInclude Include="..\game_sa\tTransmissionGear.h" />
<ClInclude Include="..\plbase\PluginBase.h" />
<ClInclude Include="..\plugin.h" />
<ClInclude Include="..\ScriptCommands.h" />
<ClInclude Include="..\third-party\inih\ini.h" />
<ClInclude Include="..\third-party\inih\INIReader.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\additional\Other.cpp" />
Expand Down Expand Up @@ -357,6 +359,7 @@
<ClCompile Include="..\game_sa\CRegisteredCorona.cpp" />
<ClCompile Include="..\game_sa\CRGBA.cpp" />
<ClCompile Include="..\game_sa\CRunningScript.cpp" />
<ClCompile Include="..\game_sa\CRunningScriptWrapper.cpp" />
<ClCompile Include="..\game_sa\CScene.cpp" />
<ClCompile Include="..\game_sa\CShadowCamera.cpp" />
<ClCompile Include="..\game_sa\CShadows.cpp" />
Expand Down Expand Up @@ -398,6 +401,9 @@
<ClCompile Include="..\game_sa\FxMemoryPool_c.cpp" />
<ClCompile Include="..\game_sa\Fx_c.cpp" />
<ClCompile Include="..\plbase\PluginBase.cpp" />
<ClCompile Include="..\ScriptCommands.cpp" />
<ClCompile Include="..\third-party\inih\ini.c" />
<ClCompile Include="..\third-party\inih\INIReader.cpp" />
</ItemGroup>
<ItemGroup>
<Text Include="..\game_sa\CMakeLists.txt" />
Expand Down
30 changes: 28 additions & 2 deletions plugin_sa/proj/plugin_sa.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
<Filter Include="additional\settings">
<UniqueIdentifier>{f4cbd8c9-57d9-4a7f-943e-d1e0965b7566}</UniqueIdentifier>
</Filter>
<Filter Include="inih">
<UniqueIdentifier>{958162d3-ed56-4faa-b3d2-a713f95873e5}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\game_sa\AnimBlendFrameData.h">
Expand Down Expand Up @@ -607,18 +610,28 @@
<ClInclude Include="..\game_sa\CAttractorScanner.h">
<Filter>game_sa</Filter>
</ClInclude>
<ClInclude Include="..\game_sa\CLoadedCarGroup.h">
<ClInclude Include="..\game_sa\CRunningScriptWrapper.h">
<Filter>game_sa</Filter>
</ClInclude>
<ClInclude Include="..\game_sa\CTaskComplexPlayHandSignalAnim.h">
<Filter>game_sa</Filter>
</ClInclude>
<ClInclude Include="..\game_sa\CPopulation.h">
<ClInclude Include="..\third-party\inih\ini.h">
<Filter>inih</Filter>
</ClInclude>
<ClInclude Include="..\third-party\inih\INIReader.h">
<Filter>inih</Filter>
</ClInclude>
<ClInclude Include="..\ScriptCommands.h" />
<ClInclude Include="..\game_sa\CLoadedCarGroup.h">
<Filter>game_sa</Filter>
</ClInclude>
<ClInclude Include="..\game_sa\CPopCycle.h">
<Filter>game_sa</Filter>
</ClInclude>
<ClInclude Include="..\game_sa\CPopulation.h">
<Filter>game_sa</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\game_sa\CAEAudioEntity.cpp">
Expand Down Expand Up @@ -975,6 +988,19 @@
<ClCompile Include="..\game_sa\CPopulation.cpp">
<Filter>game_sa</Filter>
</ClCompile>
<ClCompile Include="..\ScriptCommands.cpp" />
<ClCompile Include="..\game_sa\CRunningScriptWrapper.cpp">
<Filter>game_sa</Filter>
</ClCompile>
<ClCompile Include="..\game_sa\CTaskComplexPlayHandSignalAnim.cpp">
<Filter>game_sa</Filter>
</ClCompile>
<ClCompile Include="..\third-party\inih\ini.c">
<Filter>inih</Filter>
</ClCompile>
<ClCompile Include="..\third-party\inih\INIReader.cpp">
<Filter>inih</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<Text Include="..\game_sa\CMakeLists.txt">
Expand Down

1 comment on commit 3bcc5c8

@quiret
Copy link
Collaborator

@quiret quiret commented on 3bcc5c8 May 31, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you forgot to upload CRunningScriptWrapper.cpp/.h, ScriptCommands.cpp/.h Please upload them ASAP because people complained they cannot compile

Please sign in to comment.