Transformar esto
#1
Hola como haria para transformar esto

Código PHP:
#include <amxmodx>
#include <sqlx>
#include <cstrike>
#include <engine>
#include <fakemeta>

#define PLUGIN  "New Plug-In"
#define VERSION "1.0"
#define AUTHOR  "Sugisaki"

#define DB_HOST "127.0.0.1"
#define DB_USER "sugi"
#define DB_PASS "sugi"
#define DB_DB    "sugi"

#if AMXX_VERSION_NUM > 182
    #define client_disconnect client_disconnected
#endif

enum _:HATS_ENUM
{
    
H_NAME[32],
    
H_MDL[60],
    
H_COST
}

new 
g_hats[][HATS_ENUM] = 
{
    {
"Santa""models/hats/santa.mdl"5000}
}

new 
table1[] = "CREATE TABLE IF NOT EXISTS `hats_users` ( `user` VARCHAR(33) NOT NULL , `money` INT NOT NULL , `hats` VARCHAR(60) NOT NULL , PRIMARY KEY (`user`)) ENGINE = InnoDB;"

new Handle:g_con

new bool:hats_buyed[33][sizeof g_hats]
new 
ent_hat[33]
new 
g_menu

public plugin_init()
{
    
register_plugin(PLUGINVERSIONAUTHOR)
    
g_con SQL_MakeDbTuple(DB_HOSTDB_USERDB_PASSDB_DB)
    
db_con()
    
g_menu menu_create("\y Sombreros""mh_buy_hat")
    new 
temp[100]
    new 
cb menu_makecallback("mc_hats")
    for(new 
sizeof(g_hats) ; i++)
    {
        
formatex(tempcharsmax(temp), "%s \y[$%i]"g_hats[i][H_NAME], g_hats[i][H_COST])
        
menu_additem(g_menutemp""0cb)
    }
    
menu_setprop(g_menuMPROP_EXITMEXIT_ALL)
    
register_clcmd("say /buyhat""cmds_buyhat")
    
register_clcmd("say /hat""cmd_hats")
}
db_con()
{
    new 
error[60], errno
    SQL_Connect
(g_conerrnoerrorcharsmax(error))
    if(
errno)
    {
        
set_fail_state(error);
        return
    }
    
SQL_ThreadQuery(g_con"_table1"table1)
}
public 
_table1(failstateHandle:queryerror[], errnumdata[], sizeFloat:queuetime)
{
    if(
failstate != TQUERY_SUCCESS)
    {
        
log_amx("MYSQL ERROR: %i %s"errnumerror)
        return
    }
}
public 
plugin_precache()
{
    for(new 
sizeof(g_hats) ; i++)
    {
        
precache_model(g_hats[i][H_MDL])
    }
}
set_hat(idhat_id)
{
    if(
ent_hat[id] <= 0)
    {
        new 
ent create_entity("info_target")
        
ent_hat[id] = ent
        entity_set_string
(entEV_SZ_classname"player_hat")
        
entity_set_int(entEV_INT_movetypeMOVETYPE_FOLLOW)
        
entity_set_edict(entEV_ENT_aimentid)
        
entity_set_edict(entEV_ENT_ownerid)
    }
    if(
<= hat_id sizeof(g_hats))
    {
        
engfunc(EngFunc_SetModelent_hat[id], g_hats[hat_id][H_MDL])
    }
    else if(
is_valid_ent(ent_hat[id]) && hat_id 0)
    {
        
remove_entity(ent_hat[id])
        
ent_hat[id] = 0
    
}
}
public 
mc_hats(idmenuitem)
{

    if(
cs_get_user_money(id) < g_hats[item][H_COST] || hats_buyed[id][item])
    {
        return 
ITEM_DISABLED
    
}
    return 
ITEM_ENABLED
}
public 
mh_buy_hat(idmenuitem)
{
    if(
item == MENU_EXIT)
    {
        return
    }
    
set_hat(iditem)
    
hats_buyed[id][item] = true
}
public 
cmds_buyhat(id)
{
    
menu_display(idg_menu)
}
public 
cmd_hats(id)
{
    new 
menu menu_create("\rTus sombreros comprados""mh_hats")
    
menu_additem(menu"Sin Sombrero")
    new 
num[3]
    for(new 
sizeof(g_hats) ; i++)
    {
        if(!
hats_buyed[id][i])
        {
            continue
        }
        
num_to_str(inum2)
        
menu_additem(menug_hats[i][H_NAME], num)
    }
    
menu_setprop(menuMPROP_EXITMEXIT_ALL)
    
menu_display(idmenu)
}
public 
mh_hats(idmenuitem)
{
    if(
item == MENU_EXIT)
    {
        
menu_destroy(menu)
        return
    }
    if(
item == 0)
    {
        
set_hat(id, -1)
        
menu_destroy(menu)
        return
    }
    new 
info[3], a
    menu_item_getinfo
(menuitemainfo2""0a)
    
menu_destroy(menu)
    
set_hat(idstr_to_num(info))
}
public 
client_putinserver(id)
{
    
ent_hat[id] = 0
    
new authid[32]
    
get_user_authid(idauthidcharsmax(authid))
    new 
Query[128]
    new 
data[3]
    
data[0] = id
    formatex
(Querycharsmax(Query), "SELECT * FROM hats_users WHERE user='%s'"authid)
    
SQL_ThreadQuery(g_con"_get_data"Querydatacharsmax(data))
}
public 
_get_data(failstateHandle:queryerror[], errnumdata[], sizeFloat:queuetime)
{
    new 
id data[0]
    if(
failstate != TQUERY_SUCCESS)
    {
        
log_amx(error)
        return
    }
    if(
SQL_NumResults(query) > 0)
    {
        new 
hat_row[60], hat_id[6]
        
SQL_ReadResult(querySQL_FieldNameToNum(query"hats"), hat_rowcharsmax(hat_row))
        
cs_set_user_money(idSQL_ReadResult(querySQL_FieldNameToNum(query"money")))
        
trim(hat_row)
        if(!
hat_row[0])
        {
            return
        }
        
        new 
count 0
        
new len strlen(hat_row)
        new 
i
        
for(len i++)
        {
            if(
hat_row[i] == ',')
            {
                
count += 1
            
}
        }
        for(
<= count i++)
        {
            
strtok(hat_rowhat_idcharsmax(hat_id), hat_rowcharsmax(hat_row), ','1)
            
hats_buyed[id][str_to_num(hat_id)] = true
        
}
    }
    else
    {
        new 
authid[32]
        
get_user_authid(idauthidcharsmax(authid))
        new 
Query[128]
        
formatex(Querycharsmax(Query), "INSERT INTO `hats_users` (`user`) VALUES ('%s')"authid)
        
SQL_ThreadQuery(g_con"_insert_player"Query)
    }
}
public 
_insert_player(failstateHandle:queryerror[], errnumdata[], sizeFloat:queuetime)
{
    if(
failstate != TQUERY_SUCCESS)
    {
        
log_amx(error)
        return
    }
}
public 
client_disconnect(id)
{
    if(
is_valid_ent(ent_hat[id]))
    {
        
remove_entity(ent_hat[id])
        
ent_hat[id] = 
    
}
    new 
authid[32]
    
get_user_authid(idauthidcharsmax(authid))
    new 
Query[128]
    new 
hats[20]
    for(new 
sizeof(g_hats) ; i++)
    {
        if(
hats_buyed[id][i])
        {
            
format(hatscharsmax(hats), "%s,"i)
        }
    }
    
formatex(Querycharsmax(Query), "UPDATE `hats_users` SET `money` = '%i', `hats` = '%s' WHERE `user` = '%s';"cs_get_user_money(id), hatsauthid)
    
SQL_ThreadQuery(g_con"_update_player"Query)
}
public 
_update_player(failstateHandle:queryerror[], errnumdata[], sizeFloat:queuetime)
{
    if(
failstate != TQUERY_SUCCESS)
    {
        
log_amx(error)
        return
    }


A que en vez de guardar Hats, guarde models? un saludo a todos y gracias por la ayuda Excitedeyes
Responder
#2
No comprendí, explayate ...

Saludos,
cLAANS.-
Mi unico plugin.
Tutorial de niveles.

Ayudo, pero no de la manera que quieren, si quieren aprender les servirá lo mio, para pedir el codigo en bandeja tienen la sección 'Pedidos'

(09/11/2017, 09:30 PM)SoundBlaster escribió: Espera y llamo a los power rangers para que me digan la linea de error
Responder
#3
cambia la forma del hat, a models salu2
[Imagen: zcsztw-4.png] [Imagen: 6u5fj2-4.png]
[Imagen: linkedin_thumb_image.png][Imagen: 76561198283253977.png][Imagen: linkedin_thumb_image.png]
Responder
#4
(10/03/2018, 03:02 PM)Hypnotize escribió: cambia la forma del hat, a models salu2

Si, si, eso, esta guardando hats, pero yo quiero usar models de jugador, traje completo, no solo para la cabeza.
Responder
#5
Ahora entendí lo que deseas.

Deberás cambiar varias cosas, yo te voy a dar un empujón pero deberás llegar solo a la cima.

Cualquier duda pregunta por este medio (Dejo los nombres del plugin original para evitar que te confundas/pierdas)

Lo que si tenes un posible problema.

En caso de que tengas varios jugadores cambiándose el model, deberás utilizar la API para evitar que se caiga tu servidor.

https://forums.alliedmods.net/showthread.php?t=161255

Código PHP:
/*
    - Lo que haremos primero que nada, es cambiar el model a utilizar
    - Dado que vamos a cambiar el model de un jugador, deberemos utilizar el model de otra manera
    - Tanto para usarlo, como para precachearlo
*/

new g_hats[][HATS_ENUM] = 
{
    {
"Santa""models/hats/santa.mdl"5000}
}

// ---->

new g_hats[][HATS_ENUM] = 
{
    {
"Santa""jugadormodel1"5000}



Código PHP:
/*
    - Cambiaremos la manera de precachear el model
    - Para esto utilizaremos un "format, formatex" para concatenar 
*/

public plugin_precache()
{
    for(new 
sizeof(g_hats) ; i++)
    {
        
precache_model(g_hats[i][H_MDL])
    }
}

// ---------->

public plugin_precache()
{
    new 
iDataModel300 ], iLen;
    
    for(new 
sizeof(g_hats) ; i++)
    {
            
formatiDataModelcharsmaxiDataModel ), "models/player/%s/%s.mdl"g_hats][ H_MDL ], g_hats][ H_MDL ] );

        
precache_modeliDataModel )
    }


Código PHP:
/*
    - Ya que no utilizaremos mas gorros algunas funciones ya no son requeridas
*/

public client_disconnect(id)
{
    
// Borrar esto 
    
if(is_valid_ent(ent_hat[id]))
    {
        
remove_entity(ent_hat[id])
        
ent_hat[id] = 
    
}


Código PHP:
/*
    - Como te comente anteriormente, algunas funciones y/o acciones no son requeridas y aca tenemos otro claro ejemplo
*/

set_hat(idhat_id)
{
    if(
ent_hat[id] <= 0)
    {
        new 
ent create_entity("info_target")
        
ent_hat[id] = ent
        entity_set_string
(entEV_SZ_classname"player_hat")
        
entity_set_int(entEV_INT_movetypeMOVETYPE_FOLLOW)
        
entity_set_edict(entEV_ENT_aimentid)
        
entity_set_edict(entEV_ENT_ownerid)
    }
    if(
<= hat_id sizeof(g_hats))
    {
        
engfunc(EngFunc_SetModelent_hat[id], g_hats[hat_id][H_MDL])
    }
    else if(
is_valid_ent(ent_hat[id]) && hat_id 0)
    {
        
remove_entity(ent_hat[id])
        
ent_hat[id] = 0
    
}
}

// ----------->

set_hat(idhat_id)
{
    
cs_set_user_modelidg_hatshat_id ][ H_MDL ] )


(10/03/2018, 03:02 PM)Hypnotize escribió: cambia la forma del hat, a models salu2

Deberías dejar de dar respuestas de mierdas y/o incompletas, lo único que hacen es confundir je

Saludos,
cLAANS.-
Mi unico plugin.
Tutorial de niveles.

Ayudo, pero no de la manera que quieren, si quieren aprender les servirá lo mio, para pedir el codigo en bandeja tienen la sección 'Pedidos'

(09/11/2017, 09:30 PM)SoundBlaster escribió: Espera y llamo a los power rangers para que me digan la linea de error
Responder
#6
(10/03/2018, 03:35 PM)cLAANS escribió: Ahora entendí lo que deseas.

Deberás cambiar varias cosas, yo te voy a dar un empujón pero deberás llegar solo a la cima.

Cualquier duda pregunta por este medio (Dejo los nombres del plugin original para evitar que te confundas/pierdas)

Lo que si tenes un posible problema.

En caso de que tengas varios jugadores cambiándose el model, deberás utilizar la API para evitar que se caiga tu servidor.

https://forums.alliedmods.net/showthread.php?t=161255

Código PHP:
/*
    - Lo que haremos primero que nada, es cambiar el model a utilizar
    - Dado que vamos a cambiar el model de un jugador, deberemos utilizar el model de otra manera
    - Tanto para usarlo, como para precachearlo
*/

new g_hats[][HATS_ENUM] = 
{
    {
"Santa""models/hats/santa.mdl"5000}
}

// ---->

new g_hats[][HATS_ENUM] = 
{
    {
"Santa""jugadormodel1"5000}



Código PHP:
/*
    - Cambiaremos la manera de precachear el model
    - Para esto utilizaremos un "format, formatex" para concatenar 
*/

public plugin_precache()
{
    for(new 
sizeof(g_hats) ; i++)
    {
        
precache_model(g_hats[i][H_MDL])
    }
}

// ---------->

public plugin_precache()
{
    new 
iDataModel300 ], iLen;
    
    for(new 
sizeof(g_hats) ; i++)
    {
            
formatiDataModelcharsmaxiDataModel ), "models/player/%s/%s.mdl"g_hats][ H_MDL ], g_hats][ H_MDL ] );

        
precache_modeliDataModel )
    }


Código PHP:
/*
    - Ya que no utilizaremos mas gorros algunas funciones ya no son requeridas
*/

public client_disconnect(id)
{
    
// Borrar esto 
    
if(is_valid_ent(ent_hat[id]))
    {
        
remove_entity(ent_hat[id])
        
ent_hat[id] = 
    
}


Código PHP:
/*
    - Como te comente anteriormente, algunas funciones y/o acciones no son requeridas y aca tenemos otro claro ejemplo
*/

set_hat(idhat_id)
{
    if(
ent_hat[id] <= 0)
    {
        new 
ent create_entity("info_target")
        
ent_hat[id] = ent
        entity_set_string
(entEV_SZ_classname"player_hat")
        
entity_set_int(entEV_INT_movetypeMOVETYPE_FOLLOW)
        
entity_set_edict(entEV_ENT_aimentid)
        
entity_set_edict(entEV_ENT_ownerid)
    }
    if(
<= hat_id sizeof(g_hats))
    {
        
engfunc(EngFunc_SetModelent_hat[id], g_hats[hat_id][H_MDL])
    }
    else if(
is_valid_ent(ent_hat[id]) && hat_id 0)
    {
        
remove_entity(ent_hat[id])
        
ent_hat[id] = 0
    
}
}

// ----------->

set_hat(idhat_id)
{
    
cs_set_user_modelidg_hatshat_id ][ H_MDL ] )


(10/03/2018, 03:02 PM)Hypnotize escribió: cambia la forma del hat, a models salu2

Deberías dejar de dar respuestas de mierdas y/o incompletas, lo único que hacen es confundir je

Saludos,
cLAANS.-

Gracias por tu tiempo, probare y te comento como me va todo

Edit: Funciono, muchas gracias, todo bien por ahora, solo unos detalles, ojala me puedas ayudar..

Código PHP:
public cmd_hats(id)
{
    new 
menu menu_create("Menu""mh_hats")
    
menu_additem(menu"Sin Sombrero")
    new 
num[3]
    for(new 
sizeof(g_hats) ; i++)
    {
        if(!
hats_buyed[id][i])
        {
            continue
        }
        
num_to_str(inum2)
        
menu_additem(menug_hats[i][H_NAME], num)
    }
    
menu_setprop(menuMPROP_EXITMEXIT_ALL)
    
menu_display(idmenu)


En ese public, la opcion "Sin Sombrero" se supone que quita el model actual seleccionado, pero no hace nada, alguna manera de solucionarlo?

Otra cosa, Como podria hacer que al tener equipado un model, se indique en el menu cual tiene equipado?

Muchas gracias
Responder
#7
(10/03/2018, 03:35 PM)cLAANS escribió:
(10/03/2018, 03:02 PM)Hypnotize escribió: cambia la forma del hat, a models salu2

Deberías dejar de dar respuestas de mierdas y/o incompletas, lo único que hacen es confundir je

Saludos,
cLAANS.-
pues deberías empezar a usarlo tu mismo, ja. Whatever

---

es por esto

if(item == 0)
{
set_hat(id, -1)
menu_destroy(menu)
return
}
si apachas 0 manda -1, agrega en set_hat un chequeo si es -1 lo remueva
[Imagen: zcsztw-4.png] [Imagen: 6u5fj2-4.png]
[Imagen: linkedin_thumb_image.png][Imagen: 76561198283253977.png][Imagen: linkedin_thumb_image.png]
Responder
#8
Otra cosa, parece que tiene una falencia el plugin (no encontre otro de este tipo) y no guarda bien ;(, al hacer retry o cualquier accion de salir y entrar al servidor te vuelve a lo que tenias antes Whatever
Responder


Salto de foro:


Usuarios navegando en este tema: 1 invitado(s)