|
Veteran Member
Join Date: Jan 2006
Location: It's a mystery.
|

10-23-2007
, 07:10
Converting Engine to Fakemeta (Entities)
|
#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] != 0 ) {
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] == 0 ) {
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] != 0 ) {
new Float:PlayerOrigin[3];
pev(id, pev_origin, PlayerOrigin)
new flare = engfunc(EngFunc_CreateNamedEntity,engfunc(EngFunc_AllocString,"classname"))
set_pev(flare, pev_classname, "Flare")
engfunc(EngFunc_SetModel, flare, "models/w_flare.mdl")
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]--;
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] == 0 ) {
client_print(id,print_chat,"[FLARE-X] You are out of flares.");
}
}
return PLUGIN_HANDLED;
}
//---------------------------------------------------------------//
public RemoveFlare(flare) engfunc(EngFunc_RemoveEntity, flare)
__________________
It's a mystery.
|
|