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

Need help with entity editing.


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
[email protected]
Junior Member
Join Date: Aug 2013
Old 08-06-2013 , 18:23   Need help with entity editing.
Reply With Quote #1

So basically what I really want to do is make the same change to all entities on all maps on the server. I am trying to change the value of the OrientationType on both the classnames func_tanktrain and path_track to a value of 0.

However, I am really new to SM coding, but I really did my best. However, it ended up being more advanced than it had to, and it might be the cause I get an error on compile.

The error is: :
Code:
error 017: undefined symbol "EntIndex"
I don't know how this can not be a defined symbol, as everywhere I have looked it is.

Here are my source code.
Code:
public OnPluginStart()
{
	RegConsoleCmd("sm_spinfix", commandfixent, "");
}

public Action:commandfixent(client, args)
{
	
	new ent = GetClientAimTarget(client, false);
	
	if(ent != -1 && IsValidEntity(ent))
	{
		new String:classname[32];
		GetEdictClassname(ent, classname, 32);
		
		if(StrContains(classname, "tanktrain") != -1)
		{
			
			
			DispatchKeyValueFloat(EntIndex, "orientationtype", 0.0);
			
			
		} else {
			ReplyToCommand(client,"You're not aiming at a bug!") ;

			
		}
		
	}
	else
	{
		ReplyToCommand(client,"Please aim at a entity") ;
	}
	
	return Plugin_Handled;
	
	
	}
An easier way would be to just delete all that extra stuff about aiming at the entity, but rather just apply it to all the tanktrain and path_track entities so that every one of those entities on every map always have that setting.

I am sorry if I am unclear, this is my first try at creating something useful.

Thanks a lot.
aMasheep@gmail.com is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 08-06-2013 , 18:44   Re: Need help with entity editing.
Reply With Quote #2

Quote:
Originally Posted by [email protected] View Post
So basically what I really want to do is make the same change to all entities on all maps on the server. I am trying to change the value of the OrientationType on both the classnames func_tanktrain and path_track to a value of 0.

However, I am really new to SM coding, but I really did my best. However, it ended up being more advanced than it had to, and it might be the cause I get an error on compile.

The error is: :
Code:
error 017: undefined symbol "EntIndex"
I don't know how this can not be a defined symbol, as everywhere I have looked it is.

Here are my source code.
Code:
public OnPluginStart()
{
	RegConsoleCmd("sm_spinfix", commandfixent, "");
}

public Action:commandfixent(client, args)
{
	
	new ent = GetClientAimTarget(client, false);
	
	if(ent != -1 && IsValidEntity(ent))
	{
		new String:classname[32];
		GetEdictClassname(ent, classname, 32);
		
		if(StrContains(classname, "tanktrain") != -1)
		{
			
			
			DispatchKeyValueFloat(EntIndex, "orientationtype", 0.0);
			
			
		} else {
			ReplyToCommand(client,"You're not aiming at a bug!") ;

			
		}
		
	}
	else
	{
		ReplyToCommand(client,"Please aim at a entity") ;
	}
	
	return Plugin_Handled;
	
	
	}
An easier way would be to just delete all that extra stuff about aiming at the entity, but rather just apply it to all the tanktrain and path_track entities so that every one of those entities on every map always have that setting.

I am sorry if I am unclear, this is my first try at creating something useful.

Thanks a lot.
You're using "ent" in one spot and "EntIndex" in another one.
__________________
Not currently working on SourceMod plugin development.
Powerlord is offline
Doodil
Senior Member
Join Date: Mar 2012
Old 08-06-2013 , 18:47   Re: Need help with entity editing.
Reply With Quote #3

Well, "EntIndex" in line 17 is not defined.
Code:
DispatchKeyValueFloat(EntIndex, "orientationtype", 0.0);
You have never used/initialized "EntIndex" before, you probably want to replace that with "ent", since this is the actual entity you want to change:

Code:
DispatchKeyValueFloat(ent, "orientationtype", 0.0);

If you want to apply these changes to all entites on all maps, take a look at the function FindEntityByClassname. Hook the roundstart event or OnPluginStart and apply the changes there
Doodil is offline
[email protected]
Junior Member
Join Date: Aug 2013
Old 08-07-2013 , 05:37   Re: Need help with entity editing.
Reply With Quote #4

Thanks for the help guys!

I tried deleteing everything I didn't need, so the FindEntityByClassname is hooked to OnPluginStart. However, for some reason, it does still seem like the entities are not beeing modified.

Here is my code:
Code:
public OnPluginStart()
{
	new ent = FindEntityByClassname(ent, "func_tanktrain");
	new String:classname[32];
	GetEdictClassname(ent, classname, 32);
	DispatchKeyValueFloat(ent, "orientationtype", 0.0);
	
}
I also tried this, but still no luck. Pretty sure it is a Float value.
Code:
public OnPluginStart()
{
	new ent = FindEntityByClassname(ent, "func_tanktrain");
	new String:classname[32];
	GetEdictClassname(ent, classname, 32);
	DispatchKeyValue(ent, "orientationtype", "0");
	
}
Thanks.
aMasheep@gmail.com is offline
Doodil
Senior Member
Join Date: Mar 2012
Old 08-07-2013 , 05:56   Re: Need help with entity editing.
Reply With Quote #5

Well, first of all you are only editing one (the first) func_train. You've got to use a loop like this to process all of them:

PHP Code:
public OnPluginStart()
{
    new 
ent = -1;
    while ((
ent FindEntityByClassname(ent"func_tanktrain")) != -1)
    {
        new 
String:classname[32];
        
GetEdictClassname(entclassname32);
        
DispatchKeyValue(ent"orientationtype""0");
    }    

(Imagine the function as a list of entities, the first time you start from the very first element until you find the first entity that has the classname of "func_tanktrain", the second loop you start from the index of the first entity, to not find this one again, but instead the next entity in the list. If you move through the whole list without finding the entity, the function return -1 and therefore ends the loop)

Another thing is the way you dispatch the key value. If you are sure that it's a floatvalue you want to dispatch, use DispatchKeyValueFloat instead. You can also check the return value, if you succeeded in changing the value it returns true.

It also might be possible that you have to dispatch another keyvalue to make the changes take effect... I don't really remember which one that was, something about activate I assume (I might be wrong here, but I remember there being something like this some time ago).

I can also imagine that the OnRoundStart or OnMapStart event resets the entities, maybe check into that if the other things don't work.


And last but not least: What are you trying to achieve changing the orientationtype?
Doodil is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 08-07-2013 , 09:09   Re: Need help with entity editing.
Reply With Quote #6

Unless your plugin is late-loaded, the entities aren't going to exist when the plugin starts. Heck, entities won't exist yet during OnMapStart and the other callbacks that fire when the map starts.

SDKHooks (comes with newer SourceMod 1.5 snapshots) and its OnEntityCreated callback save you a lot of trouble in this regard.

PHP Code:
public OnEntityCreated(entity, const String:classname[])
{
    if (
StrEqual(classname"func_tanktrain"))
    {
        
SDKHook(entitySDKHook_SpawnPostSpawnTrain);
    }
}

public 
SpawnTrain(entity)
{
    
DispatchKeyValue(entity"orientationtype""0");

A Spawn hook is used here instead of doing it on creation because, if you don't, the game will overwrite the properties you set. Spawn happens after the game writes its properties.
__________________
Not currently working on SourceMod plugin development.

Last edited by Powerlord; 08-07-2013 at 09:12.
Powerlord is offline
[email protected]
Junior Member
Join Date: Aug 2013
Old 08-07-2013 , 13:09   Re: Need help with entity editing.
Reply With Quote #7

Quote:
Originally Posted by Doodil View Post
Well, first of all you are only editing one (the first) func_train. You've got to use a loop like this to process all of them:

PHP Code:
public OnPluginStart()
{
    new 
ent = -1;
    while ((
ent FindEntityByClassname(ent"func_tanktrain")) != -1)
    {
        new 
String:classname[32];
        
GetEdictClassname(entclassname32);
        
DispatchKeyValue(ent"orientationtype""0");
    }    

(Imagine the function as a list of entities, the first time you start from the very first element until you find the first entity that has the classname of "func_tanktrain", the second loop you start from the index of the first entity, to not find this one again, but instead the next entity in the list. If you move through the whole list without finding the entity, the function return -1 and therefore ends the loop)

Another thing is the way you dispatch the key value. If you are sure that it's a floatvalue you want to dispatch, use DispatchKeyValueFloat instead. You can also check the return value, if you succeeded in changing the value it returns true.

It also might be possible that you have to dispatch another keyvalue to make the changes take effect... I don't really remember which one that was, something about activate I assume (I might be wrong here, but I remember there being something like this some time ago).

I can also imagine that the OnRoundStart or OnMapStart event resets the entities, maybe check into that if the other things don't work.


And last but not least: What are you trying to achieve changing the orientationtype?
Thanks a lot. It works great. However, it is just as you said with the OnRoundStart and OnMapStart. But I cant hook the same to all of those, because the entities properties are set after roundstart and mapstart. (the only thing was that it is a float value, worked as soon as i set DispatchKeyValueFloat in stead of DispatchKeyValue.) Thanks
aMasheep@gmail.com is offline
[email protected]
Junior Member
Join Date: Aug 2013
Old 08-07-2013 , 13:14   Re: Need help with entity editing.
Reply With Quote #8

Quote:
Originally Posted by Powerlord View Post
Unless your plugin is late-loaded, the entities aren't going to exist when the plugin starts. Heck, entities won't exist yet during OnMapStart and the other callbacks that fire when the map starts.

SDKHooks (comes with newer SourceMod 1.5 snapshots) and its OnEntityCreated callback save you a lot of trouble in this regard.

PHP Code:
public OnEntityCreated(entity, const String:classname[])
{
    if (
StrEqual(classname"func_tanktrain"))
    {
        
SDKHook(entitySDKHook_SpawnPostSpawnTrain);
    }
}

public 
SpawnTrain(entity)
{
    
DispatchKeyValue(entity"orientationtype""0");

A Spawn hook is used here instead of doing it on creation because, if you don't, the game will overwrite the properties you set. Spawn happens after the game writes its properties.
This will probably work the best, however, I got a error when compiling, saying:
PHP Code:
error 017undefined symbol "SDKHook" 
I dont understand why I get that. I have included both sorurcemod(ofc) and SDKtools on the top of my script. here:
PHP Code:
#include <sourcemod>
#include <sdktools> 
Oh, and BTW. the point of editing the orientation values is so that then the tanktrain hit a path_track, it doesn't rotate. (This will in some cases throw the players off the tanktrain and that may kill them.)
aMasheep@gmail.com is offline
11530
Veteran Member
Join Date: Sep 2011
Location: Underworld
Old 08-07-2013 , 13:17   Re: Need help with entity editing.
Reply With Quote #9

SDKTools != SDKHooks
__________________
11530 is offline
[email protected]
Junior Member
Join Date: Aug 2013
Old 08-07-2013 , 13:23   Re: Need help with entity editing.
Reply With Quote #10

Quote:
Originally Posted by 11530 View Post
SDKTools != SDKHooks
But I can't #include <SDKHooks>. Gives me: Fatal error 120: cannor read from file: "SDKHooks" on compile.
aMasheep@gmail.com 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 09:09.


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