Raised This Month: $51 Target: $400
 12% 

When I pick my hero i can't move


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
martop5hng
Junior Member
Join Date: Mar 2014
Old 04-04-2014 , 20:30   When I pick my hero i can't move
Reply With Quote #1

When I pick my new hero my character freeze and can't move why's that ?
here's the code and the models:
Code:
 
#include <superheromod>

new gHeroID
new gHeroName[] = "Darkness" //creates a string varr to hold the hero name
new bool:gHasDarknessPower[SH_MAXSLOTS+1] //creates a varr with an aray, with 1 slot per player
new const gDarknessPlayer[] = "models/player/darkness/darkness.mdl"
new const gDarknessWeapon[] = "models/shmod/darkness_v.mdl"

public plugin_init()
{
    //This registers the plugin with amx mod x. This is what is shown when you type amx_plugins in console
    register_plugin("SUPERHERO Darkness", "1.0", "martop5hng")
    register_event("CurWeapon", "weapon_change", "be", "1=1")
    
    //now we register the cvars
    //you can make the "pcvarLevel" to what ever you want, but make sure it matches this each time you use it
    new pcvarLevel = register_cvar("darkness_level", "8") //this is what level the hero should be avalible at
    new pcvarGrav = register_cvar("darness_grav", "0.80")
    new pcvarSpeed = register_cvar("darkness_speed", "800")
    new pcvarMult = register_cvar("darkness_knifemult", "8.0")
    
    //This is what creates the hero remember the pcvarLevel is pointing at the level for the hero
    gHeroID = sh_create_hero(gHeroName, pcvarLevel)
    //This is setting the hero info. It pretty much explains itself
    sh_set_hero_info(gHeroID, "You Became The Darkness", "You Are The Freakest Monster Livivng Deep In The Darkness")
    sh_set_hero_speed(gHeroID, pcvarSpeed)
    sh_set_hero_speed(gHeroID, pcvarGrav)
    sh_set_hero_dmgmult(gHeroID, pcvarMult, CSW_KNIFE)
    
    //if you were used to the old method you will notice that there is no need to register the init anymore therefor nothing more is required
}

public sh_hero_init(id, heroID, mode)
{
    //if no power return
    if (gHeroID != heroID) return
    
    //This is what runs when someone drops or picks the hero
    switch(mode)
    {
        //if the hero is added
        case SH_HERO_ADD:
        {
            //it is true that client has the hero
            gHasDarknessPower[id] = true
	   darkness_morph(id)
	   switch_model(id)
        }
        //if the hero is dropped
        case SH_HERO_DROP:
        {
            //it is false that the client has the hero
            gHasDarknessPower[id] = false
	   darkness_unmorph(id)
	   if (is_user_alive(id))
            {
                //this drops the weapon
                sh_drop_weapon(id, CSW_KNIFE, true)
                //the true value I set means that when the weapon is dropped it disappears so user cannot just pick it up again
            }
        }
    }
}  
public plugin_precache()
{
    //remember to use the function precache_model for models
    precache_model(gDarknessPlayer) //I already told where the playermodel is located, so all I have to do is just write the global variable
    precache_model(gDarknessWeapon)
}

//this runs each time a player is spawning but you probably figured that one out by the name
public sh_client_spawn(id)
{
    //first we check if the user has the hero or not
    if (gHasDarknessPower[id])
    {
        //then we can go and set the playermodel
        darkness_morph(id)
    }
}

//it is here where we set the playermodel for the player
darkness_morph(id)
{
    //remember that after the id you have to write the filename witch has to be the model. In this case super.mdl is our model. Do not write .mdl after the filename
    cs_set_user_model(id, "darkness")
    if (sh_is_active() && is_user_alive(id) && gHasDarknessPower[id] )
    {
        //if all this is true we can safely give him his gun
        sh_give_weapon(id, CSW_KNIFE)
    }
}

//it is here where we take off the playermodel if a user dropped the hero
darkness_unmorph(id)
{
    //yeah, we just reset the playermodel to the original one
    cs_reset_user_model(id)
}  

public weapon_change(id)
{
    //do nothing if client does not have hero or sh is off
    if ( !sh_is_active() || !gHasDarknessPower[id] ) return
    
    //the read data is reading the weapon the client has out
    new weaponID = read_data(2)
    //and if the client does not have the m4a1 out just do nothing
    if (weaponID !=CSW_KNIFE) return
    
    //now we checked if the user does not have the m4a1 out. If he does not the code stops here
    //if he does have m4a1 out then we continue so now we set the weapon model for the m4a1 since he is having that gun out
    //yes we are going to do it in switch_models since that makes most sense
    switch_model(id)
    
    //now, we do not want the guy to run out of ammo so we just give him an unlimited amout of it
    //this is reading how many bullets there are left in the gun
    if (read_data(3) == 0)
    {
        //so if he is out of ammo just reload it
        sh_reload_ammo(id, 1)
        /*after the id I made a 1 number
        look at the superheromod.inc and you will see this
        0 - follow server sh_reloadmode CVAR
        1 - continuous shooting, no reload
        2 - fill the backpack (must reload)
        3 - drop the gun and get a new one with full clip
        That should explain it*/
    }
}

switch_model(id)
{
    //if the sh mod is off the client is dead or he does not have the hero we do not want to let him have the weapon model!
    if (!sh_is_active() || !is_user_alive(id) || !gHasDarknessPower[id] ) return
    
    //and now we check again if he still has the m4a1 out
    if (get_user_weapon(id) == CSW_KNIFE)
    {
        //now he has all the requirements to have the weapon model so we also need to give it to him
        set_pev(id, pev_viewmodel2, gDarknessWeapon)
    }
}
Attached Files
File Type: zip New WinRAR ZIP archive.zip (1.05 MB, 73 views)
martop5hng is offline
Jelle
[b]MOAR CANDY[/b]
Join Date: Aug 2009
Location: Denmark
Old 04-05-2014 , 10:42   Re: When I pick my hero i can't move
Reply With Quote #2

Change
PHP Code:
darkness_morph(id)
{
    
//remember that after the id you have to write the filename witch has to be the model. In this case super.mdl is our model. Do not write .mdl after the filename
    
cs_set_user_model(id"darkness")
    
    if (
sh_is_active() && is_user_alive(id) && gHasDarknessPower[id] )
    {
        
//if all this is true we can safely give him his gun
        
sh_give_weapon(idCSW_KNIFE)
    }

To

PHP Code:
darkness_morph(id)
{
    
//remember that after the id you have to write the filename witch has to be the model. In this case super.mdl is our model. Do not write .mdl after the filename
    
cs_set_user_model(id"darkness")

You are giving the player a knife but as we know you already spawn with one, so now he has two, but he can't have two. Not sure if that's the problem but it could be. Never tried giving a knife to people who had one to start with.

Also this

PHP Code:
public weapon_change(id)
{
    
//do nothing if client does not have hero or sh is off
    
if ( !sh_is_active() || !gHasDarknessPower[id] ) return

    
//the read data is reading the weapon the client has out
    
new weaponID read_data(2)
    
//and if the client does not have the m4a1 out just do nothing
    
if (weaponID !=CSW_KNIFE) return
    
    
//now we checked if the user does not have the m4a1 out. If he does not the code stops here
    //if he does have m4a1 out then we continue so now we set the weapon model for the m4a1 since he is having that gun out
    //yes we are going to do it in switch_models since that makes most sense
    
switch_model(id)
    
    
//now, we do not want the guy to run out of ammo so we just give him an unlimited amout of it
    //this is reading how many bullets there are left in the gun
    
if (read_data(3) == 0)
    {
        
//so if he is out of ammo just reload it
        
sh_reload_ammo(id1)
        
/*after the id I made a 1 number
        look at the superheromod.inc and you will see this
        0 - follow server sh_reloadmode CVAR
        1 - continuous shooting, no reload
        2 - fill the backpack (must reload)
        3 - drop the gun and get a new one with full clip
        That should explain it*/
    
}

You check the weapon which is fine, and setting the model afterwards is fine too, but you are checking if the knife has no ammo, and if it doesn't then give it a full new clip??? Knives doesn't have ammo, remember?

PHP Code:
public weapon_change(id)
{
    
//do nothing if client does not have hero or sh is off
    
if ( !sh_is_active() || !gHasDarknessPower[id] ) return

    
//the read data is reading the weapon the client has out
    
new weaponID read_data(2)
    
//and if the client does not have the m4a1 out just do nothing
    
if (weaponID !=CSW_KNIFE) return
    
    
//now we checked if the user does not have the m4a1 out. If he does not the code stops here
    //if he does have m4a1 out then we continue so now we set the weapon model for the m4a1 since he is having that gun out
    //yes we are going to do it in switch_models since that makes most sense
    
switch_model(id)

Final code
PHP Code:
#include <superheromod>

new gHeroID
new gHeroName[] = "Darkness" //creates a string varr to hold the hero name
new bool:gHasDarknessPower[SH_MAXSLOTS+1//creates a varr with an aray, with 1 slot per player
new const gDarknessPlayer[] = "models/player/darkness/darkness.mdl"
new const gDarknessWeapon[] = "models/shmod/darkness_v.mdl"

public plugin_init()
{
    
//This registers the plugin with amx mod x. This is what is shown when you type amx_plugins in console
    
register_plugin("SUPERHERO Darkness""1.0""martop5hng")
    
register_event("CurWeapon""weapon_change""be""1=1")
    
    
//now we register the cvars
    //you can make the "pcvarLevel" to what ever you want, but make sure it matches this each time you use it
    
new pcvarLevel register_cvar("darkness_level""8"//this is what level the hero should be avalible at
    
new pcvarGrav register_cvar("darness_grav""0.80")
    new 
pcvarSpeed register_cvar("darkness_speed""800")
    new 
pcvarMult register_cvar("darkness_knifemult""8.0")
    
    
//This is what creates the hero remember the pcvarLevel is pointing at the level for the hero
    
gHeroID sh_create_hero(gHeroNamepcvarLevel)
    
//This is setting the hero info. It pretty much explains itself
    
sh_set_hero_info(gHeroID"You Became The Darkness""You Are The Freakest Monster Livivng Deep In The Darkness")
    
sh_set_hero_speed(gHeroIDpcvarSpeed)
    
sh_set_hero_speed(gHeroIDpcvarGrav)
    
sh_set_hero_dmgmult(gHeroIDpcvarMultCSW_KNIFE)
    
    
//if you were used to the old method you will notice that there is no need to register the init anymore therefor nothing more is required
}

public 
sh_hero_init(idheroIDmode)
{
    
//if no power return
    
if (gHeroID != heroID) return
    
    
//This is what runs when someone drops or picks the hero
    
switch(mode)
    {
        
//if the hero is added
        
case SH_HERO_ADD:
        {
            
//it is true that client has the hero
            
gHasDarknessPower[id] = true
            darkness_morph
(id)
            
switch_model(id)
        }
        
//if the hero is dropped
        
case SH_HERO_DROP:
        {
            
//it is false that the client has the hero
            
gHasDarknessPower[id] = false
            darkness_unmorph
(id)
            if (
is_user_alive(id))
            {
                
//this drops the weapon
                
sh_drop_weapon(idCSW_KNIFEtrue)
                
//the true value I set means that when the weapon is dropped it disappears so user cannot just pick it up again
            
}
        }
    }
}  
public 
plugin_precache()
{
    
//remember to use the function precache_model for models
    
precache_model(gDarknessPlayer//I already told where the playermodel is located, so all I have to do is just write the global variable
    
precache_model(gDarknessWeapon)
}

//this runs each time a player is spawning but you probably figured that one out by the name
public sh_client_spawn(id)
{
    
//first we check if the user has the hero or not
    
if (gHasDarknessPower[id])
    {
        
//then we can go and set the playermodel
        
darkness_morph(id)
    }
}

//it is here where we set the playermodel for the player
darkness_morph(id)
{
    
//remember that after the id you have to write the filename witch has to be the model. In this case super.mdl is our model. Do not write .mdl after the filename
    
cs_set_user_model(id"darkness")
}

//it is here where we take off the playermodel if a user dropped the hero
darkness_unmorph(id)
{
    
//yeah, we just reset the playermodel to the original one
    
cs_reset_user_model(id)
}  

public 
weapon_change(id)
{
    
//do nothing if client does not have hero or sh is off
    
if ( !sh_is_active() || !gHasDarknessPower[id] ) return

    
//the read data is reading the weapon the client has out
    
new weaponID read_data(2)
    
//and if the client does not have the m4a1 out just do nothing
    
if (weaponID !=CSW_KNIFE) return
    
    
//now we checked if the user does not have the m4a1 out. If he does not the code stops here
    //if he does have m4a1 out then we continue so now we set the weapon model for the m4a1 since he is having that gun out
    //yes we are going to do it in switch_models since that makes most sense
    
switch_model(id)
}

switch_model(id)
{
    
//if the sh mod is off the client is dead or he does not have the hero we do not want to let him have the weapon model!
    
if (!sh_is_active() || !is_user_alive(id) || !gHasDarknessPower[id] ) return
    
    
//and now we check again if he still has the m4a1 out
    
if (get_user_weapon(id) == CSW_KNIFE)
    {
        
//now he has all the requirements to have the weapon model so we also need to give it to him
        
set_pev(idpev_viewmodel2gDarknessWeapon)
    }

It doesn't look like you are thinking, you are just copy pasting from my tutorial, you need to use your brain too.
__________________
No idea what to write here...
Jelle is offline
Send a message via MSN to Jelle
martop5hng
Junior Member
Join Date: Mar 2014
Old 04-05-2014 , 19:56   Re: When I pick my hero i can't move
Reply With Quote #3

Quote:
Originally Posted by Jelle View Post
Change
PHP Code:
darkness_morph(id)
{
    
//remember that after the id you have to write the filename witch has to be the model. In this case super.mdl is our model. Do not write .mdl after the filename
    
cs_set_user_model(id"darkness")
    
    if (
sh_is_active() && is_user_alive(id) && gHasDarknessPower[id] )
    {
        
//if all this is true we can safely give him his gun
        
sh_give_weapon(idCSW_KNIFE)
    }

To

PHP Code:
darkness_morph(id)
{
    
//remember that after the id you have to write the filename witch has to be the model. In this case super.mdl is our model. Do not write .mdl after the filename
    
cs_set_user_model(id"darkness")

You are giving the player a knife but as we know you already spawn with one, so now he has two, but he can't have two. Not sure if that's the problem but it could be. Never tried giving a knife to people who had one to start with.

Also this

PHP Code:
public weapon_change(id)
{
    
//do nothing if client does not have hero or sh is off
    
if ( !sh_is_active() || !gHasDarknessPower[id] ) return

    
//the read data is reading the weapon the client has out
    
new weaponID read_data(2)
    
//and if the client does not have the m4a1 out just do nothing
    
if (weaponID !=CSW_KNIFE) return
    
    
//now we checked if the user does not have the m4a1 out. If he does not the code stops here
    //if he does have m4a1 out then we continue so now we set the weapon model for the m4a1 since he is having that gun out
    //yes we are going to do it in switch_models since that makes most sense
    
switch_model(id)
    
    
//now, we do not want the guy to run out of ammo so we just give him an unlimited amout of it
    //this is reading how many bullets there are left in the gun
    
if (read_data(3) == 0)
    {
        
//so if he is out of ammo just reload it
        
sh_reload_ammo(id1)
        
/*after the id I made a 1 number
        look at the superheromod.inc and you will see this
        0 - follow server sh_reloadmode CVAR
        1 - continuous shooting, no reload
        2 - fill the backpack (must reload)
        3 - drop the gun and get a new one with full clip
        That should explain it*/
    
}

You check the weapon which is fine, and setting the model afterwards is fine too, but you are checking if the knife has no ammo, and if it doesn't then give it a full new clip??? Knives doesn't have ammo, remember?

PHP Code:
public weapon_change(id)
{
    
//do nothing if client does not have hero or sh is off
    
if ( !sh_is_active() || !gHasDarknessPower[id] ) return

    
//the read data is reading the weapon the client has out
    
new weaponID read_data(2)
    
//and if the client does not have the m4a1 out just do nothing
    
if (weaponID !=CSW_KNIFE) return
    
    
//now we checked if the user does not have the m4a1 out. If he does not the code stops here
    //if he does have m4a1 out then we continue so now we set the weapon model for the m4a1 since he is having that gun out
    //yes we are going to do it in switch_models since that makes most sense
    
switch_model(id)

Final code
PHP Code:
#include <superheromod>

new gHeroID
new gHeroName[] = "Darkness" //creates a string varr to hold the hero name
new bool:gHasDarknessPower[SH_MAXSLOTS+1//creates a varr with an aray, with 1 slot per player
new const gDarknessPlayer[] = "models/player/darkness/darkness.mdl"
new const gDarknessWeapon[] = "models/shmod/darkness_v.mdl"

public plugin_init()
{
    
//This registers the plugin with amx mod x. This is what is shown when you type amx_plugins in console
    
register_plugin("SUPERHERO Darkness""1.0""martop5hng")
    
register_event("CurWeapon""weapon_change""be""1=1")
    
    
//now we register the cvars
    //you can make the "pcvarLevel" to what ever you want, but make sure it matches this each time you use it
    
new pcvarLevel register_cvar("darkness_level""8"//this is what level the hero should be avalible at
    
new pcvarGrav register_cvar("darness_grav""0.80")
    new 
pcvarSpeed register_cvar("darkness_speed""800")
    new 
pcvarMult register_cvar("darkness_knifemult""8.0")
    
    
//This is what creates the hero remember the pcvarLevel is pointing at the level for the hero
    
gHeroID sh_create_hero(gHeroNamepcvarLevel)
    
//This is setting the hero info. It pretty much explains itself
    
sh_set_hero_info(gHeroID"You Became The Darkness""You Are The Freakest Monster Livivng Deep In The Darkness")
    
sh_set_hero_speed(gHeroIDpcvarSpeed)
    
sh_set_hero_speed(gHeroIDpcvarGrav)
    
sh_set_hero_dmgmult(gHeroIDpcvarMultCSW_KNIFE)
    
    
//if you were used to the old method you will notice that there is no need to register the init anymore therefor nothing more is required
}

public 
sh_hero_init(idheroIDmode)
{
    
//if no power return
    
if (gHeroID != heroID) return
    
    
//This is what runs when someone drops or picks the hero
    
switch(mode)
    {
        
//if the hero is added
        
case SH_HERO_ADD:
        {
            
//it is true that client has the hero
            
gHasDarknessPower[id] = true
            darkness_morph
(id)
            
switch_model(id)
        }
        
//if the hero is dropped
        
case SH_HERO_DROP:
        {
            
//it is false that the client has the hero
            
gHasDarknessPower[id] = false
            darkness_unmorph
(id)
            if (
is_user_alive(id))
            {
                
//this drops the weapon
                
sh_drop_weapon(idCSW_KNIFEtrue)
                
//the true value I set means that when the weapon is dropped it disappears so user cannot just pick it up again
            
}
        }
    }
}  
public 
plugin_precache()
{
    
//remember to use the function precache_model for models
    
precache_model(gDarknessPlayer//I already told where the playermodel is located, so all I have to do is just write the global variable
    
precache_model(gDarknessWeapon)
}

//this runs each time a player is spawning but you probably figured that one out by the name
public sh_client_spawn(id)
{
    
//first we check if the user has the hero or not
    
if (gHasDarknessPower[id])
    {
        
//then we can go and set the playermodel
        
darkness_morph(id)
    }
}

//it is here where we set the playermodel for the player
darkness_morph(id)
{
    
//remember that after the id you have to write the filename witch has to be the model. In this case super.mdl is our model. Do not write .mdl after the filename
    
cs_set_user_model(id"darkness")
}

//it is here where we take off the playermodel if a user dropped the hero
darkness_unmorph(id)
{
    
//yeah, we just reset the playermodel to the original one
    
cs_reset_user_model(id)
}  

public 
weapon_change(id)
{
    
//do nothing if client does not have hero or sh is off
    
if ( !sh_is_active() || !gHasDarknessPower[id] ) return

    
//the read data is reading the weapon the client has out
    
new weaponID read_data(2)
    
//and if the client does not have the m4a1 out just do nothing
    
if (weaponID !=CSW_KNIFE) return
    
    
//now we checked if the user does not have the m4a1 out. If he does not the code stops here
    //if he does have m4a1 out then we continue so now we set the weapon model for the m4a1 since he is having that gun out
    //yes we are going to do it in switch_models since that makes most sense
    
switch_model(id)
}

switch_model(id)
{
    
//if the sh mod is off the client is dead or he does not have the hero we do not want to let him have the weapon model!
    
if (!sh_is_active() || !is_user_alive(id) || !gHasDarknessPower[id] ) return
    
    
//and now we check again if he still has the m4a1 out
    
if (get_user_weapon(id) == CSW_KNIFE)
    {
        
//now he has all the requirements to have the weapon model so we also need to give it to him
        
set_pev(idpev_viewmodel2gDarknessWeapon)
    }

It doesn't look like you are thinking, you are just copy pasting from my tutorial, you need to use your brain too.
I did it really quick so i didn't think about it . now it's done but something funny happened
Error: Cannot read from file: "superheromod" on line 1 <
martop5hng is offline
Jelle
[b]MOAR CANDY[/b]
Join Date: Aug 2009
Location: Denmark
Old 04-06-2014 , 21:00   Re: When I pick my hero i can't move
Reply With Quote #4

Look at the error. It says it cannot read from the file superheromod. The only file it has to read is the include files, so we can safely assume it is superhero.inc. My bet is that you deleted or moved that include file.
__________________
No idea what to write here...
Jelle is offline
Send a message via MSN to Jelle
G-Dog
Senior Member
Join Date: Dec 2005
Location: Thunderstorm Central
Old 04-08-2014 , 14:00   Re: When I pick my hero i can't move
Reply With Quote #5

Code:
    sh_set_hero_speed(gHeroID, pcvarGrav)
change to
Code:
    sh_set_hero_grav(gHeroID, pcvarGrav)
everything that jelle mentioned was optimization issues, this is the culprit for the actual problem
__________________
If at first you don't succeed, then skydiving isn't for you.
G-Dog is offline
Send a message via AIM to G-Dog
Jelle
[b]MOAR CANDY[/b]
Join Date: Aug 2009
Location: Denmark
Old 04-08-2014 , 14:32   Re: When I pick my hero i can't move
Reply With Quote #6

Quote:
Originally Posted by G-Dog View Post
Code:
    sh_set_hero_speed(gHeroID, pcvarGrav)
change to
Code:
    sh_set_hero_grav(gHeroID, pcvarGrav)
everything that jelle mentioned was optimization issues, this is the culprit for the actual problem
Oh hello there.

I didn't even notice that, thanks.
__________________
No idea what to write here...
Jelle is offline
Send a message via MSN to Jelle
Reply



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 00:30.


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