Raised This Month: $ Target: $400
 0% 

Converting Engine to Fakemeta (Entities)


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Mini_Midget
Veteran Member
Join Date: Jan 2006
Location: It's a mystery.
Old 10-23-2007 , 07:10   Converting Engine to Fakemeta (Entities)
Reply With Quote #1

I'm using the flares plugin (http://forums.alliedmods.net/showthr...ighlight=flare)
as my example.

I just wanna learn a bit more about fakemeta so that is why I'm trying to convert small plugins.
I cut out all the crap which I don't want and got this.
This still works with no (compile) errors.
PHP Code:
#include <amxmodx> 
#include <amxmisc> 
#include <cstrike>
#include <engine> 

new FlareAmmo[33]; 

//---------------------------------------------------------------//
public plugin_init() { 
    
register_plugin("Flares","1.3","Calzinger"); 
    
    
    
register_cvar("flare_cost","400"); 
    
register_cvar("flare_max","5"); 
    
register_cvar("flare_duration","10.0"); 
    
register_cvar("flare_start","10"); 
    
    
register_clcmd("say /buyflare","AddFlare",0,": Buy a flare"); 
    
register_clcmd("shootflare","InitFlare",0,": Shoot a flare"); 
    
register_clcmd("say /shootflare","InitFlare",0,": Shoot a flare"); 

//---------------------------------------------------------------//
public plugin_precache() { 
    
precache_sound("weapons/rocketfire1.wav"); 
    
precache_model("models/w_flare.mdl"); 

//---------------------------------------------------------------//
public client_connect(id) { 
    
FlareAmmo[id] = 0

//---------------------------------------------------------------//
public client_disconnect(id) { 
    
FlareAmmo[id] = 0

//---------------------------------------------------------------//
public AddFlare(id) { 
    new 
cost get_cvar_num("flare_cost"); 
    new 
Max get_cvar_num("flare_max"); 
    if ( 
cs_get_user_money(id) < cost ) { 
        
client_print(id,print_chat,"[FLARE-X] You do not have enough money to buy a flare. You need $%i.",cost); 
    } 
    else if ( 
cs_get_user_money(id) >= cost ) { 
        if ( 
FlareAmmo[id] >= Max ) { 
            
client_print(id,print_chat,"[FLARE-X] You have your max number of flares: %i.",Max); 
        } 
        else if ( 
FlareAmmo[id] < Max ) { 
            
cs_set_user_money(id,cs_get_user_money(id) - cost); 
            
FlareAmmo[id]++; 
            
client_print(id,print_chat,"[FLARE-X] You have bought one flare for $%i. Now you have %i flares.",cost,FlareAmmo[id]); 
        } 
    } 
    return   
PLUGIN_HANDLED


//---------------------------------------------------------------//
public InitFlare(id) { 
    if (
is_user_alive(id)) { 
        if ( 
FlareAmmo[id] != ) { 
            
            new 
Float:PlayerOrigin[3]; 
            
entity_get_vector(id,EV_VEC_origin,PlayerOrigin); 
            
            new 
flare create_entity("info_target"); 
            
entity_set_string(flare,EV_SZ_classname,"Flare"); 
            
entity_set_model(flare,"models/w_flare.mdl"); 
            
entity_set_origin(flare,PlayerOrigin); 
            
            
entity_set_int(flare,EV_INT_solid,2); 
            
entity_set_edict(flare,EV_ENT_owner,id); 
            
            
entity_set_int(flare,EV_INT_movetype,4); 
            
entity_set_float(flare,EV_FL_gravity,0.5); 
            
            
entity_set_int(flare,EV_INT_effects,4); 
            
            new 
Float:PlayerVelocity[3]; 
            
VelocityByAim(id,1000,PlayerVelocity); 
            
            
entity_set_vector(flare,EV_VEC_velocity,PlayerVelocity); 
            
            
FlareAmmo[id]--; 
            
emit_sound(id,CHAN_BODY,"weapons/rocketfire1.wav",1.0,ATTN_NORM,0,PITCH_NORM); 
            
            
set_task(get_cvar_float("flare_duration"),"RemoveFlare",flare); 
        } 
        else if ( 
FlareAmmo[id] == ) { 
            
client_print(id,print_chat,"[FLARE-X] You are out of flares."); 
        } 
    } 
    return   
PLUGIN_HANDLED


//---------------------------------------------------------------//
public RemoveFlare(flare) { 
    
remove_entity(flare); 
    return   
PLUGIN_CONTINUE


Now this is what I did to convert it to fakemeta
This does not work but compiles and gives me no errors ingame.
The problem is that the flare isn't made even though it deducts the my flare ammo.

PHP Code:
#include <amxmodx> 
#include <amxmisc> 
#include <cstrike>
#include <fakemeta>
//#include <engine> 

new FlareAmmo[33]; 

//---------------------------------------------------------------//
public plugin_init() { 
    
register_plugin("Flares","1.3","Calzinger"); 
        
    
register_cvar("flare_cost","400"); 
    
register_cvar("flare_max","5"); 
    
register_cvar("flare_duration","10.0"); 
    
register_cvar("flare_start","10"); 
    
    
register_clcmd("say /buyflare","AddFlare",0,": Buy a flare"); 
    
register_clcmd("shootflare","InitFlare",0,": Shoot a flare"); 
    
register_clcmd("say /shootflare","InitFlare",0,": Shoot a flare"); 
    

//---------------------------------------------------------------//
public plugin_precache() { 
    
precache_sound("weapons/rocketfire1.wav"); 
    
precache_model("models/w_flare.mdl"); 

//---------------------------------------------------------------//
public client_connect(id) { 
    
FlareAmmo[id] = 0

//---------------------------------------------------------------//
public client_disconnect(id) { 
    
FlareAmmo[id] = 0

//---------------------------------------------------------------//
public AddFlare(id) { 
    new 
cost get_cvar_num("flare_cost"); 
    new 
Max get_cvar_num("flare_max"); 
    if ( 
cs_get_user_money(id) < cost ) { 
        
client_print(id,print_chat,"[FLARE-X] You do not have enough money to buy a flare. You need $%i.",cost); 
    } 
    else if ( 
cs_get_user_money(id) >= cost ) { 
        if ( 
FlareAmmo[id] >= Max ) { 
            
client_print(id,print_chat,"[FLARE-X] You have your max number of flares: %i.",Max); 
        } 
        else if ( 
FlareAmmo[id] < Max ) { 
            
cs_set_user_money(id,cs_get_user_money(id) - cost); 
            
FlareAmmo[id]++; 
            
client_print(id,print_chat,"[FLARE-X] You have bought one flare for $%i. Now you have %i flares.",cost,FlareAmmo[id]); 
        } 
    } 
    return   
PLUGIN_HANDLED

//---------------------------------------------------------------//
public InitFlare(id) { 
    if (
is_user_alive(id)) { 
        if ( 
FlareAmmo[id] != ) { 
            
            new 
Float:PlayerOrigin[3]; 
            
pev(idpev_originPlayerOrigin)
            
            new 
flare engfunc(EngFunc_CreateNamedEntity,engfunc(EngFunc_AllocString,"classname"))
            
set_pev(flarepev_classname"Flare")
            
engfunc(EngFunc_SetModelflare"models/w_flare.mdl"
            
            
engfunc(EngFunc_SetOriginflarePlayerOrigin)
            
set_pev(flarepev_solidSOLID_BBOX)
            
set_pev(flarepev_ownerid)
            
set_pev(flarepev_movetypeMOVETYPE_STEP)
            
set_pev(flarepev_gravity0.5)
            
set_pev(flarepev_effectsEF_BRIGHTLIGHT)
            
            new 
Float:PlayerVelocity[3]; 
            
velocity_by_aim(id,1000,PlayerVelocity); 
            
set_pev(flarepev_velocityPlayerVelocity)
            
            
FlareAmmo[id]--; 
            
emit_sound(id,CHAN_BODY,"weapons/rocketfire1.wav",1.0,ATTN_NORM,0,PITCH_NORM); 
            
            
set_task(get_cvar_float("flare_duration"),"RemoveFlare",flare); 
        } 
        else if ( 
FlareAmmo[id] == ) { 
            
client_print(id,print_chat,"[FLARE-X] You are out of flares."); 
        } 
    } 
    return   
PLUGIN_HANDLED


//---------------------------------------------------------------//
public RemoveFlare(flareengfunc(EngFunc_RemoveEntityflare
__________________
It's a mystery.
Mini_Midget is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 10-23-2007 , 10:08   Re: Converting Engine to Fakemeta (Entities)
Reply With Quote #2

I didn't use your conversion and it works so i couln't tell you what's wrong, may be something with the strings, i declare them as global const.

Also you don't need cstrike module, and you don't need a task to make the flare die.

Code:
#include <amxmodx> #include <fakemeta> #pragma semicolon 1 #define OFFSET_CSMONEY  115 new const FLARE_CLASSNAME[] = "Flare"; new const FLARE_MODEL[] = "models/w_flare.mdl"; new const FLARE_SOUND[] = "weapons/rocketfire1.wav"; new FlareAmmo[33]; new pcvar_flare_cost, pcvar_flare_max, pcvar_flare_duration; new gmsgMoney; public plugin_init() {     register_plugin("Flares","2.0","Calzinger");     pcvar_flare_cost = register_cvar("flare_cost","400");     pcvar_flare_max = register_cvar("flare_max","5");     pcvar_flare_duration = register_cvar("flare_duration","10.0");     register_forward(FM_Think,"fwdThink");     register_clcmd("say /buyflare","AddFlare",0,": Buy a flare");     register_clcmd("shootflare","InitFlare",0,": Shoot a flare");     register_clcmd("say /shootflare","InitFlare",0,": Shoot a flare");     gmsgMoney = get_user_msgid("Money"); } public plugin_precache() {     engfunc(EngFunc_PrecacheModel, FLARE_MODEL);     engfunc(EngFunc_PrecacheSound, FLARE_SOUND); } public client_putinserver(id) {     FlareAmmo[id] = 0; } public AddFlare(id) {     new cost = get_pcvar_num(pcvar_flare_cost);     new Max = get_pcvar_num(pcvar_flare_max);     new Money = __cs_get_user_money(id);     if ( Money < cost ) {         client_print(id,print_chat,"[FLARE-X] You do not have enough money to buy a flare. You need $%i.",cost);     }     else {         if ( FlareAmmo[id] >= Max ) {             client_print(id,print_chat,"[FLARE-X] You have your max number of flares: %i.",Max);         }         else {             __cs_set_user_money(id, Money - cost);             FlareAmmo[id]++;             client_print(id,print_chat,"[FLARE-X] You have bought one flare for $%i. Now you have %i flares.",cost,FlareAmmo[id]);         }     }     return PLUGIN_HANDLED; } public InitFlare(id) {     if (!is_user_alive(id))         return PLUGIN_HANDLED;       if ( !FlareAmmo[id] )     {         client_print(id,print_chat,"[FLARE-X] You are out of flares.");         return PLUGIN_HANDLED;     }     new Float:PlayerOrigin[3];     pev(id,pev_origin,PlayerOrigin);     new flare = engfunc(EngFunc_CreateNamedEntity, engfunc(EngFunc_AllocString, "info_target"));     set_pev(flare, pev_classname, FLARE_CLASSNAME);     engfunc(EngFunc_SetModel, flare, FLARE_MODEL);     engfunc(EngFunc_SetOrigin,flare, PlayerOrigin);     set_pev(flare, pev_solid, SOLID_BBOX);     set_pev(flare,pev_owner,id);     set_pev(flare,pev_movetype,MOVETYPE_STEP);     set_pev(flare,pev_gravity,0.5);     set_pev(flare,pev_effects,EF_BRIGHTLIGHT);     new Float:PlayerVelocity[3];     velocity_by_aim(id,1000,PlayerVelocity);     set_pev(flare, pev_velocity, PlayerVelocity);     FlareAmmo[id]--;     engfunc(EngFunc_EmitSound, flare, CHAN_BODY, FLARE_SOUND, VOL_NORM, ATTN_NORM, 0, PITCH_NORM);     set_pev(flare, pev_nextthink, get_gametime() + get_pcvar_float(pcvar_flare_duration));     return PLUGIN_HANDLED; } public fwdThink(ent) {     if(!pev_valid(ent))         return FMRES_IGNORED;     static classname[33];     pev(ent, pev_classname, classname, sizeof classname - 1);     if(!equal(classname,FLARE_CLASSNAME))         return FMRES_IGNORED;     engfunc(EngFunc_RemoveEntity, ent);     return FMRES_IGNORED; } __cs_get_user_money(index) {     return get_pdata_int(index, OFFSET_CSMONEY); } __cs_set_user_money(index, money, flash = 1) {     set_pdata_int(index, OFFSET_CSMONEY, money);     message_begin(MSG_ONE, gmsgMoney, _, index);     write_long(money);     write_byte(flash ? 1 : 0);     message_end(); }

Last edited by ConnorMcLeod; 10-23-2007 at 10:23.
ConnorMcLeod is offline
Mini_Midget
Veteran Member
Join Date: Jan 2006
Location: It's a mystery.
Old 10-28-2007 , 06:42   Re: Converting Engine to Fakemeta (Entities)
Reply With Quote #3

Oh sweet. It works 100% and makes the flare and stuff.
Tested this on a listenserver (I use non steam CS 1.6 btw only for testing things)
But it seems like when I upload it to my HLDS server...
When I type /flare. It doesn't work 100%... I walked around the map spamming my /flare cmd and at some locations of the map it works? But at other places I can just hear the wave file with no flare made.

Any ideas? Can you test it on your HLDS server?
__________________
It's a mystery.
Mini_Midget is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 10-28-2007 , 06:54   Re: Converting Engine to Fakemeta (Entities)
Reply With Quote #4

Well, do you know a specific place on a specific map (default map please).
I've tested on as_oilrig as it's a dark map and it worked fine...
ConnorMcLeod is offline
Mini_Midget
Veteran Member
Join Date: Jan 2006
Location: It's a mystery.
Old 10-28-2007 , 07:19   Re: Converting Engine to Fakemeta (Entities)
Reply With Quote #5

de_dust2
Next to the big box by the stairs in B tunnel.
Ramps in bombsite A and some other corners.

Maybe this will help...
I use Windows XP SP 3 (Is that the latest one? I forgot...)
I'm guessing you use linux or something...
__________________
It's a mystery.
Mini_Midget is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 01:19.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode