AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   No errors or warnings, yet it doesnt work (https://forums.alliedmods.net/showthread.php?t=129657)

RogerGjyieah 06-15-2010 10:11

No errors or warnings, yet it doesnt work
 
1 Attachment(s)
Hey!
I'm new to plugin-scripting, and this is my first 'real' plugin. There is no errors nor warnings with AMXMODX Studio, but it still doesn't work.

It is supposed to (in CS 1.6) spawn a grenade of the users choice after a predefined span of time. The sma-file is attached.

Any advice will be appriecieted.

YamiKaitou 06-15-2010 10:32

Re: No errors or warnings, yet it doesnt work
 
Is there anything in the Error Logs?

RogerGjyieah 06-15-2010 10:35

Re: No errors or warnings, yet it doesnt work
 
As said, AmxModX Studio did not repport any errors or warnings when i compiled it.. yet it says 'bad load' when i typen amx_plugins in cs console..

YamiKaitou 06-15-2010 10:37

Re: No errors or warnings, yet it doesnt work
 
Then use "amxx plugins" and see why it is giving a bad load. Also, the Error Logs are the logs generated by AMXX when a plugin encounters a run-time error, not the compile errors

drekes 06-15-2010 10:43

Re: No errors or warnings, yet it doesnt work
 
PHP Code:

#include <amxconst> 

is not needed, it is automaticly included with <amxmodx>

PHP Code:

Params[0] = get_cvar_num("amx_NadeSpawn_Time")    //Param[0] = Spawn time for a nade
    
Params[1] = get_cvar_num("amx_NadeSpawn_Type")    //Param[1] = Type of nade (1 = He | 2 = Flash | 3 = Smoke) 

You should use pcvars, because they are faster. Like this:
PHP Code:

new cvar_typecvar_time

public plugin_init() {
    new 
NadeSpawnOn 1    //used by Toogle
    
register_plugin(PLUGINVERSIONAUTHOR)    
    
register_clcmd("amx_NadeSpawn_Toogle""Toogle"//Toogle's NadeSpawn on and off
    
cvar_type register_cvar("amx_NadeSpawn_Type""1")    //which type of grenade
    
cvar_time register_cvar("amx_NadeSpawn_Time""5")    //Time in sec before grenade spawns
    
register_clcmd("amx_NadeSpawn_Help""Help")    //Displays some help in the console
    
    //Define Parameters for SpawnNade loop:
    
new Params[2]
    
Params[0] = get_pcvar_num(cvar_time)    //Param[0] = Spawn time for a nade
    
Params[1] = get_pcvar_num(cvar_type)    //Param[1] = Type of nade (1 = He | 2 = Flash | 3 = Smoke) 

Use a switch here:
PHP Code:

public PreSpawnNade(SpawnTimenumNadeTypeid) {
    
//check what nade we are spawning..
    
if (numNadeType == 1) {
        
set_task(float(SpawnTime), "SpawnHE")
    }
    if (
numNadeType == 2) {
        
set_task(float(SpawnTime), "SpawnFlash")
    }
    if (
numNadeType == 3) {
        
set_task(float(SpawnTime), "SpawnSmoke")
    }


:arrow:
PHP Code:

public PreSpawnNade(SpawnTimenumNadeTypeid) {
    
//check what nade we are spawning..
    
switch(numNadeType)
    {
        case 
1:
            
set_task(float(SpawnTime), "SpawnHE")
        case 
2:
            
set_task(float(SpawnTime), "SpawnFlash")
        
        case 
3:
            
set_task(float(SpawnTime), "SpawnSmoke")
    }


instead of setting bpammo, use give_item from
PHP Code:

 #include <fun>

give_item(id"weapon_hegrenade"

and it doesn't work because you use id in preSpawnNade, but you don't got id there. I recommend using hamsandwich to detecht player spawn, and call that function there.

RogerGjyieah 06-15-2010 14:43

Re: No errors or warnings, yet it doesnt work
 
thanks :)
I'll try/do that..

RogerGjyieah 06-16-2010 06:27

Re: No errors or warnings, yet it doesnt work
 
1 Attachment(s)
I've re-written it all, and now i get no errors from the compiler, nor amx-logs. But it still doesn't work!

I think the problem lies in this:
PHP Code:

public HE_was_thrown() {
    if (
NadeSpawnOn == 1) {
        if (
GetNadeType() == 1) {
            
set_task(get_pcvar_float(cvar_time), "SpawnHE")
        }
    }
    return 
PLUGIN_HANDLED


or perhaps in:

PHP Code:

public SpawnHE(id) {
    if (
is_user_alive(id)) {
        
give_item(id"weapon_hegrenade")
    }


cvar_time is set to be 3.0, so it should be a float..
Once again I have linked the entire plugin here..

Another thing wich annoys me is, that my plugin apearantly needs to be set in "debug mode", as I am using RegisterHam().. Is there no way to avoid that?

drekes 06-16-2010 07:00

Re: No errors or warnings, yet it doesnt work
 
PHP Code:

public HE_was_thrown() {
    if (
NadeSpawnOn == 1) {
        if (
GetNadeType() == 1) {
            
set_task(get_pcvar_float(cvar_time), "SpawnHE")
        }
    }
    else {
        return 
PLUGIN_HANDLED
    
}
    return 
PLUGIN_HANDLED


You have to pass the id of the player in that function and the other 2 PrimaryAttack so you know who you should give the nade to.
PHP Code:

public HE_was_thrown(id) {
    if (
NadeSpawnOn == 1) {
        if (
GetNadeType() == 1) {
            
set_task(get_pcvar_float(cvar_time), "SpawnHE"id)
        }
    }
    else {
        return 
PLUGIN_HANDLED
    
}
    return 
PLUGIN_HANDLED



RogerGjyieah 06-16-2010 07:57

Re: No errors or warnings, yet it doesnt work
 
still doesn't work.. :(

BTW, is the ID in set_task not an individual ID for the task (which is only used in case u wanna terminate the task)?

Bugsy 06-16-2010 10:00

Re: No errors or warnings, yet it doesnt work
 
The task id passed to set task acts as the unique id for that task and can also be used to pass a player id (or any integer val) to the called function.

PHP Code:

set_task1.0 "function" id )

//both of the below will work
remove_taskid 

public function( 
id )
{
      
//code




All times are GMT -4. The time now is 14:47.

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