19/07/2018, 01:02 AM
Pues, viendo que algunos aqui me han avanzado en su aprendizaje de pawn pues yo me puse en lo mismo a practicar, y pues queria saber si estaban bien echas estas funciones queno se usar mucho (por eso me puse a practicarlas)
Estoy armando una tienda (Nada para publicar solo practicar)
ahora quiero saber unas cosillas xD:
1.-que diferencia tiene este evento del otro
2.-Esta bien seteado el task y el bucle del round star?
seteo y bucle:
3.-Esta bien removido el task?:
y pues lo que mas dificil se me hacia el uso de una variable con array
pues es lo mas largo,
Pues al saber esto ya tendría mi base (Bien formada) de scripting
Estoy armando una tienda (Nada para publicar solo practicar)
Código PHP:
#include <amxmodx>
#include <amxmisc>
#include <cstrike>
// include fakemeta;
#define PLUGIN "New Plug-In"
#define VERSION "1.0"
#define AUTHOR "author"
new max_players, g_uso[33][4];
enum {
nombre[40],
costo,
extra_item
}
new const item[][extra_item] = {
{ "opcion 1", 500 }
{ "Opcion 2", 400 }
{ "opcion 3", 300 }
{ "opcion 4", 200 }
}
public plugin_init() {
register_plugin(PLUGIN, VERSION, AUTHOR)
register_logevent("Round_Start", "RoundStart", 2, "1=RoundStart")
register_event("HLTV", "Round_Start", 2, "1=RoundStart")
max_players = get_maxplayers
register_clcmd("say /tienda", "CmdTienda")
}
public Round_Start()
{
new i[33];
for( i = 1; 1 < max_players; i++)
{
set_task(15.0, "CmdTienda", i)
g_uso[i][0] = false;
g_uso[i][1] = false;
g_uso[i][2] = false;
g_uso[i][3] = false;
}
}
public CmdTienda(id)
{
new len[200]
new menu = menu_create("Tienda simple", "HandlerTienda")
formatex(len, charsmax(len), "%s $%d", item[0][nombre], item[0][costo])
menu_additem(menu, len, "1")
formatex(len, charsmax(len), "%s $%d", item[1][nombre], item[1][costo])
menu_additem(menu, len, "2")
formatex(len, charsmax(len), "%s $%d", item[2][nombre], item[2][costo])
menu_additem(menu, len, "3")
formatex(len, charsmax(len), "%s $%d", item[3][nombre], item[3][costo])
menu_display(id, menu, 0)
return PLUGIN_HANDLED;
}
public Handlertienda(id, menu, item)
{
if(item == MENU_EXIT)
{
menu_destroy(menu)
return PLUGIN_HANDLED;
}
if(!is_user_alive(id))
{
client_print(id, print_chat, "Debes estar vivo para habrir el menu")
return PLUGIN_HANDLED;
}
switch(item)
{
case 0:
{
if(cs_get_user_money < item[0][costo])
{
client_print(id, print_chat, "No te alcanza")
return PLUGIN_HANDLED;
}
else
{
if(g_uso[id][0] = false)
{
client_print(id, print_chat, "%s $%d", item[0][nombre], item[0][costo])
cs_set_user_money(id, cs_get_user_money(id) - item[0][costo])
g_uso[id][0] = true
return PLUGIN_HANDLED;
}
else
{
client_print(id, print_chat, "Ya haz comprado este item durante la ronda")
return PLUGIN_HANDLED;
}
}
}
case 1:
{
if(cs_get_user_money < item[1][costo])
{
client_print(id, print_chat, "No te alcanza")
return PLUGIN_HANDLED;
}
else
{
if(g_uso[id][1] = false)
{
client_print(id, print_chat, "%s $%d", item[1][nombre], item[1][costo])
cs_set_user_money(id, get_user_money(id) - item[1][costo])
g_uso[id][1] = true
return PLUGIN_HANDLED;
}
else
{
client_print(id, print_chat, "Ya haz comprado este item durante la ronda")
return PLUGIN_HANDLED;
}
}
case 2:
{
if(cs_get_user_money(id) < item[2][costo])
{
client_print(id, print_chat, "No te alcanza")
return PLUGIN_HANDLED;
}
else
{
if(g_uso[id][2] = false)
{
client_print(id, print_chat, "%s $%d", item[2][nombre], item[2][costo])
cs_set_user_money(id, cs_get_user_money(id) - item[2][costo])
g_uso[id][2] = true
return PLUGIN_HANDLED;
}
else
{
client_print(id, print_chat, "Ya haz comprado este item durante la ronda")
return PLUGIN_HANDLED;
}
}
}
case 3:
{
if(cs_get_user_money(id) < item[3][costo])
{
client_print(id, print_chat, "No te alcanza")
return PLUGIN_HANDLED;
}
else
{
if(g_uso[id][3] = false)
{
client_print(id, print_chat, "%s $%d", item[3][nombre], item[3][costo])
cs_set_user_money(id, cs_get_user_money(id) - item[3][costo])
g_uso[id][3] = true
return PLUGIN_HANDLED;
}
else
{
client_print(id, print_chat, "Ya haz comprado este item durante la ronda")
return PLUGIN_HANDLED;
}
}
}
}
return PLUGIN_HANDLED;
}
public client_disconnect(id)
{
remove_task(id)
}
ahora quiero saber unas cosillas xD:
1.-que diferencia tiene este evento del otro
Código PHP:
register_logevent("Round_Start", "RoundStart", 2, "1=RoundStart") //evento 1
register_event("HLTV", "Round_Start", 2, "1=RoundStart") // evento 2
2.-Esta bien seteado el task y el bucle del round star?
seteo y bucle:
Código PHP:
public Round_Start()
{
new i[33];
for( i = 1; 1 < max_players; i++)
{
set_task(15.0, "CmdTienda", i)
g_uso[i][0] = false;
g_uso[i][1] = false;
g_uso[i][2] = false;
g_uso[i][3] = false;
}
}
3.-Esta bien removido el task?:
Código PHP:
public client_disconnect(id)
{
remove_task(id)
}
y pues lo que mas dificil se me hacia el uso de una variable con array
pues es lo mas largo,
creacion de la variable:
Código PHP:
enum {
nombre[40],
costo,
extra_item
}
new const item[][extra_item] = {
{ "opcion 1", 500 }
{ "Opcion 2", 400 }
{ "opcion 3", 300 }
{ "opcion 4", 200 }
}
Seteo de la variable en el menu
Código PHP:
public CmdTienda(id)
{
new len[200]
new menu = menu_create("Tienda simple", "HandlerTienda")
formatex(len, charsmax(len), "%s $%d", item[0][nombre], item[0][costo])
menu_additem(menu, len, "1")
formatex(len, charsmax(len), "%s $%d", item[1][nombre], item[1][costo])
menu_additem(menu, len, "2")
formatex(len, charsmax(len), "%s $%d", item[2][nombre], item[2][costo])
menu_additem(menu, len, "3")
formatex(len, charsmax(len), "%s $%d", item[3][nombre], item[3][costo])
menu_display(id, menu, 0)
return PLUGIN_HANDLED;
}
Uso de la variable en el handler, en el checkeo de dinero y en los mensajes.
Código PHP:
public Handlertienda(id, menu, item)
{
if(item == MENU_EXIT)
{
menu_destroy(menu)
return PLUGIN_HANDLED;
}
if(!is_user_alive(id))
{
client_print(id, print_chat, "Debes estar vivo para habrir el menu")
return PLUGIN_HANDLED;
}
switch(item)
{
case 0:
{
if(cs_get_user_money < item[0][costo])
{
client_print(id, print_chat, "No te alcanza")
return PLUGIN_HANDLED;
}
else
{
if(g_uso[id][0] = false)
{
client_print(id, print_chat, "%s $%d", item[0][nombre], item[0][costo])
cs_set_user_money(id, cs_get_user_money(id) - item[0][costo])
g_uso[id][0] = true
return PLUGIN_HANDLED;
}
else
{
client_print(id, print_chat, "Ya haz comprado este item durante la ronda")
return PLUGIN_HANDLED;
}
}
}
case 1:
{
if(cs_get_user_money < item[1][costo])
{
client_print(id, print_chat, "No te alcanza")
return PLUGIN_HANDLED;
}
else
{
if(g_uso[id][1] = false)
{
client_print(id, print_chat, "%s $%d", item[1][nombre], item[1][costo])
cs_set_user_money(id, get_user_money(id) - item[1][costo])
g_uso[id][1] = true
return PLUGIN_HANDLED;
}
else
{
client_print(id, print_chat, "Ya haz comprado este item durante la ronda")
return PLUGIN_HANDLED;
}
}
case 2:
{
if(cs_get_user_money(id) < item[2][costo])
{
client_print(id, print_chat, "No te alcanza")
return PLUGIN_HANDLED;
}
else
{
if(g_uso[id][2] = false)
{
client_print(id, print_chat, "%s $%d", item[2][nombre], item[2][costo])
cs_set_user_money(id, cs_get_user_money(id) - item[2][costo])
g_uso[id][2] = true
return PLUGIN_HANDLED;
}
else
{
client_print(id, print_chat, "Ya haz comprado este item durante la ronda")
return PLUGIN_HANDLED;
}
}
}
case 3:
{
if(cs_get_user_money(id) < item[3][costo])
{
client_print(id, print_chat, "No te alcanza")
return PLUGIN_HANDLED;
}
else
{
if(g_uso[id][3] = false)
{
client_print(id, print_chat, "%s $%d", item[3][nombre], item[3][costo])
cs_set_user_money(id, cs_get_user_money(id) - item[3][costo])
g_uso[id][3] = true
return PLUGIN_HANDLED;
}
else
{
client_print(id, print_chat, "Ya haz comprado este item durante la ronda")
return PLUGIN_HANDLED;
}
}
}
}
return PLUGIN_HANDLED;
}
Pues al saber esto ya tendría mi base (Bien formada) de scripting
Si no te gusta algo, cámbialo. Si no lo puedes cambiar, cambia la forma en que piensas sobre ello <3