Raised This Month: $12 Target: $400
 3% 

Solved Am I Correct ?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Abhinash
Senior Member
Join Date: Jan 2015
Location: India,kolkata
Old 11-18-2020 , 18:34   Am I Correct ?
Reply With Quote #1

So hey guys.
Yesterday, I learned about taskids.
So, I tried to work with it and did something in code.
Since, many are veterans in coding here, I wanna know that I did it correct or not.
Please examine my code and tell me if I used taskid properly or not.
Code --

Definition part --
Code:
#define TASK_MODEL               2000
set_task part --
Code:
static Float:current_time
current_time = get_gametime()

if (current_time - g_models_targettime >= g_modelchange_delay)
{
	ChangeModels(id + TASK_MODEL) 
	g_models_targettime = current_time
}
else
{
	set_task((g_models_targettime + g_modelchange_delay) - current_time, "ChangeModels", id + TASK_MODEL)
	g_models_targettime = g_models_targettime + g_modelchange_delay
}
And finally Function part --
Code:
// Set User Model
public ChangeModels(taskid)
{
	static bool:bChange;
	static cModel[24];
	static i;
	static id;
	id = taskid - TASK_MODEL;
	bChange = true;
	fm_cs_get_user_model(id, cModel, 24);
	if (!g_zombie[id])
	{
		if (get_user_flags(id) & read_flags("a"))
		{
			if (equal(cModel, "vip", 0))
			{
				bChange = false;
			}
		}
		i = 0;
		while (i < 4)
		{
			if (equal(cModel, g_cHumanModels[i], 0))
			{
				bChange = false;
			}
			i += 1;
		}
		
	}
	if (bChange)
	{
		if (!g_zombie[id])
		{
			if (get_user_flags(id) & read_flags("a"))
			{
				set_user_info(id, "model", g_cAdminModels[random_num(0, sizeof g_cAdminModels - 1)])
			}
			else
			{
				set_user_info(id, "model", g_cHumanModels[random_num(0, sizeof g_cHumanModels - 1)])
			
			}
			if (g_survivor[id])
			{
				set_user_info(id, "model", g_cSurvivorModels[random_num(0, sizeof g_cSurvivorModels - 1)])
			}
			if (g_sniper[id])
			{
				set_user_info(id, "model", g_cSniperModels[random_num(0, sizeof g_cSniperModels - 1)])
			}
			if (g_zadoc[id])
			{
				set_user_info(id, "model", g_cZadocModels[random_num(0, sizeof g_cZadocModels - 1)])
			}
		}
		else
		{
			if (g_nemesis[id])
			{
				set_user_info(id, "model", g_cNemesisModels[random_num(0, sizeof g_cNemesisModels - 1)])
			}
			if (g_assassin[id])
			{
				set_user_info(id, "model", g_cAssassinModels[random_num(0, sizeof g_cAssassinModels - 1)])
			}
			if (g_bombardier[id])
			{
				set_user_info(id, "model", g_cBombardierModels[random_num(0, sizeof g_cBombardierModels - 1)])
			}
			else
			{
				set_user_info(id, "model", "zombie_source")
			}
		}
	}
	return 0;
}
Please dont judge me, I am still learning.

Last edited by Abhinash; 11-20-2020 at 09:49.
Abhinash is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 11-18-2020 , 19:22   Re: Am I Correct ?
Reply With Quote #2

You never did listen in this thread of yours https://forums.alliedmods.net/showthread.php?t=328516
Otherwise you wouldn't have posted again
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !

Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
Abhinash
Senior Member
Join Date: Jan 2015
Location: India,kolkata
Old 11-18-2020 , 19:29   Re: Am I Correct ?
Reply With Quote #3

Quote:
Originally Posted by Natsheh View Post
You never did listen in this thread of yours https://forums.alliedmods.net/showthread.php?t=328516
Otherwise you wouldn't have posted again
I really cant get you because that post was of a different topic and this is different. If I am wrong correct me.
Here, I tried learning something new and applied and after testing it seems that this ChangeModel() function is not working.
Can you help me fix it out ?
Please ?
Abhinash is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 11-18-2020 , 20:56   Re: Am I Correct ?
Reply With Quote #4

Did it work? Please test your own code before posting. If it doesn't work when you test it, you need to try an debug the code yourself. You can debug your code by print values to console (if you have access to the server console) or to a log file with log_to_file(). This will allow you to know what values are being used by your code. So many things can be solved this way without having to wait for someone to post.
__________________
fysiks is offline
Abhinash
Senior Member
Join Date: Jan 2015
Location: India,kolkata
Old 11-19-2020 , 09:21   Re: Am I Correct ?
Reply With Quote #5

Quote:
Originally Posted by fysiks View Post
Did it work? Please test your own code before posting. If it doesn't work when you test it, you need to try an debug the code yourself. You can debug your code by print values to console (if you have access to the server console) or to a log file with log_to_file(). This will allow you to know what values are being used by your code. So many things can be solved this way without having to wait for someone to post.
Hey fysiks.I did as you said.
I tried debugging with amx_log("Human model changed to %s", g_cHumanModels)

So here is the log --
Code:
L 11/19/2020 - 19:44:23: -------- Mapchange to de_dust2 --------
L 11/19/2020 - 19:44:23: [AMXX] Plugin "item.amxx" failed to load: Plugin uses an unknown function (name "zp_frozen") - check your modules.ini.
L 11/19/2020 - 19:44:25: [admin.amxx] Login: "EYE | NeO<33><STEAM_ID_LAN><>" became an admin (account "EYE | NeO") (access "abcdefghijklmnopqrstuv") (address "loopback")
L 11/19/2020 - 19:44:26: [admin.amxx] Login: "EYE | NeO<33><STEAM_ID_LAN><>" became an admin (account "EYE | NeO") (access "abcdefghijklmnopqrstuv") (address "loopback")
L 11/19/2020 - 19:44:28: [zombie_queen.amxx] Admin model changed to vip
L 11/19/2020 - 19:44:34: [zombie_queen.amxx] Human model changed to (8Dterror
L 11/19/2020 - 19:44:34: [zombie_queen.amxx] Human model changed to (8Dterror
L 11/19/2020 - 19:44:35: [zombie_queen.amxx] Human model changed to (8Dterror
L 11/19/2020 - 19:44:35: [zombie_queen.amxx] Human model changed to (8Dterror
L 11/19/2020 - 19:44:36: [zombie_queen.amxx] Human model changed to (8Dterror
L 11/19/2020 - 19:44:36: [zombie_queen.amxx] Human model changed to (8Dterror
L 11/19/2020 - 19:44:37: [zombie_queen.amxx] Human model changed to (8Dterror
L 11/19/2020 - 19:44:38: [zombie_queen.amxx] Human model changed to (8Dterror
L 11/19/2020 - 19:44:39: [zombie_queen.amxx] Human model changed to (8Dterror
L 11/19/2020 - 19:44:39: [zombie_queen.amxx] Human model changed to (8Dterror
L 11/19/2020 - 19:44:39: [zombie_queen.amxx] Human model changed to (8Dterror
L 11/19/2020 - 19:44:39: [zombie_queen.amxx] Human model changed to (8Dterror
L 11/19/2020 - 19:44:40: [zombie_queen.amxx] Human model changed to (8Dterror
L 11/19/2020 - 19:44:40: [zombie_queen.amxx] Human model changed to (8Dterror
L 11/19/2020 - 19:44:41: [zombie_queen.amxx] Human model changed to (8Dterror
L 11/19/2020 - 19:44:41: [zombie_queen.amxx] Human model changed to (8Dterror
L 11/19/2020 - 19:44:42: [zombie_queen.amxx] Human model changed to (8Dterror
L 11/19/2020 - 19:44:42: [zombie_queen.amxx] Human model changed to (8Dterror
L 11/19/2020 - 19:44:43: [zombie_queen.amxx] Human model changed to (8Dterror
L 11/19/2020 - 19:44:43: [zombie_queen.amxx] Human model changed to (8Dterror
L 11/19/2020 - 19:44:44: [zombie_queen.amxx] Human model changed to (8Dterror
L 11/19/2020 - 19:44:44: [zombie_queen.amxx] Human model changed to (8Dterror
L 11/19/2020 - 19:44:45: [zombie_queen.amxx] Human model changed to (8Dterror
L 11/19/2020 - 19:44:45: [zombie_queen.amxx] Human model changed to (8Dterror
L 11/19/2020 - 19:44:46: [zombie_queen.amxx] Human model changed to (8Dterror
L 11/19/2020 - 19:44:46: [zombie_queen.amxx] Human model changed to (8Dterror
L 11/19/2020 - 19:44:47: [zombie_queen.amxx] Human model changed to (8Dterror
L 11/19/2020 - 19:44:47: [zombie_queen.amxx] Human model changed to (8Dterror
L 11/19/2020 - 19:44:48: [zombie_queen.amxx] Human model changed to (8Dterror
L 11/19/2020 - 19:44:48: [zombie_queen.amxx] Human model changed to (8Dterror
L 11/19/2020 - 19:44:52: [zombie_queen.amxx] Human model changed to (8Dterror
I dont know whats wrong can you help me fix it out please ?
The function is executed but model is not set.

Last edited by Abhinash; 11-19-2020 at 09:27.
Abhinash is offline
Abhinash
Senior Member
Join Date: Jan 2015
Location: India,kolkata
Old 11-19-2020 , 14:28   Re: Am I Correct ?
Reply With Quote #6

Can anyone please help me out ?
Abhinash is offline
Black Rose
Veteran Member
Join Date: Feb 2011
Location: Stockholm, Sweden
Old 11-22-2020 , 12:20   Re: Am I Correct ?
Reply With Quote #7

The taskid looks fine. However, unneccessary if you don't have any other tasks, especially if you're not cancelling any. Then you can always straight up use the player id, just make sure the player in question is still connected and is the same player when executing the task. Userid is great for that purpose. If you cancel the task on disconnect, that's fine too. No need for checking then.

Code:
    static cModel[24];     fm_cs_get_user_model(id, cModel, 24);
Make room for null.
Code:
    static cModel[25]; // 24 or 25?     fm_cs_get_user_model(id, cModel, charsmax(cModel));


Not really problems but keep it neat:
Code:
g_cAdminModels[random_num(0, sizeof g_cAdminModels - 1)]
aka
Code:
g_cAdminModels[random(sizeof g_cAdminModels)]


Code:
        i = 0;         while (i < 4)         {             if (equal(cModel, g_cHumanModels[i], 0))             {                 bChange = false;             }             i += 1;         }
While loops are great, but use whatever fits the purpose. In this case you have a known maximum number of executions, use a for-loop.
Code:
        for ( i = 0 ; i < sizeof g_cHumanModels ; i++)         {             if (equal(cModel, g_cHumanModels[i], 0))             {                 bChange = false;                 break;             }         }


Your debug is missing an index though, so your error might not be an error at all.
Code:
new temp = random(sizeof g_cHumanModels); set_user_info(id, "model", g_cHumanModels[temp]); amx_log("Human model changed to %s", g_cHumanModels[temp]);

I would also suggest post all relevant code.
Declaration of the models and fm_cs_get_user_model().
__________________
Black Rose is offline
Abhinash
Senior Member
Join Date: Jan 2015
Location: India,kolkata
Old 11-22-2020 , 12:49   Re: Am I Correct ?
Reply With Quote #8

Quote:
Originally Posted by Black Rose View Post
The taskid looks fine. However, unneccessary if you don't have any other tasks, especially if you're not cancelling any. Then you can always straight up use the player id, just make sure the player in question is still connected and is the same player when executing the task. Userid is great for that purpose. If you cancel the task on disconnect, that's fine too. No need for checking then.

Code:
    static cModel[24];     fm_cs_get_user_model(id, cModel, 24);
Make room for null.
Code:
    static cModel[25]; // 24 or 25?     fm_cs_get_user_model(id, cModel, charsmax(cModel));


Not really problems but keep it neat:
Code:
g_cAdminModels[random_num(0, sizeof g_cAdminModels - 1)]
aka
Code:
g_cAdminModels[random(sizeof g_cAdminModels)]


Code:
        i = 0;         while (i < 4)         {             if (equal(cModel, g_cHumanModels[i], 0))             {                 bChange = false;             }             i += 1;         }
While loops are great, but use whatever fits the purpose. In this case you have a known maximum number of executions, use a for-loop.
Code:
        for ( i = 0 ; i < sizeof g_cHumanModels ; i++)         {             if (equal(cModel, g_cHumanModels[i], 0))             {                 bChange = false;                 break;             }         }


Your debug is missing an index though, so your error might not be an error at all.
Code:
new temp = random(sizeof g_cHumanModels); set_user_info(id, "model", g_cHumanModels[temp]); amx_log("Human model changed to %s", g_cHumanModels[temp]);

I would also suggest post all relevant code.
Declaration of the models and fm_cs_get_user_model().
Thanks a lot Black Rose.
Here you go --

Declaration of models --
Code:
new g_cHumanModels[][] =
{
    "sas",
    "gign",
    "gsg9",
    "arctic"
}
And fm_get_user_model() is just get_user_info() model.
Abhinash is offline
CrazY.
Veteran Member
Join Date: May 2015
Location: SP, Brazil
Old 11-22-2020 , 18:37   Re: Am I Correct ?
Reply With Quote #9

Might be a problem with fm_set_user_model. Try with this https://forums.alliedmods.net/showthread.php?t=161255 or cs_set_user_model if you're using amxmodx 1.9.0 or later
__________________








CrazY. is offline
Abhinash
Senior Member
Join Date: Jan 2015
Location: India,kolkata
Old 11-23-2020 , 10:35   Re: Am I Correct ?
Reply With Quote #10

Quote:
Originally Posted by CrazY. View Post
Might be a problem with fm_set_user_model. Try with this https://forums.alliedmods.net/showthread.php?t=161255 or cs_set_user_model if you're using amxmodx 1.9.0 or later
cs_set_user_model() causes SZ_Overflow
Abhinash is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 02:47.


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