Post by ShaunCraft15 on May 31, 2023 15:13:26 GMT
Hi Guys, i ask chatgpt for a amxmodx script that i can save my current postion on the current map for my alien plugin just i want to test it plz guys correct this code if he wrong
look at this code by chatgpt
look at this code by chatgpt
#include < amxmodx >
#include < engine >
#include < nvault >
const MAX_SAVED_POSITIONS = 10
new Float:g_savedPositions[MAX_SAVED_POSITIONS][3]
public plugin_init()
{
register_plugin("Save Position Menu", "1.0", "Your Name")
register_clcmd("say /savemappos", "Cmd_SaveMapPosition", ADMIN_MENU)
register_clcmd("say /loadmappos", "Cmd_LoadMapPosition", ADMIN_MENU)
load_saved_positions()
}
public Cmd_SaveMapPosition(id, params)
{
new index = GetFreePositionIndex()
if (index != -1)
{
new Float:pos[3]
entity_get_vector(id, EV_VEC_origin, pos)
g_savedPositions[index][0] = pos[0]
g_savedPositions[index][1] = pos[1]
g_savedPositions[index][2] = pos[2]
client_print(id, print_chat, "Position saved for the current map!")
save_saved_positions()
return PLUGIN_HANDLED
}
client_print(id, print_chat, "You have reached the maximum number of saved positions.")
return PLUGIN_HANDLED
}
public Cmd_LoadMapPosition(id, params)
{
new index = get_argc()
if (index == 2)
{
new position = get_arg(1)
new int:index = str_to_num(position)
if (index >= 0 && index < MAX_SAVED_POSITIONS)
{
new Float:pos[3]
pos[0] = g_savedPositions[index][0]
pos[1] = g_savedPositions[index][1]
pos[2] = g_savedPositions[index][2]
entity_set_vector(id, EV_VEC_origin, pos)
client_print(id, print_chat, "Position loaded from the saved positions!")
}
else
{
client_print(id, print_chat, "Invalid position index.")
}
}
else
{
client_print(id, print_chat, "Usage: /loadmappos <position>")
}
return PLUGIN_HANDLED
}
GetFreePositionIndex()
{
for (new i = 0; i < MAX_SAVED_POSITIONS; i++)
{
if (g_savedPositions[i][0] == 0.0 && g_savedPositions[i][1] == 0.0 && g_savedPositions[i][2] == 0.0)
{
return i
}
}
return -1
}
save_saved_positions()
{
new handle = nvault_open("configs/saved_positions.ini")
if (handle != INVALID_HANDLE)
{
new mapname[64]
get_mapname(mapname, sizeof(mapname))
nvault_set(handle, "mapname", mapname)
for (new i = 0; i < MAX_SAVED_POSITIONS; i++)
{
new Float:pos[3]
pos[0] = g_savedPositions[i][0]
pos[1] = g_savedPositions[i][1]
pos[2] = g_savedPositions[i][2]
new str[32]
format(str, sizeof(str), "%.3f %.3f %.3f", pos[0], pos[1], pos[2])
new key[32]
formatex(key, sizeof(key), "position_%d", i)
nvault_set(handle, key, str)
}
nvault_close(handle)
}
}
load_saved_positions()
{
new handle = nvault_open("configs/saved_positions.ini")
if (handle != INVALID_HANDLE)
{
new mapname[64]
get_mapname(mapname, sizeof(mapname))
if (stricmp(nvault_get(handle, "mapname", mapname, sizeof(mapname)), mapname) == 0)
{
for (new i = 0; i < MAX_SAVED_POSITIONS; i++)
{
new key[32]
formatex(key, sizeof(key), "position_%d", i)
new str[32]
if (nvault_get(handle, key, str, sizeof(str)) != 0)
{
new Float:pos[3]
sscanf(str, "%f %f %f", pos[0], pos[1], pos[2])
g_savedPositions[i][0] = pos[0]
g_savedPositions[i][1] = pos[1]
g_savedPositions[i][2] = pos[2]
}
}
}
nvault_close(handle)
}
}