Skip to content

Commit

Permalink
Init commit
Browse files Browse the repository at this point in the history
  • Loading branch information
kalbmar committed Mar 20, 2024
0 parents commit 421b621
Show file tree
Hide file tree
Showing 10 changed files with 776 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
plugins/
build.bat
674 changes: 674 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Pistol

- Gives players a gun

### Supported games

- Day of Defeat: Source

### Installation

- Download latest [release](https://github.com/kalbmar/pistol/releases) (compiled for SourceMod 1.11)
- Extract "plugins" folder to "addons/sourcemod" folder of your server
6 changes: 6 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash

PLUGIN_NAME="pistol"

cd scripting
spcomp $PLUGIN_NAME.sp -i include -o../plugins/$PLUGIN_NAME.smx
15 changes: 15 additions & 0 deletions scripting/include/timer.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#if defined _pistol_timer_included
#endinput
#endif
#define _pistol_timer_included

#define TEAM_ALLIES 2
#define TEAM_AXIS 3
#define ALLIES_PISTOL_IN_ARRAY 1
#define AXIS_PISTOL_IN_ARRAY 2
#define ALLIES_PISTOL_CLASS_NAME "weapon_colt"
#define AXIS_PISTOL_CLASS_NAME "weapon_p38"
#define ALLIES_BULLETS_FOR_PISTOL 14
#define AXIS_BULLETS_FOR_PISTOL 16
#define CLASS_RIFLEMAN 0
#define CLASS_SUPPORT 2
7 changes: 7 additions & 0 deletions scripting/modules/client.sp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
bool Client_IsValid(int client) {
return (1 <= client <= MaxClients && IsClientInGame(client)) ? true : false;
}

int Client_GetClass(int client) {
return GetEntProp(client, Prop_Send, "m_iPlayerClass");
}
9 changes: 9 additions & 0 deletions scripting/modules/event.sp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
void Event_Create() {
HookEvent("player_spawn", Event_PlayerSpawn);
}

public void Event_PlayerSpawn(Event event, const char[] name, bool dontBroadcast) {
int userId = event.GetInt("userid");

CreateTimer(0.1, Timer_GivePlayerPistol, userId, TIMER_FLAG_NO_MAPCHANGE);
}
23 changes: 23 additions & 0 deletions scripting/modules/timer.sp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
public Action Timer_GivePlayerPistol(Handle timer, int userId) {
int client = GetClientOfUserId(userId);

if (!Client_IsValid(client)) {
return Plugin_Stop;
}

int team = GetClientTeam(client);
int class = Client_GetClass(client);

if (class == CLASS_RIFLEMAN || class == CLASS_SUPPORT) {
if (team == TEAM_ALLIES) {
UseCase_GivePlayerPistol(client, ALLIES_PISTOL_CLASS_NAME);
UseCase_SetBulletsForPistol(client, ALLIES_BULLETS_FOR_PISTOL, ALLIES_PISTOL_IN_ARRAY);

} else if (team == TEAM_AXIS) {
UseCase_GivePlayerPistol(client, AXIS_PISTOL_CLASS_NAME);
UseCase_SetBulletsForPistol(client, AXIS_BULLETS_FOR_PISTOL, AXIS_PISTOL_IN_ARRAY);
}
}

return Plugin_Continue;
}
7 changes: 7 additions & 0 deletions scripting/modules/use-case.sp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
void UseCase_GivePlayerPistol(int client, const char[] pistolName) {
GivePlayerItem(client, pistolName);
}

void UseCase_SetBulletsForPistol(int client, int bullets, int pistols) {
SetEntProp(client, Prop_Send, "m_iAmmo", bullets, _, pistols);
}
21 changes: 21 additions & 0 deletions scripting/pistol.sp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include <sourcemod>
#include <sdktools>

#include "timer"

#include "modules/event.sp"
#include "modules/timer.sp"
#include "modules/use-case.sp"
#include "modules/client.sp"

public Plugin myinfo = {
name = "Pistol",
author = "Kalbmar",
description = "Gives players a gun",
version = "1.0.0",
url = "https://github.com/kalbmar/pistol",
};

public void OnPluginStart() {
Event_Create();
}

0 comments on commit 421b621

Please sign in to comment.