AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   World not allowed (https://forums.alliedmods.net/showthread.php?t=294209)

JanDev 02-22-2017 08:17

World not allowed
 
I'm pretty new to this forum, but I hope you can help me a bit

So I've modified a little knife plugin for me and my friends on a LAN server and I get some errors.

Code:

public Action:PlayerSpawn(Handle:event, const String:name[], bool:dontBroadcast)
{
        new client = GetClientOfUserId(GetEventInt(event, "userid"));

        if (GetClientTeam(client) > 1 && !IsPlayerAlive(client))
        {
                return;
        }
       
        new iWeapon = GetPlayerWeaponSlot(client, 2);
        new iItem;
       
        switch(weapon_choose[client]) {
                case 1: if(IsValidEntity(iWeapon) && iWeapon != INVALID_ENT_REFERENCE)
                {RemovePlayerItem(client, iWeapon), RemoveEdict(iWeapon), iItem = GivePlayerItem(client, "weapon_bayonet");}
                case 2: if(IsValidEntity(iWeapon) && iWeapon != INVALID_ENT_REFERENCE)
                {RemovePlayerItem(client, iWeapon), RemoveEdict(iWeapon), iItem = GivePlayerItem(client, "weapon_knife_gut");}
                case 3: if(IsValidEntity(iWeapon) && iWeapon != INVALID_ENT_REFERENCE)
                {RemovePlayerItem(client, iWeapon), RemoveEdict(iWeapon), iItem = GivePlayerItem(client, "weapon_knife_flip");}
                case 4: if(IsValidEntity(iWeapon) && iWeapon != INVALID_ENT_REFERENCE)
                {RemovePlayerItem(client, iWeapon), RemoveEdict(iWeapon), iItem = GivePlayerItem(client, "weapon_knife_m9_bayonet");}
                case 5: if(IsValidEntity(iWeapon) && iWeapon != INVALID_ENT_REFERENCE)
                {RemovePlayerItem(client, iWeapon), RemoveEdict(iWeapon), iItem = GivePlayerItem(client, "weapon_knife_karambit");}
                case 6: if(IsValidEntity(iWeapon) && iWeapon != INVALID_ENT_REFERENCE)
                {RemovePlayerItem(client, iWeapon), RemoveEdict(iWeapon), iItem = GivePlayerItem(client, "weapon_knife_tactical");}
                case 7: if(IsValidEntity(iWeapon) && iWeapon != INVALID_ENT_REFERENCE)
                {RemovePlayerItem(client, iWeapon), RemoveEdict(iWeapon), iItem = GivePlayerItem(client, "weapon_knife_butterfly");}
                case 8: if(IsValidEntity(iWeapon) && iWeapon != INVALID_ENT_REFERENCE)
                {RemovePlayerItem(client, iWeapon), RemoveEdict(iWeapon), iItem = GivePlayerItem(client, "weapon_knife_push");}
                case 9: if(IsValidEntity(iWeapon) && iWeapon != INVALID_ENT_REFERENCE)
                {RemovePlayerItem(client, iWeapon), RemoveEdict(iWeapon), iItem = GivePlayerItem(client, "weapon_knife_survival_bowie");}
                default: {return;}
        }
        EquipPlayerWeapon(client, iItem);
}

I get the following error (sometimes, I cant meassure when.):

Code:

L 02/21/2017 - 16:00:50: [SM] Exception reported: World not allowed
L 02/21/2017 - 16:00:50: [SM] Blaming: KNIFE.smx
L 02/21/2017 - 16:00:50: [SM] Call stack trace:
L 02/21/2017 - 16:00:50: [SM]  [0] EquipPlayerWeapon
L 02/21/2017 - 16:00:50: [SM]  [1] Line 359, /home/groups/sourcemod/upload_tmp/phpjiKbkU.sp::PlayerSpawn


friagram 02-22-2017 09:13

Re: World not allowed
 
It means you are trying to use index 0, which is world

JanDev 02-22-2017 10:13

Re: World not allowed
 
Quote:

Originally Posted by friagram (Post 2497491)
It means you are trying to use index 0, which is world

So I need to check if iItem = 0 ?

JanDev 02-22-2017 15:51

Re: World not allowed
 
Quote:

Originally Posted by friagram (Post 2497491)
It means you are trying to use index 0, which is world

I didn't quite catch what you trying to say ... maybe try to explain it a bit better :)

Mitchell 02-22-2017 16:04

Re: World not allowed
 
Just like he says check to see if iWeapon is greater than 0 (or even better greater than MaxClients.
Also you might want to rethink that switch statement either into a function or a string array. Usually if there is repeated code then you are doing something wrong.

JanDev 02-22-2017 16:51

Re: World not allowed
 
Quote:

Originally Posted by Mitchell (Post 2497604)
Just like he says check to see if iWeapon is greater than 0 (or even better greater than MaxClients.
Also you might want to rethink that switch statement either into a function or a string array. Usually if there is repeated code then you are doing something wrong.

So theoretical its this ?!:

Code:

if(IsValidEntity(iWeapon) && iWeapon != INVALID_ENT_REFERENCE && iWeapon > 0)
Of course I will change the code and change/remove the switch. It's just a first version.


All times are GMT -4. The time now is 01:33.

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