Skip to content

Commit

Permalink
1.1 changes (#3)
Browse files Browse the repository at this point in the history
* pass event data to actions

* implement player.name to Custom Lua

* implement purchase.amount to Custom Lua and Custom Console Commands

Resolves #2
  • Loading branch information
0wain committed Jan 1, 2022
1 parent e1651a0 commit d266d4c
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lua/noclip_store/core/sv_store.lua
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ function NoClip.Store.Core.EventProcess(data)
continue
end

typeFunc(receiver, expired, v)
typeFunc(receiver, expired, v, data)
end

hook.Run("NoClipStorePostEventProcess", data.id, receiver, data)
Expand Down
3 changes: 2 additions & 1 deletion lua/noclip_store/core/types/command.lua
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
-- Custom Console Command
NoClip.Store.Core.RegisterType("custom_console_command", function(ply, expired, data)
NoClip.Store.Core.RegisterType("custom_console_command", function(ply, expired, data, eventData)
local command = expired and (data.data.console_command_expire or "") or data.data.console_command
if (not command) or (command == "") then return end

command = string.Replace(command, "{player.name}", "\""..string.Replace(ply:Name(), "\"", "").."\"")
command = string.Replace(command, "{player.steamID}", ply:SteamID())
command = string.Replace(command, "{player.steamID64}", ply:SteamID64())
command = string.Replace(command, "{purchase.amount}", eventData.purchase_amount)

game.ConsoleCommand(command.."\n")
end)
4 changes: 3 additions & 1 deletion lua/noclip_store/core/types/lua.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
-- Custom Lua Action
NoClip.Store.Core.RegisterType("custom_lua", function(ply, expired, data)
NoClip.Store.Core.RegisterType("custom_lua", function(ply, expired, data, eventData)
NoClip.Store.TempPlayer = ply -- This seems like the easiest and most reliable way to pass an object.

local code = expired and (data.data.custom_lua_expire or "") or data.data.custom_lua
Expand All @@ -8,6 +8,8 @@ NoClip.Store.Core.RegisterType("custom_lua", function(ply, expired, data)
code = string.Replace(code, "{player.entity}", "NoClip.Store.TempPlayer")
code = string.Replace(code, "{player.steamID}", "\""..ply:SteamID().."\"")
code = string.Replace(code, "{player.steamID64}", "\""..ply:SteamID64().."\"")
code = string.Replace(code, "{player.name}", "\""..string.Replace(ply:Name(), "\"", "").."\"")
code = string.Replace(code, "{purchase.amount}", eventData.purchase_amount)

local errorMsg = RunString(code, "NoClipStoreCustomLuaAction", false)
if errorMsg then
Expand Down

0 comments on commit d266d4c

Please sign in to comment.