AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   First Script Problem (Very Small) (https://forums.alliedmods.net/showthread.php?t=9227)

TaRgEt*TuRkEy 01-10-2005 07:39

First Script Problem (Very Small)
 
Basically what I want to do is give random equipment, and a certain ammount of it each round to all the players (maybe different to each player?).

THE PROBLEM NOW - Look at my bottom post for explaination.

Code:
#define AMX_MOD_X #include <amxmodx> #include <cstrike> #include <fun> #define MAX_LINES 64 #define MAX_STRING_LEN 256 new Title[32] = "Random Equip" new Version[32] = "0.0.0" new Author[16] = "TaRgEt*TuRkEy" new ammo_type new ammo_amount public plugin_init() {     register_plugin(Title,Version,Author)     register_logevent("new_round", 2, "1=Round_Start") } public new_round(id) {         new weapon[32]     new User[32]     new RandomNum = random(5) +1     if (RandomNum == 1)     {         ammo_type = 1         ammo_amount = 1         client_print(0,print_chat, "[AMX] <Random Equip> Your have recieved a complimentry P228!", User)     } else if (RandomNum == 2){         ammo_type = 3         ammo_amount = 1         client_print(0,print_chat, "[AMX] <Random Equip> Your have recieved a stunning Scout!", User)     } else if (RandomNum == 3){         ammo_type = 4         ammo_amount = 2         client_print(0,print_chat, "[AMX] <Random Equip> Your have recieved a 2 Hand Grenades!", User)     } else if (RandomNum == 4){         ammo_type = 5         ammo_amount = 1         client_print(0,print_chat, "[AMX] <Random Equip> Your have recieved a noobish XM1014!", User)     } else if (RandomNum == 5){         ammo_type = 7         ammo_amount = 1         client_print(0,print_chat, "[AMX] <Random Equip> Your have recieved an unaccurate Mac10!", User)     }     get_weaponname(ammo_type,weapon,sizeof(weapon))     give_item(id,weapon)     cs_set_user_bpammo(id,ammo_type,ammo_amount)     return PLUGIN_CONTINUE }

XxAvalanchexX 01-10-2005 15:19

ammo_type and ammo_amount are defined in the heading of your script, but then you redefine them in new_round.

When you try to redefine them, you attempt to set their value to a function. The proper usage would be variable = str_to_num(stringhere), but there are no strings to convert to numbers in the first place.

Then, you try to set integers (ammo_type and ammo_amount) to a string ("1"). Just use 1.

TaRgEt*TuRkEy 01-10-2005 18:41

Alright It compiles properly now, but ingame is another story. This plugin goes crazy, it seems it runs round start sub like every .000001 seconds. Shouldn't it be only running once at round start? It's even running before anybody has joined. The exact debug targets the random function for a "stack" error. Thanks for your help.

NOTE: I updated script in first post to reflect newest.

Timmi the savage 01-11-2005 10:28

your gonna have to write the names in like this

new ammo[32]
ammo[] = "ammo_name"

XxAvalanchexX 01-11-2005 12:24

Timmi, I don't see anywhere in the script where he would need to do that. Also, I have no idea why ResetHUD is being called so many times.

TaRgEt*TuRkEy 01-11-2005 17:40

The script works perfect except for it being called so many times over and over (until it eventually gives me an overflow). Any ideas how to fix would be nice.

Da Bishop 01-11-2005 18:06

ResetHUD is called many times. How every many times its need to correct the HUD.. like time ammo etc. So you need to include something that will narrow it down a little. BTW using resetHUD for new round is bad anyways ;) EX.

Code:
register_logevent("new_round", 2, "1=Round_Start")

TaRgEt*TuRkEy 01-12-2005 00:22

Alright compiles fine, and it displays the message random equip message too, the only thing, it doesn't give the equip. Here are the errors it gives me from ingame debugger:

Code:

L 01/11/2005 - 22:28:29: [AMXX] Native error in "give_item" on line 52 (file "randomequip.sma").
L 01/11/2005 - 22:28:29: [Fun] Player out of range (0)
L 01/11/2005 - 22:28:29: [AMXX] Native error in "cs_set_user_bpammo" on line 53 (file "randomequip.sma").
L 01/11/2005 - 22:28:29: [CStrike] Player out of range

I wonder what the problem is? I have all modules activated. And before when this script was buggy, it was actually giving me the weapons, just too many, so I wonder what's up now?

Geesu 01-12-2005 09:33

add a line before line 52 that is:

Code:
if(!is_user_connected(id)) return PLUGIN_CONTINUE

TaRgEt*TuRkEy 01-12-2005 15:06

Okay then why isn't it detected when I or others are connected? I have tested with people, and it still isn't saying anybody is connected (not giving anybody anything)?

Is that a dedicated server only check? I am using listen.


All times are GMT -4. The time now is 19:16.

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