AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Problem with setting boolean... (https://forums.alliedmods.net/showthread.php?t=55947)

Rolnaaba 06-02-2007 17:47

Problem with setting boolean...
 
This is code from my SuperNade plugin:
Code:
register_forward(FM_EmitSound, "EmitSound"); register_clcmd("/nade", "buy_nade"); public buy_nade(id) {     if(!get_pcvar_num(pcvar[CMOD])) {         client_print(id, print_chat, "SuperNade Disabled by Admin, sry :(");         return PLUGIN_HANDLED;     }     if(!is_user_alive(id) || !is_user_connected(id)) {         client_print(id, print_chat, "You must be alive to buy a SuperNade!");         return PLUGIN_HANDLED;     }     if(cs_get_user_team(id) == CS_TEAM_SPECTATOR || cs_get_user_team(id) == CS_TEAM_UNASSIGNED) {         client_print(id, print_chat, "You must be on a team to buy a SuperNade!");         return PLUGIN_HANDLED;     }     if(HasSuperNade[id-1]) {         client_print(id, print_chat, "You already have a supernade!");         return PLUGIN_HANDLED;     }     if(cs_get_user_money(id) < get_pcvar_num(pcvar[CCOST])) {         client_print(id, print_chat, "You cant afford to buy a SuperNade! It cost: %i", get_pcvar_num(pcvar[CCOST]));         return PLUGIN_HANDLED;     }     cs_set_user_money(id, cs_get_user_money(id)-get_pcvar_num(pcvar[CCOST]), 1);         new wpnids[32], num;     get_user_weapons(id, wpnids, num);         new bool:has;         for(new i = 0; i < num; i++) {         if(wpnids[i] == CSW_HEGRENADE) {             has = true;         }     }         if(!has) {         give_nade(id);     }     HasSuperNade[id-1] = true;         client_print(id, print_chat, "You now hold a SuperNade...be careful!!");         return PLUGIN_HANDLED; } public EmitSound(entity, channel, const sound[]) {     if(!get_pcvar_num(pcvar[CMOD]))         return FMRES_IGNORED;             if(!pev_valid(entity))         return FMRES_IGNORED;         if(contain(sound, "debris") == -1)         return FMRES_IGNORED;         new Float:origin[3], owner;         pev(entity, pev_origin, origin);     owner = pev(entity, pev_owner);         //extend the nade's range     if(!HasSuperNade[owner])         return FMRES_IGNORED;     HasSuperNade[owner] = false;     extend_range(origin);     if(!Planted)         return FMRES_IGNORED;             //search entities around the nade explosion     new ent = -1     while((ent = engfunc(EngFunc_FindEntityInSphere, ent, origin, get_pcvar_float(pcvar[CRADIUS]))) != 0) {         if(!pev_valid(ent))             continue                 //get classname of entity         static Classname[33]         pev(ent, pev_classname, Classname, 32)                     //make sure is grenade entity, and is the c4 grenade         if(!equal(Classname,g_Classname) || fm_cs_get_grenade_type(ent) != CSW_C4)             continue         set_pdata_float(ent, 100, 0.0); //makes the c4 entity explode     }     return FMRES_IGNORED;   }

Now when I am in the server by myself and I type /buy in chat my id is returned as "1", I know this because I had many client prints telliing me everything that was happening during testing, but later when I throw it, and pev() gets the owner, my id is returned as "0". so to remedy this problem I did HasSuperNade[id-1] = true; on buy function and it works fine, if I am only person in server. If others are tho, the person with id=1 can buy multiple nades per round, but everyone else cant, it isnt setting false correctly on them, what is the problem?

Rolnaaba 06-02-2007 17:56

Re: Problem with setting boolean...
 
i.e.: if your id #1, you can buy a nade throw it and buy another, if you have enough money.
but if you are not id #1, you can buy a nade throw it, and it keeps saying that you already have a nade, which means it is not placing it as false on other people.

Zenith77 06-02-2007 18:44

Re: Problem with setting boolean...
 
Code:
id-1

Why are you doing this? If pev_owner is returning zero, the perhaps it does not store the "owner" of the grenade in that field. Valid player indexs are 1-32.

Rolnaaba 06-02-2007 18:57

Re: Problem with setting boolean...
 
Quote:

Originally Posted by organizedKaoS (Post 485032)
Set the boolean per id this way...

new bool:hasNade[33]

hasNade[id] = true

Also declare the bool as a global variable, not inside the function.

In putinserver and disconnect set the bool[id] to false.

duh I am doing that, i am not THAT big of a n00b


Quote:

Originally Posted by Zenith77 (Post 485037)
Code:
id-1
Why are you doing this? If pev_owner is returning zero, the perhaps it does not store the "owner" of the grenade in that field. Valid player indexs are 1-32.

well do you have another way to get the owner of an exploded grenade?

Cheap_Suit 06-03-2007 04:21

Re: Problem with setting boolean...
 
Probably your problem is here:

PHP Code:

owner pev(entitypev_owner);
 
    
//extend the nade's range
    
if(!HasSuperNade[owner]) 
        return 
FMRES_IGNORED;
    
HasSuperNade[owner] = false

Note that you did this:
PHP Code:

HasSuperNade[id-1] = true

Solution?
PHP Code:

HasSuperNade[owner-1

Edit:

since new bool:HasSuperNade[33] (in your plugin thread). An easier way it just to remove all the -1 in HasSuperNade[id-1].

Rolnaaba 06-03-2007 12:55

Re: Problem with setting boolean...
 
ok both of you are wrong, sorry but have to say it. Organized is talking about the wrong boolean, the HasSuperNade bool is what I am tlaking about. It IS global. The reason it is not setting right was because my pev_owner, is returning "0", because the nade is already removed it cannot find an owner. So neither of your solutions will work. I have solved this problem already but thanks anyway.
And btw, this:
Code:
new wpnids[32], num;     get_user_weapons(id, wpnids, num);         new bool:has;         for(new i = 0; i < num; i++) {         if(wpnids[i] == CSW_HEGRENADE) {             has = true;         }     }
Has nothing to do with if they have a supernade or not, this is to cycle through their weapons and detemine if they have an HEGRENADE already or if I need to give them one. but I am not using this code block anymore anyway so thanks again but not even close to what I was tlaking about.

Rolnaaba 06-03-2007 12:58

Re: Problem with setting boolean...
 
Zenith77 had nailed it when he said:

Quote:

Originally Posted by Zenith77 (Post 485037)
Code:
id-1
Why are you doing this? If pev_owner is returning zero, the perhaps it does not store the "owner" of the grenade in that field. Valid player indexs are 1-32.


Cheap_Suit 06-03-2007 13:26

Re: Problem with setting boolean...
 
If you misunderstood me, I was pointing out the problem in the HasSuperNadearray.

Rolnaaba 06-03-2007 16:48

Re: Problem with setting boolean...
 
I know but it wasnt the error you were thinking of, it was a problem with pev_owner, not the indexed array


All times are GMT -4. The time now is 10:44.

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