Skip to content

Commit

Permalink
Updating entity methodmap to be more flexible
Browse files Browse the repository at this point in the history
  • Loading branch information
safalin1 committed Dec 20, 2023
1 parent b58d5dd commit dec1a66
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 8 deletions.
75 changes: 71 additions & 4 deletions src/scripting/MethodMaps/Entity.inc
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
methodmap Entity __nullable__
{
public Entity(const char[] className)
public static Entity Create(const char[] className)
{
int entity = CreateEntityByName(className);

return view_as<Entity>(entity);
return new Entity(entity);
}

public Entity(int entityId)
{
return view_as<Entity>(entityId);
}

property int Id
Expand All @@ -15,9 +20,17 @@ methodmap Entity __nullable__
}
}

property bool IsValid
{
public get()
{
return IsValidEntity(this.Id);
}
}

public void Kill()
{
if (IsValidEntity(this.Id))
if (this.IsValid)
{
RemoveEntity(this.Id);
}
Expand All @@ -28,7 +41,7 @@ methodmap Entity __nullable__
DispatchKeyValue(this.Id, keyName, value);
}

public void Dispatch()
public void DispatchSpawn()
{
DispatchSpawn(this.Id);
}
Expand Down Expand Up @@ -61,4 +74,58 @@ methodmap Entity __nullable__
{
CreateTimer(duration, Timer_RemoveEntity, this.Id);
}


// Entity Props
public int GetPropInt(PropType type, const char[] name, int size = 4, int element = 0)
{
return GetEntProp(this.Id, type, name, size, element);
}

public void SetPropInt(PropType type, const char[] name, int value, int size = 4, int element = 0)
{
SetEntProp(this.Id, type, name, value, size, element);
}

public float GetPropFloat(PropType type, const char[] name, int element = 0)
{
return GetEntPropFloat(this.Id, type, name, element);
}

public void SetPropFloat(PropType type, const char[] name, float value, int element = 0)
{
SetEntPropFloat(this.Id, type, name, value, element);
}

public Entity GetPropEntity(PropType type, const char[] name, int element = 0)
{
int id = GetEntPropEnt(this.Id, type, name, element);

return new Entity(id);
}

public void SetPropEntityId(PropType type, const char[] name, int entityId, int element = 0)
{
SetEntPropEnt(this.Id, type, name, entityId, element);
}

public void SetPropEntity(PropType type, const char[] name, Entity entity, int element = 0)
{
SetEntPropEnt(this.Id, type, name, entity.Id, element);
}

public void GetPropVector(PropType type, const char[] name, float buffer[3], int element = 0)
{
GetEntPropVector(this.Id, type, name, buffer, element);
}

public void SetPropVector(PropType type, const char[] name, float buffer[3], int element = 0)
{
SetEntPropVector(this.Id, type, name, buffer, element);
}

public void SetModel(const char[] model)
{
SetEntityModel(this.Id, model);
}
}
4 changes: 2 additions & 2 deletions src/scripting/MethodMaps/PathTrack.inc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ methodmap PathTrack __nullable__ < Entity
{
public PathTrack()
{
return view_as<PathTrack>(new Entity("path_track"));
return view_as<PathTrack>(Entity.Create("path_track"));
}

public void SetName(const char[] name)
Expand All @@ -17,7 +17,7 @@ methodmap PathTrack __nullable__ < Entity

public void Build(const float position[3])
{
this.Dispatch();
this.DispatchSpawn();
this.Activate();
this.Teleport(position, NULL_VECTOR, NULL_VECTOR);
}
Expand Down
2 changes: 1 addition & 1 deletion src/scripting/MethodMaps/TrackTrain.inc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ methodmap TrackTrain __nullable__ < Entity
{
public TrackTrain()
{
return view_as<TrackTrain>(new Entity("func_tracktrain"));
return view_as<TrackTrain>(Entity.Create("func_tracktrain"));
}

public void SetName(const char[] name)
Expand Down
2 changes: 1 addition & 1 deletion src/scripting/Minigames/HitTheTarget.sp
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ public void Minigame18_OnMinigameSelectedPre()
g_ttMinigame18TrackTrain.KeyValue("orientationtype", "0");
g_ttMinigame18TrackTrain.KeyValue("spawnflags", "26");
g_ttMinigame18TrackTrain.SetEffects(32);
g_ttMinigame18TrackTrain.Dispatch();
g_ttMinigame18TrackTrain.DispatchSpawn();
g_ttMinigame18TrackTrain.Teleport(startPosition);

SetVariantEntity(g_ttMinigame18TrackTrain.Id);
Expand Down

0 comments on commit dec1a66

Please sign in to comment.