AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Help with improving and optimizing code (https://forums.alliedmods.net/showthread.php?t=251688)

bardukis 11-17-2014 11:56

Help with improving and optimizing code
 
1 Attachment(s)
Hello guys, I made for myself a code which satisfies my needs and I need your opinions, advices and recommendations to make it better in terms of scripting.

avril-lavigne 11-17-2014 12:07

Re: Help with improving and optimizing code
 
1.You can use offset to count spawns
2. to determine what hand use simple new hand[33]
hand[id] = 1 // lets say right hand
hand[id] = 2 // left hand
if(hand[id] == 1)
// code

bardukis 11-17-2014 12:17

Re: Help with improving and optimizing code
 
Quote:

Originally Posted by avril-lavigne (Post 2225384)
1.You can use offset to count spawns
2. to determine what hand use simple new hand[33]
hand[id] = 1 // lets say right hand
hand[id] = 2 // left hand
if(hand[id] == 1)
// code

1. I cant understand the recommendation with offset... Can you explain me?
2. Can you explain me why? I want to learn.

Xunfop 11-19-2014 08:03

Re: Help with improving and optimizing code
 
PHP Code:

new bool:leftHand;
new 
bool:rightHand

you don't need 2 booleans, not a must b, or here will go wrong
PHP Code:

if (leftHand == true) {
    
menu_additem(menu"\dLeft Hand \r[current hand]"""0);
} else {
    
menu_additem(menu"\wLeft Hand"""0);
}
if (
rightHand == true) {
    
menu_additem(menu"\dRight Hand \r[current hand]"""0);
} else {
    
menu_additem(menu"\wRight Hand"""0);


and you should check player's hand setting instead this boolean.


PHP Code:

new firstJoin[33]; 

use boolean instead this, will more readable.

Jhob94 11-19-2014 09:08

Re: Help with improving and optimizing code
 
In fact just need this:

PHP Code:

#define MAXPLAYERS 32
new boolleftHand[MAXPLAYERS 1]

// ...

if (leftHand[id])
{
    
menu_additem(menu"\dLeft Hand \r[current hand]"""0);
    
menu_additem(menu"\wRight Hand"""0);
}

else
{
    
menu_additem(menu"\wLeft Hand"""0);
    
menu_additem(menu"\dRight Hand \r[current hand]"""0);


Edit:
About the offsets, its better way. More efficience.

bardukis 11-19-2014 13:08

Re: Help with improving and optimizing code
 
Thank you @Xunfop, Thank you Johb94.
Quote:

Originally Posted by Jhob94 (Post 2225942)
About the offsets, its better way. More efficience.

Sorry but, I searched about offsets and I didnt find something... I even dont know what is offset. Can you show me?

bardukis 11-24-2014 12:37

Re: Help with improving and optimizing code
 
Can you make code better?


All times are GMT -4. The time now is 17:32.

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