SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 11/02/2018, 11:35 AM   #11
Mugala
Gangsta
 
Mugala's Avatar
 
Join Date: Nov 2012
Location: behind u
Posts: 648
Reputation: 30
Default Re: A little question

Quote:
Originally Posted by iKarim View Post
Why are you accessing it like that? It obviously is not an array. Remove the [i], it's a normal variable.



That's wrong as well, you can't initialize an array with a variable as it's size, since the arrays are initialized on compilation time instead of run time.
yeah that's right, my bad, I'm just wrote this whole code in comments.

okay here is a fixed code.
PHP Code:
OnPlayerTakeDamage/OnPlayerGiveDamage  

new Float:X,Float:Y,Float:Z;  
GetPlayerPos(playerid,X,Y,Z); 
for(new 
0GetPlayerPoolSize(); <= ji++) 

    if(
!= playerid
    { 
        new 
obj CreatePlayerObject(i,1240,X,Y,Z+1.5,0,0,0);  
        
AttachPlayerObjectToPlayer(i,obj,playerid,0,0,1.5,0,0,0);  
        
SetTimerEx("DestroyThisAttachedObject",1000,0,"ii",i,obj); 
    } 


forward DestroyThisAttachedObject(playerid,obj);  
public 
DestroyThisAttachedObject(playerid,obj)  
{  
    
DestroyPlayerObject(playerid,obj);  
    return 
1;  

P.S. when u edit this code, make sure u'll use PlayerObject and not basic Object.
__________________
here to help
Mugala is offline   Reply With Quote
Old 11/02/2018, 07:37 PM   #12
ivndosos
Huge Clucker
 
ivndosos's Avatar
 
Join Date: Sep 2014
Location: Russian Federation, Kaliningrad.
Posts: 407
Reputation: 18
Default Re: A little question

hey im bumping this topic since I have an issue, i'll show u a video I've made

https://www.youtube.com/watch?v=KuU9...ature=youtu.be
ivndosos is offline   Reply With Quote
Old 11/02/2018, 08:04 PM   #13
Mugala
Gangsta
 
Mugala's Avatar
 
Join Date: Nov 2012
Location: behind u
Posts: 648
Reputation: 30
Default Re: A little question

you have to use AttachPlayerObjectToPlayer for attachment.
also you have to use Global variables to dont create objects again (by the way, it's not a problem if there will be created 3/4 object, they all will be attached and removed in a seconds)
__________________
here to help
Mugala is offline   Reply With Quote
Old 12/02/2018, 03:32 AM   #14
ivndosos
Huge Clucker
 
ivndosos's Avatar
 
Join Date: Sep 2014
Location: Russian Federation, Kaliningrad.
Posts: 407
Reputation: 18
Default Re: A little question

yh i did thats the code

Code:
    	new Float:x, Float:y, Float:z;
    	GetPlayerPos(playerid, x,y,z);
    	for(new i = 0, j = GetPlayerPoolSize(); i <= j; i ++)
    	{
	    	new heartobject = CreatePlayerObject(i,1240, x,y,z+1.5,0,0,0);
            AttachPlayerObjectToPlayer(i,heartobject, playerid, 0,0,1.5,0,0,0);
	    	SetTimerEx("HeartObject", 3000,0,"ii", i, heartobject);
		}
 		return 1;
}

forward HeartObject(playerid,heartobject);
public HeartObject(playerid,heartobject)
{
   DestroyPlayerObject(playerid,heartobject);
   return 1;
}
ivndosos is offline   Reply With Quote
Old 12/02/2018, 03:42 PM   #15
ivndosos
Huge Clucker
 
ivndosos's Avatar
 
Join Date: Sep 2014
Location: Russian Federation, Kaliningrad.
Posts: 407
Reputation: 18
Default Re: A little question

bump
ivndosos is offline   Reply With Quote
Old 12/02/2018, 05:44 PM   #16
Mugala
Gangsta
 
Mugala's Avatar
 
Join Date: Nov 2012
Location: behind u
Posts: 648
Reputation: 30
Default Re: A little question

well given code is right.
__________________
here to help
Mugala is offline   Reply With Quote
Old 12/02/2018, 07:21 PM   #17
ivndosos
Huge Clucker
 
ivndosos's Avatar
 
Join Date: Sep 2014
Location: Russian Federation, Kaliningrad.
Posts: 407
Reputation: 18
Default Re: A little question

it doesn't seem to attach.
ivndosos is offline   Reply With Quote
Old 12/02/2018, 09:36 PM   #18
Mugala
Gangsta
 
Mugala's Avatar
 
Join Date: Nov 2012
Location: behind u
Posts: 648
Reputation: 30
Default Re: A little question

okay I'll check this code in my server and write an answer shortly.
__________________
here to help
Mugala is offline   Reply With Quote
Old 12/02/2018, 09:51 PM   #19
Mugala
Gangsta
 
Mugala's Avatar
 
Join Date: Nov 2012
Location: behind u
Posts: 648
Reputation: 30
Default Re: A little question

okay I got this message in samp-server.exe
Code:
[02:40:06] AttachPlayerObjectToPlayer : removed in 0.3. I can only attach global objects.
which means we can't use AttachPlayerObjectToPlayer and we must global objects, so we can't create an attachable object for only one player.

you have to use a previous given code, which was Global objects.
__________________
here to help
Mugala is offline   Reply With Quote
Old 13/02/2018, 03:19 AM   #20
Sew_Sumi
Godfather
 
Join Date: Jun 2008
Location: Azerbaijan
Posts: 6,152
Reputation: 515
Default Re: A little question

Use Mugalas first example, where he attempted to use an array, and use the streamers object functions to do it.

The only visible issue with the first example is the 'destroy' function, it doesn't reference the array, it treats it as a variable.

Quote:
Originally Posted by Mugala View Post
actually you can create a PlayerObject for all of these players, exept him.
it's pretty simple.

PHP Code:
OnPlayerTakeDamage/OnPlayerGiveDamage 

new Float:X,Float:Y,Float:Z
GetPlayerPos(playerid,X,Y,Z);
for(new 
0GetPlayerPoolSize(); <= ji++)
{
    if(
!= playerid)
    {
        new 
obj[i] = CreatePlayerObject(i,1240,X,Y,Z+1.5,0,0,0); 
        
AttachPlayerObjectToPlayer(i,obj[i],playerid,0,0,1.5,0,0,0); 
        
SetTimerEx("DestroyThisAttachedObject",1000,0,"ii",i,obj[i]);
    }
}

forward DestroyThisAttachedObject(playerid,obj); 
public 
DestroyThisAttachedObject(playerid,obj

    
DestroyPlayerObject(playerid,obj); 
    return 
1


With regards to the video, and the way you've got multiple hearts, use http://wiki.sa-mp.com/wiki/IsValidObject on the array to check for it being visible.

The code is also inherently bugged though... It will appear to be working 'fine', but it's not done right. It's to do with the array, and how it's being used. 1 v 1, 3, or 4 people you won't notice a problem.

When you hit higher playercount, the heart is for no matter who shot who, and is just, the last person that reported the damage. The way it's being used, the 'tracking' isn't there. If you simply did a check of IsValidObject that may help (Once you get the streamer, as the streamer should still support per user pickups/objects/attachments.)
Sew_Sumi is offline   Reply With Quote
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


Similar Threads
Thread Thread Starter Forum Replies Last Post
[QUESTION] Kind a team based question Dirkon Scripting Help 1 24/03/2013 08:05 PM
Question regarding playerid (noob question!) Mattjones17 Help Archive 5 27/10/2010 04:21 PM
Data type question.. (and mac address question) DarrenReeder Help Archive 2 21/10/2010 08:20 PM
Hello all i got one question (very easy to answer J.I.C question) SAMPfan109 General 0 06/03/2010 04:43 PM


All times are GMT. The time now is 07:11 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.