PDA

View Full Version : No errors or warnings, yet it doesnt work


RogerGjyieah
06-15-2010, 10:11
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
Is there anything in the Error Logs?

RogerGjyieah
06-15-2010, 10:35
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
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
#include <amxconst>
is not needed, it is automaticly included with <amxmodx>


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:

new cvar_type, cvar_time

public plugin_init() {
new NadeSpawnOn = 1 //used by Toogle
register_plugin(PLUGIN, VERSION, AUTHOR)
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:

public PreSpawnNade(SpawnTime, numNadeType, id) {
//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:

public PreSpawnNade(SpawnTime, numNadeType, id) {
//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

#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
thanks :)
I'll try/do that..

RogerGjyieah
06-16-2010, 06:27
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:

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


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
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.

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
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
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.

set_task( 1.0 , "function" , id )

//both of the below will work
remove_task( id )

public function( id )
{
//code
}

RogerGjyieah
06-16-2010, 14:39
Yay! Now it works :)
I've uploaded the final result (in case any1 wants it)..

EpicFail.
06-16-2010, 15:48
Ops i fail... trash my post..

drekes
06-16-2010, 16:59
Ops i fail... trash my post..

Your name says it all :grrr: