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

Using CreateDataTimer


Post New Thread Reply   
 
Thread Tools Display Modes
Halt
Senior Member
Join Date: Jan 2015
Location: Black Mesa
Old 05-26-2017 , 01:52   Re: Using CreateDataTimer
Reply With Quote #31

Quote:
Originally Posted by 8guawong View Post
you have to show us the code where your entity is suppose to explode then
Code:
public Action:ArtilleryExplosionTimer(Handle:timer, Handle:datapack)
{
	PrintToChatAll("Executed Timer");
	float _ImpactVector[3];
	_ImpactVector[0] = ReadPackFloat(datapack);
	_ImpactVector[1] = ReadPackFloat(datapack);
	_ImpactVector[2] = ReadPackFloat(datapack);
	new Client = ReadPackCell(datapack);
	for (int i = 0; i < 2; i++)
	{
		_ImpactVector[i] += GetRandomFloat(-250.0, 250.0);
	}
	
	new Explosion = CreateEntityByName("tf_generic_bomb");
	DispatchKeyValue(Explosion, "damage", "180.0");
	DispatchKeyValue(Explosion, "radius", "150.0");
	DispatchKeyValue(Explosion, "health", "1");
	DispatchKeyValue(Explosion, "explode_particle", "fireSmokeExplosion_trackb");
	DispatchKeyValue(Explosion, "sound", "weapons/explode1.wav")
	DispatchSpawn(Explosion);
	TeleportEntity(Explosion, _ImpactVector, NULL_VECTOR, NULL_VECTOR);
	AcceptEntityInput(Explosion, "detonate");
	SDKHooks_TakeDamage(Explosion, Client, Client, 9001.0, DMG_BULLET, GetEntPropEnt(Client, Prop_Send, "m_hActiveWeapon"));
	CloseHandle(datapack);
	delete datapack;
}
Halt is offline
8guawong
AlliedModders Donor
Join Date: Dec 2013
Location: BlackMarke7
Old 05-26-2017 , 07:12   Re: Using CreateDataTimer
Reply With Quote #32

Quote:
Originally Posted by Halt View Post
Code:
public Action:ArtilleryExplosionTimer(Handle:timer, Handle:datapack)
{
	PrintToChatAll("Executed Timer");
	float _ImpactVector[3];
	_ImpactVector[0] = ReadPackFloat(datapack);
	_ImpactVector[1] = ReadPackFloat(datapack);
	_ImpactVector[2] = ReadPackFloat(datapack);
	new Client = ReadPackCell(datapack);
	for (int i = 0; i < 2; i++)
	{
		_ImpactVector[i] += GetRandomFloat(-250.0, 250.0);
	}
	
	new Explosion = CreateEntityByName("tf_generic_bomb");
	DispatchKeyValue(Explosion, "damage", "180.0");
	DispatchKeyValue(Explosion, "radius", "150.0");
	DispatchKeyValue(Explosion, "health", "1");
	DispatchKeyValue(Explosion, "explode_particle", "fireSmokeExplosion_trackb");
	DispatchKeyValue(Explosion, "sound", "weapons/explode1.wav")
	DispatchSpawn(Explosion);
	TeleportEntity(Explosion, _ImpactVector, NULL_VECTOR, NULL_VECTOR);
	AcceptEntityInput(Explosion, "detonate");
	SDKHooks_TakeDamage(Explosion, Client, Client, 9001.0, DMG_BULLET, GetEntPropEnt(Client, Prop_Send, "m_hActiveWeapon"));
	CloseHandle(datapack);
	delete datapack;
}
since you didn't show ALL of your code
can't really tell what the problem is
here are some points you need to know
1. sequence that you write the datapack is the sequence you have read the datapack
so if you write client first you need to read client first

2. _ImpactVector[i] += GetRandomFloat(-250.0, 250.0);
maybe this is where the problem is

3. CloseHandle(datapack);
delete datapack;
you don't need this as WildCard65 stated here https://forums.alliedmods.net/showpo...8&postcount=25
8guawong is offline
WildCard65
Veteran Member
Join Date: Aug 2013
Location: Canada
Old 05-26-2017 , 07:24   Re: Using CreateDataTimer
Reply With Quote #33

Are you resetting the datapack before you read it (either after filling it or during timer execution)
__________________
WildCard65 is offline
Halt
Senior Member
Join Date: Jan 2015
Location: Black Mesa
Old 05-26-2017 , 08:49   Re: Using CreateDataTimer
Reply With Quote #34

Quote:
Originally Posted by 8guawong View Post
since you didn't show ALL of your code
can't really tell what the problem is
here are some points you need to know
1. sequence that you write the datapack is the sequence you have read the datapack
so if you write client first you need to read client first

2. _ImpactVector[i] += GetRandomFloat(-250.0, 250.0);
maybe this is where the problem is

3. CloseHandle(datapack);
delete datapack;
you don't need this as WildCard65 stated here https://forums.alliedmods.net/showpo...8&postcount=25
I write and read in the same sequence. And removed ClosedHandle, and delete datapack. Why might the vector corrections be an issue? I'll attempt it without it there nonetheless.

As for reseting the datapack I'm reseting it before its filled with data and before the timer is created. Here

Code:
public Action:ArtillaryStrike(Client, Args)
{
	float RandomTime = GetRandomFloat(3.0, 8.5);

	float ImpactVector[3];
	Handle datapack;
	ResetPack(datapack);
	GetAimPos(Client, ImpactVector);
	CreateTimer(0.1, ArtillarySmokeTimer, Client);
	CreateDataTimer(RandomTime, ArtilleryExplosionTimer, datapack);
	WritePackFloat(datapack, ImpactVector[0]);
	WritePackFloat(datapack, ImpactVector[1]);
	WritePackFloat(datapack, ImpactVector[2]);
	WritePackCell(datapack, Client);
	return Plugin_Handled;
}

Last edited by Halt; 05-26-2017 at 08:49.
Halt is offline
8guawong
AlliedModders Donor
Join Date: Dec 2013
Location: BlackMarke7
Old 05-26-2017 , 09:10   Re: Using CreateDataTimer
Reply With Quote #35

Quote:
Originally Posted by Halt View Post
I write and read in the same sequence. And removed ClosedHandle, and delete datapack. Why might the vector corrections be an issue? I'll attempt it without it there nonetheless.

As for reseting the datapack I'm reseting it before its filled with data and before the timer is created. Here

Code:
public Action:ArtillaryStrike(Client, Args)
{
	float RandomTime = GetRandomFloat(3.0, 8.5);

	float ImpactVector[3];
	Handle datapack;
	ResetPack(datapack);
	GetAimPos(Client, ImpactVector);
	CreateTimer(0.1, ArtillarySmokeTimer, Client);
	CreateDataTimer(RandomTime, ArtilleryExplosionTimer, datapack);
	WritePackFloat(datapack, ImpactVector[0]);
	WritePackFloat(datapack, ImpactVector[1]);
	WritePackFloat(datapack, ImpactVector[2]);
	WritePackCell(datapack, Client);
	return Plugin_Handled;
}
you only need to reset the pack before you read it
you do not need to reset it before writing to it

because when you randomize the location it might be somwhere you could not see? try with smaller values first?
8guawong is offline
brunoronning
Senior Member
Join Date: Jan 2014
Location: Brazil
Old 05-26-2017 , 09:23   Re: Using CreateDataTimer
Reply With Quote #36

Quote:
Originally Posted by Halt View Post
I write and read in the same sequence. And removed ClosedHandle, and delete datapack. Why might the vector corrections be an issue? I'll attempt it without it there nonetheless.

As for reseting the datapack I'm reseting it before its filled with data and before the timer is created. Here
Try:
PHP Code:
public Action ArtillaryStrike(int clientint args)
{
    
float RandomTime GetRandomFloat(3.08.5);

    
float ImpactVector[3];
    
GetAimPos(clientImpactVector);

    
CreateTimer(0.1ArtillarySmokeTimerclient);
    
    
DataPack ArtillaryPack;
    
CreateDataTimer(RandomTimeArtilleryExplosionTimerArtillaryPack);
    
ArtillaryPack.WriteFloat(ImpactVector[0]);
    
ArtillaryPack.WriteFloat(ImpactVector[1]);
    
ArtillaryPack.WriteFloat(ImpactVector[2]);
    
ArtillaryPack.WriteCell(client);
    
    return 
Plugin_Handled;
}

public 
Action ArtilleryExplosionTimer(Handle timerDataPack ArtillaryPack)
{
    
float ImpactVector[3];
    
int client;

    
ArtillaryPack.Reset();

    
PrintToChatAll("Executed Timer");
    
ImpactVector[0] = ArtillaryPack.ReadFloat();
    
ImpactVector[1] = ArtillaryPack.ReadFloat();
    
ImpactVector[2] = ArtillaryPack.ReadFloat();
    
client ArtillaryPack.ReadCell();

    if (!
client || !IsClientInGame(client))
        return 
Plugin_Stop;

    for (
int i 02i++)
    {
        
ImpactVector[i] += GetRandomFloat(-250.0250.0);
    }

    
int Explosion CreateEntityByName("tf_generic_bomb");
    
DispatchKeyValue(Explosion"damage""180.0");
    
DispatchKeyValue(Explosion"radius""150.0");
    
DispatchKeyValue(Explosion"health""1");
    
DispatchKeyValue(Explosion"explode_particle""fireSmokeExplosion_trackb");
    
DispatchKeyValue(Explosion"sound""weapons/explode1.wav")
    
DispatchSpawn(Explosion);
    
TeleportEntity(ExplosionImpactVectorNULL_VECTORNULL_VECTOR);
    
AcceptEntityInput(Explosion"detonate");
    
SDKHooks_TakeDamage(Explosionclientclient9001.0DMG_BULLETGetEntPropEnt(clientProp_Send"m_hActiveWeapon"));

    return 
Plugin_Handled;


Last edited by brunoronning; 05-26-2017 at 09:34. Reason: client valid
brunoronning is offline
Halt
Senior Member
Join Date: Jan 2015
Location: Black Mesa
Old 05-26-2017 , 15:15   Re: Using CreateDataTimer
Reply With Quote #37

It works now ;) thanks everyone for your help and patience. Solved.
Halt is offline
asherkin
SourceMod Developer
Join Date: Aug 2009
Location: OnGameFrame()
Old 05-26-2017 , 18:34   Re: Using CreateDataTimer
Reply With Quote #38

Quote:
Originally Posted by Halt View Post
I write and read in the same sequence. And removed ClosedHandle, and delete datapack. Why might the vector corrections be an issue? I'll attempt it without it there nonetheless.

As for reseting the datapack I'm reseting it before its filled with data and before the timer is created. Here

Code:
public Action:ArtillaryStrike(Client, Args)
{
	float RandomTime = GetRandomFloat(3.0, 8.5);

	float ImpactVector[3];
	Handle datapack;
	ResetPack(datapack);
	GetAimPos(Client, ImpactVector);
	CreateTimer(0.1, ArtillarySmokeTimer, Client);
	CreateDataTimer(RandomTime, ArtilleryExplosionTimer, datapack);
	WritePackFloat(datapack, ImpactVector[0]);
	WritePackFloat(datapack, ImpactVector[1]);
	WritePackFloat(datapack, ImpactVector[2]);
	WritePackCell(datapack, Client);
	return Plugin_Handled;
}
Just a note, if you'd bothered checking the error logs, you would have seen this throwing an error on the ResetPack call, and thus not executing the rest of the code at all.
__________________
asherkin is offline
Halt
Senior Member
Join Date: Jan 2015
Location: Black Mesa
Old 05-26-2017 , 22:39   Re: Using CreateDataTimer
Reply With Quote #39

Quote:
Originally Posted by asherkin View Post
Just a note, if you'd bothered checking the error logs, you would have seen this throwing an error on the ResetPack call, and thus not executing the rest of the code at all.
I noticed that when I read it and re-located ResetPack() just above where I write them.

Spoiler


And so far its worked properly. I use the command it creates explosions at random times and random vectors every time I use it.

Last edited by Halt; 05-26-2017 at 22:43.
Halt is offline
hmmmmm
Great Tester of Whatever
Join Date: Mar 2017
Location: ...
Old 05-27-2017 , 01:04   Re: Using CreateDataTimer
Reply With Quote #40

This is the kind of situation where loops and arrays are very helpful. Can condense a lot of that code and avoid repeating stuff 6 different times.
hmmmmm is offline
Reply



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 15:53.


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