Raised This Month: $ Target: $400
 0% 

Converting Engine to Fakemeta (Entities)


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
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
 



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