AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Help Model Precaching (https://forums.alliedmods.net/showthread.php?t=112839)

laziboi72 12-21-2009 14:17

Help Model Precaching
 
This code complies with no error/warnings its just that When I use this plugin cs1.6 works fine and I am able to get the "gun menu" to appear but the moment I select a weapon from the menu the game crashes and tells me that my models aren't precached... but i did include all the models in public precache...
can some one help? thanks

PHP Code:

#include <amxmodx>
#include <amxmisc>
#include <cstrike>
#include <fun>
#include <fakemeta> 

new gMOD;

new 
bool:hasAK[33] = false;
new 
bool:hasM4[33] = false;
new 
bool:hasM5[33] = false;
new 
bool:hasMG[33] = false;
new 
bool:hasXM[33] = false;
new 
bool:hasM3[33] = false;

new 
CVAR_AKCOST;
new 
CVAR_M4COST;
new 
CVAR_M5COST;
new 
CVAR_MGCOST;
new 
CVAR_XMCOST;
new 
CVAR_M3COST;

public 
plugin_init()
{
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
gMOD register_menuid("GunMOD");
    
register_menucmd(gMOD1023"menuhandle");
    
register_clcmd("say /gunmenu""GunMenu")
    
register_clcmd("say_team /gunmenu""GunMenu")
    
    
CVAR_AKCOST register_cvar("amx_AKcost""15000"); 
    
CVAR_M4COST register_cvar("amx_M4cost""15000");
    
CVAR_M5COST register_cvar("amx_M5cost""15000");
    
CVAR_MGCOST register_cvar("amx_MGcost""15000");
    
CVAR_XMCOST register_cvar("amx_XMcost""15000");
    
CVAR_M3COST register_cvar("amx_M3cost""15000");
}
public 
plugin_precache(){    
    
precache_model("models/v_ak47_1.mdl")
    
precache_model("models/p_ak47_1.mdl")

    
precache_model("models/v_m3_1.mdl")
    
precache_model("models/p_m3_1.mdl")

    
precache_model("models/v_m4a1_1.mdl")
    
precache_model("models/p_m4a1_1.mdl")

    
precache_model("models/v_m249_2.mdl")
    
precache_model("models/p_m249_2.mdl")

    
precache_model("models/v_xm1014_1.mdl")
    
precache_model("models/P_xm1014_1.mdl")
    
    
precache_model("models/v_mp5_1.mdl")
    
precache_model("models/p_mp5_1.mdl")        
}   
public 
GunMenu(id)

    new 
akcost get_pcvar_num(CVAR_AKCOST);
    new 
m4cost get_pcvar_num(CVAR_M4COST);
    new 
m5cost get_pcvar_num(CVAR_M5COST);
    new 
m3cost get_pcvar_num(CVAR_M3COST);
    new 
mgcost get_pcvar_num(CVAR_MGCOST);
    new 
xmcost get_pcvar_num(CVAR_XMCOST);
    
    
    new 
menu[512];
    
format(menu511"\wGunMOD\w^n^n1. Buy M3    \y($%i)\w^n2. Buy XM    \y($%i)\w^n3. Buy MP5    \y($%i)\w^n4. Buy m4a1    \y($%i)\w^n5. Buy ak47    \y($%i)\w^n6.  Buy m249    \y($%i)\w^n^n7 .Exit^n"m3costxmcostm5costm4costakcostmgcost);
    
    new 
keys = (1<<0|1<<1|1<<2|1<<3|1<<4|1<<5|1<<9);
    
show_menu(idkeysmenu, -1"GunMOD");
}


public 
menuhandle(idkeys

    switch(
keys
    { 
        case 
0SetM3(id)
        case 
1SetXM(id)
        case 
2SetM5(id)
        case 
3SetM4(id)
        case 
4SetAK(id)
        case 
5SetMG(id)
        default: return 
PLUGIN_HANDLED;
    }
    return 
PLUGIN_HANDLED;
}
public 
SetM3(id)
{
    new 
money cs_get_user_money(id);
    new 
price get_pcvar_num(CVAR_M3COST);
        
    if(!
is_user_alive(id)) {
        
client_print(idprint_chat"Dead people can't buy weapons!");
    } else if(
hasM3[id]) {
        
client_print(idprint_chat"You already have a M3");
    } else if(
money price) {
        
client_print(idprint_chat"You can't afford that!");
    } else {
            
hasM3[id] = true;
            
cs_set_user_money(idmoney price);
            
            
give_item(id,"weapon_m3");
            
give_item(id,"ammo_buckshot");
            
give_item(id,"ammo_buckshot");
            
give_item(id,"ammo_buckshot");
            
            
set_pev(idpev_viewmodel"models/v_m3_1.mdl");
            
set_pev(idpev_weaponmodel"models/p_m3_1.mdl");
            
            
client_print(id,print_chat,"You have bought the M3 for %i dollars",price);
    
    }
    return 
PLUGIN_HANDLED;
}
public 
SetXM(id)
{
    new 
money cs_get_user_money(id);
    new 
price get_pcvar_num(CVAR_XMCOST);
        
    if(!
is_user_alive(id)) {
        
client_print(idprint_chat"Dead people can't buy weapons!");
    } else if(
hasXM[id]) {
        
client_print(idprint_chat"You already have a XM");
    } else if(
money price) {
        
client_print(idprint_chat"You can't afford that!");
    } else {
            
hasXM[id] = true;
            
cs_set_user_money(idmoney price);
            
            
give_item(id,"weapon_xm1014");
            
give_item(id,"ammo_buckshot");
            
give_item(id,"ammo_buckshot");
            
give_item(id,"ammo_buckshot");
            
            
set_pev(idpev_viewmodel"models/v_xm1014_1.mdl");
            
set_pev(idpev_weaponmodel"models/p_xm1014_1.mdl");
            
            
client_print(id,print_chat,"You have bought the XM for %i dollars",price);
        
    }
    return 
PLUGIN_HANDLED;
}
public 
SetM5(id)
{
    new 
money cs_get_user_money(id);
    new 
price get_pcvar_num(CVAR_M5COST);
        
    if(!
is_user_alive(id)) {
        
client_print(idprint_chat"Dead people can't buy weapons!");
    } else if(
hasM5[id]) {
        
client_print(idprint_chat"You already have a MP5");
    } else if(
money price) {
        
client_print(idprint_chat"You can't afford that!");
    } else {
            
hasM5[id] = true;
            
cs_set_user_money(idmoney price);
            
            
give_item(id,"weapon_mp5navy");
            
give_item(id,"ammo_9mm");
            
give_item(id,"ammo_9mm");
            
give_item(id,"ammo_9mm");
            
            
set_pev(idpev_viewmodel"models/v_mp5_1.mdl");
            
set_pev(idpev_weaponmodel"models/p_mp5_1.mdl");
            
            
client_print(id,print_chat,"You have bought the MP5 for %i dollars",price);
        
    }
    return 
PLUGIN_HANDLED;
}
public 
SetM4(id)
{
    new 
money cs_get_user_money(id);
    new 
price get_pcvar_num(CVAR_M4COST);
        
    if(!
is_user_alive(id)) {
        
client_print(idprint_chat"Dead people can't buy weapons!");
    } else if(
hasM4[id]) {
        
client_print(idprint_chat"You already have a M4");
    } else if(
money price) {
        
client_print(idprint_chat"You can't afford that!");
    } else {
            
hasM4[id] = true;
            
cs_set_user_money(idmoney price);
            
            
give_item(id,"weapon_m4a1");
            
give_item(id,"ammo_556nato");
            
give_item(id,"ammo_556nato");
            
give_item(id,"ammo_556nato");
            
            
set_pev(idpev_viewmodel"models/v_m4a1_1.mdl");
            
set_pev(idpev_weaponmodel"models/p_m4a1_1.mdl");
            
            
client_print(id,print_chat,"You have bought the M4 for %i dollars",price);

    }
    return 
PLUGIN_HANDLED;
}
public 
SetAK(id)
{
    new 
money cs_get_user_money(id);
    new 
price get_pcvar_num(CVAR_AKCOST);
        
    if(!
is_user_alive(id)) {
        
client_print(idprint_chat"Dead people can't buy weapons!");
    } else if(
hasAK[id]) {
        
client_print(idprint_chat"You already have a AK");
    } else if(
money price) {
        
client_print(idprint_chat"You can't afford that!");
    } else {
            
hasAK[id] = true;
            
cs_set_user_money(idmoney price);
            
            
give_item(id,"weapon_ak47");
            
give_item(id,"ammo_762nato");
            
give_item(id,"ammo_762nato");
            
give_item(id,"ammo_762nato");
            
            
set_pev(idpev_viewmodel"models/v_ak47_1.mdl");
            
set_pev(idpev_weaponmodel"models/p_ak47_1.mdl");
            
            
client_print(id,print_chat,"You have bought the AK for %i dollars",price);
        
    }
    return 
PLUGIN_HANDLED;
}
public 
SetMG(id)
{
    new 
money cs_get_user_money(id);
    new 
price get_pcvar_num(CVAR_MGCOST);
        
    if(!
is_user_alive(id)) {
        
client_print(idprint_chat"Dead people can't buy weapons!");
    } else if(
hasMG[id]) {
        
client_print(idprint_chat"You already have a MG");
    } else if(
money price) {
        
client_print(idprint_chat"You can't afford that!");
    } else {
            
hasMG[id] = true;
            
cs_set_user_money(idmoney price);
            
            
give_item(id,"weapon_ak47");
            
give_item(id,"ammo_762nato");
            
give_item(id,"ammo_762nato");
            
give_item(id,"ammo_762nato");
            
            
set_pev(idpev_viewmodel"models/v_m249_2.mdl");
            
set_pev(idpev_weaponmodel"models/p_m249_2.mdl");
            
            
client_print(id,print_chat,"You have bought the MG for %i dollars",price);
    
    }
    return 
PLUGIN_HANDLED;



Zombiezzz 12-21-2009 15:16

Re: Help Model Precaching
 
lol we both need help on this >.>

Arkshine 12-21-2009 15:18

Re: Help Model Precaching
 
pev_viewmodel -> pev_viewmodel2
pev_weaponmodel -> pev_weaponmodel2

laziboi72 12-21-2009 15:21

Re: Help Model Precaching
 
thanks

Arkshine 12-21-2009 15:24

Re: Help Model Precaching
 
To explain, if you use pev_viewmodel/pev_weaponmodel ; you need to allocate the string before using EngFunc_AllocString

pev_viewmodel2/pev_weaponmodel2 allocate for you the string before, that's why you can use directly the string.

laziboi72 12-21-2009 16:04

Re: Help Model Precaching
 
ooh ic thanks


All times are GMT -4. The time now is 04:08.

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